Skip to content

Commit

Permalink
fix: Use story type in StoryState constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
y-lohse committed Sep 18, 2018
1 parent 04bec09 commit da796fe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/Story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ export class Story extends InkObject{
throw new Error("Can't " + activityStr + '. Story is in the middle of a ContinueAsync(). Make more ContinueAsync() calls or a single Continue() call beforehand.');
}

public ChoosePath(p: Path | null){
public ChoosePath(p: Path){
this.state.SetChosenPath(p);

// Take a note of newly visited containers for read counts etc
Expand All @@ -1216,6 +1216,7 @@ export class Story extends InkObject{

let choiceToChoose = choices[choiceIdx];
if (choiceToChoose.threadAtGeneration === null) { return throwNullException('choiceToChoose.threadAtGeneration'); }
if (choiceToChoose.targetPath === null) { return throwNullException('choiceToChoose.targetPath'); }

this.state.callStack.currentThread = choiceToChoose.threadAtGeneration;

Expand Down Expand Up @@ -1656,6 +1657,8 @@ export class Story extends InkObject{

let choice = invisibleChoices[0];

if (choice.targetPath === null) { return throwNullException('choice.targetPath'); }

this.ChoosePath(choice.targetPath);

return true;
Expand Down
11 changes: 7 additions & 4 deletions src/StoryState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import {JsonSerialisation} from './JsonSerialisation';
import {PRNG} from './PRNG';
import {Void} from './Void';
import {Pointer} from './Pointer';
import { tryGetValueFromMap } from './TryGetResult';
import {tryGetValueFromMap} from './TryGetResult';
import {Choice} from './Choice';
import {asOrNull, asOrThrows, nullIfUndefined} from './TypeAssertion';
import {JObject} from './JObject';
import {Debug} from './Debug';
import {Container} from './Container';
import {InkObject} from './Object';
import { throwNullException } from './NullException';
import { Story } from './Story';

export class StoryState{

Expand Down Expand Up @@ -108,7 +109,7 @@ export class StoryState{
public previousRandom: number = 0;
public didSafeExit: boolean = false;

public story: any /* Story */;
public story: Story;

get currentPathString(){
let pointer = this.currentPointer;
Expand Down Expand Up @@ -221,7 +222,7 @@ export class StoryState{
this.callStack.currentElement.inExpressionEvaluation = value;
}

constructor(story: any /* Story */){
constructor(story: Story){
this.story = story;

this._outputStream = [];
Expand Down Expand Up @@ -672,7 +673,9 @@ export class StoryState{
rawList.origins.length = 0;

for (let n of rawList.originNames) {
if (this.story.listDefinitions === null) return throwNullException('StoryState.story.listDefinitions');
let def = this.story.listDefinitions.TryListGetDefinition(n, null);
if (def.result === null) return throwNullException('StoryState def.result');
if (rawList.origins.indexOf(def.result) < 0) rawList.origins.push(def.result);
}
}
Expand Down Expand Up @@ -749,7 +752,7 @@ export class StoryState{
this.callStack.Pop(popType);
}

public SetChosenPath(path: Path | null){
public SetChosenPath(path: Path){
// Changing direction, assume we need to clear current set of choices
this._currentChoices.length = 0;

Expand Down
5 changes: 3 additions & 2 deletions src/VariablesState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class VariablesState{
}
}

constructor(callStack: CallStack, listDefsOrigin: ListDefinitionsOrigin){
constructor(callStack: CallStack, listDefsOrigin: ListDefinitionsOrigin | null){
this._globalVariables = new Map();
this._callStack = callStack;
this._listDefsOrigin = listDefsOrigin;
Expand Down Expand Up @@ -173,6 +173,7 @@ export class VariablesState{
if (variableValue.exists)
return variableValue.result;

if (this._listDefsOrigin === null) return throwNullException('VariablesState._listDefsOrigin');
let listItemValue = this._listDefsOrigin.FindSingleItemListWithName(name);
if (listItemValue)
return listItemValue;
Expand Down Expand Up @@ -306,5 +307,5 @@ export class VariablesState{

private _callStack: CallStack;
private _changedVariables: Set<string> | null = new Set();
private _listDefsOrigin: ListDefinitionsOrigin;
private _listDefsOrigin: ListDefinitionsOrigin | null;
}

0 comments on commit da796fe

Please sign in to comment.