mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
feat: refactor quest models
+ separate stage and exception + reuse commandResponder
This commit is contained in:
1 parent
b41e67ee0b
commit
bb968706ad
10 files changed
+146
-94
No files matched your search
@@ -0,0 +1,19 @@
|
|||||||
|
import { Schema } from 'mongoose'
|
||||||
|
import conditionSchema from './condition.js'
|
||||||
|
import responseSchema from './response.js'
|
||||||
|
import hintSchema from './hint.js'
|
||||||
|
|
||||||
|
const commandResponderSchema = new Schema({
|
||||||
|
condition: {
|
||||||
|
type: conditionSchema,
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
responses: {
|
||||||
|
type: [responseSchema],
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
commandResponderSchema.add(hintSchema)
|
||||||
|
|
||||||
|
export default commandResponderSchema
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { Schema } from 'mongoose'
|
||||||
|
|
||||||
|
const fileConditionSchema = new Schema({
|
||||||
|
path: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
type: String,
|
||||||
|
exists: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const conditionSchema = new Schema({
|
||||||
|
command: [String],
|
||||||
|
output: [String],
|
||||||
|
error: [String],
|
||||||
|
pwd: [String],
|
||||||
|
files: [fileConditionSchema],
|
||||||
|
})
|
||||||
|
|
||||||
|
conditionSchema.add({
|
||||||
|
or: [conditionSchema],
|
||||||
|
not: conditionSchema,
|
||||||
|
})
|
||||||
|
|
||||||
|
export default conditionSchema
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { Schema } from 'mongoose'
|
||||||
|
import commandResponderSchema from './commandResponder.js'
|
||||||
|
|
||||||
|
const exceptionSchema = new Schema({})
|
||||||
|
|
||||||
|
exceptionSchema.add(commandResponderSchema)
|
||||||
|
|
||||||
|
export default exceptionSchema
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { Schema } from 'mongoose'
|
||||||
|
import exceptionSchema from './exception.js'
|
||||||
|
import requirementSchema from './requirement.js'
|
||||||
|
|
||||||
|
const globalExceptionSchema = new Schema({})
|
||||||
|
|
||||||
|
globalExceptionSchema.add(exceptionSchema)
|
||||||
|
globalExceptionSchema.add(requirementSchema)
|
||||||
|
|
||||||
|
export default globalExceptionSchema
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { Schema } from 'mongoose'
|
||||||
|
|
||||||
|
const hintSchema = new Schema({
|
||||||
|
hints: {
|
||||||
|
type: [String],
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default hintSchema
|
||||||
@@ -1,98 +1,6 @@
|
|||||||
import { model, Schema } from 'mongoose'
|
import { model, Schema } from 'mongoose'
|
||||||
|
import stageSchema from './stage.js'
|
||||||
const responseSchema = new Schema({
|
import globalExceptionSchema from './globalException.js'
|
||||||
type: {
|
|
||||||
type: String,
|
|
||||||
enum: ['narrative', 'dialogue'],
|
|
||||||
default: 'dialogue',
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
content: [String],
|
|
||||||
speaker: { type: String, default: 'Ada' },
|
|
||||||
color: String,
|
|
||||||
})
|
|
||||||
|
|
||||||
const fileConditionSchema = new Schema({
|
|
||||||
path: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
type: String,
|
|
||||||
exists: {
|
|
||||||
type: Boolean,
|
|
||||||
default: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const conditionSchema = new Schema({
|
|
||||||
command: [String],
|
|
||||||
output: [String],
|
|
||||||
error: [String],
|
|
||||||
pwd: [String],
|
|
||||||
files: [fileConditionSchema],
|
|
||||||
})
|
|
||||||
|
|
||||||
conditionSchema.add({
|
|
||||||
or: [conditionSchema],
|
|
||||||
not: conditionSchema,
|
|
||||||
})
|
|
||||||
|
|
||||||
const exceptionSchema = new Schema({
|
|
||||||
condition: {
|
|
||||||
type: conditionSchema,
|
|
||||||
required: false,
|
|
||||||
},
|
|
||||||
catchAll: {
|
|
||||||
type: Boolean,
|
|
||||||
required: true,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
responses: {
|
|
||||||
type: [responseSchema],
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
hints: {
|
|
||||||
type: [String],
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const stageSchema = new Schema({
|
|
||||||
id: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
task: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
requirements: [
|
|
||||||
{
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
repeatable: {
|
|
||||||
type: Boolean,
|
|
||||||
required: true,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
condition: {
|
|
||||||
type: conditionSchema,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
responses: {
|
|
||||||
type: [responseSchema],
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
hints: {
|
|
||||||
type: [String],
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
exceptions: {
|
|
||||||
type: [exceptionSchema],
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const Quest = model(
|
const Quest = model(
|
||||||
'Quest',
|
'Quest',
|
||||||
@@ -126,6 +34,10 @@ const Quest = model(
|
|||||||
type: [stageSchema],
|
type: [stageSchema],
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
exceptions: {
|
||||||
|
type: [globalExceptionSchema],
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { Schema } from 'mongoose'
|
||||||
|
|
||||||
|
const requirementSchema = new Schema({
|
||||||
|
requirements: [
|
||||||
|
{
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
export default requirementSchema
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { Schema } from 'mongoose'
|
||||||
|
|
||||||
|
const responseSchema = new Schema({
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
enum: ['narrative', 'dialogue'],
|
||||||
|
default: 'dialogue',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
content: [String],
|
||||||
|
speaker: { type: String, default: 'Ada' },
|
||||||
|
color: String,
|
||||||
|
})
|
||||||
|
|
||||||
|
export default responseSchema
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { Schema } from 'mongoose'
|
||||||
|
import commandResponderSchema from './commandResponder.js'
|
||||||
|
import stageExceptionSchema from './stageException.js'
|
||||||
|
import requirementSchema from './requirement.js'
|
||||||
|
|
||||||
|
const stageSchema = new Schema({
|
||||||
|
id: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
task: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
exceptions: {
|
||||||
|
type: [stageExceptionSchema],
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
stageSchema.add(commandResponderSchema)
|
||||||
|
stageSchema.add(requirementSchema)
|
||||||
|
|
||||||
|
export default stageSchema
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { Schema } from 'mongoose'
|
||||||
|
import exceptionSchema from './exception.js'
|
||||||
|
|
||||||
|
const stageExceptionSchema = new Schema({
|
||||||
|
catchAll: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
stageExceptionSchema.add(exceptionSchema)
|
||||||
|
|
||||||
|
export default stageExceptionSchema
|
||||||
Reference in new issue
Block a user