mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 03:20:12 +08:00
wip: integrate filegraph into session
This commit is contained in:
1 parent
cdd22634e0
commit
2d95ca382f
13 files changed
+105
-42
No files matched your search
@@ -7,6 +7,7 @@ import {
|
||||
IFileExistenceChecker,
|
||||
IResponse,
|
||||
ITask,
|
||||
ICommandParams,
|
||||
} from './schema'
|
||||
|
||||
export class GameSession {
|
||||
@@ -22,7 +23,7 @@ export class GameSession {
|
||||
this.completed = completedEvents || []
|
||||
this.quest = new Quest(quest, checker)
|
||||
this.graph = new FileGraph(
|
||||
graph ?? new FileNode({ path: '/', type: 'root', discovered: false })
|
||||
graph ?? { path: '/', type: 'directory', discovered: false }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -39,6 +40,9 @@ export class GameSession {
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
@@ -168,4 +168,47 @@ describe('Session', () => {
|
||||
{ id: 'stage4', name: 'Stage 4', completed: false },
|
||||
])
|
||||
})
|
||||
|
||||
it('should update graph', () => {
|
||||
const session = new GameSession({}, quest, new MockFileChecker())
|
||||
|
||||
expect(session.getGraph()).toMatchObject({
|
||||
path: '/',
|
||||
type: 'directory',
|
||||
discovered: false,
|
||||
})
|
||||
|
||||
session.runCommand({
|
||||
command: 'ls',
|
||||
params: {
|
||||
discover: [
|
||||
{
|
||||
path: '/home/user',
|
||||
type: 'directory',
|
||||
discovered: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
expect(session.getGraph()).toMatchObject({
|
||||
path: '/',
|
||||
type: 'directory',
|
||||
discovered: false,
|
||||
children: [
|
||||
{
|
||||
path: '/home',
|
||||
type: 'directory',
|
||||
discovered: false,
|
||||
children: [
|
||||
{
|
||||
path: '/home/user',
|
||||
type: 'directory',
|
||||
discovered: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user