feat: add initial task on session creation

This commit is contained in:
wancat committed 2023-09-01 17:16:32 +08:00
1 parent 97b0fb0f1d
commit 0ea44e1f71
7 files changed
+59 -28

No files matched your search

+21 -9
View File
@@ -1,8 +1,9 @@
import { pushToSession } from '../api/socket.js'
export default class SessionWrapper {
export default class SessionHandler {
constructor(session) {
this.session = session
this.quest = session.quest
}
getTask(stage) {
@@ -22,29 +23,40 @@ export default class SessionWrapper {
)
}
getNewTasks() {
const stages = this.getStages()
return stages
.filter((s) => s.task)
.filter((s) => !this.session.tasks.some((t) => t.id === s.id))
.map((s) => ({ id: s.id, name: s.task, completed: false }))
}
addNewTasks() {
const newTasks = this.getNewTasks()
this.session.tasks.push(...newTasks)
pushToSession(this.session.id, 'tasks', this.session.tasks)
}
execute(stage) {
this.session.tasks
.filter((t) => t.id === stage.id)
.forEach((t) => {
t.completed = true
})
this.session.hints.push(...stage.hints)
pushToSession(this.session.id, 'hints', stage.hints)
if (stage.id === 'END') {
this.session.status = 'finished'
this.session.finishedAt = new Date()
}
const stages = this.getStages()
console.debug(stages)
const newTasks = stages
.filter((s) => s.task)
.map((s) => ({ id: s.id, name: s.task, completed: false }))
this.session.tasks.push(...newTasks)
pushToSession(this.session.id, 'tasks', this.session.tasks)
this.addNewTasks()
return {
responses: stage.responses,
hints: stage.hints,
tasks: newTasks,
}
}
}