refactor(state): address HMR and defensive slicing recommendations for runtime

This commit is contained in:
ginnoir
2026-06-11 21:23:18 -05:00
parent b29b17c6cb
commit ed9607e9e8
2 changed files with 11 additions and 2 deletions
+10 -1
View File
@@ -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();
});
}
+1 -1
View File
@@ -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 };