Files

1 line
2.4 KiB
JavaScript
Raw Permalink Normal View History

2026-03-22 03:21:45 +02:00
"use strict";var e=function(e){return e&&e.__esModule?e["default"]:e},t=function(){function e(e,t){for(var r in t){var a=t[r];a.configurable=!0,a.value&&(a.writable=!0)}Object.defineProperties(e,t)}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),r=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},a=e(require("pascal-case")),o=e(require("path")),s=require("events").EventEmitter,i=e(require("./blackboard")),n=e(require("callsite")),u=function(){function e(t,a,o,s,i){r(this,e),this.root=t,this.blackboard=a,this.notepad=o,this.result=s,this.emitter=i}return t(e,{status:{get:function(){return this.root.status}},start:{value:function(){return this.root.start()}},stop:{value:function(){this.root.stop()}},pause:{value:function(){this.root.pause()}},unpause:{value:function(){this.root.unpause()}},update:{value:function(){return this.root.update()}}}),e}(),c=function(){function e(){r(this,e),this.behaviors={}}return t(e,{addBehavior:{value:function(e,t){t=t||"";var r=a(o.parse(e.filename).name);this.behaviors[t+"-"+r]=e.exports,0===t.length&&(this.behaviors["core-"+r]=e.exports)}},create:{value:function(e){var t=void 0===arguments[1]?{}:arguments[1],r=void 0;if(e=e.substr(0,e.lastIndexOf(o.parse(e).ext)),o.isAbsolute(e))r=e;else{var a=n()[1].getFileName();r=o.join(a,"..",e)}var c=void 0;try{c=require(r)}catch(l){throw new Error(e+" is not a valid behavior tree")}var h=t.blackboard||i,v=t.notepad||{},d={},f=new s,p=c(h,v,d,f),b={},g=void 0,k=void 0,m=void 0,w=void 0,y=Object.keys(p),q="";for(g=0;g<y.length;g++){w=y[g],m=p[w],q=m["asset-pack"]||"","core"===m["asset-pack"]&&(q="");var x=this.behaviors[q+"-"+m["class"]];if(!x)throw new Error("The behavior "+m["class"]+" is not registered with the behavior factory");var E=m.args?[m.name].concat(m.args):[m.name];b[w]=x.apply(null,E),b[w].emitter=f,b[w].blackboard=h,t.assetPack&&(b[w].assetPack=t.assetPack)}var j={};for(g=0;g<y.length;g++)if(w=y[g],m=p[w],m.parent||(j[m.id]=!0),m.skipped)delete j[m.id];else{var O=b[m.id];if(m.children){var P=[];for(k=0;k<m.children.length;k++){var C=m.children[k],T=b[C];p[C].skipped||(T.parent=O,P.push(T))}O.setChildren(P)}if(m.decorators){var _=[];for(k=0;k<m.decorators.length;k++){var A=b[m.decorators[k]];delete j[m.decorators[k]],p[m.decorators[k]].skipped||_.push(A)}_.length>0&&O.setDecorators(_)}}var B=b[Object.keys(j)[0]];return new u(B,i,v,d,f)}}}),e}();module.exports=new c;