// 数据模型定义 - 对应Unity中的数据结构 // 动作类型枚举 const ProcessActionType = { DEFAULT: 0, // 默认 JUDGMENT: 1, // 判断题 MULTIPLE_CHOICE: 2 // 多选题 }; // 目标类型枚举 const ProcessTargetType = { MODEL: 0, // 模型 EVENT: 1 // 事件 }; // 目标对象配置类 function TargetObjectConfig() { this.ObjectName = ""; this.Type = ProcessTargetType.MODEL; this.Score = 0; } // 判断题配置类 function JudgmentQuestionConfig() { this.Question = ""; this.CorrectAnswer = ""; this.Score = 0; } // 多选题配置类 function MultipleChoiceConfig() { this.Question = ""; this.Options = []; this.CorrectAnswers = []; this.Score = 0; } // 流程步骤描述类 function ProcessStepDescription() { this.ActionType = ProcessActionType.DEFAULT; this.JudgmentQuestions = []; this.MultipleChoiceQuestions = []; this.Title = "新动作"; this.TargetObjects = []; this.Action = null; this.Description = ""; this.IsSequential = false; this.ClickedObjects = []; this.CurrentObjectIndex = 0; this.FeedbackDisplayed = false; this.StepDescription = ""; this.Score = 0; this.SceneName = null; this.RequiresSceneSwitch = false; this.TargetObjectEvents = {}; this.ProcessStepIndex = 0; this.RequireCorrectCompletion = true; this.IsCompleted = false; } // 流程步骤类 function ProcessStep() { this.StepDescription = "新步骤"; this.Actions = []; this.IsCompleted = false; this.StepNumber = 0; } // 工具函数 var DataUtils = { // 创建新步骤 createNewStep: function() { return new ProcessStep(); }, // 创建新动作 createNewAction: function() { return new ProcessStepDescription(); }, // 创建新目标对象 createNewTargetObject: function() { return new TargetObjectConfig(); }, // 创建新判断题 createNewJudgmentQuestion: function() { return new JudgmentQuestionConfig(); }, // 创建新多选题 createNewMultipleChoice: function() { return new MultipleChoiceConfig(); }, // 深拷贝对象 deepClone: function(obj) { return JSON.parse(JSON.stringify(obj)); }, // 验证数据完整性 validateStep: function(step) { if (!step.StepDescription || step.StepDescription.trim() === "") { return { valid: false, message: "步骤描述不能为空" }; } for (let i = 0; i < step.Actions.length; i++) { const action = step.Actions[i]; if (!action.Title || action.Title.trim() === "") { return { valid: false, message: `动作 ${i + 1} 的标题不能为空` }; } if (action.ActionType === ProcessActionType.DEFAULT) { if (action.TargetObjects.length === 0) { return { valid: false, message: `动作 "${action.Title}" 必须至少有一个目标对象` }; } for (let j = 0; j < action.TargetObjects.length; j++) { const target = action.TargetObjects[j]; if (!target.ObjectName || target.ObjectName.trim() === "") { return { valid: false, message: `动作 "${action.Title}" 的目标对象 ${j + 1} 名称不能为空` }; } } } else if (action.ActionType === ProcessActionType.JUDGMENT) { if (action.JudgmentQuestions.length === 0) { return { valid: false, message: `判断题动作 "${action.Title}" 必须至少有一个题目` }; } for (let j = 0; j < action.JudgmentQuestions.length; j++) { const question = action.JudgmentQuestions[j]; if (!question.Question || question.Question.trim() === "") { return { valid: false, message: `动作 "${action.Title}" 的判断题 ${j + 1} 题目不能为空` }; } if (!question.CorrectAnswer || question.CorrectAnswer.trim() === "") { return { valid: false, message: `动作 "${action.Title}" 的判断题 ${j + 1} 正确答案不能为空` }; } } } else if (action.ActionType === ProcessActionType.MULTIPLE_CHOICE) { if (action.MultipleChoiceQuestions.length === 0) { return { valid: false, message: `多选题动作 "${action.Title}" 必须至少有一个题目` }; } for (let j = 0; j < action.MultipleChoiceQuestions.length; j++) { const question = action.MultipleChoiceQuestions[j]; if (!question.Question || question.Question.trim() === "") { return { valid: false, message: `动作 "${action.Title}" 的多选题 ${j + 1} 题目不能为空` }; } if (question.Options.length < 2) { return { valid: false, message: `动作 "${action.Title}" 的多选题 ${j + 1} 至少需要2个选项` }; } if (question.CorrectAnswers.length === 0) { return { valid: false, message: `动作 "${action.Title}" 的多选题 ${j + 1} 必须至少有一个正确答案` }; } } } } return { valid: true }; }, // 清理动作数据(根据动作类型清除不需要的数据) cleanActionData: function(action) { const cleanedAction = DataUtils.deepClone(action); if (cleanedAction.ActionType === ProcessActionType.DEFAULT) { cleanedAction.JudgmentQuestions = null; cleanedAction.MultipleChoiceQuestions = null; } else if (cleanedAction.ActionType === ProcessActionType.JUDGMENT) { cleanedAction.TargetObjects = []; cleanedAction.MultipleChoiceQuestions = null; cleanedAction.IsSequential = false; } else if (cleanedAction.ActionType === ProcessActionType.MULTIPLE_CHOICE) { cleanedAction.TargetObjects = []; cleanedAction.JudgmentQuestions = null; cleanedAction.IsSequential = false; } return cleanedAction; }, // 获取动作类型显示名称 getActionTypeName: function(actionType) { switch (actionType) { case ProcessActionType.DEFAULT: return "默认"; case ProcessActionType.JUDGMENT: return "判断题"; case ProcessActionType.MULTIPLE_CHOICE: return "多选题"; default: return "未知"; } }, // 获取目标类型显示名称 getTargetTypeName: function(targetType) { switch (targetType) { case ProcessTargetType.MODEL: return "Model"; case ProcessTargetType.EVENT: return "Event"; default: return "未知"; } } };