Skip to content

Commit da796fe

Browse files
committed
fix: Use story type in StoryState constructor
1 parent 04bec09 commit da796fe

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/Story.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ export class Story extends InkObject{
12021202
throw new Error("Can't " + activityStr + '. Story is in the middle of a ContinueAsync(). Make more ContinueAsync() calls or a single Continue() call beforehand.');
12031203
}
12041204

1205-
public ChoosePath(p: Path | null){
1205+
public ChoosePath(p: Path){
12061206
this.state.SetChosenPath(p);
12071207

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

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

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

@@ -1656,6 +1657,8 @@ export class Story extends InkObject{
16561657

16571658
let choice = invisibleChoices[0];
16581659

1660+
if (choice.targetPath === null) { return throwNullException('choice.targetPath'); }
1661+
16591662
this.ChoosePath(choice.targetPath);
16601663

16611664
return true;

src/StoryState.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ import {JsonSerialisation} from './JsonSerialisation';
1212
import {PRNG} from './PRNG';
1313
import {Void} from './Void';
1414
import {Pointer} from './Pointer';
15-
import { tryGetValueFromMap } from './TryGetResult';
15+
import {tryGetValueFromMap} from './TryGetResult';
1616
import {Choice} from './Choice';
1717
import {asOrNull, asOrThrows, nullIfUndefined} from './TypeAssertion';
1818
import {JObject} from './JObject';
1919
import {Debug} from './Debug';
2020
import {Container} from './Container';
2121
import {InkObject} from './Object';
2222
import { throwNullException } from './NullException';
23+
import { Story } from './Story';
2324

2425
export class StoryState{
2526

@@ -108,7 +109,7 @@ export class StoryState{
108109
public previousRandom: number = 0;
109110
public didSafeExit: boolean = false;
110111

111-
public story: any /* Story */;
112+
public story: Story;
112113

113114
get currentPathString(){
114115
let pointer = this.currentPointer;
@@ -221,7 +222,7 @@ export class StoryState{
221222
this.callStack.currentElement.inExpressionEvaluation = value;
222223
}
223224

224-
constructor(story: any /* Story */){
225+
constructor(story: Story){
225226
this.story = story;
226227

227228
this._outputStream = [];
@@ -672,7 +673,9 @@ export class StoryState{
672673
rawList.origins.length = 0;
673674

674675
for (let n of rawList.originNames) {
676+
if (this.story.listDefinitions === null) return throwNullException('StoryState.story.listDefinitions');
675677
let def = this.story.listDefinitions.TryListGetDefinition(n, null);
678+
if (def.result === null) return throwNullException('StoryState def.result');
676679
if (rawList.origins.indexOf(def.result) < 0) rawList.origins.push(def.result);
677680
}
678681
}
@@ -749,7 +752,7 @@ export class StoryState{
749752
this.callStack.Pop(popType);
750753
}
751754

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

src/VariablesState.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class VariablesState{
8686
}
8787
}
8888

89-
constructor(callStack: CallStack, listDefsOrigin: ListDefinitionsOrigin){
89+
constructor(callStack: CallStack, listDefsOrigin: ListDefinitionsOrigin | null){
9090
this._globalVariables = new Map();
9191
this._callStack = callStack;
9292
this._listDefsOrigin = listDefsOrigin;
@@ -173,6 +173,7 @@ export class VariablesState{
173173
if (variableValue.exists)
174174
return variableValue.result;
175175

176+
if (this._listDefsOrigin === null) return throwNullException('VariablesState._listDefsOrigin');
176177
let listItemValue = this._listDefsOrigin.FindSingleItemListWithName(name);
177178
if (listItemValue)
178179
return listItemValue;
@@ -306,5 +307,5 @@ export class VariablesState{
306307

307308
private _callStack: CallStack;
308309
private _changedVariables: Set<string> | null = new Set();
309-
private _listDefsOrigin: ListDefinitionsOrigin;
310+
private _listDefsOrigin: ListDefinitionsOrigin | null;
310311
}

0 commit comments

Comments
 (0)