refactor(state): address HMR and defensive slicing recommendations for runtime
This commit is contained in:
+10
-1
@@ -87,6 +87,7 @@ export class GameRuntime {
|
|||||||
}
|
}
|
||||||
document.removeEventListener('visibilitychange', this.visibilityChangeListener);
|
document.removeEventListener('visibilitychange', this.visibilityChangeListener);
|
||||||
window.removeEventListener('beforeunload', this.beforeUnloadListener);
|
window.removeEventListener('beforeunload', this.beforeUnloadListener);
|
||||||
|
this.booted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
performAction(actionId: string): void {
|
performAction(actionId: string): void {
|
||||||
@@ -196,7 +197,9 @@ export class GameRuntime {
|
|||||||
const store = useGameStore.getState();
|
const store = useGameStore.getState();
|
||||||
for (const entry of entries) store.appendStoryLog(entry);
|
for (const entry of entries) store.appendStoryLog(entry);
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
store.appendLog(`Story: ${content.storyNodesById[entry.nodeId]?.prose.slice(0, 40)}…`);
|
store.appendLog(
|
||||||
|
`Story: ${(content.storyNodesById[entry.nodeId]?.prose ?? '').slice(0, 40)}…`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const prefs = store.prefs;
|
const prefs = store.prefs;
|
||||||
if (shouldAutoNavigateToStory(prefs, 'fork_choice', content)) {
|
if (shouldAutoNavigateToStory(prefs, 'fork_choice', content)) {
|
||||||
@@ -295,3 +298,9 @@ export class GameRuntime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const gameRuntime = new GameRuntime();
|
export const gameRuntime = new GameRuntime();
|
||||||
|
|
||||||
|
if (import.meta.hot) {
|
||||||
|
import.meta.hot.dispose(() => {
|
||||||
|
gameRuntime.stop();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export function processStoryTriggers(
|
|||||||
...logEntries.map((e) =>
|
...logEntries.map((e) =>
|
||||||
e.choiceLabel
|
e.choiceLabel
|
||||||
? `Story: ${e.choiceLabel}`
|
? `Story: ${e.choiceLabel}`
|
||||||
: `Story: ${content.storyNodesById[e.nodeId]?.prose.slice(0, 40)}…`,
|
: `Story: ${(content.storyNodesById[e.nodeId]?.prose ?? '').slice(0, 40)}…`,
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
return { enteredNodeIds, logEntries, shouldOpenPanel, eventLogLines };
|
return { enteredNodeIds, logEntries, shouldOpenPanel, eventLogLines };
|
||||||
|
|||||||
Reference in New Issue
Block a user