refactor: clean up unused panel overlay state and methods
This commit is contained in:
@@ -48,7 +48,6 @@ describe('GameRuntime', () => {
|
|||||||
// Setup clean store
|
// Setup clean store
|
||||||
useGameStore.setState({
|
useGameStore.setState({
|
||||||
log: [],
|
log: [],
|
||||||
storyPanelOpen: false,
|
|
||||||
storyHasUnread: false,
|
storyHasUnread: false,
|
||||||
storyLog: [],
|
storyLog: [],
|
||||||
prefs: getPrefs(),
|
prefs: getPrefs(),
|
||||||
@@ -160,7 +159,6 @@ describe('GameRuntime', () => {
|
|||||||
|
|
||||||
// Force play panel and closed/no unread story
|
// Force play panel and closed/no unread story
|
||||||
store.setActivePanel('play');
|
store.setActivePanel('play');
|
||||||
store.setStoryPanelOpen(false);
|
|
||||||
store.setStoryHasUnread(false);
|
store.setStoryHasUnread(false);
|
||||||
|
|
||||||
runtime.continueStory();
|
runtime.continueStory();
|
||||||
@@ -169,7 +167,7 @@ describe('GameRuntime', () => {
|
|||||||
// Verifies it advances to fork_choice
|
// Verifies it advances to fork_choice
|
||||||
expect(updated.storyLog.some((entry) => entry.nodeId === 'fork_choice')).toBe(true);
|
expect(updated.storyLog.some((entry) => entry.nodeId === 'fork_choice')).toBe(true);
|
||||||
// Verifies it opens panel and does not set unread (since it's open)
|
// Verifies it opens panel and does not set unread (since it's open)
|
||||||
expect(updated.storyPanelOpen).toBe(true);
|
expect(updated.activePanel).toBe('story');
|
||||||
expect(updated.storyHasUnread).toBe(false);
|
expect(updated.storyHasUnread).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -179,7 +177,6 @@ describe('GameRuntime', () => {
|
|||||||
|
|
||||||
// Force play panel and closed/no unread story
|
// Force play panel and closed/no unread story
|
||||||
store.setActivePanel('play');
|
store.setActivePanel('play');
|
||||||
store.setStoryPanelOpen(false);
|
|
||||||
store.setStoryHasUnread(false);
|
store.setStoryHasUnread(false);
|
||||||
|
|
||||||
runtime.continueStory();
|
runtime.continueStory();
|
||||||
@@ -188,7 +185,7 @@ describe('GameRuntime', () => {
|
|||||||
// Verifies it advances to fork_choice
|
// Verifies it advances to fork_choice
|
||||||
expect(updated.storyLog.some((entry) => entry.nodeId === 'fork_choice')).toBe(true);
|
expect(updated.storyLog.some((entry) => entry.nodeId === 'fork_choice')).toBe(true);
|
||||||
// Verifies it does NOT open panel and sets unread flag to true
|
// Verifies it does NOT open panel and sets unread flag to true
|
||||||
expect(updated.storyPanelOpen).toBe(false);
|
expect(updated.activePanel).toBe('play');
|
||||||
expect(updated.storyHasUnread).toBe(true);
|
expect(updated.storyHasUnread).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -249,18 +246,6 @@ describe('GameRuntime', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('delegates openStoryPanel and closeStoryPanel to setActivePanel', () => {
|
|
||||||
// Force activePanel back to play first
|
|
||||||
runtime.setActivePanel('play');
|
|
||||||
expect(useGameStore.getState().activePanel).toBe('play');
|
|
||||||
|
|
||||||
runtime.openStoryPanel();
|
|
||||||
expect(useGameStore.getState().activePanel).toBe('story');
|
|
||||||
|
|
||||||
runtime.closeStoryPanel();
|
|
||||||
expect(useGameStore.getState().activePanel).toBe('play');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('registers lifecycle listeners on boot and removes them on stop', () => {
|
it('registers lifecycle listeners on boot and removes them on stop', () => {
|
||||||
const addSpyDoc = vi.spyOn(document, 'addEventListener');
|
const addSpyDoc = vi.spyOn(document, 'addEventListener');
|
||||||
const removeSpyDoc = vi.spyOn(document, 'removeEventListener');
|
const removeSpyDoc = vi.spyOn(document, 'removeEventListener');
|
||||||
|
|||||||
+2
-14
@@ -159,7 +159,6 @@ export class GameRuntime {
|
|||||||
for (const entry of entries) store.appendStoryLog(entry);
|
for (const entry of entries) store.appendStoryLog(entry);
|
||||||
const choiceLabel = entries.at(-1)?.choiceLabel;
|
const choiceLabel = entries.at(-1)?.choiceLabel;
|
||||||
if (choiceLabel) store.appendLog(`Story: ${choiceLabel}`);
|
if (choiceLabel) store.appendLog(`Story: ${choiceLabel}`);
|
||||||
store.setStoryPanelOpen(false);
|
|
||||||
this.runPublishTriggers();
|
this.runPublishTriggers();
|
||||||
this.publish();
|
this.publish();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -180,14 +179,6 @@ export class GameRuntime {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
openStoryPanel(): void {
|
|
||||||
this.setActivePanel('story');
|
|
||||||
}
|
|
||||||
|
|
||||||
closeStoryPanel(): void {
|
|
||||||
this.setActivePanel('play');
|
|
||||||
}
|
|
||||||
|
|
||||||
continueStory(): void {
|
continueStory(): void {
|
||||||
const state = this.state;
|
const state = this.state;
|
||||||
if (!state) return;
|
if (!state) return;
|
||||||
@@ -203,16 +194,14 @@ export class GameRuntime {
|
|||||||
}
|
}
|
||||||
const prefs = store.prefs;
|
const prefs = store.prefs;
|
||||||
if (shouldAutoNavigateToStory(prefs, 'fork_choice', content)) {
|
if (shouldAutoNavigateToStory(prefs, 'fork_choice', content)) {
|
||||||
store.setStoryPanelOpen(true);
|
this.setActivePanel('story');
|
||||||
store.setStoryHasUnread(false);
|
|
||||||
} else {
|
} else {
|
||||||
store.setStoryHasUnread(true);
|
store.setStoryHasUnread(true);
|
||||||
store.setStoryPanelOpen(false);
|
|
||||||
}
|
}
|
||||||
this.publish();
|
this.publish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.closeStoryPanel();
|
this.setActivePanel('play');
|
||||||
this.publish();
|
this.publish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,7 +218,6 @@ export class GameRuntime {
|
|||||||
} else {
|
} else {
|
||||||
store.setStoryHasUnread(true);
|
store.setStoryHasUnread(true);
|
||||||
}
|
}
|
||||||
store.setStoryPanelOpen(true);
|
|
||||||
} else if (effect.enteredNodeIds.length > 0) {
|
} else if (effect.enteredNodeIds.length > 0) {
|
||||||
store.setStoryHasUnread(true);
|
store.setStoryHasUnread(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,20 +20,16 @@ export type ActivePanel = 'play' | 'story' | 'settings' | 'about';
|
|||||||
|
|
||||||
export interface GameStoreState extends GameView {
|
export interface GameStoreState extends GameView {
|
||||||
log: string[];
|
log: string[];
|
||||||
storyPanelOpen: boolean;
|
|
||||||
storyHasUnread: boolean;
|
storyHasUnread: boolean;
|
||||||
storyLog: StoryLogEntry[];
|
storyLog: StoryLogEntry[];
|
||||||
prefs: GamePrefs;
|
prefs: GamePrefs;
|
||||||
settingsOpen: boolean;
|
|
||||||
activePanel: ActivePanel;
|
activePanel: ActivePanel;
|
||||||
selectedStoryNodeId: string | null;
|
selectedStoryNodeId: string | null;
|
||||||
setView: (view: GameView) => void;
|
setView: (view: GameView) => void;
|
||||||
appendLog: (line: string) => void;
|
appendLog: (line: string) => void;
|
||||||
appendStoryLog: (entry: StoryLogEntry) => void;
|
appendStoryLog: (entry: StoryLogEntry) => void;
|
||||||
setStoryPanelOpen: (open: boolean) => void;
|
|
||||||
setStoryHasUnread: (unread: boolean) => void;
|
setStoryHasUnread: (unread: boolean) => void;
|
||||||
setPrefs: (partial: Partial<GamePrefs>) => void;
|
setPrefs: (partial: Partial<GamePrefs>) => void;
|
||||||
setSettingsOpen: (open: boolean) => void;
|
|
||||||
setActivePanel: (panel: ActivePanel) => void;
|
setActivePanel: (panel: ActivePanel) => void;
|
||||||
setSelectedStoryNodeId: (id: string | null) => void;
|
setSelectedStoryNodeId: (id: string | null) => void;
|
||||||
toggleActionGroupCollapsed: (groupKey: string) => void;
|
toggleActionGroupCollapsed: (groupKey: string) => void;
|
||||||
@@ -50,23 +46,19 @@ export const useGameStore = create<GameStoreState>((set, get) => ({
|
|||||||
story: { currentProse: null, choices: [], tree: [] },
|
story: { currentProse: null, choices: [], tree: [] },
|
||||||
actionColumns: [],
|
actionColumns: [],
|
||||||
log: [],
|
log: [],
|
||||||
storyPanelOpen: false,
|
|
||||||
storyHasUnread: false,
|
storyHasUnread: false,
|
||||||
storyLog: [],
|
storyLog: [],
|
||||||
prefs: getPrefs(),
|
prefs: getPrefs(),
|
||||||
settingsOpen: false,
|
|
||||||
activePanel: 'play',
|
activePanel: 'play',
|
||||||
selectedStoryNodeId: null,
|
selectedStoryNodeId: null,
|
||||||
setView: (view) => set((state) => ({ ...state, ...view })),
|
setView: (view) => set((state) => ({ ...state, ...view })),
|
||||||
appendLog: (line) => set((state) => ({ log: [...state.log, line].slice(-MAX_LOG_LINES) })),
|
appendLog: (line) => set((state) => ({ log: [...state.log, line].slice(-MAX_LOG_LINES) })),
|
||||||
appendStoryLog: (entry) => set((state) => ({ storyLog: [...state.storyLog, entry] })),
|
appendStoryLog: (entry) => set((state) => ({ storyLog: [...state.storyLog, entry] })),
|
||||||
setStoryPanelOpen: (open) => set({ storyPanelOpen: open }),
|
|
||||||
setStoryHasUnread: (unread) => set({ storyHasUnread: unread }),
|
setStoryHasUnread: (unread) => set({ storyHasUnread: unread }),
|
||||||
setPrefs: (partial) => {
|
setPrefs: (partial) => {
|
||||||
const prefs = persistPrefs(partial);
|
const prefs = persistPrefs(partial);
|
||||||
set({ prefs });
|
set({ prefs });
|
||||||
},
|
},
|
||||||
setSettingsOpen: (open) => set({ settingsOpen: open }),
|
|
||||||
setActivePanel: (panel) => set({ activePanel: panel }),
|
setActivePanel: (panel) => set({ activePanel: panel }),
|
||||||
setSelectedStoryNodeId: (id) => set({ selectedStoryNodeId: id }),
|
setSelectedStoryNodeId: (id) => set({ selectedStoryNodeId: id }),
|
||||||
toggleActionGroupCollapsed: (groupKey) => {
|
toggleActionGroupCollapsed: (groupKey) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user