@esengine/behavior-tree 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +2 -0
- package/index.cjs.map +1 -0
- package/index.d.ts +2875 -0
- package/index.es5.js +4 -0
- package/index.es5.js.map +1 -0
- package/index.mjs +2 -0
- package/index.mjs.map +1 -0
- package/index.umd.js +2 -0
- package/index.umd.js.map +1 -0
- package/package.json +56 -0
package/index.es5.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";var e,t,o,r,n,i,s=require("@esengine/ecs-framework");function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var o=0,r=Array(t);o<t;o++)r[o]=e[o];return r}function d(e,t,o,r,n,i,s){try{var a=e[i](s),d=a.value}catch(e){return void o(e)}a.done?t(d):Promise.resolve(d).then(r,n)}function u(e){return function(){var t=this,o=arguments;return new Promise((function(r,n){var i=e.apply(t,o);function s(e){d(i,r,n,s,a,"next",e)}function a(e){d(i,r,n,s,a,"throw",e)}s(void 0)}))}}function c(e,t){var o="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(o)return(o=o.call(e)).next.bind(o);if(Array.isArray(e)||(o=function(e,t){if(e){if("string"==typeof e)return a(e,t);var o={}.toString.call(e).slice(8,-1);return"Object"===o&&e.constructor&&(o=e.constructor.name),"Map"===o||"Set"===o?Array.from(e):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?a(e,t):void 0}}(e))||t){o&&(e=o);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var r in o)({}).hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e},p.apply(null,arguments)}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}function h(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,m(e,t)}function f(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(f=function(){return!!e})()}function v(){
|
|
2
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
3
|
+
var e,t,o="function"==typeof Symbol?Symbol:{},r=o.iterator||"@@iterator",n=o.toStringTag||"@@toStringTag";function i(o,r,n,i){var d=r&&r.prototype instanceof a?r:a,u=Object.create(d.prototype);return y(u,"_invoke",function(o,r,n){var i,a,d,u=0,c=n||[],p=!1,l={p:0,n:0,v:e,a:h,f:h.bind(e,4),d:function(t,o){return i=t,a=0,d=e,l.n=o,s}};function h(o,r){for(a=o,d=r,t=0;!p&&u&&!n&&t<c.length;t++){var n,i=c[t],h=l.p,f=i[2];o>3?(n=f===r)&&(d=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=h&&((n=o<2&&h<i[1])?(a=0,l.v=r,l.n=i[1]):h<f&&(n=o<3||i[0]>r||r>f)&&(i[4]=o,i[5]=r,l.n=f,a=0))}if(n||o>1)return s;throw p=!0,r}return function(n,c,f){if(u>1)throw TypeError("Generator is already running");for(p&&1===c&&h(c,f),a=c,d=f;(t=a<2?e:d)||!p;){i||(a?a<3?(a>1&&(l.n=-1),h(a,d)):l.n=d:l.v=d);try{if(u=2,i){if(a||(n="next"),t=i[n]){if(!(t=t.call(i,d)))throw TypeError("iterator result is not an object");if(!t.done)return t;d=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(d=TypeError("The iterator does not provide a '"+n+"' method"),a=1);i=e}else if((t=(p=l.n<0)?d:o.call(r,l))!==s)break}catch(t){i=e,a=1,d=t}finally{u=1}}return{value:t,done:p}}}(o,n,i),!0),u}var s={};function a(){}function d(){}function u(){}t=Object.getPrototypeOf;var c=[][r]?t(t([][r]())):(y(t={},r,(function(){return this})),t),p=u.prototype=a.prototype=Object.create(c);function l(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,y(e,n,"GeneratorFunction")),e.prototype=Object.create(p),e}return d.prototype=u,y(p,"constructor",u),y(u,"constructor",d),d.displayName="GeneratorFunction",y(u,n,"GeneratorFunction"),y(p),y(p,n,"Generator"),y(p,r,(function(){return this})),y(p,"toString",(function(){return"[object Generator]"})),(v=function(){return{w:i,m:l}})()}function y(e,t,o,r){var n=Object.defineProperty;try{n({},"",{})}catch(e){n=0}y=function(e,t,o,r){function i(t,o){y(e,t,(function(e){return this._invoke(t,o,e)}))}t?n?n(e,t,{value:o,enumerable:!r,configurable:!r,writable:!r}):e[t]=o:(i("next",0),i("throw",1),i("return",2))},y(e,t,o,r)}function m(e,t){return m=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},m(e,t)}function g(e){var t="function"==typeof Map?new Map:void 0;return g=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,o)}function o(){return function(e,t,o){if(f())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var n=new(e.bind.apply(e,r));return o&&m(n,o.prototype),n}(e,arguments,l(this).constructor)}return o.prototype=Object.create(e.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),m(o,e)},g(e)}function x(e,t,o,r){var n,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,o,r);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(s=(i<3?n(s):i>3?n(t,o,s):n(t,o))||s);return i>3&&s&&Object.defineProperty(t,o,s),s}function b(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}"function"==typeof SuppressedError&&SuppressedError,exports.TaskStatus=void 0,(e=exports.TaskStatus||(exports.TaskStatus={}))[e.Invalid=0]="Invalid",e[e.Success=1]="Success",e[e.Failure=2]="Failure",e[e.Running=3]="Running",exports.NodeType=void 0,(t=exports.NodeType||(exports.NodeType={})).Composite="composite",t.Decorator="decorator",t.Action="action",t.Condition="condition",exports.CompositeType=void 0,(o=exports.CompositeType||(exports.CompositeType={})).Sequence="sequence",o.Selector="selector",o.Parallel="parallel",o.ParallelSelector="parallel-selector",o.RandomSequence="random-sequence",o.RandomSelector="random-selector",exports.DecoratorType=void 0,(r=exports.DecoratorType||(exports.DecoratorType={})).Inverter="inverter",r.Repeater="repeater",r.UntilSuccess="until-success",r.UntilFail="until-fail",r.AlwaysSucceed="always-succeed",r.AlwaysFail="always-fail",r.Conditional="conditional",r.Cooldown="cooldown",r.Timeout="timeout",exports.AbortType=void 0,(n=exports.AbortType||(exports.AbortType={})).None="none",n.Self="self",n.LowerPriority="lower-priority",n.Both="both",exports.BlackboardValueType=void 0,(i=exports.BlackboardValueType||(exports.BlackboardValueType={})).String="string",i.Number="number",i.Boolean="boolean",i.Vector2="vector2",i.Vector3="vector3",i.Object="object",i.Array="array";var C=function(){function e(){}return e.registerNodeClass=function(e,t){var o=t.category+":"+t.displayName;this.nodeClasses.set(o,{metadata:t,constructor:e})},e.getAllNodeClasses=function(){return Array.from(this.nodeClasses.values())},e.getNodeClass=function(e,t){var o,r=e+":"+t;return null===(o=this.nodeClasses.get(r))||void 0===o?void 0:o.constructor},e.clear=function(){this.nodeClasses.clear()},e}();function T(e){return function(t){var o=p({},e,{className:t.name});return C.registerNodeClass(t,o),t}}function S(e){return function(t,o){t.constructor.__nodeProperties||(t.constructor.__nodeProperties=[]),t.constructor.__nodeProperties.push(p({name:o},e))}}C.nodeClasses=new Map;var N,w,k=S;function B(){return C.getAllNodeClasses().map((function(e){var t=e.metadata,o=e.constructor,r=o.__nodeProperties||[],n={nodeType:t.type.toLowerCase()},i=new o,s=r.map((function(e){var t=i[e.name];return void 0!==t&&(n[e.name]=t),p({},e,{defaultValue:void 0!==t?t:e.defaultValue})}));switch(t.type){case exports.NodeType.Composite:n.compositeType=t.displayName;break;case exports.NodeType.Decorator:n.decoratorType=t.displayName;break;case exports.NodeType.Action:n.actionType=t.displayName;break;case exports.NodeType.Condition:n.conditionType=t.displayName}return{type:t.type,displayName:t.displayName,category:t.category,icon:t.icon,description:t.description,color:t.color,className:t.className,requiresChildren:t.requiresChildren,defaultConfig:n,properties:s}}))}exports.ExecuteAction=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).actionCode="return TaskStatus.Success;",t.parameters={},t}h(t,e);var o=t.prototype;return o.getFunction=function(){var e=this;if(!this.compiledFunction&&this.actionCode)try{var t=new Function("entity","blackboard","deltaTime","parameters","TaskStatus","\n const { Success, Failure, Running, Invalid } = TaskStatus;\n try {\n "+this.actionCode+"\n } catch (error) {\n return TaskStatus.Failure;\n }\n ");this.compiledFunction=function(o,r,n){return t(o,r,n,e.parameters,exports.TaskStatus)||exports.TaskStatus.Success}}catch(e){return}return this.compiledFunction},o.setFunction=function(e){this.compiledFunction=e},t}(s.Component),x([S({label:"动作代码",type:"code",description:"JavaScript 代码,返回 TaskStatus",required:!0}),s.Serialize(),b("design:type",String)],exports.ExecuteAction.prototype,"actionCode",void 0),x([s.Serialize(),b("design:type",Object)],exports.ExecuteAction.prototype,"parameters",void 0),x([s.IgnoreSerialization(),b("design:type",Function)],exports.ExecuteAction.prototype,"compiledFunction",void 0),exports.ExecuteAction=x([T({displayName:"自定义动作",category:"动作",type:exports.NodeType.Action,icon:"Code",description:"执行自定义代码",color:"#FFC107"}),s.ECSComponent("ExecuteAction"),s.Serializable({version:1})],exports.ExecuteAction),exports.WaitAction=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).waitTime=1,t.elapsedTime=0,t}return h(t,e),t.prototype.reset=function(){this.elapsedTime=0},t}(s.Component),x([S({label:"等待时间",type:"number",min:0,step:.1,description:"等待时间(秒)",required:!0}),s.Serialize(),b("design:type",Number)],exports.WaitAction.prototype,"waitTime",void 0),x([s.IgnoreSerialization(),b("design:type",Number)],exports.WaitAction.prototype,"elapsedTime",void 0),exports.WaitAction=x([T({displayName:"等待",category:"动作",type:exports.NodeType.Action,icon:"Clock",description:"等待指定时间",color:"#9E9E9E"}),s.ECSComponent("WaitAction"),s.Serializable({version:1})],exports.WaitAction),exports.LogAction=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).message="Hello",t.level="log",t.includeEntityInfo=!1,t}return h(t,e),t}(s.Component),x([S({label:"消息",type:"string",required:!0}),s.Serialize(),b("design:type",String)],exports.LogAction.prototype,"message",void 0),x([S({label:"级别",type:"select",options:[{label:"Log",value:"log"},{label:"Info",value:"info"},{label:"Warn",value:"warn"},{label:"Error",value:"error"}]}),s.Serialize(),b("design:type",String)],exports.LogAction.prototype,"level",void 0),x([S({label:"包含实体信息",type:"boolean"}),s.Serialize(),b("design:type",Boolean)],exports.LogAction.prototype,"includeEntityInfo",void 0),exports.LogAction=x([T({displayName:"日志",category:"动作",type:exports.NodeType.Action,icon:"FileText",description:"输出日志消息",color:"#673AB7"}),s.ECSComponent("LogAction"),s.Serializable({version:1})],exports.LogAction),exports.SetBlackboardValueAction=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).variableName="",t.value="",t.force=!1,t}return h(t,e),t}(s.Component),x([S({label:"变量名",type:"variable",required:!0}),s.Serialize(),b("design:type",String)],exports.SetBlackboardValueAction.prototype,"variableName",void 0),x([S({label:"值",type:"string",description:"可以使用 {{varName}} 引用其他变量"}),s.Serialize(),b("design:type",Object)],exports.SetBlackboardValueAction.prototype,"value",void 0),x([s.Serialize(),b("design:type",String)],exports.SetBlackboardValueAction.prototype,"sourceVariable",void 0),x([s.Serialize(),b("design:type",Boolean)],exports.SetBlackboardValueAction.prototype,"force",void 0),exports.SetBlackboardValueAction=x([T({displayName:"设置变量",category:"动作",type:exports.NodeType.Action,icon:"Edit",description:"设置黑板变量的值",color:"#3F51B5"}),s.ECSComponent("SetBlackboardValueAction"),s.Serializable({version:1})],exports.SetBlackboardValueAction),exports.ModifyOperation=void 0,(N=exports.ModifyOperation||(exports.ModifyOperation={})).Add="add",N.Subtract="subtract",N.Multiply="multiply",N.Divide="divide",N.Modulo="modulo",N.Append="append",N.Remove="remove",exports.ModifyBlackboardValueAction=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).variableName="",t.operation=exports.ModifyOperation.Add,t.operand=0,t.force=!1,t}return h(t,e),t}(s.Component),x([S({label:"变量名",type:"variable",required:!0}),s.Serialize(),b("design:type",String)],exports.ModifyBlackboardValueAction.prototype,"variableName",void 0),x([S({label:"操作类型",type:"select",options:[{label:"加法",value:"add"},{label:"减法",value:"subtract"},{label:"乘法",value:"multiply"},{label:"除法",value:"divide"},{label:"取模",value:"modulo"},{label:"追加",value:"append"},{label:"移除",value:"remove"}]}),s.Serialize(),b("design:type",String)],exports.ModifyBlackboardValueAction.prototype,"operation",void 0),x([S({label:"操作数",type:"string",description:"可以是固定值或变量引用 {{varName}}"}),s.Serialize(),b("design:type",Object)],exports.ModifyBlackboardValueAction.prototype,"operand",void 0),x([s.Serialize(),b("design:type",Boolean)],exports.ModifyBlackboardValueAction.prototype,"force",void 0),exports.ModifyBlackboardValueAction=x([T({displayName:"修改变量",category:"动作",type:exports.NodeType.Action,icon:"Calculator",description:"对黑板变量执行数学或逻辑操作",color:"#FF9800"}),s.ECSComponent("ModifyBlackboardValueAction"),s.Serializable({version:1})],exports.ModifyBlackboardValueAction),exports.CompareOperator=void 0,(w=exports.CompareOperator||(exports.CompareOperator={})).Equal="equal",w.NotEqual="notEqual",w.Greater="greater",w.GreaterOrEqual="greaterOrEqual",w.Less="less",w.LessOrEqual="lessOrEqual",w.Contains="contains",w.Matches="matches",exports.BlackboardCompareCondition=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).variableName="",t.operator=exports.CompareOperator.Equal,t.compareValue=null,t.invertResult=!1,t}return h(t,e),t}(s.Component),x([S({label:"变量名",type:"variable",required:!0}),s.Serialize(),b("design:type",String)],exports.BlackboardCompareCondition.prototype,"variableName",void 0),x([S({label:"运算符",type:"select",options:[{label:"等于",value:"equal"},{label:"不等于",value:"notEqual"},{label:"大于",value:"greater"},{label:"大于等于",value:"greaterOrEqual"},{label:"小于",value:"less"},{label:"小于等于",value:"lessOrEqual"},{label:"包含",value:"contains"},{label:"正则匹配",value:"matches"}]}),s.Serialize(),b("design:type",String)],exports.BlackboardCompareCondition.prototype,"operator",void 0),x([S({label:"比较值",type:"string",description:"可以是固定值或变量引用 {{varName}}"}),s.Serialize(),b("design:type",Object)],exports.BlackboardCompareCondition.prototype,"compareValue",void 0),x([S({label:"反转结果",type:"boolean"}),s.Serialize(),b("design:type",Boolean)],exports.BlackboardCompareCondition.prototype,"invertResult",void 0),exports.BlackboardCompareCondition=x([T({displayName:"比较变量",category:"条件",type:exports.NodeType.Condition,icon:"Scale",description:"比较黑板变量与指定值",color:"#2196F3"}),s.ECSComponent("BlackboardCompareCondition"),s.Serializable({version:1})],exports.BlackboardCompareCondition),exports.BlackboardExistsCondition=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).variableName="",t.checkNotNull=!1,t.invertResult=!1,t}return h(t,e),t}(s.Component),x([S({label:"变量名",type:"variable",required:!0}),s.Serialize(),b("design:type",String)],exports.BlackboardExistsCondition.prototype,"variableName",void 0),x([S({label:"检查非空",type:"boolean",description:"检查值不为 null/undefined"}),s.Serialize(),b("design:type",Boolean)],exports.BlackboardExistsCondition.prototype,"checkNotNull",void 0),x([S({label:"反转结果",type:"boolean",description:"检查不存在"}),s.Serialize(),b("design:type",Boolean)],exports.BlackboardExistsCondition.prototype,"invertResult",void 0),exports.BlackboardExistsCondition=x([T({displayName:"检查变量存在",category:"条件",type:exports.NodeType.Condition,icon:"Search",description:"检查黑板变量是否存在",color:"#00BCD4"}),s.ECSComponent("BlackboardExistsCondition"),s.Serializable({version:1})],exports.BlackboardExistsCondition),exports.RandomProbabilityCondition=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).probability=.5,t.alwaysRandomize=!0,t}h(t,e);var o=t.prototype;return o.evaluate=function(){return(this.alwaysRandomize||void 0===this.cachedResult)&&(this.cachedResult=Math.random()<this.probability),this.cachedResult},o.reset=function(){this.cachedResult=void 0},t}(s.Component),x([S({label:"成功概率",type:"number",min:0,max:1,step:.1,description:"0.0 - 1.0",required:!0}),s.Serialize(),b("design:type",Number)],exports.RandomProbabilityCondition.prototype,"probability",void 0),x([S({label:"总是重新随机",type:"boolean",description:"false则第一次随机后固定结果"}),s.Serialize(),b("design:type",Boolean)],exports.RandomProbabilityCondition.prototype,"alwaysRandomize",void 0),exports.RandomProbabilityCondition=x([T({displayName:"随机概率",category:"条件",type:exports.NodeType.Condition,icon:"Dice",description:"根据概率返回成功或失败",color:"#E91E63"}),s.ECSComponent("RandomProbabilityCondition"),s.Serializable({version:1})],exports.RandomProbabilityCondition),exports.ExecuteCondition=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).parameters={},t.invertResult=!1,t}h(t,e);var o=t.prototype;return o.getFunction=function(){var e=this;if(!this.compiledFunction&&this.conditionCode)try{var t=new Function("entity","blackboard","deltaTime","parameters","\n try {\n "+this.conditionCode+"\n } catch (error) {\n return false;\n }\n ");this.compiledFunction=function(o,r,n){return Boolean(t(o,r,n,e.parameters))}}catch(e){return}return this.compiledFunction},o.setFunction=function(e){this.compiledFunction=e},t}(s.Component),x([S({label:"条件代码",type:"code",description:"JavaScript 代码,返回 boolean",required:!0}),s.Serialize(),b("design:type",String)],exports.ExecuteCondition.prototype,"conditionCode",void 0),x([s.Serialize(),b("design:type",Object)],exports.ExecuteCondition.prototype,"parameters",void 0),x([S({label:"反转结果",type:"boolean"}),s.Serialize(),b("design:type",Boolean)],exports.ExecuteCondition.prototype,"invertResult",void 0),x([s.IgnoreSerialization(),b("design:type",Function)],exports.ExecuteCondition.prototype,"compiledFunction",void 0),exports.ExecuteCondition=x([T({displayName:"自定义条件",category:"条件",type:exports.NodeType.Condition,icon:"Code",description:"执行自定义条件代码",color:"#9C27B0"}),s.ECSComponent("ExecuteCondition"),s.Serializable({version:1})],exports.ExecuteCondition),exports.CompositeNodeComponent=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).compositeType=exports.CompositeType.Sequence,t.shuffledIndices=[],t.reshuffleOnRestart=!0,t}h(t,e);var o=t.prototype;return o.getNextChildIndex=function(e,t){return this.compositeType===exports.CompositeType.RandomSequence||this.compositeType===exports.CompositeType.RandomSelector?((0===this.shuffledIndices.length||0===e&&this.reshuffleOnRestart)&&this.shuffleIndices(t),e<this.shuffledIndices.length?this.shuffledIndices[e]:t):e},o.shuffleIndices=function(e){this.shuffledIndices=Array.from({length:e},(function(e,t){return t}));for(var t=this.shuffledIndices.length-1;t>0;t--){var o=Math.floor(Math.random()*(t+1)),r=[this.shuffledIndices[o],this.shuffledIndices[t]];this.shuffledIndices[t]=r[0],this.shuffledIndices[o]=r[1]}},o.resetShuffle=function(){this.shuffledIndices=[]},t}(s.Component),x([s.Serialize(),b("design:type",String)],exports.CompositeNodeComponent.prototype,"compositeType",void 0),exports.CompositeNodeComponent=x([s.ECSComponent("CompositeNode"),s.Serializable({version:1})],exports.CompositeNodeComponent),exports.SequenceNode=function(e){function t(){var t;return(t=e.call(this)||this).abortType=exports.AbortType.None,t.compositeType=exports.CompositeType.Sequence,t}return h(t,e),t}(exports.CompositeNodeComponent),x([S({label:"中止类型",type:"select",description:"条件变化时的中止行为",options:[{label:"无",value:"none"},{label:"自身",value:"self"},{label:"低优先级",value:"lower-priority"},{label:"两者",value:"both"}]}),s.Serialize(),b("design:type",String)],exports.SequenceNode.prototype,"abortType",void 0),exports.SequenceNode=x([T({displayName:"序列",category:"组合",type:exports.NodeType.Composite,icon:"List",description:"按顺序执行子节点,全部成功才成功",color:"#4CAF50"}),s.ECSComponent("SequenceNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.SequenceNode),exports.SelectorNode=function(e){function t(){var t;return(t=e.call(this)||this).abortType=exports.AbortType.None,t.compositeType=exports.CompositeType.Selector,t}return h(t,e),t}(exports.CompositeNodeComponent),x([S({label:"中止类型",type:"select",description:"条件变化时的中止行为",options:[{label:"无",value:"none"},{label:"自身",value:"self"},{label:"低优先级",value:"lower-priority"},{label:"两者",value:"both"}]}),s.Serialize(),b("design:type",String)],exports.SelectorNode.prototype,"abortType",void 0),exports.SelectorNode=x([T({displayName:"选择",category:"组合",type:exports.NodeType.Composite,icon:"GitBranch",description:"按顺序执行子节点,任一成功则成功",color:"#8BC34A"}),s.ECSComponent("SelectorNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.SelectorNode),exports.ParallelNode=function(e){function t(){var t;return(t=e.call(this)||this).successPolicy="all",t.failurePolicy="one",t.compositeType=exports.CompositeType.Parallel,t}return h(t,e),t}(exports.CompositeNodeComponent),x([S({label:"成功策略",type:"select",description:"多少个子节点成功时整体成功",options:[{label:"全部成功",value:"all"},{label:"任意一个成功",value:"one"}]}),s.Serialize(),b("design:type",String)],exports.ParallelNode.prototype,"successPolicy",void 0),x([S({label:"失败策略",type:"select",description:"多少个子节点失败时整体失败",options:[{label:"任意一个失败",value:"one"},{label:"全部失败",value:"all"}]}),s.Serialize(),b("design:type",String)],exports.ParallelNode.prototype,"failurePolicy",void 0),exports.ParallelNode=x([T({displayName:"并行",category:"组合",type:exports.NodeType.Composite,icon:"Layers",description:"同时执行所有子节点",color:"#CDDC39"}),s.ECSComponent("ParallelNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.ParallelNode),exports.ParallelSelectorNode=function(e){function t(){var t;return(t=e.call(this)||this).failurePolicy="all",t.compositeType=exports.CompositeType.ParallelSelector,t}return h(t,e),t}(exports.CompositeNodeComponent),x([S({label:"失败策略",type:"select",description:"多少个子节点失败时整体失败",options:[{label:"任意一个失败",value:"one"},{label:"全部失败",value:"all"}]}),s.Serialize(),b("design:type",String)],exports.ParallelSelectorNode.prototype,"failurePolicy",void 0),exports.ParallelSelectorNode=x([T({displayName:"并行选择",category:"组合",type:exports.NodeType.Composite,icon:"Sparkles",description:"并行执行子节点,任一成功则成功",color:"#FFC107"}),s.ECSComponent("ParallelSelectorNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.ParallelSelectorNode),exports.RandomSequenceNode=function(e){function t(){var t;return(t=e.call(this)||this).reshuffleOnRestart=!0,t.compositeType=exports.CompositeType.RandomSequence,t}return h(t,e),t}(exports.CompositeNodeComponent),x([S({label:"重启时重新洗牌",type:"boolean",description:"每次重启时是否重新随机子节点顺序"}),s.Serialize(),b("design:type",Boolean)],exports.RandomSequenceNode.prototype,"reshuffleOnRestart",void 0),exports.RandomSequenceNode=x([T({displayName:"随机序列",category:"组合",type:exports.NodeType.Composite,icon:"Shuffle",description:"随机顺序执行子节点序列",color:"#FF5722"}),s.ECSComponent("RandomSequenceNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.RandomSequenceNode),exports.RandomSelectorNode=function(e){function t(){var t;return(t=e.call(this)||this).reshuffleOnRestart=!0,t.compositeType=exports.CompositeType.RandomSelector,t}return h(t,e),t}(exports.CompositeNodeComponent),x([S({label:"重启时重新洗牌",type:"boolean",description:"每次重启时是否重新随机子节点顺序"}),s.Serialize(),b("design:type",Boolean)],exports.RandomSelectorNode.prototype,"reshuffleOnRestart",void 0),exports.RandomSelectorNode=x([T({displayName:"随机选择",category:"组合",type:exports.NodeType.Composite,icon:"Dices",description:"随机顺序执行子节点选择",color:"#F44336"}),s.ECSComponent("RandomSelectorNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.RandomSelectorNode),exports.SubTreeNode=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).assetId="",t.inheritParentBlackboard=!0,t.propagateFailure=!0,t.preload=!0,t.subTreeCompleted=!1,t.subTreeResult=exports.TaskStatus.Invalid,t}h(t,e);var o=t.prototype;return o.getSubTreeRoot=function(){return this.subTreeRoot},o.setSubTreeRoot=function(e){this.subTreeRoot=e,this.subTreeCompleted=!1,this.subTreeResult=exports.TaskStatus.Invalid},o.markSubTreeCompleted=function(e){this.subTreeCompleted=!0,this.subTreeResult=e},o.isSubTreeCompleted=function(){return this.subTreeCompleted},o.getSubTreeResult=function(){return this.subTreeResult},o.reset=function(){this.subTreeRoot=void 0,this.subTreeCompleted=!1,this.subTreeResult=exports.TaskStatus.Invalid},o.resetCompletionState=function(){this.subTreeCompleted=!1,this.subTreeResult=exports.TaskStatus.Invalid},o.validate=function(){var e=[];return this.assetId&&""!==this.assetId.trim()||e.push("SubTree 节点必须指定资产ID"),e},t}(exports.CompositeNodeComponent),x([S({label:"资产ID",type:"asset",description:"要引用的行为树资产ID"}),s.Serialize(),b("design:type",String)],exports.SubTreeNode.prototype,"assetId",void 0),x([S({label:"继承父黑板",type:"boolean",description:"子树是否可以访问父树的黑板变量"}),s.Serialize(),b("design:type",Boolean)],exports.SubTreeNode.prototype,"inheritParentBlackboard",void 0),x([S({label:"传播失败",type:"boolean",description:"子树失败时是否传播失败状态"}),s.Serialize(),b("design:type",Boolean)],exports.SubTreeNode.prototype,"propagateFailure",void 0),x([S({label:"预加载",type:"boolean",description:"在行为树启动时预加载子树,避免运行时加载延迟"}),s.Serialize(),b("design:type",Boolean)],exports.SubTreeNode.prototype,"preload",void 0),exports.SubTreeNode=x([T({displayName:"子树",category:"组合",type:exports.NodeType.Composite,icon:"GitBranch",description:"引用并执行外部行为树文件(不支持静态子节点)",color:"#FF9800",requiresChildren:!1}),s.ECSComponent("SubTreeNode"),s.Serializable({version:1})],exports.SubTreeNode),exports.DecoratorNodeComponent=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).decoratorType=exports.DecoratorType.Inverter,t}return h(t,e),t}(s.Component),x([s.Serialize(),b("design:type",String)],exports.DecoratorNodeComponent.prototype,"decoratorType",void 0),exports.DecoratorNodeComponent=x([s.ECSComponent("DecoratorNode"),s.Serializable({version:1})],exports.DecoratorNodeComponent),exports.InverterNode=function(e){function t(){var t;return(t=e.call(this)||this).decoratorType=exports.DecoratorType.Inverter,t}return h(t,e),t}(exports.DecoratorNodeComponent),exports.InverterNode=x([T({displayName:"反转",category:"装饰器",type:exports.NodeType.Decorator,icon:"RotateCcw",description:"反转子节点的执行结果",color:"#607D8B"}),s.ECSComponent("InverterNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.InverterNode),exports.RepeaterNode=function(e){function t(){var t;return(t=e.call(this)||this).repeatCount=1,t.endOnFailure=!1,t.currentRepeatCount=0,t.decoratorType=exports.DecoratorType.Repeater,t}h(t,e);var o=t.prototype;return o.incrementRepeat=function(){this.currentRepeatCount++},o.shouldContinueRepeat=function(){return-1===this.repeatCount||this.currentRepeatCount<this.repeatCount},o.reset=function(){this.currentRepeatCount=0},t}(exports.DecoratorNodeComponent),x([S({label:"重复次数",type:"number",min:-1,step:1,description:"-1表示无限重复",required:!0}),s.Serialize(),b("design:type",Number)],exports.RepeaterNode.prototype,"repeatCount",void 0),x([S({label:"失败时停止",type:"boolean",description:"子节点失败时是否停止重复"}),s.Serialize(),b("design:type",Boolean)],exports.RepeaterNode.prototype,"endOnFailure",void 0),x([s.IgnoreSerialization(),b("design:type",Number)],exports.RepeaterNode.prototype,"currentRepeatCount",void 0),exports.RepeaterNode=x([T({displayName:"重复",category:"装饰器",type:exports.NodeType.Decorator,icon:"Repeat",description:"重复执行子节点指定次数",color:"#9E9E9E"}),s.ECSComponent("RepeaterNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.RepeaterNode),exports.UntilSuccessNode=function(e){function t(){var t;return(t=e.call(this)||this).decoratorType=exports.DecoratorType.UntilSuccess,t}return h(t,e),t}(exports.DecoratorNodeComponent),exports.UntilSuccessNode=x([T({displayName:"直到成功",category:"装饰器",type:exports.NodeType.Decorator,icon:"CheckCircle",description:"重复执行子节点直到成功",color:"#4CAF50"}),s.ECSComponent("UntilSuccessNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.UntilSuccessNode),exports.UntilFailNode=function(e){function t(){var t;return(t=e.call(this)||this).decoratorType=exports.DecoratorType.UntilFail,t}return h(t,e),t}(exports.DecoratorNodeComponent),exports.UntilFailNode=x([T({displayName:"直到失败",category:"装饰器",type:exports.NodeType.Decorator,icon:"XCircle",description:"重复执行子节点直到失败",color:"#F44336"}),s.ECSComponent("UntilFailNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.UntilFailNode),exports.AlwaysSucceedNode=function(e){function t(){var t;return(t=e.call(this)||this).decoratorType=exports.DecoratorType.AlwaysSucceed,t}return h(t,e),t}(exports.DecoratorNodeComponent),exports.AlwaysSucceedNode=x([T({displayName:"总是成功",category:"装饰器",type:exports.NodeType.Decorator,icon:"ThumbsUp",description:"无论子节点结果如何都返回成功",color:"#8BC34A"}),s.ECSComponent("AlwaysSucceedNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.AlwaysSucceedNode),exports.AlwaysFailNode=function(e){function t(){var t;return(t=e.call(this)||this).decoratorType=exports.DecoratorType.AlwaysFail,t}return h(t,e),t}(exports.DecoratorNodeComponent),exports.AlwaysFailNode=x([T({displayName:"总是失败",category:"装饰器",type:exports.NodeType.Decorator,icon:"ThumbsDown",description:"无论子节点结果如何都返回失败",color:"#FF5722"}),s.ECSComponent("AlwaysFailNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.AlwaysFailNode),exports.ConditionalNode=function(e){function t(){var t;return(t=e.call(this)||this).shouldReevaluate=!0,t.decoratorType=exports.DecoratorType.Conditional,t}h(t,e);var o=t.prototype;return o.evaluateCondition=function(e,t){if(!this.conditionCode)return!1;if(!this.compiledCondition)try{var o=new Function("entity","blackboard","\n try {\n return Boolean("+this.conditionCode+");\n } catch (error) {\n return false;\n }\n ");this.compiledCondition=function(e,t){return Boolean(o(e,t))}}catch(e){return!1}return this.compiledCondition(e,t)},o.setConditionFunction=function(e){this.compiledCondition=e},t}(exports.DecoratorNodeComponent),x([S({label:"条件代码",type:"code",description:"JavaScript 代码,返回 boolean",required:!0}),s.Serialize(),b("design:type",String)],exports.ConditionalNode.prototype,"conditionCode",void 0),x([S({label:"重新评估条件",type:"boolean",description:"每次执行时是否重新评估条件"}),s.Serialize(),b("design:type",Boolean)],exports.ConditionalNode.prototype,"shouldReevaluate",void 0),x([s.IgnoreSerialization(),b("design:type",Function)],exports.ConditionalNode.prototype,"compiledCondition",void 0),exports.ConditionalNode=x([T({displayName:"条件装饰器",category:"装饰器",type:exports.NodeType.Decorator,icon:"Filter",description:"基于条件判断是否执行子节点",color:"#3F51B5"}),s.ECSComponent("ConditionalNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.ConditionalNode),exports.CooldownNode=function(e){function t(){var t;return(t=e.call(this)||this).cooldownTime=1,t.lastExecutionTime=0,t.decoratorType=exports.DecoratorType.Cooldown,t}h(t,e);var o=t.prototype;return o.canExecute=function(e){return 0===this.lastExecutionTime||e-this.lastExecutionTime>=this.cooldownTime},o.recordExecution=function(e){this.lastExecutionTime=e},o.reset=function(){this.lastExecutionTime=0},t}(exports.DecoratorNodeComponent),x([S({label:"冷却时间",type:"number",min:0,step:.1,description:"冷却时间(秒)",required:!0}),s.Serialize(),b("design:type",Number)],exports.CooldownNode.prototype,"cooldownTime",void 0),x([s.IgnoreSerialization(),b("design:type",Number)],exports.CooldownNode.prototype,"lastExecutionTime",void 0),exports.CooldownNode=x([T({displayName:"冷却",category:"装饰器",type:exports.NodeType.Decorator,icon:"Timer",description:"在冷却时间内阻止子节点执行",color:"#00BCD4"}),s.ECSComponent("CooldownNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.CooldownNode),exports.TimeoutNode=function(e){function t(){var t;return(t=e.call(this)||this).timeoutDuration=5,t.startTime=0,t.decoratorType=exports.DecoratorType.Timeout,t}h(t,e);var o=t.prototype;return o.recordStartTime=function(e){0===this.startTime&&(this.startTime=e)},o.isTimeout=function(e){return 0!==this.startTime&&e-this.startTime>=this.timeoutDuration},o.reset=function(){this.startTime=0},t}(exports.DecoratorNodeComponent),x([S({label:"超时时间",type:"number",min:0,step:.1,description:"超时时间(秒)",required:!0}),s.Serialize(),b("design:type",Number)],exports.TimeoutNode.prototype,"timeoutDuration",void 0),x([s.IgnoreSerialization(),b("design:type",Number)],exports.TimeoutNode.prototype,"startTime",void 0),exports.TimeoutNode=x([T({displayName:"超时",category:"装饰器",type:exports.NodeType.Decorator,icon:"Clock",description:"子节点执行超时则返回失败",color:"#FF9800"}),s.ECSComponent("TimeoutNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.TimeoutNode),exports.BehaviorTreeNode=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).nodeType=exports.NodeType.Action,t.nodeName="Node",t.status=exports.TaskStatus.Invalid,t.currentChildIndex=0,t}h(t,e);var o=t.prototype;return o.reset=function(){this.status=exports.TaskStatus.Invalid,this.currentChildIndex=0},o.invalidate=function(){this.reset()},t}(s.Component),x([s.Serialize(),b("design:type",String)],exports.BehaviorTreeNode.prototype,"nodeType",void 0),x([s.Serialize(),b("design:type",String)],exports.BehaviorTreeNode.prototype,"nodeName",void 0),x([s.IgnoreSerialization(),b("design:type",Number)],exports.BehaviorTreeNode.prototype,"status",void 0),x([s.IgnoreSerialization(),b("design:type",Number)],exports.BehaviorTreeNode.prototype,"currentChildIndex",void 0),exports.BehaviorTreeNode=x([s.ECSComponent("BehaviorTreeNode"),s.Serializable({version:1})],exports.BehaviorTreeNode);var A=function(){function e(){this.variables=new Map}var t=e.prototype;return t.dispose=function(){this.variables.clear()},t.defineVariable=function(e,t,o,r){var n;this.variables.set(e,{name:e,type:t,value:o,readonly:null!==(n=null==r?void 0:r.readonly)&&void 0!==n&&n,description:null==r?void 0:r.description})},t.getValue=function(e){var t=this.variables.get(e);return null==t?void 0:t.value},t.setValue=function(e,t,o){void 0===o&&(o=!1);var r=this.variables.get(e);return!!r&&(!(r.readonly&&!o)&&(r.value=t,!0))},t.hasVariable=function(e){return this.variables.has(e)},t.removeVariable=function(e){return this.variables.delete(e)},t.getVariableNames=function(){return Array.from(this.variables.keys())},t.getAllVariables=function(){return Array.from(this.variables.values())},t.clear=function(){this.variables.clear()},t.setVariables=function(e){for(var t=0,o=Object.entries(e);t<o.length;t++){var r=o[t],n=r[0],i=r[1],s=this.variables.get(n);s&&!s.readonly&&(s.value=i)}},t.getVariables=function(e){for(var t,o={},r=c(e);!(t=r()).done;){var n=t.value,i=this.getValue(n);void 0!==i&&(o[n]=i)}return o},t.exportConfig=function(){return{version:"1.0",variables:Array.from(this.variables.values())}},t.importConfig=function(e){this.variables.clear();for(var t,o=c(e.variables);!(t=o()).done;){var r=t.value;this.variables.set(r.name,r)}},t.toJSON=function(){return JSON.stringify(this.exportConfig(),null,2)},e.fromJSON=function(e){return JSON.parse(e)},e}();exports.BlackboardComponent=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).variables=new Map,t.useGlobalBlackboard=!0,t}h(t,e);var o=t.prototype;return o.defineVariable=function(e,t,o,r){var n;this.variables.set(e,{name:e,type:t,value:o,readonly:null!==(n=null==r?void 0:r.readonly)&&void 0!==n&&n,description:null==r?void 0:r.description})},o.getValue=function(e){var t=this.variables.get(e);return void 0!==t?t.value:this.useGlobalBlackboard?s.Core.services.resolve(A).getValue(e):void 0},o.getLocalValue=function(e){var t=this.variables.get(e);return null==t?void 0:t.value},o.setValue=function(e,t,o){void 0===o&&(o=!1);var r=this.variables.get(e);return r?!(r.readonly&&!o)&&(r.value=t,!0):!!this.useGlobalBlackboard&&s.Core.services.resolve(A).setValue(e,t,o)},o.setLocalValue=function(e,t,o){void 0===o&&(o=!1);var r=this.variables.get(e);return!!r&&(!(r.readonly&&!o)&&(r.value=t,!0))},o.hasVariable=function(e){return!!this.variables.has(e)||!!this.useGlobalBlackboard&&s.Core.services.resolve(A).hasVariable(e)},o.hasLocalVariable=function(e){return this.variables.has(e)},o.removeVariable=function(e){return this.variables.delete(e)},o.getVariableNames=function(){return Array.from(this.variables.keys())},o.clear=function(){this.variables.clear()},o.setUseGlobalBlackboard=function(e){this.useGlobalBlackboard=e},o.isUsingGlobalBlackboard=function(){return this.useGlobalBlackboard},o.getAllVariables=function(){var e=Array.from(this.variables.values());if(this.useGlobalBlackboard){var t=s.Core.services.resolve(A).getAllVariables(),o=new Set(this.variables.keys()),r=t.filter((function(e){return!o.has(e.name)}));return[].concat(e,r)}return e},t.getGlobalBlackboard=function(){return s.Core.services.resolve(A)},t}(s.Component),x([s.Serialize(),b("design:type",Map)],exports.BlackboardComponent.prototype,"variables",void 0),exports.BlackboardComponent=x([s.ECSComponent("Blackboard"),s.Serializable({version:1})],exports.BlackboardComponent),exports.ActiveNode=function(e){function t(){return e.apply(this,arguments)||this}return h(t,e),t}(s.Component),exports.ActiveNode=x([s.ECSComponent("ActiveNode")],exports.ActiveNode);var E=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).bindings=new Map,t}h(t,e);var o=t.prototype;return o.addBinding=function(e,t){this.bindings.set(e,t)},o.getBinding=function(e){return this.bindings.get(e)},o.hasBinding=function(e){return this.bindings.has(e)},o.clearBindings=function(){this.bindings.clear()},t}(s.Component);exports.LogOutput=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).messages=[],t}h(t,e);var o=t.prototype;return o.addMessage=function(e,t){void 0===t&&(t="log"),this.messages.push({timestamp:Date.now(),message:e,level:t})},o.clear=function(){this.messages=[]},t}(s.Component),exports.LogOutput=x([s.ECSComponent("LogOutput")],exports.LogOutput),exports.BehaviorTreeAssetMetadata=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).assetId="",t.assetVersion="",t.assetName="",t.loadedAt=0,t.description="",t}return h(t,e),t.prototype.initialize=function(e,t,o){this.assetId=e,this.assetVersion=t,this.assetName=o||e,this.loadedAt=Date.now()},t}(s.Component),x([s.Serialize(),b("design:type",String)],exports.BehaviorTreeAssetMetadata.prototype,"assetId",void 0),x([s.Serialize(),b("design:type",String)],exports.BehaviorTreeAssetMetadata.prototype,"assetVersion",void 0),x([s.Serialize(),b("design:type",String)],exports.BehaviorTreeAssetMetadata.prototype,"assetName",void 0),x([s.Serialize(),b("design:type",Number)],exports.BehaviorTreeAssetMetadata.prototype,"loadedAt",void 0),x([s.Serialize(),b("design:type",String)],exports.BehaviorTreeAssetMetadata.prototype,"description",void 0),exports.BehaviorTreeAssetMetadata=x([s.ECSComponent("BehaviorTreeAssetMetadata"),s.Serializable({version:1})],exports.BehaviorTreeAssetMetadata),exports.RootNode=function(e){function t(){var t;return(t=e.call(this)||this).compositeType=exports.CompositeType.Sequence,t}return h(t,e),t}(exports.CompositeNodeComponent),exports.RootNode=x([T({displayName:"根节点",category:"根节点",type:exports.NodeType.Composite,icon:"TreePine",description:"行为树的根节点",color:"#FFD700"}),s.ECSComponent("RootNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.RootNode);const R=new TextEncoder;function I(e,t,o){e.length>50?function(e,t,o){R.encodeInto(e,t.subarray(o))}(e,t,o):function(e,t,o){const r=e.length;let n=o,i=0;for(;i<r;){let o=e.charCodeAt(i++);if(4294967168&o){if(4294965248&o){if(o>=55296&&o<=56319&&i<r){const t=e.charCodeAt(i);56320==(64512&t)&&(++i,o=((1023&o)<<10)+(1023&t)+65536)}4294901760&o?(t[n++]=o>>18&7|240,t[n++]=o>>12&63|128,t[n++]=o>>6&63|128):(t[n++]=o>>12&15|224,t[n++]=o>>6&63|128)}else t[n++]=o>>6&31|192;t[n++]=63&o|128}else t[n++]=o}}(e,t,o)}function L(e,t,o){let r=t;const n=r+o,i=[];let s="";for(;r<n;){const t=e[r++];if(128&t)if(192==(224&t)){const o=63&e[r++];i.push((31&t)<<6|o)}else if(224==(240&t)){const o=63&e[r++],n=63&e[r++];i.push((31&t)<<12|o<<6|n)}else if(240==(248&t)){let o=(7&t)<<18|(63&e[r++])<<12|(63&e[r++])<<6|63&e[r++];o>65535&&(o-=65536,i.push(o>>>10&1023|55296),o=56320|1023&o),i.push(o)}else i.push(t);else i.push(t);i.length>=4096&&(s+=String.fromCharCode(...i),i.length=0)}return i.length>0&&(s+=String.fromCharCode(...i)),s}const F=new TextDecoder;function U(e,t,o){return o>200?function(e,t,o){const r=e.subarray(t,t+o);return F.decode(r)}(e,t,o):L(e,t,o)}class z{constructor(e,t){this.type=e,this.data=t}}class P extends Error{constructor(e){super(e);const t=Object.create(P.prototype);Object.setPrototypeOf(this,t),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:P.name})}}const M=4294967295;function D(e,t,o){const r=Math.floor(o/4294967296),n=o;e.setUint32(t,r),e.setUint32(t+4,n)}function O(e,t){return 4294967296*e.getInt32(t)+e.getUint32(t+4)}const V={type:-1,encode:function(e){if(e instanceof Date){return function({sec:e,nsec:t}){if(e>=0&&t>=0&&e<=17179869183){if(0===t&&e<=4294967295){const t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e),t}{const o=e/4294967296,r=4294967295&e,n=new Uint8Array(8),i=new DataView(n.buffer);return i.setUint32(0,t<<2|3&o),i.setUint32(4,r),n}}{const o=new Uint8Array(12),r=new DataView(o.buffer);return r.setUint32(0,t),D(r,4,e),o}}(function(e){const t=e.getTime(),o=Math.floor(t/1e3),r=1e6*(t-1e3*o),n=Math.floor(r/1e9);return{sec:o+n,nsec:r-1e9*n}}(e))}return null},decode:function(e){const t=function(e){const t=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.byteLength){case 4:return{sec:t.getUint32(0),nsec:0};case 8:{const e=t.getUint32(0);return{sec:4294967296*(3&e)+t.getUint32(4),nsec:e>>>2}}case 12:return{sec:O(t,4),nsec:t.getUint32(0)};default:throw new P(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${e.length}`)}}(e);return new Date(1e3*t.sec+t.nsec/1e6)}};class q{constructor(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(V)}register({type:e,encode:t,decode:o}){if(e>=0)this.encoders[e]=t,this.decoders[e]=o;else{const r=-1-e;this.builtInEncoders[r]=t,this.builtInDecoders[r]=o}}tryToEncode(e,t){for(let o=0;o<this.builtInEncoders.length;o++){const r=this.builtInEncoders[o];if(null!=r){const n=r(e,t);if(null!=n){return new z(-1-o,n)}}}for(let o=0;o<this.encoders.length;o++){const r=this.encoders[o];if(null!=r){const n=r(e,t);if(null!=n){return new z(o,n)}}}return e instanceof z?e:null}decode(e,t,o){const r=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return r?r(e,t,o):new z(t,e)}}function j(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):function(e){return e instanceof ArrayBuffer||"undefined"!=typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer}(e)?new Uint8Array(e):Uint8Array.from(e)}q.defaultCodec=new q;class W{constructor(e){this.entered=!1,this.extensionCodec=e?.extensionCodec??q.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.maxDepth=e?.maxDepth??100,this.initialBufferSize=e?.initialBufferSize??2048,this.sortKeys=e?.sortKeys??!1,this.forceFloat32=e?.forceFloat32??!1,this.ignoreUndefined=e?.ignoreUndefined??!1,this.forceIntegerToFloat=e?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new W({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(e){if(this.entered){return this.clone().encodeSharedRef(e)}try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(e){if(this.entered){return this.clone().encode(e)}try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(e,t){if(t>this.maxDepth)throw new Error(`Too deep objects in depth ${t}`);null==e?this.encodeNil():"boolean"==typeof e?this.encodeBoolean(e):"number"==typeof e?this.forceIntegerToFloat?this.encodeNumberAsFloat(e):this.encodeNumber(e):"string"==typeof e?this.encodeString(e):this.useBigInt64&&"bigint"==typeof e?this.encodeBigInt64(e):this.encodeObject(e,t)}ensureBufferSizeToWrite(e){const t=this.pos+e;this.view.byteLength<t&&this.resizeBuffer(2*t)}resizeBuffer(e){const t=new ArrayBuffer(e),o=new Uint8Array(t),r=new DataView(t);o.set(this.bytes),this.view=r,this.bytes=o}encodeNil(){this.writeU8(192)}encodeBoolean(e){!1===e?this.writeU8(194):this.writeU8(195)}encodeNumber(e){!this.forceIntegerToFloat&&Number.isSafeInteger(e)?e>=0?e<128?this.writeU8(e):e<256?(this.writeU8(204),this.writeU8(e)):e<65536?(this.writeU8(205),this.writeU16(e)):e<4294967296?(this.writeU8(206),this.writeU32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(207),this.writeU64(e)):e>=-32?this.writeU8(224|e+32):e>=-128?(this.writeU8(208),this.writeI8(e)):e>=-32768?(this.writeU8(209),this.writeI16(e)):e>=-2147483648?(this.writeU8(210),this.writeI32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(211),this.writeI64(e)):this.encodeNumberAsFloat(e)}encodeNumberAsFloat(e){this.forceFloat32?(this.writeU8(202),this.writeF32(e)):(this.writeU8(203),this.writeF64(e))}encodeBigInt64(e){e>=BigInt(0)?(this.writeU8(207),this.writeBigUint64(e)):(this.writeU8(211),this.writeBigInt64(e))}writeStringHeader(e){if(e<32)this.writeU8(160+e);else if(e<256)this.writeU8(217),this.writeU8(e);else if(e<65536)this.writeU8(218),this.writeU16(e);else{if(!(e<4294967296))throw new Error(`Too long string: ${e} bytes in UTF-8`);this.writeU8(219),this.writeU32(e)}}encodeString(e){const t=function(e){const t=e.length;let o=0,r=0;for(;r<t;){let n=e.charCodeAt(r++);if(4294967168&n)if(4294965248&n){if(n>=55296&&n<=56319&&r<t){const t=e.charCodeAt(r);56320==(64512&t)&&(++r,n=((1023&n)<<10)+(1023&t)+65536)}o+=4294901760&n?4:3}else o+=2;else o++}return o}(e);this.ensureBufferSizeToWrite(5+t),this.writeStringHeader(t),I(e,this.bytes,this.pos),this.pos+=t}encodeObject(e,t){const o=this.extensionCodec.tryToEncode(e,this.context);if(null!=o)this.encodeExtension(o);else if(Array.isArray(e))this.encodeArray(e,t);else if(ArrayBuffer.isView(e))this.encodeBinary(e);else{if("object"!=typeof e)throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(e)}`);this.encodeMap(e,t)}}encodeBinary(e){const t=e.byteLength;if(t<256)this.writeU8(196),this.writeU8(t);else if(t<65536)this.writeU8(197),this.writeU16(t);else{if(!(t<4294967296))throw new Error(`Too large binary: ${t}`);this.writeU8(198),this.writeU32(t)}const o=j(e);this.writeU8a(o)}encodeArray(e,t){const o=e.length;if(o<16)this.writeU8(144+o);else if(o<65536)this.writeU8(220),this.writeU16(o);else{if(!(o<4294967296))throw new Error(`Too large array: ${o}`);this.writeU8(221),this.writeU32(o)}for(const o of e)this.doEncode(o,t+1)}countWithoutUndefined(e,t){let o=0;for(const r of t)void 0!==e[r]&&o++;return o}encodeMap(e,t){const o=Object.keys(e);this.sortKeys&&o.sort();const r=this.ignoreUndefined?this.countWithoutUndefined(e,o):o.length;if(r<16)this.writeU8(128+r);else if(r<65536)this.writeU8(222),this.writeU16(r);else{if(!(r<4294967296))throw new Error(`Too large map object: ${r}`);this.writeU8(223),this.writeU32(r)}for(const r of o){const o=e[r];this.ignoreUndefined&&void 0===o||(this.encodeString(r),this.doEncode(o,t+1))}}encodeExtension(e){if("function"==typeof e.data){const t=e.data(this.pos+6),o=t.length;if(o>=4294967296)throw new Error(`Too large extension object: ${o}`);return this.writeU8(201),this.writeU32(o),this.writeI8(e.type),void this.writeU8a(t)}const t=e.data.length;if(1===t)this.writeU8(212);else if(2===t)this.writeU8(213);else if(4===t)this.writeU8(214);else if(8===t)this.writeU8(215);else if(16===t)this.writeU8(216);else if(t<256)this.writeU8(199),this.writeU8(t);else if(t<65536)this.writeU8(200),this.writeU16(t);else{if(!(t<4294967296))throw new Error(`Too large extension object: ${t}`);this.writeU8(201),this.writeU32(t)}this.writeI8(e.type),this.writeU8a(e.data)}writeU8(e){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,e),this.pos++}writeU8a(e){const t=e.length;this.ensureBufferSizeToWrite(t),this.bytes.set(e,this.pos),this.pos+=t}writeI8(e){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,e),this.pos++}writeU16(e){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,e),this.pos+=2}writeI16(e){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,e),this.pos+=2}writeU32(e){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,e),this.pos+=4}writeI32(e){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,e),this.pos+=4}writeF32(e){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,e),this.pos+=4}writeF64(e){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,e),this.pos+=8}writeU64(e){this.ensureBufferSizeToWrite(8),function(e,t,o){const r=o/4294967296,n=o;e.setUint32(t,r),e.setUint32(t+4,n)}(this.view,this.pos,e),this.pos+=8}writeI64(e){this.ensureBufferSizeToWrite(8),D(this.view,this.pos,e),this.pos+=8}writeBigUint64(e){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,e),this.pos+=8}writeBigInt64(e){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,e),this.pos+=8}}function _(e){return`${e<0?"-":""}0x${Math.abs(e).toString(16).padStart(2,"0")}`}const $="array",G="map_key",J="map_value",H=e=>{if("string"==typeof e||"number"==typeof e)return e;throw new P("The type of key must be string or number but "+typeof e)};class K{constructor(){this.stack=[],this.stackHeadPosition=-1}get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){const t=this.getUninitializedStateFromPool();t.type=$,t.position=0,t.size=e,t.array=new Array(e)}pushMapState(e){const t=this.getUninitializedStateFromPool();t.type=G,t.readCount=0,t.size=e,t.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){const e={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(e)}return this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw new Error("Invalid stack state. Released state is not on top of the stack.");if(e.type===$){const t=e;t.size=0,t.array=void 0,t.position=0,t.type=void 0}if(e.type===G||e.type===J){const t=e;t.size=0,t.map=void 0,t.readCount=0,t.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}const X=new DataView(new ArrayBuffer(0)),Z=new Uint8Array(X.buffer);try{X.getInt8(0)}catch(e){if(!(e instanceof RangeError))throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}const Q=new RangeError("Insufficient data"),Y=new class{constructor(e=16,t=16){this.hit=0,this.miss=0,this.maxKeyLength=e,this.maxLengthPerKey=t,this.caches=[];for(let e=0;e<this.maxKeyLength;e++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,t,o){const r=this.caches[o-1];e:for(const n of r){const r=n.bytes;for(let n=0;n<o;n++)if(r[n]!==e[t+n])continue e;return n.str}return null}store(e,t){const o=this.caches[e.length-1],r={bytes:e,str:t};o.length>=this.maxLengthPerKey?o[Math.random()*o.length|0]=r:o.push(r)}decode(e,t,o){const r=this.find(e,t,o);if(null!=r)return this.hit++,r;this.miss++;const n=L(e,t,o),i=Uint8Array.prototype.slice.call(e,t,t+o);return this.store(i,n),n}};class ee{constructor(e){this.totalPos=0,this.pos=0,this.view=X,this.bytes=Z,this.headByte=-1,this.stack=new K,this.entered=!1,this.extensionCodec=e?.extensionCodec??q.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.rawStrings=e?.rawStrings??!1,this.maxStrLength=e?.maxStrLength??M,this.maxBinLength=e?.maxBinLength??M,this.maxArrayLength=e?.maxArrayLength??M,this.maxMapLength=e?.maxMapLength??M,this.maxExtLength=e?.maxExtLength??M,this.keyDecoder=void 0!==e?.keyDecoder?e.keyDecoder:Y,this.mapKeyConverter=e?.mapKeyConverter??H}clone(){return new ee({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=-1,this.stack.reset()}setBuffer(e){const t=j(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(-1!==this.headByte||this.hasRemaining(1)){const t=this.bytes.subarray(this.pos),o=j(e),r=new Uint8Array(t.length+o.length);r.set(t),r.set(o,t.length),this.setBuffer(r)}else this.setBuffer(e)}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){const{view:t,pos:o}=this;return new RangeError(`Extra ${t.byteLength-o} of ${t.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered){return this.clone().decode(e)}try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);const t=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return t}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){const t=this.clone();yield*t.decodeMulti(e)}else try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered){return this.clone().decodeAsync(e)}try{this.entered=!0;let t,o=!1;for await(const r of e){if(o)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(r);try{t=this.doDecodeSync(),o=!0}catch(e){if(!(e instanceof RangeError))throw e}this.totalPos+=this.pos}if(o){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return t}const{headByte:r,pos:n,totalPos:i}=this;throw new RangeError(`Insufficient data in parsing ${_(r)} at ${i} (${n} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,t){if(this.entered){const o=this.clone();yield*o.decodeMultiAsync(e,t)}else try{this.entered=!0;let o=t,r=-1;for await(const n of e){if(t&&0===r)throw this.createExtraByteError(this.totalPos);this.appendBuffer(n),o&&(r=this.readArraySize(),o=!1,this.complete());try{for(;yield this.doDecodeSync(),0!==--r;);}catch(e){if(!(e instanceof RangeError))throw e}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){e:for(;;){const e=this.readHeadByte();let t;if(e>=224)t=e-256;else if(e<192)if(e<128)t=e;else if(e<144){const o=e-128;if(0!==o){this.pushMapState(o),this.complete();continue e}t={}}else if(e<160){const o=e-144;if(0!==o){this.pushArrayState(o),this.complete();continue e}t=[]}else{const o=e-160;t=this.decodeString(o,0)}else if(192===e)t=null;else if(194===e)t=!1;else if(195===e)t=!0;else if(202===e)t=this.readF32();else if(203===e)t=this.readF64();else if(204===e)t=this.readU8();else if(205===e)t=this.readU16();else if(206===e)t=this.readU32();else if(207===e)t=this.useBigInt64?this.readU64AsBigInt():this.readU64();else if(208===e)t=this.readI8();else if(209===e)t=this.readI16();else if(210===e)t=this.readI32();else if(211===e)t=this.useBigInt64?this.readI64AsBigInt():this.readI64();else if(217===e){const e=this.lookU8();t=this.decodeString(e,1)}else if(218===e){const e=this.lookU16();t=this.decodeString(e,2)}else if(219===e){const e=this.lookU32();t=this.decodeString(e,4)}else if(220===e){const e=this.readU16();if(0!==e){this.pushArrayState(e),this.complete();continue e}t=[]}else if(221===e){const e=this.readU32();if(0!==e){this.pushArrayState(e),this.complete();continue e}t=[]}else if(222===e){const e=this.readU16();if(0!==e){this.pushMapState(e),this.complete();continue e}t={}}else if(223===e){const e=this.readU32();if(0!==e){this.pushMapState(e),this.complete();continue e}t={}}else if(196===e){const e=this.lookU8();t=this.decodeBinary(e,1)}else if(197===e){const e=this.lookU16();t=this.decodeBinary(e,2)}else if(198===e){const e=this.lookU32();t=this.decodeBinary(e,4)}else if(212===e)t=this.decodeExtension(1,0);else if(213===e)t=this.decodeExtension(2,0);else if(214===e)t=this.decodeExtension(4,0);else if(215===e)t=this.decodeExtension(8,0);else if(216===e)t=this.decodeExtension(16,0);else if(199===e){const e=this.lookU8();t=this.decodeExtension(e,1)}else if(200===e){const e=this.lookU16();t=this.decodeExtension(e,2)}else{if(201!==e)throw new P(`Unrecognized type byte: ${_(e)}`);{const e=this.lookU32();t=this.decodeExtension(e,4)}}this.complete();const o=this.stack;for(;o.length>0;){const e=o.top();if(e.type===$){if(e.array[e.position]=t,e.position++,e.position!==e.size)continue e;t=e.array,o.release(e)}else{if(e.type===G){if("__proto__"===t)throw new P("The key __proto__ is not allowed");e.key=this.mapKeyConverter(t),e.type=J;continue e}if(e.map[e.key]=t,e.readCount++,e.readCount!==e.size){e.key=null,e.type=G;continue e}t=e.map,o.release(e)}}return t}}readHeadByte(){return-1===this.headByte&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=-1}readArraySize(){const e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:if(e<160)return e-144;throw new P(`Unrecognized array type byte: ${_(e)}`)}}pushMapState(e){if(e>this.maxMapLength)throw new P(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new P(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,t){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(e,t):this.decodeBinary(e,t)}decodeUtf8String(e,t){if(e>this.maxStrLength)throw new P(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+e)throw Q;const o=this.pos+t;let r;return r=this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?this.keyDecoder.decode(this.bytes,o,e):U(this.bytes,o,e),this.pos+=t+e,r}stateIsMapKey(){if(this.stack.length>0){return this.stack.top().type===G}return!1}decodeBinary(e,t){if(e>this.maxBinLength)throw new P(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+t))throw Q;const o=this.pos+t,r=this.bytes.subarray(o,o+e);return this.pos+=t+e,r}decodeExtension(e,t){if(e>this.maxExtLength)throw new P(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);const o=this.view.getInt8(this.pos+t),r=this.decodeBinary(e,t+1);return this.extensionCodec.decode(r,o,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){const e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){const e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){const e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){const e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){const e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){const e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){const e=(t=this.view,o=this.pos,4294967296*t.getUint32(o)+t.getUint32(o+4));var t,o;return this.pos+=8,e}readI64(){const e=O(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){const e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){const e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){const e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){const e=this.view.getFloat64(this.pos);return this.pos+=8,e}}function te(e,t){return new ee(t).decode(e)}var oe,re=function(){function e(){}return e.validate=function(e){var t=[],o=[];if(e.version||t.push("Missing version field"),e.metadata&&e.metadata.name||t.push("Missing or invalid metadata"),e.rootNodeId||t.push("Missing rootNodeId"),e.nodes&&Array.isArray(e.nodes)){var r=new Set;e.nodes.find((function(t){return t.id===e.rootNodeId}))||t.push("Root node '"+e.rootNodeId+"' not found in nodes array");for(var n,i=c(e.nodes);!(n=i()).done;){var s=n.value;if(s.id){if(r.has(s.id)&&t.push("Duplicate node id: "+s.id),r.add(s.id),s.nodeType||t.push("Node "+s.id+" missing nodeType"),s.children)for(var a,d=function(){var o=a.value;e.nodes.find((function(e){return e.id===o}))||t.push("Node "+s.id+" references non-existent child: "+o)},u=c(s.children);!(a=u()).done;)d()}else t.push("Node missing id field")}var p=new Set([e.rootNodeId]),l=function(t){var o=e.nodes.find((function(e){return e.id===t}));if(o&&o.children)for(var r,n=c(o.children);!(r=n()).done;){var i=r.value;p.add(i),l(i)}};l(e.rootNodeId);for(var h,f=c(e.nodes);!(h=f()).done;){var v=h.value;p.has(v.id)||o.push("Orphaned node detected: "+v.id+" ("+v.name+")")}}else t.push("Missing or invalid nodes array");if(e.blackboard&&Array.isArray(e.blackboard))for(var y,m=new Set,g=c(e.blackboard);!(y=g()).done;){var x=y.value;x.name?(m.has(x.name)&&t.push("Duplicate blackboard variable: "+x.name),m.add(x.name),x.type||t.push("Blackboard variable "+x.name+" missing type")):t.push("Blackboard variable missing name")}if(e.propertyBindings&&Array.isArray(e.propertyBindings))for(var b,C,T=new Set(e.nodes.map((function(e){return e.id}))),S=new Set((null===(b=e.blackboard)||void 0===b?void 0:b.map((function(e){return e.name})))||[]),N=c(e.propertyBindings);!(C=N()).done;){var w=C.value;T.has(w.nodeId)||t.push("Property binding references non-existent node: "+w.nodeId),S.has(w.variableName)||t.push("Property binding references non-existent variable: "+w.variableName),w.propertyName||t.push("Property binding missing propertyName")}return{valid:0===t.length,errors:t.length>0?t:void 0,warnings:o.length>0?o:void 0}},e.getStats=function(e){for(var t,o,r,n=0,i=0,s=0,a=0,d=c(e.nodes);!(r=d()).done;){switch(r.value.nodeType){case exports.NodeType.Action:n++;break;case exports.NodeType.Condition:i++;break;case exports.NodeType.Composite:s++;break;case exports.NodeType.Decorator:a++}}var u=function(t,o){void 0===o&&(o=0);var r=e.nodes.find((function(e){return e.id===t}));if(!r||!r.children||0===r.children.length)return o;for(var n,i=o,s=c(r.children);!(n=s()).done;){var a=n.value,d=u(a,o+1);i=Math.max(i,d)}return i};return{nodeCount:e.nodes.length,actionCount:n,conditionCount:i,compositeCount:s,decoratorCount:a,blackboardVariableCount:(null===(t=e.blackboard)||void 0===t?void 0:t.length)||0,propertyBindingCount:(null===(o=e.propertyBindings)||void 0===o?void 0:o.length)||0,maxDepth:u(e.rootNodeId)}},e}(),ne=s.createLogger("EditorFormatConverter"),ie=function(){function e(){}return e.toAsset=function(e,t){var o,r,n;ne.info("开始转换编辑器格式到资产格式");var i=this.findRootNode(e.nodes);if(!i)throw new Error("未找到根节点");var s={name:(null==t?void 0:t.name)||(null===(o=e.metadata)||void 0===o?void 0:o.name)||"Untitled Behavior Tree",description:(null==t?void 0:t.description)||(null===(r=e.metadata)||void 0===r?void 0:r.description),version:(null==t?void 0:t.version)||e.version||"1.0.0",createdAt:(null==t?void 0:t.createdAt)||(null===(n=e.metadata)||void 0===n?void 0:n.createdAt),modifiedAt:(null==t?void 0:t.modifiedAt)||(new Date).toISOString()},a=this.convertNodes(e.nodes),d=this.convertBlackboard(e.blackboard),u=this.convertPropertyBindings(e.connections,e.nodes,d),c={version:"1.0.0",metadata:s,rootNodeId:i.id,nodes:a,blackboard:d,propertyBindings:u.length>0?u:void 0};return ne.info("转换完成: "+a.length+"个节点, "+d.length+"个黑板变量, "+u.length+"个属性绑定"),c},e.findRootNode=function(e){return e.find((function(e){return"根节点"===e.template.category||"root"===e.data.nodeType}))||null},e.convertNodes=function(e){var t=this;return e.map((function(e){return t.convertNode(e)}))},e.convertNode=function(e){var t=p({},e.data);return delete t.nodeType,{id:e.id,name:e.template.displayName||e.data.name||"Node",nodeType:e.template.type,data:t,children:e.children||[]}},e.convertBlackboard=function(e){for(var t=[],o=0,r=Object.entries(e);o<r.length;o++){var n=r[o],i=n[0],s=n[1],a=this.inferBlackboardType(s);t.push({name:i,type:a,defaultValue:s})}return t},e.inferBlackboardType=function(e){return"number"==typeof e?exports.BlackboardValueType.Number:"string"==typeof e?exports.BlackboardValueType.String:"boolean"==typeof e?exports.BlackboardValueType.Boolean:exports.BlackboardValueType.Object},e.convertPropertyBindings=function(e,t,o){for(var r,n=[],i=new Set(o.map((function(e){return e.name}))),s=function(){var e,o=r.value,s=t.find((function(e){return e.id===o.from})),a=t.find((function(e){return e.id===o.to}));return s&&a&&o.toProperty?("blackboard-variable"===s.data.nodeType?e=s.data.variableName:o.fromProperty&&(e=o.fromProperty),e?i.has(e)?void n.push({nodeId:a.id,propertyName:o.toProperty,variableName:e}):(ne.warn("属性绑定引用了不存在的黑板变量: "+e),0):(ne.warn("无法确定变量名: from节点="+s.template.displayName),0)):(ne.warn("跳过无效的属性连接: from="+o.from+", to="+o.to),0)},a=c(e.filter((function(e){return"property"===e.connectionType})));!(r=a()).done;)s();return n},e.fromAsset=function(e){ne.info("开始转换资产格式到编辑器格式");for(var t,o=this.convertNodesFromAsset(e.nodes),r={},n=c(e.blackboard);!(t=n()).done;){var i=t.value;r[i.name]=i.defaultValue}var s=this.convertPropertyBindingsToConnections(e.propertyBindings||[],e.nodes),a=this.buildNodeConnections(e.nodes);s.push.apply(s,a);var d={version:e.metadata.version,metadata:{name:e.metadata.name,description:e.metadata.description,createdAt:e.metadata.createdAt,modifiedAt:e.metadata.modifiedAt},nodes:o,connections:s,blackboard:r,canvasState:{offset:{x:0,y:0},scale:1}};return ne.info("转换完成: "+o.length+"个节点, "+s.length+"个连接"),d},e.convertNodesFromAsset=function(e){var t=this;return e.map((function(e,o){var r={x:100+o%5*250,y:100+150*Math.floor(o/5)};return{id:e.id,template:{displayName:e.name,category:t.inferCategory(e.nodeType),type:e.nodeType},data:p({},e.data),position:r,children:e.children}}))},e.inferCategory=function(e){switch(e){case exports.NodeType.Action:return"动作";case exports.NodeType.Condition:return"条件";case exports.NodeType.Composite:return"组合";case exports.NodeType.Decorator:return"装饰器";default:return"其他"}},e.convertPropertyBindingsToConnections=function(e,t){for(var o,r=[],n=c(e);!(o=n()).done;){var i=o.value;r.push({from:"blackboard",to:i.nodeId,toProperty:i.propertyName,connectionType:"property"})}return r},e.buildNodeConnections=function(e){for(var t,o=[],r=c(e);!(t=r()).done;)for(var n,i=t.value,s=c(i.children);!(n=s()).done;){var a=n.value;o.push({from:i.id,to:a,connectionType:"node"})}return o},e}(),se=s.createLogger("BehaviorTreeAssetSerializer"),ae=function(){function e(){}return e.serialize=function(e,t){if(void 0===t&&(t={format:"json",pretty:!0}),!1!==t.validate){var o=re.validate(e);if(!o.valid){var r,n=(null===(r=o.errors)||void 0===r?void 0:r.join(", "))||"Unknown error";throw new Error("资产验证失败: "+n)}o.warnings&&o.warnings.length>0&&se.warn("资产验证警告: "+o.warnings.join(", "))}return"json"===t.format?this.serializeToJSON(e,t.pretty):this.serializeToBinary(e)},e.serializeToJSON=function(e,t){void 0===t&&(t=!0);try{var o=t?JSON.stringify(e,null,2):JSON.stringify(e);return se.info("已序列化为JSON: "+o.length+" 字符"),o}catch(e){throw new Error("JSON序列化失败: "+e)}},e.serializeToBinary=function(e){try{var t=(o=e,new W(r).encodeSharedRef(o));return se.info("已序列化为二进制: "+t.length+" 字节"),t}catch(e){throw new Error("二进制序列化失败: "+e)}var o,r},e.deserialize=function(e,t){var o;void 0===t&&(t={validate:!0,strict:!0});try{o="string"==typeof e?this.deserializeFromJSON(e):this.deserializeFromBinary(e)}catch(e){throw new Error("反序列化失败: "+e)}if(!1!==t.validate){var r=re.validate(o);if(!r.valid){var n,i=(null===(n=r.errors)||void 0===n?void 0:n.join(", "))||"Unknown error";if(t.strict)throw new Error("资产验证失败: "+i);se.error("资产验证失败: "+i)}r.warnings&&r.warnings.length>0&&se.warn("资产验证警告: "+r.warnings.join(", "))}return o},e.deserializeFromJSON=function(e){try{var t=JSON.parse(e);if(!t.rootNodeId&&t.nodes&&t.connections){se.info("检测到编辑器格式,正在转换为运行时资产格式...");var o=t,r=ie.toAsset(o);return se.info("已从编辑器格式转换: "+r.nodes.length+" 个节点"),r}var n=t;return se.info("已从运行时资产格式反序列化: "+n.nodes.length+" 个节点"),n}catch(e){throw new Error("JSON解析失败: "+e)}},e.deserializeFromBinary=function(e){try{var t=te(e);return se.info("已从二进制反序列化: "+t.nodes.length+" 个节点"),t}catch(e){throw new Error("二进制解码失败: "+e)}},e.detectFormat=function(e){return"string"==typeof e?"json":"binary"},e.getInfo=function(e){try{var t,o=this.detectFormat(e);t="json"===o?JSON.parse(e):te(e);var r=e.length;return{format:o,name:t.metadata.name,version:t.version,nodeCount:t.nodes.length,blackboardVariableCount:t.blackboard.length,size:r}}catch(e){return se.error("获取资产信息失败: "+e),null}},e.convert=function(e,t,o){void 0===o&&(o=!0);var r=this.deserialize(e,{validate:!1});return this.serialize(r,{format:t,pretty:o,validate:!1})},e.compareSize=function(e,t){var o=e.length,r=t.length,n=o-r;return{jsonSize:o,binarySize:r,compressionRatio:n/o*100,savedBytes:n}},e}(),de=s.createLogger("FileSystemAssetLoader"),ue=function(){function e(e){var t;this.cache=new Map,this.config={basePath:e.basePath,format:e.format,extension:e.extension||("json"===e.format?".btree.json":".btree.bin"),enableCache:null===(t=e.enableCache)||void 0===t||t,readFile:e.readFile||this.defaultReadFile.bind(this)},this.config.basePath=this.config.basePath.replace(/\\/g,"/").replace(/\/$/,"")}var t=e.prototype;return t.loadBehaviorTree=function(){var e=u(v().m((function e(t){var o,r,n,i,s;return v().w((function(e){for(;;)switch(e.p=e.n){case 0:if(!this.config.enableCache||!this.cache.has(t)){e.n=1;break}return de.debug("从缓存加载资产: "+t),e.a(2,this.cache.get(t));case 1:return de.info("加载行为树资产: "+t),e.p=2,o=this.resolveAssetPath(t),e.n=3,this.config.readFile(o);case 3:return r=e.v,n={validate:!0,strict:!0},i=ae.deserialize(r,n),this.config.enableCache&&this.cache.set(t,i),de.info("成功加载资产: "+t),e.a(2,i);case 4:throw e.p=4,s=e.v,de.error("加载资产失败: "+t,s),new Error("Failed to load behavior tree asset '"+t+"': "+s);case 5:return e.a(2)}}),e,this,[[2,4]])})));return function(t){return e.apply(this,arguments)}}(),t.exists=function(){var e=u(v().m((function e(t){var o;return v().w((function(e){for(;;)switch(e.p=e.n){case 0:if(!this.config.enableCache||!this.cache.has(t)){e.n=1;break}return e.a(2,!0);case 1:return e.p=1,o=this.resolveAssetPath(t),e.n=2,this.config.readFile(o);case 2:return e.a(2,!0);case 3:return e.p=3,e.v,e.a(2,!1)}}),e,this,[[1,3]])})));return function(t){return e.apply(this,arguments)}}(),t.preload=function(){var e=u(v().m((function e(t){var o,r=this;return v().w((function(e){for(;;)switch(e.n){case 0:return de.info("预加载 "+t.length+" 个资产..."),o=t.map((function(e){return r.loadBehaviorTree(e).catch((function(t){de.warn("预加载资产失败: "+e,t)}))})),e.n=1,Promise.all(o);case 1:de.info("预加载完成");case 2:return e.a(2)}}),e)})));return function(t){return e.apply(this,arguments)}}(),t.unload=function(e){this.cache.has(e)&&(this.cache.delete(e),de.debug("卸载资产: "+e))},t.clearCache=function(){this.cache.clear(),de.info("缓存已清空")},t.getCacheSize=function(){return this.cache.size},t.dispose=function(){this.clearCache()},t.resolveAssetPath=function(e){var t=e.replace(/^\/+/,"");return this.config.basePath+"/"+t+this.config.extension},t.defaultReadFile=function(){var e=u(v().m((function e(t){var o,r,n,i,s;return v().w((function(e){for(;;)switch(e.p=e.n){case 0:if("undefined"==typeof window||"undefined"==typeof fetch){e.n=7;break}return e.n=1,fetch(t);case 1:if((o=e.v).ok){e.n=2;break}throw new Error("HTTP "+o.status+": "+o.statusText);case 2:if("binary"!==this.config.format){e.n=4;break}return e.n=3,o.arrayBuffer();case 3:return r=e.v,e.a(2,new Uint8Array(r));case 4:return e.n=5,o.text();case 5:case 11:return e.a(2,e.v);case 6:case 14:e.n=16;break;case 7:if("undefined"==typeof require){e.n=15;break}if(e.p=8,n=require("fs").promises,"binary"!==this.config.format){e.n=10;break}return e.n=9,n.readFile(t);case 9:return i=e.v,e.a(2,new Uint8Array(i));case 10:return e.n=11,n.readFile(t,"utf-8");case 12:e.n=14;break;case 13:throw e.p=13,s=e.v,new Error("Failed to read file '"+t+"': "+s);case 15:throw new Error("No default file reading implementation available. Please provide a custom readFile function in the config.");case 16:return e.a(2)}}),e,this,[[8,13]])})));return function(t){return e.apply(this,arguments)}}(),e}(),ce=s.createLogger("BehaviorTreeAssetLoader"),pe=function(){function e(){}return e.instantiate=function(e,t,o){void 0===o&&(o={}),ce.info("开始实例化行为树: "+e.metadata.name);for(var r,n=new Map,i=c(e.nodes);!(r=i()).done;){var s=r.value;n.set(s.id,s)}var a=n.get(e.rootNodeId);if(!a)throw new Error("未找到根节点: "+e.rootNodeId);var d=new Map,u=this.createEntityTree(a,n,d,t,o.namePrefix,o.asSubTree);return this.setupBlackboard(u,e.blackboard,o.blackboardOverrides),e.propertyBindings&&e.propertyBindings.length>0&&this.setupPropertyBindings(e.propertyBindings,d),ce.info("行为树实例化完成: "+e.nodes.length+" 个节点"),u},e.createEntityTree=function(e,t,o,r,n,i,s){void 0===s&&(s=!0);var a=n?n+"_"+e.name:e.name,d=r.createEntity(a);o.set(e.id,d);var u=d.addComponent(new exports.BehaviorTreeNode);u.nodeType=e.nodeType,u.nodeName=e.name,this.addNodeComponents(d,e,i&&s);for(var p,l=c(e.children);!(p=l()).done;){var h=p.value,f=t.get(h);if(f){var v=this.createEntityTree(f,t,o,r,n,i,!1);d.addChild(v)}else ce.warn("子节点未找到: "+h)}return d},e.addNodeComponents=function(e,t,o){void 0===o&&(o=!1);var r=t.nodeType,n=t.data,i=t.name;ce.debug("addNodeComponents: name="+i+", data.nodeType="+n.nodeType+", skipRootNode="+o),"root"===n.nodeType||"根节点"===i||"Root"===i?o?(ce.debug("跳过为子树根节点添加 RootNode: "+i),this.addCompositeComponent(e,"序列",n)):(ce.debug("添加 RootNode 组件: "+i),e.addComponent(new exports.RootNode)):r===exports.NodeType.Composite?this.addCompositeComponent(e,i,n):r===exports.NodeType.Decorator?this.addDecoratorComponent(e,i,n):r===exports.NodeType.Action?this.addActionComponent(e,i,n):r===exports.NodeType.Condition&&this.addConditionComponent(e,i,n)},e.addCompositeComponent=function(e,t,o){var r,n=t.toLowerCase();if(n.includes("sequence")||n.includes("序列"))e.addComponent(new exports.SequenceNode).abortType=null!==(r=o.abortType)&&void 0!==r?r:exports.AbortType.None;else if(n.includes("selector")||n.includes("选择")){var i;e.addComponent(new exports.SelectorNode).abortType=null!==(i=o.abortType)&&void 0!==i?i:exports.AbortType.None}else if(n.includes("parallelselector")||n.includes("并行选择")){var s;e.addComponent(new exports.ParallelSelectorNode).failurePolicy=null!==(s=o.failurePolicy)&&void 0!==s?s:"one"}else if(n.includes("parallel")||n.includes("并行")){var a,d,u=e.addComponent(new exports.ParallelNode);u.successPolicy=null!==(a=o.successPolicy)&&void 0!==a?a:"all",u.failurePolicy=null!==(d=o.failurePolicy)&&void 0!==d?d:"one"}else n.includes("randomsequence")||n.includes("随机序列")?e.addComponent(new exports.RandomSequenceNode):n.includes("randomselector")||n.includes("随机选择")?e.addComponent(new exports.RandomSelectorNode):ce.warn("未知的组合节点类型: "+t)},e.addDecoratorComponent=function(e,t,o){var r=t.toLowerCase();if(r.includes("inverter")||r.includes("反转"))e.addComponent(new exports.InverterNode);else if(r.includes("repeater")||r.includes("重复")){var n,i,s=e.addComponent(new exports.RepeaterNode);s.repeatCount=null!==(n=o.repeatCount)&&void 0!==n?n:-1,s.endOnFailure=null!==(i=o.endOnFailure)&&void 0!==i&&i}else if(r.includes("untilsuccess")||r.includes("直到成功"))e.addComponent(new exports.UntilSuccessNode);else if(r.includes("untilfail")||r.includes("直到失败"))e.addComponent(new exports.UntilFailNode);else if(r.includes("alwayssucceed")||r.includes("总是成功"))e.addComponent(new exports.AlwaysSucceedNode);else if(r.includes("alwaysfail")||r.includes("总是失败"))e.addComponent(new exports.AlwaysFailNode);else if(r.includes("conditional")||r.includes("条件装饰")){var a,d,u=e.addComponent(new exports.ConditionalNode);u.conditionCode=null!==(a=o.conditionCode)&&void 0!==a?a:"",u.shouldReevaluate=null===(d=o.shouldReevaluate)||void 0===d||d}else if(r.includes("cooldown")||r.includes("冷却")){var c;e.addComponent(new exports.CooldownNode).cooldownTime=null!==(c=o.cooldownTime)&&void 0!==c?c:1}else if(r.includes("timeout")||r.includes("超时")){var p;e.addComponent(new exports.TimeoutNode).timeoutDuration=null!==(p=o.timeoutDuration)&&void 0!==p?p:1}else ce.warn("未知的装饰器类型: "+t)},e.addActionComponent=function(e,t,o){var r,n=t.toLowerCase();if(n.includes("wait")||n.includes("等待"))e.addComponent(new exports.WaitAction).waitTime=null!==(r=o.waitTime)&&void 0!==r?r:1;else if(n.includes("log")||n.includes("日志")){var i,s,a=e.addComponent(new exports.LogAction);a.message=null!==(i=o.message)&&void 0!==i?i:"",a.level=null!==(s=o.level)&&void 0!==s?s:"log"}else if(n.includes("setblackboard")||n.includes("setvalue")||n.includes("设置变量")){var d,u=e.addComponent(new exports.SetBlackboardValueAction);u.variableName=null!==(d=o.variableName)&&void 0!==d?d:"",u.value=o.value}else if(n.includes("modifyblackboard")||n.includes("modifyvalue")||n.includes("修改变量")){var c,p,l,h=e.addComponent(new exports.ModifyBlackboardValueAction);h.variableName=null!==(c=o.variableName)&&void 0!==c?c:"",h.operation=null!==(p=o.operation)&&void 0!==p?p:"add",h.operand=null!==(l=o.operand)&&void 0!==l?l:0}else if(n.includes("execute")||n.includes("自定义")){var f;e.addComponent(new exports.ExecuteAction).actionCode=null!==(f=o.actionCode)&&void 0!==f?f:"return TaskStatus.Success;"}else ce.warn("未知的动作类型: "+t)},e.addConditionComponent=function(e,t,o){var r=t.toLowerCase();if(r.includes("compare")||r.includes("比较变量")){var n,i,s,a=e.addComponent(new exports.BlackboardCompareCondition);a.variableName=null!==(n=o.variableName)&&void 0!==n?n:"",a.operator=null!==(i=o.operator)&&void 0!==i?i:exports.CompareOperator.Equal,a.compareValue=o.compareValue,a.invertResult=null!==(s=o.invertResult)&&void 0!==s&&s}else if(r.includes("exists")||r.includes("变量存在")){var d,u,c,p=e.addComponent(new exports.BlackboardExistsCondition);p.variableName=null!==(d=o.variableName)&&void 0!==d?d:"",p.checkNotNull=null!==(u=o.checkNotNull)&&void 0!==u&&u,p.invertResult=null!==(c=o.invertResult)&&void 0!==c&&c}else if(r.includes("random")||r.includes("概率")){var l;e.addComponent(new exports.RandomProbabilityCondition).probability=null!==(l=o.probability)&&void 0!==l?l:.5}else if(r.includes("execute")||r.includes("执行条件")){var h,f,v=e.addComponent(new exports.ExecuteCondition);v.conditionCode=null!==(h=o.conditionCode)&&void 0!==h?h:"",v.invertResult=null!==(f=o.invertResult)&&void 0!==f&&f}else ce.warn("未知的条件类型: "+t)},e.setupBlackboard=function(e,t,o){for(var r,n=e.addComponent(new exports.BlackboardComponent),i=c(t);!(r=i()).done;){var s=r.value,a=o&&void 0!==o[s.name]?o[s.name]:s.defaultValue;n.defineVariable(s.name,s.type,a,{readonly:s.readonly,description:s.description})}ce.info("已设置黑板: "+t.length+" 个变量")},e.setupPropertyBindings=function(e,t){for(var o,r=c(e);!(o=r()).done;){var n=o.value,i=t.get(n.nodeId);if(i){var s=i.getComponent(E);s||(s=i.addComponent(new E)),s.addBinding(n.propertyName,n.variableName)}else ce.warn("属性绑定引用的节点不存在: "+n.nodeId)}ce.info("已设置属性绑定: "+e.length+" 个绑定")},e}();!function(e){e[e.NotStarted=0]="NotStarted",e[e.Loading=1]="Loading",e[e.Completed=2]="Completed",e[e.Failed=3]="Failed"}(oe||(oe={}));var le,he=function(e){function t(){var t;return(t=e.call(this,s.Matcher.empty().all(exports.BehaviorTreeNode,exports.ActiveNode))||this).preloadStates=new Map,t.preloadTasks=new Map,t.updateOrder=350,t}h(t,e);var o=t.prototype;return o.process=function(e){for(var t,o=c(e);!(t=o()).done;){var r=t.value,n=r.getComponent(exports.BehaviorTreeNode);n.nodeType===exports.NodeType.Composite&&(r.hasComponent(exports.RootNode)&&this.executeRoot(r,n))}},o.executeRoot=function(e,t){var o=this.preloadStates.get(e.id)||oe.NotStarted;if(o!==oe.NotStarted)if(o!==oe.Loading){if(o===oe.Failed)return t.status=exports.TaskStatus.Failure,void e.removeComponentByType(exports.ActiveNode);var r=e.children;if(0!==r.length){var n=r[0],i=n.getComponent(exports.BehaviorTreeNode);if(i)return n.hasComponent(exports.ActiveNode)?void(i.status===exports.TaskStatus.Running?t.status=exports.TaskStatus.Running:i.status===exports.TaskStatus.Success?(t.status=exports.TaskStatus.Success,e.removeComponentByType(exports.ActiveNode)):i.status===exports.TaskStatus.Failure&&(t.status=exports.TaskStatus.Failure,e.removeComponentByType(exports.ActiveNode))):(n.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running));t.status=exports.TaskStatus.Failure}else t.status=exports.TaskStatus.Success}else t.status=exports.TaskStatus.Running;else this.startPreload(e,t)},o.startPreload=function(e,t){var o=this,r=this.scanSubTreeNodes(e);if(0===r.length)return this.preloadStates.set(e.id,oe.Completed),void this.outputLog(e,"没有需要预加载的子树","info");this.preloadStates.set(e.id,oe.Loading),t.status=exports.TaskStatus.Running,this.outputLog(e,"开始预加载 "+r.length+" 个子树...","info");var n=this.preloadAllSubTrees(e,r);this.preloadTasks.set(e.id,n),n.then((function(){o.preloadStates.set(e.id,oe.Completed),o.outputLog(e,"所有子树预加载完成","info")})).catch((function(t){o.preloadStates.set(e.id,oe.Failed),o.outputLog(e,"子树预加载失败: "+t.message,"error")}))},o.scanSubTreeNodes=function(e){var t=[],o=e.getComponent(exports.SubTreeNode);o&&o.preload&&t.push({entity:e,subTree:o});for(var r,n=c(e.children);!(r=n()).done;){var i=r.value;t.push.apply(t,this.scanSubTreeNodes(i))}return t},o.preloadAllSubTrees=function(){var e=u(v().m((function e(t,o){var r=this;return v().w((function(e){for(;;)switch(e.p=e.n){case 0:if(this.assetLoader){e.n=3;break}e.p=1,this.assetLoader=s.Core.services.resolve(ue),e.n=3;break;case 2:throw e.p=2,e.v,new Error("AssetLoader 未配置,无法预加载子树");case 3:return e.n=4,Promise.all(o.map((function(e){var o=e.entity,n=e.subTree;return r.preloadSingleSubTree(t,o,n)})));case 4:return e.a(2)}}),e,this,[[1,2]])})));return function(t,o){return e.apply(this,arguments)}}(),o.preloadSingleSubTree=function(){var e=u(v().m((function e(t,o,r){var n,i,s;return v().w((function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,this.outputLog(t,"预加载子树: "+r.assetId,"info"),e.n=1,this.assetLoader.loadBehaviorTree(r.assetId);case 1:n=e.v,i=pe.instantiate(n,this.scene,{asSubTree:!0}),r.setSubTreeRoot(i),o.addChild(i),i.addComponent(new exports.BehaviorTreeAssetMetadata).initialize(r.assetId,"1.0.0"),r.inheritParentBlackboard&&this.setupBlackboardInheritance(o,i),this.outputLog(t,"=== 预加载子树 "+r.assetId+" 的内部结构 ===","info"),this.logSubTreeStructure(t,i,0),this.outputLog(t,"=== 预加载子树结构结束 ===","info"),this.outputLog(t,"✓ 子树 "+r.assetId+" 预加载完成","info"),e.n=3;break;case 2:throw e.p=2,s=e.v,this.outputLog(t,"✗ 子树 "+r.assetId+" 预加载失败: "+s.message,"error"),s;case 3:return e.a(2)}}),e,this,[[0,2]])})));return function(t,o,r){return e.apply(this,arguments)}}(),o.setupBlackboardInheritance=function(e,t){if(this.findBlackboard(e)){var o=t.getComponent(exports.BlackboardComponent);o&&o.setUseGlobalBlackboard(!0)}},o.findBlackboard=function(e){for(var t=e;t;){var o=t.getComponent(exports.BlackboardComponent);if(o)return o;t=t.parent}},o.findRootEntity=function(e){for(var t=e;t;){if(!t.parent)return t;t=t.parent}return null},o.outputLog=function(e,t,o){switch(void 0===o&&(o="info"),o){case"info":default:this.logger.info(t);break;case"warn":this.logger.warn(t);break;case"error":this.logger.error(t)}var r=this.findRootEntity(e);if(r){var n=r.getComponent(exports.LogOutput);n&&n.addMessage(t,o)}},o.logSubTreeStructure=function(e,t,o){var r=this,n=" ".repeat(o);t.getComponent(exports.BehaviorTreeNode);var i=t.components.map((function(e){return e.constructor.name})).find((function(e){return"BehaviorTreeNode"!==e&&"ActiveNode"!==e&&"BlackboardComponent"!==e&&"LogOutput"!==e&&"PropertyBindings"!==e&&"BehaviorTreeAssetMetadata"!==e}))||"Unknown",s=t.name;"Unknown"!==i&&(s=s+" ["+i+"]"),this.outputLog(e,n+"└─ "+s,"info"),t.children.length>0&&(this.outputLog(e,n+" 子节点数: "+t.children.length,"info"),t.children.forEach((function(t){r.logSubTreeStructure(e,t,o+1)})))},o.onDestroy=function(){this.preloadStates.clear(),this.preloadTasks.clear(),e.prototype.onDestroy.call(this)},o.getLoggerName=function(){return"RootExecutionSystem"},t}(s.EntitySystem),fe=function(e){function t(){var t;return(t=e.call(this,s.Matcher.empty().all(exports.BehaviorTreeNode,exports.ActiveNode))||this).updateOrder=100,t}h(t,e);var o=t.prototype;return o.process=function(e){for(var t,o=c(e);!(t=o()).done;){var r=t.value,n=r.getComponent(exports.BehaviorTreeNode);n.nodeType===exports.NodeType.Action?this.executeAction(r,n):n.nodeType===exports.NodeType.Condition&&this.executeCondition(r,n)}},o.executeAction=function(e,t){var o=exports.TaskStatus.Failure,r=this.getNodeInfo(e),n=r.displayName,i=r.nodeIdShort;e.hasComponent(exports.WaitAction)?o=this.executeWaitAction(e):e.hasComponent(exports.LogAction)?o=this.executeLogAction(e):e.hasComponent(exports.SetBlackboardValueAction)?o=this.executeSetBlackboardValue(e):e.hasComponent(exports.ModifyBlackboardValueAction)?o=this.executeModifyBlackboardValue(e):e.hasComponent(exports.ExecuteAction)?o=this.executeCustomAction(e):this.outputLog(e,"动作节点没有找到任何已知的动作组件","warn"),t.status=o;var s=o===exports.TaskStatus.Success?"Success":o===exports.TaskStatus.Failure?"Failure":o===exports.TaskStatus.Running?"Running":"Unknown";o!==exports.TaskStatus.Running&&this.outputLog(e,"["+n+"#"+i+"] 执行完成 -> "+s,o===exports.TaskStatus.Success?"info":"warn"),o!==exports.TaskStatus.Running&&(this.deactivateNode(e),this.notifyParent(e))},o.executeWaitAction=function(e){var t=e.getComponent(exports.WaitAction);e.getComponent(exports.BehaviorTreeNode);var o=this.getNodeInfo(e),r=o.displayName,n=o.nodeIdShort,i=this.resolvePropertyValue(e,"waitTime",t.waitTime);return t.elapsedTime+=s.Time.deltaTime,this.outputLog(e,"["+r+"#"+n+"] deltaTime="+s.Time.deltaTime.toFixed(3)+"s, elapsed="+t.elapsedTime.toFixed(3)+"s/"+i.toFixed(3)+"s","info"),t.elapsedTime>=i?(t.reset(),this.outputLog(e,"["+r+"#"+n+"] 等待完成,返回成功","info"),exports.TaskStatus.Success):exports.TaskStatus.Running},o.executeLogAction=function(e){var t=e.getComponent(exports.LogAction),o=e.getComponent(exports.BehaviorTreeNode),r=this.resolvePropertyValue(e,"message",t.message),n=this.getNodeInfo(e),i=n.displayName,s=n.nodeIdShort;switch(o&&(r="["+i+"#"+s+"] "+r),t.includeEntityInfo&&(r="[Entity: "+e.name+"] "+r),t.level){case"info":console.info(r);break;case"warn":console.warn(r);break;case"error":console.error(r);break;default:console.log(r)}var a=this.findRootEntity(e);if(a){var d=a.getComponent(exports.LogOutput);d&&d.addMessage(r,t.level)}return exports.TaskStatus.Success},o.findRootEntity=function(e){for(var t=e;t;){if(!t.parent)return t;t=t.parent}return null},o.executeSetBlackboardValue=function(e){var t,o=e.getComponent(exports.SetBlackboardValueAction),r=this.findBlackboard(e);if(!r)return this.outputLog(e,"未找到黑板组件","warn"),exports.TaskStatus.Failure;if(o.sourceVariable){if(!r.hasVariable(o.sourceVariable))return this.outputLog(e,"源变量不存在: "+o.sourceVariable,"warn"),exports.TaskStatus.Failure;t=r.getValue(o.sourceVariable)}else t=this.resolvePropertyValue(e,"value",o.value);return r.setValue(o.variableName,t,o.force)?exports.TaskStatus.Success:exports.TaskStatus.Failure},o.executeModifyBlackboardValue=function(e){var t=e.getComponent(exports.ModifyBlackboardValueAction),o=this.findBlackboard(e);if(!o)return this.outputLog(e,"未找到黑板组件","warn"),exports.TaskStatus.Failure;if(!o.hasVariable(t.variableName))return this.outputLog(e,"变量不存在: "+t.variableName,"warn"),exports.TaskStatus.Failure;var r,n=o.getValue(t.variableName),i=this.resolvePropertyValue(e,"operand",t.operand);switch(t.operation){case exports.ModifyOperation.Add:r=Number(n)+Number(i);break;case exports.ModifyOperation.Subtract:r=Number(n)-Number(i);break;case exports.ModifyOperation.Multiply:r=Number(n)*Number(i);break;case exports.ModifyOperation.Divide:if(0===Number(i))return this.outputLog(e,"除数不能为0","warn"),exports.TaskStatus.Failure;r=Number(n)/Number(i);break;case exports.ModifyOperation.Modulo:r=Number(n)%Number(i);break;case exports.ModifyOperation.Append:if(Array.isArray(n))r=[].concat(n,[i]);else{if("string"!=typeof n)return this.outputLog(e,"变量 "+t.variableName+" 不支持 append 操作","warn"),exports.TaskStatus.Failure;r=n+i}break;case exports.ModifyOperation.Remove:if(!Array.isArray(n))return this.outputLog(e,"变量 "+t.variableName+" 不是数组,不支持 remove 操作","warn"),exports.TaskStatus.Failure;r=n.filter((function(e){return e!==i}));break;default:return exports.TaskStatus.Failure}return o.setValue(t.variableName,r,t.force)?exports.TaskStatus.Success:exports.TaskStatus.Failure},o.executeCustomAction=function(e){var t=e.getComponent(exports.ExecuteAction).getFunction();return t?t(e,this.findBlackboard(e),s.Time.deltaTime):exports.TaskStatus.Failure},o.executeCondition=function(e,t){var o=!1,r=this.getNodeInfo(e),n=r.displayName,i=r.nodeIdShort;e.hasComponent(exports.BlackboardCompareCondition)?o=this.evaluateBlackboardCompare(e):e.hasComponent(exports.BlackboardExistsCondition)?o=this.evaluateBlackboardExists(e):e.hasComponent(exports.RandomProbabilityCondition)?o=this.evaluateRandomProbability(e):e.hasComponent(exports.ExecuteCondition)?o=this.evaluateCustomCondition(e):this.outputLog(e,"条件节点没有找到任何已知的条件组件","warn"),t.status=o?exports.TaskStatus.Success:exports.TaskStatus.Failure;var s=o?"Success (true)":"Failure (false)";this.outputLog(e,"["+n+"#"+i+"] 条件评估 -> "+s,o?"info":"warn"),this.deactivateNode(e),this.notifyParent(e)},o.evaluateBlackboardCompare=function(e){var t=e.getComponent(exports.BlackboardCompareCondition),o=this.findBlackboard(e);if(!o||!o.hasVariable(t.variableName))return!1;var r=o.getValue(t.variableName),n=this.resolvePropertyValue(e,"compareValue",t.compareValue),i=!1;switch(t.operator){case exports.CompareOperator.Equal:i=r===n;break;case exports.CompareOperator.NotEqual:i=r!==n;break;case exports.CompareOperator.Greater:i=r>n;break;case exports.CompareOperator.GreaterOrEqual:i=r>=n;break;case exports.CompareOperator.Less:i=r<n;break;case exports.CompareOperator.LessOrEqual:i=r<=n;break;case exports.CompareOperator.Contains:("string"==typeof r||Array.isArray(r))&&(i=r.includes(n));break;case exports.CompareOperator.Matches:if("string"==typeof r&&"string"==typeof n)i=new RegExp(n).test(r)}return t.invertResult?!i:i},o.evaluateBlackboardExists=function(e){var t=e.getComponent(exports.BlackboardExistsCondition),o=this.findBlackboard(e);if(!o)return!1;var r=o.hasVariable(t.variableName);if(r&&t.checkNotNull){var n=o.getValue(t.variableName);r=null!=n}return t.invertResult?!r:r},o.evaluateRandomProbability=function(e){var t=e.getComponent(exports.RandomProbabilityCondition),o=this.resolvePropertyValue(e,"probability",t.probability);return(t.alwaysRandomize||void 0===t.cachedResult)&&(t.cachedResult=Math.random()<o),t.cachedResult},o.evaluateCustomCondition=function(e){var t=e.getComponent(exports.ExecuteCondition),o=t.getFunction();if(!o)return!1;var r=o(e,this.findBlackboard(e),s.Time.deltaTime);return t.invertResult?!r:r},o.resolvePropertyValue=function(e,t,o){var r=e.getComponent(E);if(!r||!r.hasBinding(t))return o;var n=r.getBinding(t),i=this.findBlackboard(e);return i?i.hasVariable(n)?i.getValue(n):(this.outputLog(e,"[属性绑定] 黑板变量不存在: "+n,"warn"),o):(this.outputLog(e,"[属性绑定] 未找到黑板组件,实体: "+e.name,"warn"),o)},o.deactivateNode=function(e){e.removeComponentByType(exports.ActiveNode)},o.notifyParent=function(e){e.parent&&e.parent.hasComponent(exports.BehaviorTreeNode)&&(e.parent.hasComponent(exports.ActiveNode)||e.parent.addComponent(new exports.ActiveNode))},o.findBlackboard=function(e){for(var t=e;t;){var o=t.getComponent(exports.BlackboardComponent);if(o)return o;t=t.parent}},o.getNodeInfo=function(e){var t="Node",o="";if(e.name&&e.name.includes("#")){var r=e.name.split("#");t=r[0],o=r[1]}else o=e.id.toString().substring(0,8);return{displayName:t,nodeIdShort:o}},o.outputLog=function(e,t,o){switch(void 0===o&&(o="info"),o){case"info":default:this.logger.info(t);break;case"warn":this.logger.warn(t);break;case"error":this.logger.error(t)}var r=this.findRootEntity(e);if(r){var n=r.getComponent(exports.LogOutput);n&&n.addMessage(t,o)}},o.getLoggerName=function(){return"LeafExecutionSystem"},t}(s.EntitySystem),ve=function(e){function t(){var t;return(t=e.call(this,s.Matcher.empty().all(exports.BehaviorTreeNode,exports.ActiveNode))||this).updateOrder=200,t}h(t,e);var o=t.prototype;return o.process=function(e){for(var t,o=c(e);!(t=o()).done;){var r=t.value,n=r.getComponent(exports.BehaviorTreeNode);if(n.nodeType===exports.NodeType.Decorator){var i=r.getComponentByType(exports.DecoratorNodeComponent);i&&this.executeDecorator(r,n,i)}}},o.executeDecorator=function(e,t,o){var r=e.children;if(0===r.length)return this.logger.warn("装饰器节点没有子节点"),t.status=exports.TaskStatus.Failure,void this.completeNode(e);var n=r[0],i=n.getComponent(exports.BehaviorTreeNode);if(!i)return t.status=exports.TaskStatus.Failure,void this.completeNode(e);switch(o.decoratorType){case exports.DecoratorType.Inverter:this.handleInverter(e,t,n,i);break;case exports.DecoratorType.Repeater:this.handleRepeater(e,t,o,n,i);break;case exports.DecoratorType.UntilSuccess:this.handleUntilSuccess(e,t,n,i);break;case exports.DecoratorType.UntilFail:this.handleUntilFail(e,t,n,i);break;case exports.DecoratorType.AlwaysSucceed:this.handleAlwaysSucceed(e,t,n,i);break;case exports.DecoratorType.AlwaysFail:this.handleAlwaysFail(e,t,n,i);break;case exports.DecoratorType.Conditional:this.handleConditional(e,t,o,n,i);break;case exports.DecoratorType.Cooldown:this.handleCooldown(e,t,o,n,i);break;case exports.DecoratorType.Timeout:this.handleTimeout(e,t,o,n,i);break;default:t.status=exports.TaskStatus.Failure,this.completeNode(e)}},o.handleInverter=function(e,t,o,r){o.hasComponent(exports.ActiveNode)||o.addComponent(new exports.ActiveNode),t.status=exports.TaskStatus.Running,r.status!==exports.TaskStatus.Success&&r.status!==exports.TaskStatus.Failure||(t.status=r.status===exports.TaskStatus.Success?exports.TaskStatus.Failure:exports.TaskStatus.Success,this.completeNode(e))},o.handleRepeater=function(e,t,o,r,n){var i=o,s=this.resolvePropertyValue(e,"repeatCount",i.repeatCount),a=this.resolvePropertyValue(e,"endOnFailure",i.endOnFailure);if(!r.hasComponent(exports.ActiveNode))return r.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running);if(n.status!==exports.TaskStatus.Running){if(n.status===exports.TaskStatus.Failure&&a)return t.status=exports.TaskStatus.Failure,i.reset(),void this.completeNode(e);i.incrementRepeat(),-1===s||i.currentRepeatCount<s?(n.invalidate(),r.addComponent(new exports.ActiveNode),t.status=exports.TaskStatus.Running):(t.status=exports.TaskStatus.Success,i.reset(),this.completeNode(e))}else t.status=exports.TaskStatus.Running},o.handleUntilSuccess=function(e,t,o,r){if(!o.hasComponent(exports.ActiveNode))return o.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running);r.status!==exports.TaskStatus.Running?r.status===exports.TaskStatus.Success?(t.status=exports.TaskStatus.Success,this.completeNode(e)):(r.invalidate(),o.addComponent(new exports.ActiveNode),t.status=exports.TaskStatus.Running):t.status=exports.TaskStatus.Running},o.handleUntilFail=function(e,t,o,r){if(!o.hasComponent(exports.ActiveNode))return o.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running);r.status!==exports.TaskStatus.Running?r.status===exports.TaskStatus.Failure?(t.status=exports.TaskStatus.Success,this.completeNode(e)):(r.invalidate(),o.addComponent(new exports.ActiveNode),t.status=exports.TaskStatus.Running):t.status=exports.TaskStatus.Running},o.handleAlwaysSucceed=function(e,t,o,r){if(!o.hasComponent(exports.ActiveNode))return o.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running);r.status===exports.TaskStatus.Running?t.status=exports.TaskStatus.Running:(t.status=exports.TaskStatus.Success,this.completeNode(e))},o.handleAlwaysFail=function(e,t,o,r){if(!o.hasComponent(exports.ActiveNode))return o.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running);r.status===exports.TaskStatus.Running?t.status=exports.TaskStatus.Running:(t.status=exports.TaskStatus.Failure,this.completeNode(e))},o.handleConditional=function(e,t,o,r,n){return o.evaluateCondition(e,this.findBlackboard(e))?r.hasComponent(exports.ActiveNode)?(t.status=n.status,void(n.status!==exports.TaskStatus.Running&&this.completeNode(e))):(r.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running)):(t.status=exports.TaskStatus.Failure,void this.completeNode(e))},o.handleCooldown=function(e,t,o,r,n){var i=o,a=this.resolvePropertyValue(e,"cooldownTime",i.cooldownTime),d=s.Time.totalTime-i.lastExecutionTime,u=0===i.lastExecutionTime||d>=a;return this.outputLog(e,"[冷却检查] Time.totalTime="+s.Time.totalTime.toFixed(3)+", lastExecution="+i.lastExecutionTime.toFixed(3)+", cooldownTime="+a+", timeSince="+d.toFixed(3)+", canExecute="+u+", childStatus="+n.status,"info"),u?n.status!==exports.TaskStatus.Invalid&&n.status!==exports.TaskStatus.Running?(t.status=n.status,i.recordExecution(s.Time.totalTime),this.outputLog(e,"[冷却记录] 记录执行时间: "+s.Time.totalTime.toFixed(3)+", 下次可执行时间: "+(s.Time.totalTime+a).toFixed(3),"info"),void this.completeNode(e)):(r.hasComponent(exports.ActiveNode)||r.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running)):(t.status=exports.TaskStatus.Failure,void this.completeNode(e))},o.handleTimeout=function(e,t,o,r,n){var i=o,a=this.resolvePropertyValue(e,"timeoutDuration",i.timeoutDuration);return i.recordStartTime(s.Time.totalTime),i.startTime>0&&s.Time.totalTime-i.startTime>=a?(t.status=exports.TaskStatus.Failure,i.reset(),r.removeComponentByType(exports.ActiveNode),void this.completeNode(e)):r.hasComponent(exports.ActiveNode)?(t.status=n.status,void(n.status!==exports.TaskStatus.Running&&(i.reset(),this.completeNode(e)))):(r.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running))},o.completeNode=function(e){e.removeComponentByType(exports.ActiveNode),e.parent&&e.parent.hasComponent(exports.BehaviorTreeNode)&&(e.parent.hasComponent(exports.ActiveNode)||e.parent.addComponent(new exports.ActiveNode))},o.findBlackboard=function(e){for(var t=e;t;){var o=t.getComponent(exports.BlackboardComponent);if(o)return o;t=t.parent}},o.resolvePropertyValue=function(e,t,o){var r=e.getComponent(E);if(!r||!r.hasBinding(t))return o;var n=r.getBinding(t),i=this.findBlackboard(e);return i&&i.hasVariable(n)?i.getValue(n):o},o.findRootEntity=function(e){for(var t=e;t;){if(!t.parent)return t;t=t.parent}return null},o.outputLog=function(e,t,o){switch(void 0===o&&(o="info"),o){case"info":default:this.logger.info(t);break;case"warn":this.logger.warn(t);break;case"error":this.logger.error(t)}var r=this.findRootEntity(e);if(r){var n=r.getComponent(exports.LogOutput);n&&n.addMessage(t,o)}},o.getLoggerName=function(){return"DecoratorExecutionSystem"},t}(s.EntitySystem),ye=function(e){function t(){var t;return(t=e.call(this,s.Matcher.empty().all(exports.BehaviorTreeNode,exports.ActiveNode).exclude(exports.RootNode,exports.SubTreeNode))||this).updateOrder=300,t}h(t,e);var o=t.prototype;return o.process=function(e){for(var t,o=c(e);!(t=o()).done;){var r=t.value,n=r.getComponent(exports.BehaviorTreeNode);if(n.nodeType===exports.NodeType.Composite){var i=r.getComponentByType(exports.CompositeNodeComponent);if(i)this.executeComposite(r,n,i);else{this.logger.warn("复合节点 "+r.name+" 没有找到复合节点组件");var s=r.components.map((function(e){return e.constructor.name})).join(", ");this.logger.warn(" 组件列表: "+s)}}}},o.executeComposite=function(e,t,o){var r=e.children;if(0===r.length)return t.status=exports.TaskStatus.Success,void this.completeNode(e);switch(o.compositeType){case exports.CompositeType.Sequence:this.handleSequence(e,t,r);break;case exports.CompositeType.Selector:this.handleSelector(e,t,r);break;case exports.CompositeType.Parallel:this.handleParallel(e,t,r);break;case exports.CompositeType.ParallelSelector:this.handleParallelSelector(e,t,r);break;case exports.CompositeType.RandomSequence:this.handleRandomSequence(e,t,o,r);break;case exports.CompositeType.RandomSelector:this.handleRandomSelector(e,t,o,r);break;default:t.status=exports.TaskStatus.Failure,this.completeNode(e)}},o.handleSequence=function(e,t,o){var r=e.getComponentByType(exports.SequenceNode);if(!r||r.abortType===exports.AbortType.None||!this.shouldAbort(e,t,o,r.abortType)){if(t.currentChildIndex>=o.length)return t.status=exports.TaskStatus.Success,t.currentChildIndex=0,void this.completeNode(e);var n=o[t.currentChildIndex],i=n.getComponent(exports.BehaviorTreeNode);return i?i.status===exports.TaskStatus.Invalid?(n.hasComponent(exports.ActiveNode)||n.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running)):void(i.status===exports.TaskStatus.Running?t.status=exports.TaskStatus.Running:i.status===exports.TaskStatus.Failure?(t.status=exports.TaskStatus.Failure,t.currentChildIndex=0,this.completeNode(e)):i.status===exports.TaskStatus.Success&&(i.reset(),t.currentChildIndex++,t.status=exports.TaskStatus.Running)):(t.status=exports.TaskStatus.Failure,void this.completeNode(e))}this.abortExecution(e,t,o)},o.handleSelector=function(e,t,o){var r=e.getComponentByType(exports.SelectorNode);if(!r||r.abortType===exports.AbortType.None||!this.shouldAbort(e,t,o,r.abortType)){if(t.currentChildIndex>=o.length)return t.status=exports.TaskStatus.Failure,t.currentChildIndex=0,void this.completeNode(e);var n=o[t.currentChildIndex],i=n.getComponent(exports.BehaviorTreeNode);return i?i.status===exports.TaskStatus.Invalid?(n.hasComponent(exports.ActiveNode)||n.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running)):void(i.status===exports.TaskStatus.Running?t.status=exports.TaskStatus.Running:i.status===exports.TaskStatus.Success?(t.status=exports.TaskStatus.Success,t.currentChildIndex=0,this.completeNode(e)):i.status===exports.TaskStatus.Failure&&(i.reset(),t.currentChildIndex++,t.status=exports.TaskStatus.Running)):(t.status=exports.TaskStatus.Failure,void this.completeNode(e))}this.abortExecution(e,t,o)},o.handleParallel=function(e,t,o){for(var r,n=!1,i=!1,s=c(o);!(r=s()).done;){var a=r.value;a.hasComponent(exports.ActiveNode)||a.addComponent(new exports.ActiveNode);var d=a.getComponent(exports.BehaviorTreeNode);d&&(d.status===exports.TaskStatus.Running?n=!0:d.status===exports.TaskStatus.Failure&&(i=!0))}n?t.status=exports.TaskStatus.Running:i?(t.status=exports.TaskStatus.Failure,t.currentChildIndex=0,this.completeNode(e)):(t.status=exports.TaskStatus.Success,t.currentChildIndex=0,this.completeNode(e))},o.handleParallelSelector=function(e,t,o){for(var r,n=!1,i=!1,s=c(o);!(r=s()).done;){var a=r.value;a.hasComponent(exports.ActiveNode)||a.addComponent(new exports.ActiveNode);var d=a.getComponent(exports.BehaviorTreeNode);d&&(d.status===exports.TaskStatus.Running?n=!0:d.status===exports.TaskStatus.Success&&(i=!0))}if(i){t.status=exports.TaskStatus.Success,t.currentChildIndex=0;for(var u,p=c(o);!(u=p()).done;){u.value.removeComponentByType(exports.ActiveNode)}this.completeNode(e)}else n?t.status=exports.TaskStatus.Running:(t.status=exports.TaskStatus.Failure,t.currentChildIndex=0,this.completeNode(e))},o.handleRandomSequence=function(e,t,o,r){var n=o.getNextChildIndex(t.currentChildIndex,r.length);if(n>=r.length)return t.status=exports.TaskStatus.Success,t.currentChildIndex=0,o.resetShuffle(),void this.completeNode(e);var i=r[n],s=i.getComponent(exports.BehaviorTreeNode);return s?s.status===exports.TaskStatus.Invalid?(i.hasComponent(exports.ActiveNode)||i.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running)):void(s.status===exports.TaskStatus.Running?t.status=exports.TaskStatus.Running:s.status===exports.TaskStatus.Failure?(t.status=exports.TaskStatus.Failure,t.currentChildIndex=0,o.resetShuffle(),this.completeNode(e)):s.status===exports.TaskStatus.Success&&(s.reset(),t.currentChildIndex++,t.status=exports.TaskStatus.Running)):(t.status=exports.TaskStatus.Failure,void this.completeNode(e))},o.handleRandomSelector=function(e,t,o,r){var n=o.getNextChildIndex(t.currentChildIndex,r.length);if(n>=r.length)return t.status=exports.TaskStatus.Failure,t.currentChildIndex=0,o.resetShuffle(),void this.completeNode(e);var i=r[n],s=i.getComponent(exports.BehaviorTreeNode);return s?s.status===exports.TaskStatus.Invalid?(i.hasComponent(exports.ActiveNode)||i.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running)):void(s.status===exports.TaskStatus.Running?t.status=exports.TaskStatus.Running:s.status===exports.TaskStatus.Success?(t.status=exports.TaskStatus.Success,t.currentChildIndex=0,o.resetShuffle(),this.completeNode(e)):s.status===exports.TaskStatus.Failure&&(s.reset(),t.currentChildIndex++,t.status=exports.TaskStatus.Running)):(t.status=exports.TaskStatus.Failure,void this.completeNode(e))},o.shouldAbort=function(e,t,o,r){var n=t.currentChildIndex;if(0===n)return!1;if(r===exports.AbortType.Self||r===exports.AbortType.Both)for(var i=0;i<n;i++){var s=o[i].getComponent(exports.BehaviorTreeNode);if(s&&s.nodeType===exports.NodeType.Condition&&s.status===exports.TaskStatus.Failure)return!0}if(r===exports.AbortType.LowerPriority||r===exports.AbortType.Both)for(var a=0;a<n;a++){var d=o[a],u=d.getComponent(exports.BehaviorTreeNode);if(u)if(u.nodeType===exports.NodeType.Condition){if(this.evaluateCondition(d,u))return!0}else if(u.nodeType===exports.NodeType.Composite&&d.children.length>0){var c=d.children[0],p=c.getComponent(exports.BehaviorTreeNode);if(p&&p.nodeType===exports.NodeType.Condition&&this.evaluateCondition(c,p))return!0}}return!1},o.evaluateCondition=function(e,t){if(t.nodeType!==exports.NodeType.Condition)return!1;var o=!1;return e.hasComponent(exports.BlackboardCompareCondition)?o=this.evaluateBlackboardCompare(e):e.hasComponent(exports.BlackboardExistsCondition)?o=this.evaluateBlackboardExists(e):e.hasComponent(exports.RandomProbabilityCondition)?o=this.evaluateRandomProbability(e):e.hasComponent(exports.ExecuteCondition)&&(o=this.evaluateCustomCondition(e)),o},o.evaluateBlackboardCompare=function(e){var t=e.getComponent(exports.BlackboardCompareCondition),o=this.findBlackboard(e);if(!o||!o.hasVariable(t.variableName))return!1;var r=o.getValue(t.variableName),n=t.compareValue;"string"==typeof n&&(n=this.resolveVariableReferences(n,o));var i=!1;switch(t.operator){case exports.CompareOperator.Equal:i=r===n;break;case exports.CompareOperator.NotEqual:i=r!==n;break;case exports.CompareOperator.Greater:i=r>n;break;case exports.CompareOperator.GreaterOrEqual:i=r>=n;break;case exports.CompareOperator.Less:i=r<n;break;case exports.CompareOperator.LessOrEqual:i=r<=n;break;case exports.CompareOperator.Contains:("string"==typeof r||Array.isArray(r))&&(i=r.includes(n));break;case exports.CompareOperator.Matches:if("string"==typeof r&&"string"==typeof n)i=new RegExp(n).test(r)}return t.invertResult?!i:i},o.evaluateBlackboardExists=function(e){var t=e.getComponent(exports.BlackboardExistsCondition),o=this.findBlackboard(e);if(!o)return!1;var r=o.hasVariable(t.variableName);if(r&&t.checkNotNull){var n=o.getValue(t.variableName);r=null!=n}return t.invertResult?!r:r},o.evaluateRandomProbability=function(e){return e.getComponent(exports.RandomProbabilityCondition).evaluate()},o.evaluateCustomCondition=function(e){var t=e.getComponent(exports.ExecuteCondition),o=t.getFunction();if(!o)return!1;var r=o(e,this.findBlackboard(e),0);return t.invertResult?!r:r},o.resolveVariableReferences=function(e,t){var o=e.match(/^{{\s*(\w+)\s*}}$/);if(o){var r=o[1];return t.hasVariable(r)?t.getValue(r):e}return e.replace(/\{\{(\w+)\}\}/g,(function(e,o){if(t.hasVariable(o)){var r=t.getValue(o);return void 0!==r?String(r):e}return e}))},o.findBlackboard=function(e){for(var t=e;t;){var o=t.getComponent(exports.BlackboardComponent);if(o)return o;t=t.parent}},o.abortExecution=function(e,t,o){var r=t.currentChildIndex;if(r<o.length){var n=o[r];this.deactivateNode(n)}t.currentChildIndex=0,t.status=exports.TaskStatus.Running},o.deactivateNode=function(e){e.removeComponentByType(exports.ActiveNode);var t=e.getComponent(exports.BehaviorTreeNode);t&&t.reset();for(var o,r=c(e.children);!(o=r()).done;){var n=o.value;this.deactivateNode(n)}},o.resetAllChildren=function(e){for(var t,o=c(e.children);!(t=o()).done;){var r=t.value,n=r.getComponent(exports.BehaviorTreeNode);n&&n.reset(),this.resetAllChildren(r)}},o.completeNode=function(e){e.removeComponentByType(exports.ActiveNode);var t=e.getComponent(exports.BehaviorTreeNode);t&&t.nodeType===exports.NodeType.Composite&&this.resetAllChildren(e),e.parent&&e.parent.hasComponent(exports.BehaviorTreeNode)&&(e.parent.hasComponent(exports.ActiveNode)||e.parent.addComponent(new exports.ActiveNode))},o.getLoggerName=function(){return"CompositeExecutionSystem"},t}(s.EntitySystem);exports.LoadingState=void 0,(le=exports.LoadingState||(exports.LoadingState={})).Idle="idle",le.Pending="pending",le.Loading="loading",le.Loaded="loaded",le.Failed="failed",le.Timeout="timeout",le.Cancelled="cancelled";var me,ge=function(e){function t(t){var o;return(o=e.call(this,t)||this).name="TimeoutError",o}return h(t,e),t}(g(Error)),xe=function(e){function t(t){var o;return(o=e.call(this,t)||this).name="CircularDependencyError",o}return h(t,e),t}(g(Error)),be=function(e){function t(t){var o;return(o=e.call(this,t)||this).name="EntityDestroyedError",o}return h(t,e),t}(g(Error)),Ce=s.createLogger("AssetLoadingManager"),Te=function(){function e(){this.tasks=new Map,this.loadingStack=new Set,this.defaultOptions={timeoutMs:5e3,maxRetries:3,retryDelayBase:100,maxRetryDelay:2e3}}var t=e.prototype;return t.startLoading=function(e,t,o,r){void 0===r&&(r={});var n=p({},this.defaultOptions,r);if(r.parentAssetId&&this.detectCircularDependency(e,r.parentAssetId)){var i=new xe("检测到循环引用: "+r.parentAssetId+" → "+e+"\n加载栈: "+Array.from(this.loadingStack).join(" → "));throw Ce.error(i.message),i}var s=this.tasks.get(e);if(s)return Ce.debug("资产 "+e+" 已在加载中,返回现有任务"),this.createHandle(s);var a={assetId:e,promise:null,startTime:Date.now(),lastRetryTime:0,retryCount:0,maxRetries:n.maxRetries,timeoutMs:n.timeoutMs,state:exports.LoadingState.Pending,parentEntityId:t.id,parentEntity:t,parentAssetId:r.parentAssetId};return this.loadingStack.add(e),a.promise=this.loadWithTimeoutAndRetry(a,o,n),a.state=exports.LoadingState.Loading,this.tasks.set(e,a),Ce.info("开始加载资产: "+e,{timeoutMs:n.timeoutMs,maxRetries:n.maxRetries,parentAssetId:r.parentAssetId}),this.createHandle(a)},t.loadWithTimeoutAndRetry=function(){var e=u(v().m((function e(t,o,r){var n,i,s,a,d,u;return v().w((function(e){for(;;)switch(e.p=e.n){case 0:n=null,i=0;case 1:if(!(i<=t.maxRetries)){e.n=10;break}if(!t.parentEntity.isDestroyed){e.n=2;break}throw s=new be("父实体已销毁,取消加载: "+t.assetId),t.state=exports.LoadingState.Cancelled,this.cleanup(t.assetId),Ce.warn(s.message),s;case 2:return e.p=2,t.retryCount=i,t.lastRetryTime=Date.now(),Ce.debug("加载尝试 "+(i+1)+"/"+(t.maxRetries+1)+": "+t.assetId),e.n=3,this.withTimeout(o(),t.timeoutMs,"加载资产 "+t.assetId+" 超时("+t.timeoutMs+"ms)");case 3:return a=e.v,t.state=exports.LoadingState.Loaded,t.result=a,this.cleanup(t.assetId),Ce.info("资产加载成功: "+t.assetId,{attempts:i+1,elapsedMs:Date.now()-t.startTime}),e.a(2,a);case 4:if(e.p=4,u=e.v,n=u,!(u instanceof ge)){e.n=5;break}t.state=exports.LoadingState.Timeout,Ce.warn("资产加载超时: "+t.assetId+" (尝试 "+(i+1)+")"),e.n=7;break;case 5:if(!(u instanceof be)){e.n=6;break}throw u;case 6:Ce.warn("资产加载失败: "+t.assetId+" (尝试 "+(i+1)+")",u);case 7:if(i!==t.maxRetries){e.n=8;break}throw t.state=exports.LoadingState.Failed,t.error=n,this.cleanup(t.assetId),Ce.error("资产加载最终失败: "+t.assetId,{attempts:i+1,error:n.message}),n;case 8:return d=Math.min(Math.pow(2,i)*r.retryDelayBase,r.maxRetryDelay),Ce.debug("等待 "+d+"ms 后重试..."),e.n=9,this.delay(d);case 9:i++,e.n=1;break;case 10:throw n;case 11:return e.a(2)}}),e,this,[[2,4]])})));return function(t,o,r){return e.apply(this,arguments)}}(),t.withTimeout=function(e,t,o){var r,n=new Promise((function(e,n){r=setTimeout((function(){n(new ge(o))}),t)}));return Promise.race([e.then((function(e){return clearTimeout(r),e})),n]).catch((function(e){throw clearTimeout(r),e}))},t.detectCircularDependency=function(e,t){return!!this.loadingStack.has(t)},t.getTaskState=function(e){var t,o;return null!==(t=null===(o=this.tasks.get(e))||void 0===o?void 0:o.state)&&void 0!==t?t:exports.LoadingState.Idle},t.getTask=function(e){return this.tasks.get(e)},t.cancelLoading=function(e){var t=this.tasks.get(e);t&&(t.state=exports.LoadingState.Cancelled,this.cleanup(e),Ce.info("取消加载: "+e))},t.cleanup=function(e){var t=this.tasks.get(e);t&&(t.parentEntity=null),this.tasks.delete(e),this.loadingStack.delete(e)},t.delay=function(e){return new Promise((function(t){return setTimeout(t,e)}))},t.createHandle=function(e){var t=this;return{assetId:e.assetId,getState:function(){return e.state},getError:function(){return e.error},getProgress:function(){var t=Date.now()-e.startTime,o=Math.max(0,e.timeoutMs-t);return{state:e.state,elapsedMs:t,remainingTimeoutMs:o,retryCount:e.retryCount,maxRetries:e.maxRetries}},cancel:function(){return t.cancelLoading(e.assetId)},promise:e.promise}},t.getLoadingAssets=function(){return Array.from(this.tasks.keys())},t.getStats=function(){var e=Array.from(this.tasks.values());return{totalTasks:e.length,loadingTasks:e.filter((function(e){return e.state===exports.LoadingState.Loading})).length,failedTasks:e.filter((function(e){return e.state===exports.LoadingState.Failed})).length,timeoutTasks:e.filter((function(e){return e.state===exports.LoadingState.Timeout})).length}},t.clear=function(){Ce.info("清空所有加载任务",this.getStats()),this.tasks.clear(),this.loadingStack.clear()},t.dispose=function(){this.clear()},e}(),Se=function(e){function t(t){var o;return(o=e.call(this,s.Matcher.empty().all(exports.SubTreeNode,exports.ActiveNode,exports.BehaviorTreeNode))||this).assetLoaderInitialized=!1,o.hasLoggedMissingAssetLoader=!1,o.loadingTasks=new Map,o.updateOrder=300,o.loadingManager=t||new Te,o}h(t,e);var o=t.prototype;return o.onInitialize=function(){},o.process=function(e){for(var t,o=c(e);!(t=o()).done;){var r=t.value,n=r.getComponent(exports.SubTreeNode),i=r.getComponent(exports.BehaviorTreeNode);this.executeSubTree(r,n,i)}},o.executeSubTree=function(e,t,o){var r=t.validate();if(r.length>0)return this.logger.error("SubTree 节点配置错误: "+r.join(", ")),o.status=exports.TaskStatus.Failure,void this.completeNode(e);var n=t.getSubTreeRoot();if(n){var i=n.getComponent(exports.BehaviorTreeNode);if(i){var s=exports.TaskStatus[i.status],a=n.hasComponent(exports.ActiveNode);if(this.outputLog(e,"检查预加载子树 "+t.assetId+": status="+s+", hasActive="+a,"info"),i.status===exports.TaskStatus.Invalid){if(this.outputLog(e,"使用预加载的子树: "+t.assetId,"info"),this.outputLog(e,"激活前:子树根节点 "+n.name+" 有 "+n.children.length+" 个子节点","info"),n.children.length>0){var d=n.children[0];this.outputLog(e," 第一个子节点: "+d.name,"info")}n.hasComponent(exports.ActiveNode)||(n.addComponent(new exports.ActiveNode),this.outputLog(e,"为子树根节点添加 ActiveNode: "+n.name,"info"));var u=n.getComponent(exports.BehaviorTreeNode);return u&&(this.outputLog(e,"设置子树根节点状态: "+n.name+" -> Running","info"),u.status=exports.TaskStatus.Running),this.outputLog(e,"激活后:子树根节点 "+n.name+" 有 "+n.children.length+" 个子节点","info"),this.outputLog(e,"激活预加载的子树: "+t.assetId,"info"),void(o.status=exports.TaskStatus.Running)}}this.updateSubTree(e,t,o)}else this.outputLog(e,"子树未预加载,开始运行时加载: "+t.assetId,"info"),this.loadAndInstantiateSubTree(e,t,o)},o.ensureAssetLoaderInitialized=function(){if(!this.assetLoaderInitialized)try{this.assetLoader=s.Core.services.resolve(ue),this.assetLoaderInitialized=!0,this.logger.debug("AssetLoader 已初始化")}catch(e){return this.assetLoaderInitialized=!0,this.assetLoader=void 0,this.hasLoggedMissingAssetLoader||(this.logger.warn("AssetLoader 未配置。SubTree 节点需要 AssetLoader 来加载子树资产。\n如果您在编辑器中,请确保已打开项目并配置了项目路径。\n如果您在运行时环境,请确保已正确注册 FileSystemAssetLoader 服务。"),this.hasLoggedMissingAssetLoader=!0),!1}return void 0!==this.assetLoader},o.loadAndInstantiateSubTree=function(e,t,o){if(!this.ensureAssetLoaderInitialized())return this.logger.debug("AssetLoader 不可用,SubTree 节点执行失败"),o.status=exports.TaskStatus.Failure,void this.completeNode(e);var r=t.assetId,n=this.loadingTasks.get(e.id);if(n)switch(n.getState()){case exports.LoadingState.Loading:case exports.LoadingState.Pending:o.status=exports.TaskStatus.Running;var i=n.getProgress();return void(i.elapsedMs>1e3&&this.logger.debug("子树加载中: "+r+" (已耗时: "+Math.round(i.elapsedMs/1e3)+"s, 重试: "+i.retryCount+"/"+i.maxRetries+")"));case exports.LoadingState.Loaded:return void this.onLoadingComplete(e,t,o,n);case exports.LoadingState.Failed:case exports.LoadingState.Timeout:var s=n.getError();return this.outputLog(e,"子树加载失败: "+r+" - "+((null==s?void 0:s.message)||"未知错误"),"error"),o.status=exports.TaskStatus.Failure,this.loadingTasks.delete(e.id),void this.completeNode(e);case exports.LoadingState.Cancelled:return void this.loadingTasks.delete(e.id)}this.startNewLoading(e,t,o)},o.startNewLoading=function(e,t,o){var r=this,n=t.assetId,i=this.getParentTreeAssetId(e);try{var s=this.loadingManager.startLoading(n,e,(function(){return r.loadAsset(n)}),{timeoutMs:5e3,maxRetries:2,parentAssetId:i});this.loadingTasks.set(e.id,s),o.status=exports.TaskStatus.Running,this.outputLog(e,"开始加载子树: "+n+" (父树: "+(i||"none")+")","info")}catch(t){t instanceof xe?this.outputLog(e,"检测到循环引用: "+t.message,"error"):this.outputLog(e,"启动加载失败: "+n,"error"),o.status=exports.TaskStatus.Failure,this.completeNode(e)}},o.onLoadingComplete=function(e,t,o,r){var n=this;r.promise.then((function(o){if(e.isDestroyed)return n.logger.warn("父实体已销毁,丢弃加载结果: "+r.assetId),void o.destroy();t.setSubTreeRoot(o),e.addChild(o),o.addComponent(new exports.BehaviorTreeAssetMetadata).initialize(r.assetId,"1.0.0"),t.inheritParentBlackboard&&n.setupBlackboardInheritance(e,o),n.outputLog(e,"子树 "+r.assetId+" 加载成功并激活","info"),n.outputLog(e,"=== 子树 "+r.assetId+" 内部结构 ===","info"),n.logSubTreeStructure(e,o,0),n.outputLog(e,"=== 子树结构结束 ===","info"),n.startSubTreeExecution(o,e),n.loadingTasks.delete(e.id)})).catch((function(e){e instanceof be||n.logger.error("意外错误:",e)}))},o.loadAsset=function(){var e=u(v().m((function e(t){var o,r;return v().w((function(e){for(;;)switch(e.n){case 0:if(this.scene){e.n=1;break}throw new Error("Scene 不存在");case 1:return e.n=2,this.assetLoader.loadBehaviorTree(t);case 2:return o=e.v,r=pe.instantiate(o,this.scene,{asSubTree:!0}),e.a(2,r)}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),o.setupBlackboardInheritance=function(e,t){if(this.findBlackboard(e)){var o=t.getComponent(exports.BlackboardComponent);o&&o.setUseGlobalBlackboard(!0)}},o.findBlackboard=function(e){for(var t=e;t;){var o=t.getComponent(exports.BlackboardComponent);if(o)return o;t=t.parent}},o.startSubTreeExecution=function(e,t){t&&this.outputLog(t,"子树根节点 "+e.name+" 有 "+e.children.length+" 个子节点","info"),e.hasComponent(exports.ActiveNode)||(e.addComponent(new exports.ActiveNode),t&&this.outputLog(t,"为子树根节点添加 ActiveNode: "+e.name,"info"));var o=e.getComponent(exports.BehaviorTreeNode);o&&(t&&this.outputLog(t,"设置子树根节点状态: "+e.name+" -> Running","info"),o.status=exports.TaskStatus.Running)},o.updateSubTree=function(e,t,o){var r=t.getSubTreeRoot();if(r){var n=r.getComponent(exports.BehaviorTreeNode);if(n){var i=exports.TaskStatus[n.status];this.outputLog(e,"子树 "+t.assetId+" 当前状态: "+i,"info"),n.status!==exports.TaskStatus.Running?this.onSubTreeCompleted(e,t,o,n.status):o.status=exports.TaskStatus.Running}}},o.onSubTreeCompleted=function(e,t,o,r){this.outputLog(e,"子树完成,状态: "+exports.TaskStatus[r],"info"),this.outputLog(e,"完成前:SubTreeNode "+e.name+" 有 "+e.children.length+" 个子节点","info"),t.markSubTreeCompleted(r),r===exports.TaskStatus.Success?o.status=exports.TaskStatus.Success:r===exports.TaskStatus.Failure?t.propagateFailure?o.status=exports.TaskStatus.Failure:o.status=exports.TaskStatus.Success:o.status=r,this.cleanupSubTree(t),this.outputLog(e,"清理后:SubTreeNode "+e.name+" 有 "+e.children.length+" 个子节点","info"),this.completeNode(e)},o.cleanupSubTree=function(e){var t=e.getSubTreeRoot();t&&(e.preload?(this.logger.debug("重置预加载子树以便复用: "+e.assetId),this.resetSubTreeRecursively(t),e.resetCompletionState()):(this.logger.debug("销毁运行时加载的子树: "+e.assetId),t.destroy(),e.setSubTreeRoot(void 0),e.reset()))},o.resetSubTreeRecursively=function(e){e.hasComponent(exports.ActiveNode)&&e.removeComponentByType(exports.ActiveNode);var t=e.getComponent(exports.BehaviorTreeNode);t&&(t.status=exports.TaskStatus.Invalid);for(var o,r=c(e.children);!(o=r()).done;){var n=o.value;this.resetSubTreeRecursively(n)}},o.completeNode=function(e){e.removeComponentByType(exports.ActiveNode),e.parent&&e.parent.hasComponent(exports.BehaviorTreeNode)&&(e.parent.hasComponent(exports.ActiveNode)||e.parent.addComponent(new exports.ActiveNode))},o.getParentTreeAssetId=function(e){for(var t=e;t;){var o=t.getComponent(exports.BehaviorTreeAssetMetadata);if(o&&o.assetId)return o.assetId;t=t.parent}},o.onDestroy=function(){for(var t,o=c(this.loadingTasks.values());!(t=o()).done;){t.value.cancel()}this.loadingTasks.clear(),e.prototype.onDestroy.call(this)},o.findRootEntity=function(e){for(var t=e;t;){if(!t.parent)return t;t=t.parent}return null},o.outputLog=function(e,t,o){switch(void 0===o&&(o="info"),o){case"info":default:this.logger.info(t);break;case"warn":this.logger.warn(t);break;case"error":this.logger.error(t)}var r=this.findRootEntity(e);if(r){var n=r.getComponent(exports.LogOutput);n&&n.addMessage(t,o)}},o.logSubTreeStructure=function(e,t,o){var r=this,n=" ".repeat(o);t.getComponent(exports.BehaviorTreeNode);var i=t.components.map((function(e){return e.constructor.name})).find((function(e){return"BehaviorTreeNode"!==e&&"ActiveNode"!==e&&"BlackboardComponent"!==e&&"LogOutput"!==e&&"PropertyBindings"!==e&&"BehaviorTreeAssetMetadata"!==e}))||"Unknown",s=t.name;"Unknown"!==i&&(s=s+" ["+i+"]"),this.outputLog(e,n+"└─ "+s,"info"),t.children.length>0&&(this.outputLog(e,n+" 子节点数: "+t.children.length,"info"),t.children.forEach((function(t){r.logSubTreeStructure(e,t,o+1)})))},o.getLoggerName=function(){return"SubTreeExecutionSystem"},t}(s.EntitySystem);exports.AssetType=void 0,(me=exports.AssetType||(exports.AssetType={})).BehaviorTree="behavior-tree",me.Blackboard="blackboard",me.Unknown="unknown";var Ne=function(){function e(){this.config=null,this.assetMap=new Map,this.assetPathMap=new Map}var t=e.prototype;return t.initialize=function(e){this.config=e,this.rebuildAssetMaps()},t.rebuildAssetMaps=function(){if(this.assetMap.clear(),this.assetPathMap.clear(),this.config)for(var e,t=c(this.config.assets);!(e=t()).done;){var o=e.value;this.assetMap.set(o.id,o),this.assetPathMap.set(o.path,o)}},t.getConfig=function(){return this.config},t.updateConfig=function(e){this.config=e,this.rebuildAssetMaps()},t.registerAsset=function(e){if(!this.config)throw new Error("工作区未初始化");var t=this.config.assets.find((function(t){return t.id===e.id}));t?Object.assign(t,e):this.config.assets.push(e),this.rebuildAssetMaps()},t.unregisterAsset=function(e){if(this.config){var t=this.config.assets.findIndex((function(t){return t.id===e}));-1!==t&&(this.config.assets.splice(t,1),this.rebuildAssetMaps())}},t.getAssetById=function(e){return this.assetMap.get(e)},t.getAssetByPath=function(e){return this.assetPathMap.get(e)},t.getAllAssets=function(){var e;return(null===(e=this.config)||void 0===e?void 0:e.assets)||[]},t.getAssetsByType=function(e){return this.getAllAssets().filter((function(t){return t.type===e}))},t.getBehaviorTreeAssets=function(){return this.getAssetsByType(exports.AssetType.BehaviorTree)},t.getBlackboardAssets=function(){return this.getAssetsByType(exports.AssetType.Blackboard)},t.getAssetDependencies=function(e,t){if(void 0===t&&(t=new Set),t.has(e))return[];t.add(e);var o=this.getAssetById(e);if(!o)return[];for(var r,n=[],i=c(o.dependencies);!(r=i()).done;){var s=r.value,a=this.getAssetById(s);a&&(n.push(a),n.push.apply(n,this.getAssetDependencies(s,t)))}return n},t.detectCircularDependency=function(e){var t=this,o=new Set,r=[],n=function(e){if(r.includes(e))return r.push(e),!0;if(o.has(e))return!1;o.add(e),r.push(e);var i=t.getAssetById(e);if(i)for(var s,a=c(i.dependencies);!(s=a()).done;){var d=s.value;if(n(d))return!0}return r.pop(),!1};return n(e)?r:null},t.canAddDependency=function(e,t){var o=this.getAssetById(e);if(!o)return!1;var r=[].concat(o.dependencies);o.dependencies.push(t);var n=null!==this.detectCircularDependency(e);return o.dependencies=r,!n},t.addAssetDependency=function(e,t){if(!this.canAddDependency(e,t))return!1;var o=this.getAssetById(e);return!!o&&(o.dependencies.includes(t)||o.dependencies.push(t),!0)},t.removeAssetDependency=function(e,t){var o=this.getAssetById(e);if(o){var r=o.dependencies.indexOf(t);-1!==r&&o.dependencies.splice(r,1)}},t.resolveAssetPath=function(e){return this.config?e.startsWith("/")||e.match(/^[A-Za-z]:/)?e:(this.config.rootPath+"/"+e).replace(/\\/g,"/"):e},t.getRelativePath=function(e){if(!this.config)return e;var t=this.config.rootPath.replace(/\\/g,"/"),o=e.replace(/\\/g,"/");return o.startsWith(t)?o.substring(t.length+1):e},t.dispose=function(){this.config=null,this.assetMap.clear(),this.assetPathMap.clear()},e}(),we=function(){function e(){this.name="@esengine/behavior-tree",this.version="1.0.0",this.worldManager=null,this.services=null}var t=e.prototype;return t.install=function(){var e=u(v().m((function e(t,o){return v().w((function(e){for(;;)switch(e.n){case 0:this.services=o,o.registerSingleton(A),this.worldManager=o.resolve(s.WorldManager);case 1:return e.a(2)}}),e,this)})));return function(t,o){return e.apply(this,arguments)}}(),t.uninstall=function(){var e=u(v().m((function e(){return v().w((function(e){for(;;)switch(e.n){case 0:this.services&&this.services.unregister(A),this.worldManager=null,this.services=null;case 1:return e.a(2)}}),e,this)})));return function(){return e.apply(this,arguments)}}(),t.setupScene=function(e){e.addSystem(new fe),e.addSystem(new ve),e.addSystem(new ye),e.addSystem(new Se)},t.setupAllScenes=function(){if(!this.worldManager)throw new Error("Plugin not installed");for(var e,t=c(this.worldManager.getAllWorlds());!(e=t()).done;)for(var o,r=c(e.value.getAllScenes());!(o=r()).done;){var n=o.value;this.setupScene(n)}},e}(),ke=function(){function e(){}return e.start=function(e){if(!e.hasComponent(exports.BehaviorTreeNode))throw new Error("Entity must have BehaviorTreeNode component");e.hasComponent(exports.ActiveNode)||e.addComponent(new exports.ActiveNode)},e.stop=function(e){this.stopRecursive(e)},e.stopRecursive=function(e){e.hasComponent(exports.ActiveNode)&&e.removeComponentByType(exports.ActiveNode);var t=e.getComponent(exports.BehaviorTreeNode);t&&t.reset();for(var o,r=c(e.children);!(o=r()).done;){var n=o.value;this.stopRecursive(n)}},e.pause=function(e){this.pauseRecursive(e)},e.pauseRecursive=function(e){e.hasComponent(exports.ActiveNode)&&e.removeComponentByType(exports.ActiveNode);for(var t,o=c(e.children);!(t=o()).done;){var r=t.value;this.pauseRecursive(r)}},e.resume=function(e){this.resumeRecursive(e)},e.resumeRecursive=function(e){var t=e.getComponent(exports.BehaviorTreeNode);if(t){t.status===exports.TaskStatus.Running&&(e.hasComponent(exports.ActiveNode)||e.addComponent(new exports.ActiveNode));for(var o,r=c(e.children);!(o=r()).done;){var n=o.value;this.resumeRecursive(n)}}},e.restart=function(e){this.stop(e),this.start(e)},e.isRunning=function(e){return e.hasComponent(exports.ActiveNode)},e}(),Be=function(){function e(e,t){this.entityStack=[],this.scene=e,this.currentEntity=e.createEntity(t)}e.create=function(t,o){return void 0===o&&(o="BehaviorTreeRoot"),new e(t,o)};var t=e.prototype;return t.blackboard=function(){return this.blackboardEntity=this.currentEntity,this.currentEntity.addComponent(new exports.BlackboardComponent),this},t.defineVariable=function(e,t,o,r){if(!this.blackboardEntity)throw new Error("Must call blackboard() first");var n=this.blackboardEntity.getComponent(exports.BlackboardComponent);return n&&n.defineVariable(e,t,o,r),this},t.endBlackboard=function(){return this.blackboardEntity=void 0,this},t.sequence=function(e){return void 0===e&&(e="Sequence"),this.composite(e,exports.CompositeType.Sequence)},t.selector=function(e){return void 0===e&&(e="Selector"),this.composite(e,exports.CompositeType.Selector)},t.parallel=function(e){return void 0===e&&(e="Parallel"),this.composite(e,exports.CompositeType.Parallel)},t.parallelSelector=function(e){return void 0===e&&(e="ParallelSelector"),this.composite(e,exports.CompositeType.ParallelSelector)},t.randomSequence=function(e){return void 0===e&&(e="RandomSequence"),this.composite(e,exports.CompositeType.RandomSequence)},t.randomSelector=function(e){return void 0===e&&(e="RandomSelector"),this.composite(e,exports.CompositeType.RandomSelector)},t.composite=function(e,t){this.entityStack.push(this.currentEntity);var o=this.scene.createEntity(e);this.currentEntity.addChild(o);var r=o.addComponent(new exports.BehaviorTreeNode);r.nodeType=exports.NodeType.Composite,r.nodeName=e;var n=o.addComponent(new exports.CompositeNodeComponent);return n.compositeType=t,this.currentEntity=o,this},t.inverter=function(e){void 0===e&&(e="Inverter"),this.entityStack.push(this.currentEntity);var t=this.scene.createEntity(e);this.currentEntity.addChild(t);var o=t.addComponent(new exports.BehaviorTreeNode);return o.nodeType=exports.NodeType.Decorator,o.nodeName=e,t.addComponent(new exports.InverterNode),this.currentEntity=t,this},t.repeater=function(e,t,o){void 0===e&&(e="Repeater"),void 0===t&&(t=-1),void 0===o&&(o=!1),this.entityStack.push(this.currentEntity);var r=this.scene.createEntity(e);this.currentEntity.addChild(r);var n=r.addComponent(new exports.BehaviorTreeNode);n.nodeType=exports.NodeType.Decorator,n.nodeName=e;var i=r.addComponent(new exports.RepeaterNode);return i.repeatCount=t,i.endOnFailure=o,this.currentEntity=r,this},t.untilSuccess=function(e){void 0===e&&(e="UntilSuccess"),this.entityStack.push(this.currentEntity);var t=this.scene.createEntity(e);this.currentEntity.addChild(t);var o=t.addComponent(new exports.BehaviorTreeNode);return o.nodeType=exports.NodeType.Decorator,o.nodeName=e,t.addComponent(new exports.UntilSuccessNode),this.currentEntity=t,this},t.untilFail=function(e){void 0===e&&(e="UntilFail"),this.entityStack.push(this.currentEntity);var t=this.scene.createEntity(e);this.currentEntity.addChild(t);var o=t.addComponent(new exports.BehaviorTreeNode);return o.nodeType=exports.NodeType.Decorator,o.nodeName=e,t.addComponent(new exports.UntilFailNode),this.currentEntity=t,this},t.alwaysSucceed=function(e){void 0===e&&(e="AlwaysSucceed"),this.entityStack.push(this.currentEntity);var t=this.scene.createEntity(e);this.currentEntity.addChild(t);var o=t.addComponent(new exports.BehaviorTreeNode);return o.nodeType=exports.NodeType.Decorator,o.nodeName=e,t.addComponent(new exports.AlwaysSucceedNode),this.currentEntity=t,this},t.alwaysFail=function(e){void 0===e&&(e="AlwaysFail"),this.entityStack.push(this.currentEntity);var t=this.scene.createEntity(e);this.currentEntity.addChild(t);var o=t.addComponent(new exports.BehaviorTreeNode);return o.nodeType=exports.NodeType.Decorator,o.nodeName=e,t.addComponent(new exports.AlwaysFailNode),this.currentEntity=t,this},t.conditional=function(e,t){this.entityStack.push(this.currentEntity);var o=this.scene.createEntity(e);this.currentEntity.addChild(o);var r=o.addComponent(new exports.BehaviorTreeNode);return r.nodeType=exports.NodeType.Decorator,r.nodeName=e,o.addComponent(new exports.ConditionalNode).conditionCode=t,this.currentEntity=o,this},t.cooldown=function(e,t){void 0===e&&(e="Cooldown"),void 0===t&&(t=1),this.entityStack.push(this.currentEntity);var o=this.scene.createEntity(e);this.currentEntity.addChild(o);var r=o.addComponent(new exports.BehaviorTreeNode);return r.nodeType=exports.NodeType.Decorator,r.nodeName=e,o.addComponent(new exports.CooldownNode).cooldownTime=t,this.currentEntity=o,this},t.timeout=function(e,t){void 0===e&&(e="Timeout"),void 0===t&&(t=5),this.entityStack.push(this.currentEntity);var o=this.scene.createEntity(e);this.currentEntity.addChild(o);var r=o.addComponent(new exports.BehaviorTreeNode);return r.nodeType=exports.NodeType.Decorator,r.nodeName=e,o.addComponent(new exports.TimeoutNode).timeoutDuration=t,this.currentEntity=o,this},t.wait=function(e,t){void 0===t&&(t="Wait");var o=this.scene.createEntity(t);this.currentEntity.addChild(o);var r=o.addComponent(new exports.BehaviorTreeNode);return r.nodeType=exports.NodeType.Action,r.nodeName=t,o.addComponent(new exports.WaitAction).waitTime=e,this},t.log=function(e,t,o){void 0===t&&(t="log"),void 0===o&&(o="Log");var r=this.scene.createEntity(o);this.currentEntity.addChild(r);var n=r.addComponent(new exports.BehaviorTreeNode);n.nodeType=exports.NodeType.Action,n.nodeName=o;var i=r.addComponent(new exports.LogAction);return i.message=e,i.level=t,this},t.setBlackboardValue=function(e,t,o){void 0===o&&(o="SetValue");var r=this.scene.createEntity(o);this.currentEntity.addChild(r);var n=r.addComponent(new exports.BehaviorTreeNode);n.nodeType=exports.NodeType.Action,n.nodeName=o;var i=r.addComponent(new exports.SetBlackboardValueAction);return i.variableName=e,i.value=t,this},t.modifyBlackboardValue=function(e,t,o,r){void 0===r&&(r="ModifyValue");var n=this.scene.createEntity(r);this.currentEntity.addChild(n);var i=n.addComponent(new exports.BehaviorTreeNode);i.nodeType=exports.NodeType.Action,i.nodeName=r;var s=n.addComponent(new exports.ModifyBlackboardValueAction);return s.variableName=e,s.operation=t,s.operand=o,this},t.action=function(e,t){var o=this.scene.createEntity(e);this.currentEntity.addChild(o);var r=o.addComponent(new exports.BehaviorTreeNode);r.nodeType=exports.NodeType.Action,r.nodeName=e;var n=o.addComponent(new exports.ExecuteAction);return n.setFunction(t),this},t.compareBlackboardValue=function(e,t,o,r){void 0===r&&(r="Compare");var n=this.scene.createEntity(r);this.currentEntity.addChild(n);var i=n.addComponent(new exports.BehaviorTreeNode);i.nodeType=exports.NodeType.Condition,i.nodeName=r;var s=n.addComponent(new exports.BlackboardCompareCondition);return s.variableName=e,s.operator=t,s.compareValue=o,this},t.checkBlackboardExists=function(e,t,o){void 0===t&&(t=!1),void 0===o&&(o="Exists");var r=this.scene.createEntity(o);this.currentEntity.addChild(r);var n=r.addComponent(new exports.BehaviorTreeNode);n.nodeType=exports.NodeType.Condition,n.nodeName=o;var i=r.addComponent(new exports.BlackboardExistsCondition);return i.variableName=e,i.checkNotNull=t,this},t.randomProbability=function(e,t){void 0===t&&(t="Random");var o=this.scene.createEntity(t);this.currentEntity.addChild(o);var r=o.addComponent(new exports.BehaviorTreeNode);return r.nodeType=exports.NodeType.Condition,r.nodeName=t,o.addComponent(new exports.RandomProbabilityCondition).probability=e,this},t.condition=function(e,t){void 0===t&&(t="Condition");var o=this.scene.createEntity(t);this.currentEntity.addChild(o);var r=o.addComponent(new exports.BehaviorTreeNode);r.nodeType=exports.NodeType.Condition,r.nodeName=t;var n=o.addComponent(new exports.ExecuteCondition);return n.setFunction(e),this},t.end=function(){if(0===this.entityStack.length)throw new Error("No parent node to return to");return this.currentEntity=this.entityStack.pop(),this},t.build=function(){for(;this.entityStack.length>0;)this.currentEntity=this.entityStack.pop();return this.currentEntity},e}(),Ae=function(){function e(){}return e.serialize=function(e,t){if(void 0===t&&(t=!0),!e.hasComponent(exports.BehaviorTreeNode))throw new Error("Entity must have BehaviorTreeNode component");if(!e.scene)throw new Error("Entity must be attached to a scene");return s.SceneSerializer.serialize(e.scene,{format:"json",pretty:t,includeMetadata:!0})},e.deserialize=function(e,t){s.SceneSerializer.deserialize(e,t,{strategy:"merge"})},e.toJSON=function(e,t){void 0===t&&(t=!0);var o=this.serialize(e,t);return JSON.stringify(o,null,t?2:0)},e.fromJSON=function(e,t){this.deserialize(e,t)},e.saveToFile=function(){var e=u(v().m((function e(t,o){return v().w((function(e){for(;;)switch(e.n){case 0:throw this.toJSON(t,!0),new Error("saveToFile requires Tauri environment. Use toJSON() for manual saving.");case 1:return e.a(2)}}),e,this)})));return function(t,o){return e.apply(this,arguments)}}(),e.loadFromFile=function(){var e=u(v().m((function e(t,o){return v().w((function(e){for(;;)switch(e.n){case 0:throw new Error("loadFromFile requires Tauri environment. Use fromJSON() for manual loading.");case 1:return e.a(2)}}),e)})));return function(t,o){return e.apply(this,arguments)}}(),e.validate=function(e){try{var t=JSON.parse(e);return!(!t||"object"!=typeof t)&&(!!(t.name&&"number"==typeof t.version&&Array.isArray(t.entities)&&Array.isArray(t.componentTypeRegistry))&&t.entities.some((function(e){return e.components.some((function(e){return"BehaviorTreeNode"===e.type}))})))}catch(e){return!1}},e.clone=function(e,t){var o=this.serialize(t),r=e.entities.count;this.deserialize(e,o);for(var n=Array.from(e.entities.buffer),i=n.length-1;i>=r;i--){var s=n[i];if(s.hasComponent(exports.BehaviorTreeNode)&&!s.parent)return s}throw new Error("Failed to find cloned root entity")},e}(),Ee=function(){function e(){}return e.getAllTemplates=function(){return B()},e.getTemplate=function(e,t){return this.getAllTemplates().find((function(o){if(o.type!==e)return!1;var r=o.defaultConfig;switch(e){case exports.NodeType.Composite:return r.compositeType===t;case exports.NodeType.Decorator:return r.decoratorType===t;case exports.NodeType.Action:return r.actionType===t;case exports.NodeType.Condition:return r.conditionType===t;default:return!1}}))},e}();exports.AssetLoadingManager=Te,exports.BehaviorNode=T,exports.BehaviorProperty=S,exports.BehaviorTreeAssetLoader=pe,exports.BehaviorTreeAssetSerializer=ae,exports.BehaviorTreeAssetValidator=re,exports.BehaviorTreeBuilder=Be,exports.BehaviorTreePersistence=Ae,exports.BehaviorTreePlugin=we,exports.BehaviorTreeStarter=ke,exports.CircularDependencyError=xe,exports.CompositeExecutionSystem=ye,exports.DecoratorExecutionSystem=ve,exports.EditorFormatConverter=ie,exports.EntityDestroyedError=be,exports.FileSystemAssetLoader=ue,exports.GlobalBlackboardService=A,exports.LeafExecutionSystem=fe,exports.NodeClassRegistry=C,exports.NodeProperty=k,exports.NodeTemplates=Ee,exports.PropertyBindings=E,exports.RootExecutionSystem=he,exports.SubTreeExecutionSystem=Se,exports.TimeoutError=ge,exports.WorkspaceService=Ne,exports.clearRegisteredNodes=function(){C.clear()},exports.getRegisteredNodeTemplates=B;
|
|
4
|
+
//# sourceMappingURL=index.es5.js.map
|