mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 03:20:12 +08:00
feat: getTasks
This commit is contained in:
1 parent
254e4f75ed
commit
d2cdd1304a
4 files changed
+74
-1
No files matched your search
@@ -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,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)
|
||||
}
|
||||
}
|
||||
@@ -15,3 +15,9 @@ export interface ICommand {
|
||||
export interface ISession {
|
||||
completedEvents: string[]
|
||||
}
|
||||
|
||||
export interface ITask {
|
||||
id: string
|
||||
name: string
|
||||
completed: boolean
|
||||
}
|
||||
Reference in new issue
Block a user