mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
wip: replace packages with pure files
This commit is contained in:
1 parent
2d95ca382f
commit
87b8ca5d04
112 files changed
+740
-522
No files matched your search
@@ -0,0 +1,67 @@
|
||||
import { FileGraph, IFileNode } from '../../packages/file-graph'
|
||||
import { Quest } from './Quest'
|
||||
import {
|
||||
IQuest,
|
||||
ICommand,
|
||||
ISession,
|
||||
IFileExistenceChecker,
|
||||
IResponse,
|
||||
ITask,
|
||||
} from './schema'
|
||||
|
||||
export class GameSession {
|
||||
private completed: string[] = []
|
||||
private quest: Quest
|
||||
private graph: FileGraph
|
||||
|
||||
constructor(
|
||||
{ completedEvents, graph }: Partial<ISession>,
|
||||
quest: IQuest,
|
||||
checker: IFileExistenceChecker
|
||||
) {
|
||||
this.completed = completedEvents || []
|
||||
this.quest = new Quest(quest, checker)
|
||||
this.graph = new FileGraph(
|
||||
graph ?? { path: '/', type: 'directory', discovered: false }
|
||||
)
|
||||
}
|
||||
|
||||
get completedEvents() {
|
||||
return this.completed
|
||||
}
|
||||
|
||||
complete(stageId: string) {
|
||||
this.completed.push(stageId)
|
||||
}
|
||||
|
||||
getActiveStages(): string[] {
|
||||
return this.quest.getActiveStages(this.completed).map((stage) => stage.id)
|
||||
}
|
||||
|
||||
async runCommand(command: ICommand) {
|
||||
if (command.params) {
|
||||
this.graph.handleEvent(command.params)
|
||||
}
|
||||
const stageId = await this.quest.findSatisfiedEvent(command, this.completed)
|
||||
if (stageId) {
|
||||
this.complete(stageId)
|
||||
}
|
||||
return stageId
|
||||
}
|
||||
|
||||
isFinished() {
|
||||
return this.getActiveStages().length === 0
|
||||
}
|
||||
|
||||
getResponses(): IResponse[] {
|
||||
return this.quest.getResponses(this.completed)
|
||||
}
|
||||
|
||||
getTasks(): ITask[] {
|
||||
return this.quest.getTasks(this.completed)
|
||||
}
|
||||
|
||||
getGraph(): IFileNode {
|
||||
return this.graph
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user