Files

1 line
4.0 KiB
JavaScript
Raw Permalink Normal View History

2026-03-22 03:21:45 +02:00
"use strict";function t(t){var r;r=t.hasOwnProperty("constructor")?t.constructor:function(){};for(var s=Object.keys(t),e=0;e<s.length;e++){var i=s[e];"constructor"!==i&&(r.prototype[i]=t[i])}var a=function(){var t=Array.prototype.slice.call(arguments),s=t.shift(),e=Object.create(r.prototype);return r.apply(e,t),new o(s,e)};return a.getConstructor=function(){return r},a.getPrototype=function(){return r.prototype},a}function r(t){var r;r=t.hasOwnProperty("constructor")?t.constructor:function(){};for(var o=Object.keys(t),e=0;e<o.length;e++){var i=o[e];"constructor"!==i&&(r.prototype[i]=t[i])}var a=function(){var t=Array.prototype.slice.call(arguments),o=t.shift(),e=Object.create(r.prototype);return r.apply(e,t),new s(o,e)};return a.getConstructor=function(){return r},a.getPrototype=function(){return r.prototype},a}function s(t,r){var s=this;this.name=t,this.decorator=r,this.status=e.INVALID,this.decorator.getAssetPack=function(){return s.assetPack?s.assetPack:""},this.decorator.getEmitter=function(){return s.emitter},this.decorator.getBlackboard=function(){return s.blackboard},this.decorator.getName=function(){return t}}function o(t,r){var s=this;this.name=t,this.behavior=r,this.status=e.INVALID,this.behavior.getAssetPack=function(){return s.assetPack?s.assetPack:""},this.behavior.getEmitter=function(){return s.emitter},this.behavior.getBlackboard=function(){return s.blackboard},this.behavior.getName=function(){return t},this.behavior.getStatus=function(){return s.status}}var e={SUCCEEDED:"SUCCEEDED",FAILED:"FAILED",INTERRUPTED:"INTERRUPTED",IN_PROGRESS:"IN_PROGRESS",INVALID:"INVALID",PAUSED:"PAUSED",WAIT:"WAIT"};s.prototype={start:function(){var t=this.decorator.start();return t?(this.status=e.IN_PROGRESS,t):(this.status=e.FAILED,t)},stop:function(){this.status=e.INTERRUPTED,this.decorator.stop()},update:function(t){return this.status=this.decorator.update(t),this.status}},o.prototype={setChildren:function(t){for(var r=0;r<t.length;r++)t.parent=this;this.behavior.children=t},setDecorators:function(t){this.decorators=t;for(var r=function(t){return function(){return t}}(this),s=0;s<this.decorators.length;s++)this.decorators[s].decorator.getBehavior=r;return this},start:function(){if(this.status===e.IN_PROGRESS)return!1;var t;if(this.waitDecorators=[],this.waitDecoratorsLength=0,this.decorators)for(var r=0;r<this.decorators.length;r++)if(t=this.decorators[r].start(),t===e.WAIT)this.waitDecorators.push(this.decorators[r]),this.waitDecoratorsLength++;else if(!t)return this.status=e.FAILED,this.stop(),!1;return 0===this.waitDecorators.length?(t=this.behavior.start(),this.status=t?e.IN_PROGRESS:e.FAILED,t||this.stop(),t):(this.status=e.IN_PROGRESS,!0)},stop:function(){this.decorators&&this.decorators.forEach(function(t){t.status===e.IN_PROGRESS&&t.stop()}),this.behavior.children&&this.behavior.children.forEach(function(t){t.status===e.IN_PROGRESS&&t.stop()}),this.status===e.IN_PROGRESS&&(this.status=e.INTERRUPTED,this.behavior.stop())},pause:function(){this.previousStatus=this.status,this.status=e.PAUSED},unpause:function(){this.status=this.previousStatus},update:function(){var t,r=0;if(this.waitDecoratorsLength>0){for(r=0;r<this.waitDecorators.length;r++)this.waitDecorators[r]&&(t=this.waitDecorators[r].update(this.status),t!==e.WAIT&&(this.waitDecoratorsLength--,this.waitDecorators[r]=null));if(0!==this.waitDecoratorsLength)return e.IN_PROGRESS;var s=this.behavior.start();this.status=s?e.IN_PROGRESS:e.FAILED,s||this.stop()}if(this.status===e.PAUSED){if(t=this.status,this.decorators)for(r=0;r<this.decorators.length;r++)if(t=this.decorators[r].update(this.status),t!==e.IN_PROGRESS)return this.stop(),t;return this.status}if(this.status===e.IN_PROGRESS){var o=this.behavior.update();if(o!==e.IN_PROGRESS&&(this.status=o,this.stop()),this.decorators)for(r=0;r<this.decorators.length;r++)if(o=this.decorators[r].update(this.status),o!==e.IN_PROGRESS)return this.stop(),this.status=o,this.status;return this.status}return this.status===e.SUCCEEDED?e.SUCCEEDED:e.FAILED}},module.exports.Status=e,module.exports.createBehavior=t,module.exports