Skip to content

Commit

Permalink
moar typing
Browse files Browse the repository at this point in the history
  • Loading branch information
kenerwin88 committed Jan 11, 2023
1 parent 234ba58 commit 85b2985
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 225 deletions.
8 changes: 0 additions & 8 deletions src/bondage.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import bondage from './bondage';
import { CommandResult, OptionsResult, TextResult } from './results';
import YarnBound from './yarn-bound';
const { OptionsResult, TextResult, CommandResult } = bondage;

export { YarnBound, OptionsResult, TextResult, CommandResult };
8 changes: 1 addition & 7 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as results from './results';

const nodeTypes = types.types;

class Runner {
export class Runner {
private readonly noEscape: boolean;
private readonly yarnNodes: {};
private variables: DefaultVariableStorage;
Expand Down Expand Up @@ -398,9 +398,3 @@ class Runner {
}
}

export default {
Runner,
TextResult: results.TextResult,
CommandResult: results.CommandResult,
OptionsResult: results.OptionsResult,
};
17 changes: 8 additions & 9 deletions src/yarn-bound.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import bondage from './bondage';
import parseLine from './line-parser';
import { CommandResult, OptionsResult, TextResult } from './results';
import { Runner } from './runner';

interface props {
dialogue: string;
Expand Down Expand Up @@ -37,12 +37,11 @@ export default class YarnBound {
}: props) {
this.handleCommand = handleCommand;
this.combineTextAndOptionsResults = combineTextAndOptionsResults;
this.bondage = bondage;
this.bufferedNode = null;
this.currentResult = null;
this.history = [];
this.locale = locale;
this.runner = new bondage.Runner();
this.runner = new Runner();
this.runner.noEscape = true;

this.runner.load(dialogue);
Expand Down Expand Up @@ -78,21 +77,21 @@ export default class YarnBound {
// We either return the command as normal or, if a handler
// is supplied, use that and don't bother the consuming app
if (this.handleCommand) {
while (next instanceof bondage.CommandResult) {
while (next instanceof CommandResult) {
this.handleCommand(next);
next = this.generator.next().value;
}
}

// Lookahead for combining text + options, and for end of dialogue.
// Can't look ahead of option nodes (what would you look ahead at?)
if (!(next instanceof bondage.OptionsResult)) {
if (!(next instanceof OptionsResult)) {
const upcoming = this.generator.next();
buffered = upcoming.value;
if (
next instanceof bondage.TextResult &&
next instanceof TextResult &&
this.combineTextAndOptionsResults &&
buffered instanceof bondage.OptionsResult
buffered instanceof OptionsResult
) {
next = Object.assign(buffered, next);
buffered = null;
Expand All @@ -105,9 +104,9 @@ export default class YarnBound {
this.history.push(this.currentResult);
}

if (next instanceof bondage.TextResult) {
if (next instanceof TextResult) {
parseLine(next, this.locale);
} else if (next instanceof bondage.OptionsResult) {
} else if (next instanceof OptionsResult) {
// @ts-ignore
if (next.text) {
parseLine(next, this.locale);
Expand Down
Loading

0 comments on commit 85b2985

Please sign in to comment.