mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
refactor: remove condition tests and update file node interfaces in game session
TODO: replace "folder" with "directory"
This commit is contained in:
1 parent
0685d71299
commit
7e50c8e06c
6 files changed
+46
-46
No files matched your search
@@ -1,13 +0,0 @@
|
||||
import { describe, it, expect } from '@jest/globals'
|
||||
import { conditionSchema } from '../src/index.js'
|
||||
|
||||
describe('parsing condition', () => {
|
||||
it('should parse condition', () => {
|
||||
const condition = {
|
||||
command: ['^echo start$'],
|
||||
output: ['^start$'],
|
||||
}
|
||||
const result = conditionSchema.safeParse(condition)
|
||||
expect(result.error).toBeUndefined()
|
||||
})
|
||||
})
|
||||
@@ -2,9 +2,9 @@ export { default as File, FileObject } from './file.js'
|
||||
export { default as FileNode } from './fileNode.js'
|
||||
export { default as FileGraph, Event } from './fileGraph.js'
|
||||
|
||||
export interface INode {
|
||||
export interface IFileNode {
|
||||
path: string
|
||||
type: string
|
||||
discovered: boolean
|
||||
children?: INode[]
|
||||
children?: IFileNode[]
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { FileGraph, INode } from '@linux-odyssey/file-graph'
|
||||
import { FileGraph, FileNode, IFileNode } from '@linux-odyssey/file-graph'
|
||||
import { Quest } from './Quest'
|
||||
import {
|
||||
IQuest,
|
||||
@@ -15,13 +15,15 @@ export class GameSession {
|
||||
private graph: FileGraph
|
||||
|
||||
constructor(
|
||||
{ completedEvents, graph }: ISession,
|
||||
{ completedEvents, graph }: Partial<ISession>,
|
||||
quest: IQuest,
|
||||
checker: IFileExistenceChecker
|
||||
) {
|
||||
this.completed = completedEvents
|
||||
this.completed = completedEvents || []
|
||||
this.quest = new Quest(quest, checker)
|
||||
this.graph = new FileGraph(graph)
|
||||
this.graph = new FileGraph(
|
||||
graph ?? new FileNode({ path: '/', type: 'root', discovered: false })
|
||||
)
|
||||
}
|
||||
|
||||
get completedEvents() {
|
||||
@@ -56,7 +58,7 @@ export class GameSession {
|
||||
return this.quest.getTasks(this.completed)
|
||||
}
|
||||
|
||||
getGraph(): INode {
|
||||
getGraph(): IFileNode {
|
||||
return this.graph
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
const fileSchema = z.object({
|
||||
path: z.string(),
|
||||
type: z.enum(['file', 'directory']),
|
||||
discovered: z.boolean(),
|
||||
})
|
||||
|
||||
export const commandParamsSchema = z.object({
|
||||
discover: fileSchema.array().optional(),
|
||||
})
|
||||
|
||||
export type ICommandParams = z.infer<typeof commandParamsSchema>
|
||||
|
||||
export const commandSchema = z.object({
|
||||
command: z.string().optional(),
|
||||
output: z.string().optional(),
|
||||
error: z.string().optional(),
|
||||
pwd: z.string().optional(),
|
||||
params: commandParamsSchema.optional(),
|
||||
})
|
||||
|
||||
export type ICommand = z.infer<typeof commandSchema>
|
||||
@@ -1,4 +1,4 @@
|
||||
import { INode } from '@linux-odyssey/file-graph'
|
||||
import { IFileNode } from '@linux-odyssey/file-graph'
|
||||
|
||||
export * from './condition.js'
|
||||
export * from './stage.js'
|
||||
@@ -6,17 +6,11 @@ export * from './requirements.js'
|
||||
export * from './response.js'
|
||||
export * from './quest.js'
|
||||
export * from './exception.js'
|
||||
|
||||
export interface ICommand {
|
||||
command?: string
|
||||
output?: string
|
||||
error?: string
|
||||
pwd?: string
|
||||
}
|
||||
export * from './command.js'
|
||||
|
||||
export interface ISession {
|
||||
completedEvents: string[]
|
||||
graph: INode
|
||||
graph: IFileNode
|
||||
}
|
||||
|
||||
export interface ITask {
|
||||
|
||||
Reference in new issue
Block a user