wip: migrating game handler

This commit is contained in:
Justin Lin committed 2025-04-18 14:27:36 +08:00
1 parent 61d1871e95
commit 6043226142
26 files changed
+85 -364

No files matched your search

-22
View File
@@ -1,22 +0,0 @@
import { Schema } from 'mongoose'
import { conditionSchema, ICondition } from './condition.js'
import { responseSchema, IResponse } from './response.js'
import { hintSchema, IHint } from './hint.js'
export interface ICommandResponder extends IHint {
condition?: ICondition
responses: IResponse[]
}
export const commandResponderSchema = new Schema<ICommandResponder>({
condition: {
type: conditionSchema,
required: false,
},
responses: {
type: [responseSchema],
required: true,
},
})
commandResponderSchema.add(hintSchema)
-42
View File
@@ -1,42 +0,0 @@
import { Schema } from 'mongoose'
export interface IFileCondition {
path: string
type: string
exists: boolean
}
export interface ICondition {
command?: string[]
output?: string[]
error?: string[]
pwd?: string[]
files?: IFileCondition[]
or?: ICondition[]
not?: ICondition
}
export const fileConditionSchema = new Schema<IFileCondition>({
path: {
type: String,
required: true,
},
type: String,
exists: {
type: Boolean,
default: true,
},
})
export const conditionSchema = new Schema<ICondition>({
command: [String],
output: [String],
error: [String],
pwd: [String],
files: [fileConditionSchema],
})
conditionSchema.add({
or: [conditionSchema],
not: conditionSchema,
})
-11
View File
@@ -1,11 +0,0 @@
import { Schema } from 'mongoose'
import {
commandResponderSchema,
ICommandResponder,
} from './commandResponder.js'
export interface IException extends ICommandResponder {}
export const exceptionSchema = new Schema<IException>({})
exceptionSchema.add(commandResponderSchema)
-10
View File
@@ -1,10 +0,0 @@
import { Schema } from 'mongoose'
import { exceptionSchema, IException } from './exception.js'
import { requirementSchema, IRequirement } from './requirement.js'
export interface IGlobalException extends IException, IRequirement {}
export const globalExceptionSchema = new Schema<IGlobalException>({})
globalExceptionSchema.add(exceptionSchema)
globalExceptionSchema.add(requirementSchema)
-12
View File
@@ -1,12 +0,0 @@
import { Schema } from 'mongoose'
export interface IHint {
hints: string[]
}
export const hintSchema = new Schema({
hints: {
type: [String],
required: true,
},
})
+1 -7
View File
@@ -1,15 +1,9 @@
import mongoose from 'mongoose'
export { User, IUser } from './user.js'
export { Quest, IQuest } from './quest.js'
export { Session, ISession, ITask } from './session.js'
export { Session, ISession } from './session.js'
export { Command, ICommand } from './command.js'
export { UserProfile, IUserProfile, IProgress } from './userProfile.js'
export { IFileCondition, ICondition } from './condition.js'
export { IStage } from './stage.js'
export { IRequirement } from './requirement.js'
export { IResponse } from './response.js'
export { IException } from './exception.js'
export default async function connectDB(uri: string) {
const db = await mongoose.connect(uri)
-52
View File
@@ -1,52 +0,0 @@
import { model, Schema } from 'mongoose'
import { IStage, stageSchema } from './stage.js'
import { globalExceptionSchema, IGlobalException } from './globalException.js'
import { IRequirement } from './requirement.js'
export interface IQuest extends IRequirement {
_id: string
title: string
image: string
instruction: string
stages: IStage[]
exceptions: IGlobalException[]
}
export const Quest = model<IQuest>(
'Quest',
new Schema<IQuest>({
_id: {
type: String,
required: true,
},
title: {
type: String,
required: true,
},
image: {
type: String,
required: true,
},
requirements: {
type: [
{
type: String,
ref: 'Quest',
},
],
required: true,
},
instruction: {
type: String,
required: true,
},
stages: {
type: [stageSchema],
required: true,
},
exceptions: {
type: [globalExceptionSchema],
required: true,
},
})
)
-14
View File
@@ -1,14 +0,0 @@
import { Schema } from 'mongoose'
export interface IRequirement {
requirements: string[]
}
export const requirementSchema = new Schema<IRequirement>({
requirements: [
{
type: String,
required: true,
},
],
})
-23
View File
@@ -1,23 +0,0 @@
import { Schema } from 'mongoose'
export interface IResponse {
type: 'narrative' | 'dialogue'
content: string[]
speaker?: string
color?: string
}
export const responseSchema = new Schema<IResponse>({
type: {
type: String,
enum: ['narrative', 'dialogue'],
default: 'dialogue',
required: true,
},
content: {
type: [String],
required: true,
},
speaker: { type: String, default: 'Ada' },
color: String,
})
+2 -33
View File
@@ -1,7 +1,5 @@
import { model, Schema, Types } from 'mongoose'
import { IResponse, responseSchema } from './response.js'
export interface INode {
path: string
type: string
@@ -22,27 +20,6 @@ nodeSchema.add({
children: [nodeSchema],
})
export interface ITask {
id: string
name: string
completed: boolean
}
const taskSchema = new Schema<ITask>({
id: {
type: String,
required: true,
},
name: {
type: String,
required: true,
},
completed: {
type: Boolean,
default: false,
},
})
export interface ISession {
_id: Types.ObjectId
user: Types.ObjectId
@@ -53,9 +30,7 @@ export interface ISession {
updatedAt: Date
finishedAt?: Date
lastActivityAt: Date
tasks: ITask[]
hints: string[][]
responses: IResponse[][]
stages: string[]
graph: INode
}
@@ -86,13 +61,7 @@ export const Session = model<ISession>(
default: Date.now,
required: true,
},
tasks: [taskSchema],
hints: [[String]],
responses: {
type: [[responseSchema]],
required: true,
default: [],
},
stages: [String],
graph: {
type: nodeSchema,
default: {
-31
View File
@@ -1,31 +0,0 @@
import { Schema } from 'mongoose'
import {
commandResponderSchema,
ICommandResponder,
} from './commandResponder.js'
import { stageExceptionSchema, IStageException } from './stageException.js'
import { requirementSchema, IRequirement } from './requirement.js'
export interface IStage extends IRequirement, ICommandResponder {
id: string
task: string
exceptions: IStageException[]
}
export const stageSchema = new Schema<IStage>({
id: {
type: String,
required: true,
},
task: {
type: String,
required: true,
},
exceptions: {
type: [stageExceptionSchema],
required: true,
},
})
stageSchema.add(commandResponderSchema)
stageSchema.add(requirementSchema)
-16
View File
@@ -1,16 +0,0 @@
import { Schema } from 'mongoose'
import { exceptionSchema, IException } from './exception.js'
export interface IStageException extends IException {
catchAll: boolean
}
export const stageExceptionSchema = new Schema<IStageException>({
catchAll: {
type: Boolean,
required: true,
default: false,
},
})
stageExceptionSchema.add(exceptionSchema)