From 2dc40a225432334ca0277c9fc815e44a2846cd2d Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Mon, 21 Apr 2025 11:58:05 +0800 Subject: [PATCH] refactor: add new name "Event" for the set Stage and Exception --- packages/game/src/Quest.ts | 2 +- packages/game/src/Session.ts | 8 ++++---- packages/game/src/schema/index.ts | 2 +- packages/game/test/exceptions.test.ts | 8 ++++---- packages/game/test/session.test.ts | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/game/src/Quest.ts b/packages/game/src/Quest.ts index cb6eca3..56985d7 100644 --- a/packages/game/src/Quest.ts +++ b/packages/game/src/Quest.ts @@ -37,7 +37,7 @@ export class Quest { ) } - async findSatisfiedStage( + async findSatisfiedEvent( command: ICommand, completed: string[] ): Promise { diff --git a/packages/game/src/Session.ts b/packages/game/src/Session.ts index 173117b..484d8c5 100644 --- a/packages/game/src/Session.ts +++ b/packages/game/src/Session.ts @@ -12,15 +12,15 @@ export class Session implements ISession { private quest: Quest constructor( - { completedStages }: ISession, + { completedEvents }: ISession, quest: IQuest, checker: IFileExistenceChecker ) { - this.completed = completedStages + this.completed = completedEvents this.quest = new Quest(quest, checker) } - get completedStages() { + get completedEvents() { return this.completed } @@ -33,7 +33,7 @@ export class Session implements ISession { } async runCommand(command: ICommand) { - const stageId = await this.quest.findSatisfiedStage(command, this.completed) + const stageId = await this.quest.findSatisfiedEvent(command, this.completed) if (stageId) { this.complete(stageId) } diff --git a/packages/game/src/schema/index.ts b/packages/game/src/schema/index.ts index cd022e7..8b74f38 100644 --- a/packages/game/src/schema/index.ts +++ b/packages/game/src/schema/index.ts @@ -12,5 +12,5 @@ export interface ICommand { } export interface ISession { - completedStages: string[] + completedEvents: string[] } diff --git a/packages/game/test/exceptions.test.ts b/packages/game/test/exceptions.test.ts index bc0215b..b43f722 100644 --- a/packages/game/test/exceptions.test.ts +++ b/packages/game/test/exceptions.test.ts @@ -66,19 +66,19 @@ const quest: IQuest = { describe('exceptions', () => { it('should return the stage exception', async () => { const session = new Session( - { completedStages: [] }, + { completedEvents: [] }, quest, new MockFileChecker() ) expect(await session.runCommand({ command: 'ls' })).toBe('exception1') await session.runCommand({ command: 'echo start' }) - console.log('completed', session.completedStages) + console.log('completed', session.completedEvents) expect(await session.runCommand({ command: 'ls' })).toBe('stage2') }) it('should return the catch all exception', async () => { const session = new Session( - { completedStages: [] }, + { completedEvents: [] }, quest, new MockFileChecker() ) @@ -89,7 +89,7 @@ describe('exceptions', () => { it('should return the global exception', async () => { const session = new Session( - { completedStages: [] }, + { completedEvents: [] }, quest, new MockFileChecker() ) diff --git a/packages/game/test/session.test.ts b/packages/game/test/session.test.ts index 9eb0679..cc6de8b 100644 --- a/packages/game/test/session.test.ts +++ b/packages/game/test/session.test.ts @@ -49,7 +49,7 @@ describe('Session', () => { it('should return active stages', () => { const session = new Session( { - completedStages: [], + completedEvents: [], }, quest, new MockFileChecker() @@ -69,7 +69,7 @@ describe('Session', () => { it('should run command', async () => { const session = new Session( { - completedStages: [], + completedEvents: [], }, quest, new MockFileChecker() @@ -96,7 +96,7 @@ describe('Session', () => { it('should return all responses', () => { const session = new Session( { - completedStages: ['stage1'], + completedEvents: ['stage1'], }, quest, new MockFileChecker()