feat: getTasks

This commit is contained in:
Justin Lin committed 2025-04-21 18:31:33 +08:00
1 parent 254e4f75ed
commit d2cdd1304a
4 files changed
+74 -1

No files matched your search

+24 -1
View File
@@ -1,7 +1,13 @@
/* eslint-disable no-await-in-loop */
import { Event } from './Event'
import { GlobalException } from './Exception'
import { IQuest, IFileExistenceChecker, ICommand, IResponse } from './schema'
import {
IQuest,
IFileExistenceChecker,
ICommand,
IResponse,
ITask,
} from './schema'
import { Stage } from './Stage'
export class Quest {
@@ -67,4 +73,21 @@ export class Quest {
getResponses(completed: string[]): IResponse[] {
return completed.map((id) => this.events.get(id)!.getResponse())
}
getTasks(completed: string[]): ITask[] {
const completedSet = new Set(completed)
const completedStages = this.stages
.filter((stage) => completedSet.has(stage.id))
.map((stage) => ({
id: stage.id,
name: stage.name,
completed: true,
}))
const activeStages = this.getActiveStages(completed).map((stage) => ({
id: stage.id,
name: stage.name,
completed: false,
}))
return [...completedStages, ...activeStages]
}
}
+5
View File
@@ -5,6 +5,7 @@ import {
ISession,
IFileExistenceChecker,
IResponse,
ITask,
} from './schema'
export class Session implements ISession {
@@ -43,4 +44,8 @@ export class Session implements ISession {
getResponses(): IResponse[] {
return this.quest.getResponses(this.completed)
}
getTasks(): ITask[] {
return this.quest.getTasks(this.completed)
}
}
+6
View File
@@ -15,3 +15,9 @@ export interface ICommand {
export interface ISession {
completedEvents: string[]
}
export interface ITask {
id: string
name: string
completed: boolean
}