@eva/eva.js 1.2.7-fix.3 → 1.2.7-fix.4

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.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("eventemitter3"),t=require("lodash-es"),r=require("@eva/inspector-decorator"),o=require("resource-loader");function n(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var a=n(e),s=function(e,t){return(s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("eventemitter3"),t=require("lodash-es"),r=require("@eva/inspector-decorator"),o=require("resource-loader");function n(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var a=n(e),i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])},i(e,t)};
2
2
  /*! *****************************************************************************
3
3
  Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use
@@ -12,4 +12,4 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
12
12
 
13
13
  See the Apache Version 2.0 License for specific language governing permissions
14
14
  and limitations under the License.
15
- ***************************************************************************** */function i(e,t){function r(){this.constructor=e}s(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function c(e,t,r,o){var n,a=arguments.length,s=a<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,o);else for(var i=e.length-1;i>=0;i--)(n=e[i])&&(s=(a<3?n(s):a>3?n(t,r,s):n(t,r))||s);return a>3&&s&&Object.defineProperty(t,r,s),s}function u(e,t,r,o){return new(r||(r=Promise))((function(n,a){function s(e){try{c(o.next(e))}catch(e){a(e)}}function i(e){try{c(o.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):new r((function(t){t(e.value)})).then(s,i)}c((o=o.apply(e,t||[])).next())}))}function p(e,t){var r,o,n,a,s={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,o&&(n=2&a[0]?o.return:a[0]?o.throw||((n=o.return)&&n.call(o),0):o.next)&&!(n=n.call(o,a[1])).done)return n;switch(o=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,o=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(n=s.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){s.label=a[1];break}if(6===a[0]&&s.label<n[1]){s.label=n[1],n=a;break}if(n&&s.label<n[2]){s.label=n[2],s.ops.push(a);break}n[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],o=0}finally{r=n=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,i])}}}function l(e){var t="function"==typeof Symbol&&e[Symbol.iterator],r=0;return t?t.call(e):{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}function f(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var o,n,a=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(o=a.next()).done;)s.push(o.value)}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return s}function h(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(f(arguments[t]));return e}var y,m=function(e){function t(t){var r=e.call(this)||this;return r.started=!1,r.name=r.constructor.componentName,r.__componentDefaultParams=t,r}return i(t,e),t}(a),d=m;exports.OBSERVER_TYPE=void 0,(y=exports.OBSERVER_TYPE||(exports.OBSERVER_TYPE={})).ADD="ADD",y.REMOVE="REMOVE",y.CHANGE="CHANGE";var v={},g={},b={},E={};function _(e,t){v[e.gameObject.id]||(v[e.gameObject.id]={});var r=v[e.gameObject.id],o=e.name+"_"+t.join(",");if(r[o])return r[o];for(var n=t.length-1,a=e,s=0;s<n;s++)a=a[t[s]];return r[o]={property:a,key:t[n]},r[o]}function O(e){var t,r,o=e.systemName,n=e.componentName,a=e.component,s=e.prop,i=e.type;null===(r=null===(t=g[o])||void 0===t?void 0:t.componentObserver)||void 0===r||r.add({component:a,prop:s,type:i,componentName:n})}function R(e){var r,o,n=e.obj,a=e.key,s=e.prop,i=e.component,c=e.componentName;if(void 0!==n)if(a in n){if(Object.defineProperty(n,"_"+a,{enumerable:!1,writable:!0,value:n[a]}),s.deep&&t.isObject(n[a]))try{for(var u=l(Object.keys(n[a])),p=u.next();!p.done;p=u.next()){var f=p.value;R({obj:n[a],key:f,prop:s,component:i,componentName:c})}}catch(e){r={error:e}}finally{try{p&&!p.done&&(o=u.return)&&o.call(u)}finally{if(r)throw r.error}}Object.defineProperty(n,a,{enumerable:!0,set:function(e){n["_"+a]!==e&&(n["_"+a]=e,function(e){var r=e.prop,o=e.component,n=e.componentName;for(var a in b){var s=(b[a]||{})[n];s&&s.findIndex((function(e){return t.isEqual(e,r)}))>-1&&O({systemName:a,componentName:n,component:o,prop:r,type:exports.OBSERVER_TYPE.CHANGE})}}({prop:s,component:i,componentName:c}))},get:function(){return n["_"+a]}})}else console.error("prop "+a+" not in component: "+c+", Can not observer")}function x(e,t){var r,o;for(var n in void 0===t&&(t=e.name),b){(b[n]||{})[t]&&(null===(o=null===(r=g[n])||void 0===r?void 0:r.componentObserver)||void 0===o||o.add({component:e,type:exports.OBSERVER_TYPE.REMOVE,componentName:t}))}!function(e){e.gameObject&&delete v[e.gameObject.id]}(e)}var T=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.name="Transform",t._parent=null,t.inScene=!1,t.children=[],t.position={x:0,y:0},t.size={width:0,height:0},t.origin={x:0,y:0},t.anchor={x:0,y:0},t.scale={x:1,y:1},t.skew={x:0,y:0},t.rotation=0,t}return i(t,e),t.prototype.init=function(e){var t,r;void 0===e&&(e={});try{for(var o=l(["position","size","origin","anchor","scale","skew"]),n=o.next();!n.done;n=o.next()){var a=n.value;Object.assign(this[a],e[a])}}catch(e){t={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}this.rotation=e.rotation||this.rotation},Object.defineProperty(t.prototype,"parent",{get:function(){return this._parent},set:function(e){e?e.addChild(this):this.parent&&this.parent.removeChild(this)},enumerable:!1,configurable:!0}),t.prototype.addChild=function(e){if(e.parent===this){var t=this.children.findIndex((function(t){return t===e}));this.children.splice(t,1)}else e.parent&&e.parent.removeChild(e);e._parent=this,this.children.push(e)},t.prototype.removeChild=function(e){var t=this.children.findIndex((function(t){return t===e}));t>-1&&(this.children.splice(t,1),e._parent=null)},t.prototype.clearChildren=function(){this.children.length=0},t.componentName="Transform",c([r.type("vector2"),r.step(1)],t.prototype,"position",void 0),c([r.type("size"),r.step(1)],t.prototype,"size",void 0),c([r.type("vector2"),r.step(.1)],t.prototype,"origin",void 0),c([r.type("vector2"),r.step(.1)],t.prototype,"anchor",void 0),c([r.type("vector2"),r.step(.1)],t.prototype,"scale",void 0),c([r.type("vector2"),r.step(.1)],t.prototype,"skew",void 0),c([r.type("number"),r.step(.1)],t.prototype,"rotation",void 0),t}(d),S=0;var w=function(){function e(e,t){this._componentCache={},this.components=[],this.destroyed=!1,this._name=e,this.id=++S,this.addComponent(T,t)}return Object.defineProperty(e.prototype,"transform",{get:function(){return this.getComponent(T)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this.transform&&this.transform.parent&&this.transform.parent.gameObject},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"name",{get:function(){return this._name},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"scene",{get:function(){return this._scene},set:function(e){var t,r;if(this._scene!==e){var o=this._scene;if(this._scene=e,this.transform&&this.transform.children)try{for(var n=l(this.transform.children),a=n.next();!a.done;a=n.next()){a.value.gameObject.scene=e}}catch(e){t={error:e}}finally{try{a&&!a.done&&(r=n.return)&&r.call(n)}finally{if(t)throw t.error}}e?e.addGameObject(this):o&&o.removeGameObject(this)}},enumerable:!1,configurable:!0}),e.prototype.addChild=function(t){if(t&&t.transform&&t!==this){if(!(t instanceof e))throw new Error("addChild only receive GameObject");if(!this.transform)throw new Error("gameObject '"+this.name+"' has been destroy");t.transform.parent=this.transform,t.scene=this.scene}},e.prototype.removeChild=function(t){return t instanceof e&&t.parent&&t.parent===this?(t.transform.parent=null,t.scene=null,t):t},e.prototype.addComponent=function(e,t){if(!this.destroyed){var r=function(e){return e instanceof m?e.name:e instanceof Function?e.componentName:void 0}(e);if(!this._componentCache[r]){var o;if(e instanceof Function)o=new e(t);else{if(!(e instanceof d))throw new Error("addComponent recieve Component and Component Constructor");o=e}if(o.gameObject)throw new Error("component has been added on gameObject "+o.gameObject.name);return o.gameObject=this,o.init&&o.init(o.__componentDefaultParams),function(e,t){var r,o;for(var n in void 0===t&&(t=e.name),b)(b[n]||{})[t]&&(null===(o=null===(r=g[n])||void 0===r?void 0:r.componentObserver)||void 0===o||o.add({component:e,type:exports.OBSERVER_TYPE.ADD,componentName:t}))}(o,o.name),function(e,t){var r,o;if(void 0===t&&(t=e.name),t&&E[t]){if(!(e&&(n=e,n&&n.constructor&&"componentName"in n.constructor)))throw new Error("component param must be an instance of Component");var n;if(!e.gameObject||!e.gameObject.id)throw new Error("component should be add to a gameObject");try{for(var a=l(E[t]),s=a.next();!s.done;s=a.next()){var i=s.value,c=_(e,i.prop);R({obj:c.property,key:c.key,prop:i,component:e,componentName:t})}}catch(e){r={error:e}}finally{try{s&&!s.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}}}(o,o.name),this.components.push(o),this._componentCache[r]=o,o.awake&&o.awake(),o}}},e.prototype.removeComponent=function(e){var t;if("string"==typeof e?t=e:e instanceof d?t=e.name:e.componentName&&(t=e.componentName),"Transform"===t)throw new Error("Transform can't be removed");return this._removeComponent(t)},e.prototype._removeComponent=function(e){var t=this.components.findIndex((function(t){return t.name===e}));if(-1!==t){var r=this.components.splice(t,1)[0];return delete this._componentCache[e],delete r.__componentDefaultParams,r.onDestroy&&r.onDestroy(),x(r,e),r.gameObject=void 0,r}},e.prototype.getComponent=function(e){var t;return"string"==typeof e?t=e:e instanceof d?t=e.name:e.componentName&&(t=e.componentName),void 0!==this._componentCache[t]?this._componentCache[t]:void 0},e.prototype.remove=function(){if(this.parent)return this.parent.removeChild(this)},e.prototype.destroy=function(){if(this.transform){for(var e in Array.from(this.transform.children).forEach((function(e){e.gameObject.destroy()})),this.remove(),this.transform.clearChildren(),this._componentCache)this._removeComponent(e);this.components.length=0,this.destroyed=!0}else console.error("Cannot destroy gameObject that have already been destroyed.")},e}(),k=function(){function e(){this.events=[]}return e.prototype.add=function(e){var r=e.component,o=e.prop,n=e.type,a=e.componentName;if(n===exports.OBSERVER_TYPE.REMOVE){if(this.events.find((function(e){return e.component===r&&e.type===exports.OBSERVER_TYPE.ADD})))return void(this.events=this.events.filter((function(e){return e.component!==r})));this.events=this.events.filter((function(e){return e.component!==r}))}var s=this.events.findIndex((function(e){return e.component===r&&t.isEqual(e.prop,o)&&e.type===n}));s>-1&&this.events.splice(s,1),this.events.push({gameObject:r.gameObject,component:r,prop:o,type:n,componentName:a})},e.prototype.getChanged=function(){return this.events},Object.defineProperty(e.prototype,"changed",{get:function(){return this.events},enumerable:!1,configurable:!0}),e.prototype.clear=function(){var e=this.events;return this.events=[],e},e}(),P=function(){function e(e){this.started=!1,this.componentObserver=new k,this.__systemDefaultParams=e,this.name=this.constructor.systemName}return e.prototype.destroy=function(){var e;this.componentObserver=null,this.__systemDefaultParams=null,null===(e=this.onDestroy)||void 0===e||e.call(this)},e}();var j,L=Date.now?Date.now:function(){return(new Date).getTime()},C={originTime:0,playbackRate:1},M=function(){function e(t,r){t instanceof e&&(r=t,t={}),t=Object.assign({},C,t),r&&(this._parent=r),this._createTime=L(),this._timeMark=[{globalTime:this.globalTime,localTime:-t.originTime,entropy:-t.originTime,playbackRate:t.playbackRate,globalEntropy:0}],this._parent&&(this._timeMark[0].globalEntropy=this._parent.entropy),this._playbackRate=t.playbackRate}return Object.defineProperty(e.prototype,"globalTime",{get:function(){return this.parent?this.parent.currentTime:L()-this._createTime},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"lastTimeMark",{get:function(){return this._timeMark[this._timeMark.length-1]},enumerable:!1,configurable:!0}),e.prototype.markTime=function(e){var t=void 0===e?{}:e,r=t.time,o=void 0===r?this.currentTime:r,n=t.entropy,a=void 0===n?this.entropy:n,s=t.playbackRate,i=void 0===s?this.playbackRate:s,c={globalTime:this.globalTime,localTime:o,entropy:a,playbackRate:i,globalEntropy:this.globalEntropy};this._timeMark.push(c)},Object.defineProperty(e.prototype,"currentTime",{get:function(){var e=this.lastTimeMark,t=e.localTime,r=e.globalTime;return t+(this.globalTime-r)*this.playbackRate},set:function(e){this.markTime({time:e})},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"globalEntropy",{get:function(){return this._parent?this._parent.entropy:this.globalTime},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"entropy",{get:function(){var e=this.lastTimeMark,t=e.entropy,r=e.globalEntropy;return t+Math.abs((this.globalEntropy-r)*this.playbackRate)},set:function(e){if(this.entropy>e){var t=this.seekTimeMark(e);this._timeMark.length=t+1}this.markTime({entropy:e})},enumerable:!1,configurable:!0}),e.prototype.fork=function(t){return new e(t,this)},e.prototype.seekGlobalTime=function(e){var t=this.seekTimeMark(e),r=this._timeMark[t],o=r.entropy,n=r.playbackRate;return r.globalTime+(e-o)/Math.abs(n)},e.prototype.seekLocalTime=function(e){var t=this.seekTimeMark(e),r=this._timeMark[t],o=r.localTime,n=r.entropy;return r.playbackRate>0?o+(e-n):o-(e-n)},e.prototype.seekTimeMark=function(e){var t=this._timeMark,r=0,o=t.length-1;if(e<=t[r].entropy)return r;if(e>=t[o].entropy)return o;for(var n=Math.floor((r+o)/2);n>r&&n<o;){if(e===t[n].entropy)return n;e<t[n].entropy?o=n:e>t[n].entropy&&(r=n),n=Math.floor((r+o)/2)}return r},Object.defineProperty(e.prototype,"playbackRate",{get:function(){return this._playbackRate},set:function(e){e!==this.playbackRate&&(this.markTime({playbackRate:e}),this._playbackRate=e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"paused",{get:function(){if(0===this.playbackRate)return!0;for(var e=this.parent;e;){if(0===e.playbackRate)return!0;e=e.parent}return!1},enumerable:!1,configurable:!0}),e}(),N={autoStart:!0,frameRate:60},A=function(){function e(e){var t=this;e=Object.assign({},N,e),this._frameCount=0,this._frameDuration=1e3/e.frameRate,this.autoStart=e.autoStart,this.frameRate=e.frameRate,this.timeline=new M({originTime:0,playbackRate:1}),this._lastFrameTime=this.timeline.currentTime,this._tickers=new Set,this._requestId=null,this._ticker=function(){t._started&&(t._requestId=requestAnimationFrame(t._ticker),t.update())},this.autoStart&&this.start()}return e.prototype.update=function(){var e,t,r=this.timeline.currentTime,o=r-this._lastFrameTime;if(o>=this._frameDuration){var n=r-o%this._frameDuration,a=n-this._lastFrameTime;this._lastFrameTime=n;var s={deltaTime:a,time:n,currentTime:n,frameCount:++this._frameCount,fps:Math.round(1e3/a)};try{for(var i=l(this._tickers),c=i.next();!c.done;c=i.next()){var u=c.value;"function"==typeof u&&u(s)}}catch(t){e={error:t}}finally{try{c&&!c.done&&(t=i.return)&&t.call(i)}finally{if(e)throw e.error}}}},e.prototype.add=function(e){this._tickers.add(e)},e.prototype.remove=function(e){this._tickers.delete(e)},e.prototype.start=function(){this._started||(this._started=!0,this.timeline.playbackRate=1,this._requestId=requestAnimationFrame(this._ticker))},e.prototype.pause=function(){this._started=!1,this.timeline.playbackRate=0},e.prototype.setPlaybackRate=function(e){this.timeline.playbackRate=e},e}(),I=function(e){function t(t,r){var o=e.call(this,t,r)||this;return o.gameObjects=[],o.scene=o,o}return i(t,e),t.prototype.addGameObject=function(e){this.gameObjects.push(e),e.transform&&(e.transform.inScene=!0)},t.prototype.removeGameObject=function(e){var t=this.gameObjects.indexOf(e);-1!==t&&(e.transform&&(e.transform.inScene=!1),this.gameObjects.splice(t,1))},t.prototype.destroy=function(){this.scene=null,e.prototype.destroy.call(this),this.gameObjects=null,this.canvas=null},t}(w);exports.LOAD_SCENE_MODE=void 0,(j=exports.LOAD_SCENE_MODE||(exports.LOAD_SCENE_MODE={})).SINGLE="SINGLE",j.MULTI_CANVAS="MULTI_CANVAS";var D=function(e){if((e instanceof P||e instanceof d)&&!e.started){e.started=!0;try{e.start&&e.start()}catch(t){e instanceof d?console.error(e.constructor.componentName+" start error",t):console.error(e.constructor.systemName+" start error",t)}}},V=function(e){function r(t){var r,o,n=void 0===t?{}:t,a=n.systems,s=n.frameRate,i=void 0===s?60:s,c=n.autoStart,u=void 0===c||c,p=n.needScene,f=void 0===p||p,h=e.call(this)||this;if(h.playing=!1,h.started=!1,h.multiScenes=[],h.systems=[],window.__EVA_INSPECTOR_ENV__&&(window.__EVA_GAME_INSTANCE__=h),h.ticker=new A({autoStart:!1,frameRate:i}),h.initTicker(),a&&a.length)try{for(var y=l(a),m=y.next();!m.done;m=y.next()){var d=m.value;h.addSystem(d)}}catch(e){r={error:e}}finally{try{m&&!m.done&&(o=y.return)&&o.call(y)}finally{if(r)throw r.error}}return f&&h.loadScene(new I("scene")),u&&h.start(),h}return i(r,e),Object.defineProperty(r.prototype,"scene",{get:function(){return this._scene},set:function(e){this._scene=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"gameObjects",{get:function(){return function(e){var t,r,o,n=(null===(o=null==e?void 0:e.scene)||void 0===o?void 0:o.gameObjects)||[],a=null==e?void 0:e.multiScenes.map((function(e){return e.gameObjects})),s=[];try{for(var i=l(a),c=i.next();!c.done;c=i.next())s=h(s,c.value)}catch(e){t={error:e}}finally{try{c&&!c.done&&(r=i.return)&&r.call(i)}finally{if(t)throw t.error}}return h(n,s)}(this)},enumerable:!1,configurable:!0}),r.prototype.addSystem=function(e,r){var o;if(e instanceof Function)o=new e(r);else{if(!(e instanceof P))return void console.warn("can only add System");o=e}if(!this.systems.find((function(e){return e.constructor===o.constructor}))){o.game=this,o.init&&o.init(o.__systemDefaultParams),function(e,t){b[t.systemName]=t.observerInfo,g[t.systemName]=e}(o,o.constructor),function(e){var r,o,n,a,s=[];e instanceof Array?s.push.apply(s,h(e)):s.push(e);try{for(var i=l(s),c=i.next();!c.done;c=i.next()){var u=c.value;for(var p in u.observerInfo){E[p]=E[p]||[];var f=E[p],y=function(e){-1===f.findIndex((function(r){return t.isEqual(r,e)}))&&E[p].push(e)};try{for(var m=(n=void 0,l(u.observerInfo[p])),d=m.next();!d.done;d=m.next())y(d.value)}catch(e){n={error:e}}finally{try{d&&!d.done&&(a=m.return)&&a.call(m)}finally{if(n)throw n.error}}}}}catch(e){r={error:e}}finally{try{c&&!c.done&&(o=i.return)&&o.call(i)}finally{if(r)throw r.error}}}(o.constructor);try{o.awake&&o.awake()}catch(e){console.error(o.constructor.systemName+" awake error",e)}return this.systems.push(o),o}console.warn(o.constructor.systemName+" System has been added")},r.prototype.removeSystem=function(e){if(e){var t=-1;"string"==typeof e?t=this.systems.findIndex((function(t){return t.name===e})):e instanceof Function?t=this.systems.findIndex((function(t){return t.constructor===e})):e instanceof P&&(t=this.systems.findIndex((function(t){return t===e}))),t>-1&&(this.systems[t].destroy&&this.systems[t].destroy(),this.systems.splice(t,1))}},r.prototype.getSystem=function(e){return this.systems.find((function(t){return"string"==typeof e?t.name===e:t instanceof e}))},r.prototype.pause=function(){this.playing&&(this.playing=!1,this.ticker.pause(),this.triggerPause())},r.prototype.start=function(){this.playing||(this.playing=!0,this.started=!0,this.ticker.start())},r.prototype.resume=function(){this.playing||(this.playing=!0,this.ticker.start(),this.triggerResume())},r.prototype.initTicker=function(){var e=this;this.ticker.add((function(t){var r,o,n,a;e.scene&&function(e,t){var r,o,n,a,s,i,c,u;void 0===t&&(t=[]);try{for(var p=l(t),f=p.next();!f.done;f=p.next()){var h=f.value;try{for(var y=(n=void 0,l(h.components)),m=y.next();!m.done;m=y.next()){var d=m.value;try{D(d),d.update&&d.update(e)}catch(e){console.error("gameObject: "+h.name+" "+d.name+" update error",e)}}}catch(e){n={error:e}}finally{try{m&&!m.done&&(a=y.return)&&a.call(y)}finally{if(n)throw n.error}}}}catch(e){r={error:e}}finally{try{f&&!f.done&&(o=p.return)&&o.call(p)}finally{if(r)throw r.error}}try{for(var v=l(t),g=v.next();!g.done;g=v.next()){h=g.value;try{for(var b=(c=void 0,l(h.components)),E=b.next();!E.done;E=b.next()){d=E.value;try{d.lateUpdate&&d.lateUpdate(e)}catch(e){console.error("gameObject: "+h.name+" "+d.name+" lateUpdate error",e)}}}catch(e){c={error:e}}finally{try{E&&!E.done&&(u=b.return)&&u.call(b)}finally{if(c)throw c.error}}}}catch(e){s={error:e}}finally{try{g&&!g.done&&(i=v.return)&&i.call(v)}finally{if(s)throw s.error}}}(t,e.gameObjects);try{for(var s=l(e.systems),i=s.next();!i.done;i=s.next()){var c=i.value;try{D(c),c.update&&c.update(t)}catch(t){console.error(c.constructor.systemName+" update error",t)}}}catch(e){r={error:e}}finally{try{i&&!i.done&&(o=s.return)&&o.call(s)}finally{if(r)throw r.error}}try{for(var u=l(e.systems),p=u.next();!p.done;p=u.next()){c=p.value;try{c.lateUpdate&&c.lateUpdate(t)}catch(t){console.error(c.constructor.systemName+" lateUpdate error",t)}}}catch(e){n={error:e}}finally{try{p&&!p.done&&(a=u.return)&&a.call(u)}finally{if(n)throw n.error}}}))},r.prototype.triggerResume=function(){var e,t;!function(e){var t,r,o,n;try{for(var a=l(e),s=a.next();!s.done;s=a.next()){var i=s.value;try{for(var c=(o=void 0,l(i.components)),u=c.next();!u.done;u=c.next()){var p=u.value;try{p.onResume&&p.onResume()}catch(e){console.error("gameObject: "+i.name+", "+p.name+", onResume error",e)}}}catch(e){o={error:e}}finally{try{u&&!u.done&&(n=c.return)&&n.call(c)}finally{if(o)throw o.error}}}}catch(e){t={error:e}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}}(this.gameObjects);try{for(var r=l(this.systems),o=r.next();!o.done;o=r.next()){var n=o.value;try{n.onResume&&n.onResume()}catch(e){console.error(n.constructor.systemName+", onResume error",e)}}}catch(t){e={error:t}}finally{try{o&&!o.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}},r.prototype.triggerPause=function(){var e,t;!function(e){var t,r,o,n;try{for(var a=l(e),s=a.next();!s.done;s=a.next()){var i=s.value;try{for(var c=(o=void 0,l(i.components)),u=c.next();!u.done;u=c.next()){var p=u.value;try{p.onPause&&p.onPause()}catch(e){console.error("gameObject: "+i.name+", "+p.name+", onResume error",e)}}}catch(e){o={error:e}}finally{try{u&&!u.done&&(n=c.return)&&n.call(c)}finally{if(o)throw o.error}}}}catch(e){t={error:e}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}}(this.gameObjects);try{for(var r=l(this.systems),o=r.next();!o.done;o=r.next()){var n=o.value;try{n.onPause&&n.onPause()}catch(e){console.error(n.constructor.systemName+", onPause error",e)}}}catch(t){e={error:t}}finally{try{o&&!o.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}},r.prototype.destroySystems=function(){var e,t;try{for(var r=l(h(this.systems)),o=r.next();!o.done;o=r.next()){var n=o.value;this.removeSystem(n)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}this.systems.length=0},r.prototype.destroy=function(){this.removeAllListeners(),this.pause(),this.scene.destroy(),this.destroySystems(),this.ticker=null,this.scene=null,this.canvas=null,this.multiScenes=null},r.prototype.loadScene=function(e){var t=e.scene,r=e.mode,o=void 0===r?exports.LOAD_SCENE_MODE.SINGLE:r,n=e.params,a=void 0===n?{}:n;if(t){switch(o){case exports.LOAD_SCENE_MODE.SINGLE:this.scene=t;break;case exports.LOAD_SCENE_MODE.MULTI_CANVAS:this.multiScenes.push(t)}this.emit("sceneChanged",{scene:t,mode:o,params:a})}},r}(a);function X(e,t){e.constructor.IDEProps||(e.constructor.IDEProps=[]),e.constructor.IDEProps.push(t)}function G(e){return void 0===e&&(e={}),function(t){if(!t.observerInfo){for(var r in e)for(var o in e[r]){"string"==typeof e[r][o]&&(e[r][o]=[e[r][o]]);var n=void 0;Array.isArray(e[r][o])&&(n={prop:e[r][o],deep:!1},e[r][o]=n),"string"==typeof(n=e[r][o]).prop&&(n.prop=[n.prop])}t.observerInfo=e}}}var F,U,Y=function(e){function t(t){var r=t.resource,o=t.resourceTotal,n=e.call(this)||this;return n.progress=0,n.resourceTotal=0,n.resourceLoadedCount=0,n.resource=r,n.resourceTotal=o,0===o&&n.resource.emit(exports.LOAD_EVENT.COMPLETE,n),n}return i(t,e),t.prototype.onStart=function(){this.resource.emit(exports.LOAD_EVENT.START,this)},t.prototype.onProgress=function(e){this.resourceLoadedCount++,this.progress=Math.floor(this.resourceLoadedCount/this.resourceTotal*100)/100,e.success?this.resource.emit(exports.LOAD_EVENT.LOADED,this,e):this.resource.emit(exports.LOAD_EVENT.ERROR,this,e),this.resource.emit(exports.LOAD_EVENT.PROGRESS,this,e),this.resourceLoadedCount===this.resourceTotal&&this.resource.emit(exports.LOAD_EVENT.COMPLETE,this)},t}(a),q={AbstractLoadStrategy:o.AbstractLoadStrategy,AudioLoadStrategy:o.AudioLoadStrategy,ImageLoadStrategy:o.ImageLoadStrategy,XhrResponseType:o.XhrResponseType,MediaElementLoadStrategy:o.MediaElementLoadStrategy,VideoLoadStrategy:o.VideoLoadStrategy,XhrLoadStrategy:o.XhrLoadStrategy,Loader:o.Loader,Resource:o.Resource,ResourceType:o.ResourceType,ResourceState:o.ResourceState};exports.LOAD_EVENT=void 0,(F=exports.LOAD_EVENT||(exports.LOAD_EVENT={})).START="start",F.PROGRESS="progress",F.LOADED="loaded",F.COMPLETE="complete",F.ERROR="error",exports.RESOURCE_TYPE=void 0,(U=exports.RESOURCE_TYPE||(exports.RESOURCE_TYPE={})).IMAGE="IMAGE",U.SPRITE="SPRITE",U.SPRITE_ANIMATION="SPRITE_ANIMATION",U.AUDIO="AUDIO",U.VIDEO="VIDEO",o.XhrLoadStrategy.setExtensionXhrType("json",o.XhrResponseType.Json),o.XhrLoadStrategy.setExtensionXhrType("tex",o.XhrResponseType.Json),o.XhrLoadStrategy.setExtensionXhrType("ske",o.XhrResponseType.Json),o.XhrLoadStrategy.setExtensionXhrType("mp3",o.XhrResponseType.Buffer),o.XhrLoadStrategy.setExtensionXhrType("wav",o.XhrResponseType.Buffer),o.XhrLoadStrategy.setExtensionXhrType("aac",o.XhrResponseType.Buffer),o.XhrLoadStrategy.setExtensionXhrType("ogg",o.XhrResponseType.Buffer);var B={png:o.ImageLoadStrategy,jpg:o.ImageLoadStrategy,jpeg:o.ImageLoadStrategy,webp:o.ImageLoadStrategy,json:o.XhrLoadStrategy,tex:o.XhrLoadStrategy,ske:o.XhrLoadStrategy,audio:o.XhrLoadStrategy,video:o.VideoLoadStrategy},H=new(function(e){function t(t){var r=e.call(this)||this;return r.timeout=6e3,r.preProcessResourceHandlers=[],r.resourcesMap={},r.makeInstanceFunctions={},r.destroyInstanceFunctions={},r.promiseMap={},r.loaders=[],t&&"number"==typeof t.timeout&&(r.timeout=t.timeout),r}return i(t,e),t.prototype.loadConfig=function(e){this.addResource(e),this.preload()},t.prototype.loadSingle=function(e){return this.addResource([e]),this.getResource(e.name)},t.prototype.addResource=function(e){var t,r;if(!e||e.length<1)console.warn("no resources");else try{for(var o=l(e),n=o.next();!n.done;n=o.next()){var a=n.value;this.resourcesMap[a.name]?console.warn(a.name+" was already added"):(this.resourcesMap[a.name]=a,this.resourcesMap[a.name].data={})}}catch(e){t={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}},t.prototype.addPreProcessResourceHandler=function(e){this.preProcessResourceHandlers.push(e)},t.prototype.removePreProcessResourceHandler=function(e){this.preProcessResourceHandlers.splice(this.preProcessResourceHandlers.indexOf(e),1)},t.prototype.preload=function(){var e=[];for(var t in this.resourcesMap){var r=this.resourcesMap[t];!r.preload||r.complete||this.promiseMap[t]||e.push(r.name)}this.progress=new Y({resource:this,resourceTotal:e.length}),this.loadResource({names:e,preload:!0})},t.prototype.getResource=function(e){return u(this,void 0,void 0,(function(){return p(this,(function(t){return this.loadResource({names:[e]}),[2,this.promiseMap[e]||Promise.resolve({})]}))}))},t.prototype.instance=function(e){return u(this,void 0,void 0,(function(){var t,r;return p(this,(function(o){switch(o.label){case 0:return t=this.resourcesMap[e],(r=this.makeInstanceFunctions[t.type])?[4,this.makeInstanceFunctions[t.type](t)]:[3,2];case 1:r=o.sent(),o.label=2;case 2:return[2,r]}}))}))},t.prototype.destroy=function(e){return u(this,void 0,void 0,(function(){return p(this,(function(t){switch(t.label){case 0:return[4,this._destroy(e)];case 1:return t.sent(),[2]}}))}))},t.prototype._destroy=function(e,t){return void 0===t&&(t=!1),u(this,void 0,void 0,(function(){var r,o;return p(this,(function(n){switch(n.label){case 0:if(!(r=this.resourcesMap[e]))return[2];if(t)return[3,5];n.label=1;case 1:return n.trys.push([1,4,,5]),this.destroyInstanceFunctions[r.type]?[4,this.destroyInstanceFunctions[r.type](r)]:[3,3];case 2:n.sent(),n.label=3;case 3:return[3,5];case 4:return o=n.sent(),console.warn("destroy resource "+r.name+" error with '"+o.message+"'"),[3,5];case 5:return delete this.promiseMap[e],r.data={},r.complete=!1,r.instance=void 0,[2]}}))}))},t.prototype.registerResourceType=function(e,t){if(void 0===t&&(t=e),exports.RESOURCE_TYPE[e])throw new Error("The type "+e+" already exists in RESOURCE_TYPE");exports.RESOURCE_TYPE[e]=t},t.prototype.registerInstance=function(e,t){this.makeInstanceFunctions[e]=t},t.prototype.registerDestroy=function(e,t){this.destroyInstanceFunctions[e]=t},t.prototype.loadResource=function(e){var t=this,r=e.names,o=void 0===r?[]:r,n=e.preload,a=void 0!==n&&n,s=o.filter((function(e){return!t.promiseMap[e]&&t.resourcesMap[e]}));if(s.length){var i={},c=this.getLoader(a);s.forEach((function(e){var r,o;t.promiseMap[e]=new Promise((function(t){return i[e]=t}));var n=t.resourcesMap[e];try{for(var s=l(t.preProcessResourceHandlers),u=s.next();!u.done;u=s.next()){(0,u.value)(n)}}catch(e){r={error:e}}finally{try{u&&!u.done&&(o=s.return)&&o.call(s)}finally{if(r)throw r.error}}for(var p in n.src){var f=n.src[p].type;"data"===f?(n.data[p]=n.src[p].data,t.doComplete(e,i[e],a)):c.add({url:n.src[p].url,name:n.name+"_"+p,strategy:B[f],metadata:{key:p,name:n.name,resolves:i}})}})),c.load()}},t.prototype.doComplete=function(e,t,r){return void 0===r&&(r=!1),u(this,void 0,void 0,(function(){var o,n,a,s;return p(this,(function(i){switch(i.label){case 0:if(o=this.resourcesMap[e],n={name:e,resource:this.resourcesMap[e],success:!0},!this.checkAllLoaded(e))return[3,4];i.label=1;case 1:return i.trys.push([1,3,,4]),a=o,[4,this.instance(e)];case 2:return a.instance=i.sent(),o.complete=!0,r&&this.progress.onProgress(n),t(o),[3,4];case 3:return s=i.sent(),console.error(s),o.complete=!1,r&&(n.errMsg=s.message,n.success=!1,this.progress.onProgress(n)),t({}),[3,4];case 4:return[2]}}))}))},t.prototype.checkAllLoaded=function(e){var t=this.resourcesMap[e];return Array.from(Object.keys(t.src)).every((function(e){return t.data[e]}))},t.prototype.getLoader=function(e){var t=this;void 0===e&&(e=!1);var r=this.loaders.find((function(e){return!e.loading}));return r||(r=new o.Loader,this.loaders.push(r)),e&&r.onStart.once((function(){t.progress.onStart()})),r.onLoad.add((function(r,o){t.onLoad({preload:e,resource:o})})),r.onError.add((function(r,o,n){t.onError({errMsg:r,resource:n,preload:e})})),r.onComplete.once((function(){r.onLoad.detachAll(),r.onError.detachAll(),r.reset()})),r},t.prototype.onLoad=function(e){var t=e.preload,r=void 0!==t&&t,o=e.resource;return u(this,void 0,void 0,(function(){var e,t,n,a,s;return p(this,(function(i){return e=o.metadata,t=e.key,n=e.name,a=e.resolves,s=o.data,this.resourcesMap[n].data[t]=s,this.doComplete(n,a[n],r),[2]}))}))},t.prototype.onError=function(e){var t=e.errMsg,r=e.preload,o=void 0!==r&&r,n=e.resource;return u(this,void 0,void 0,(function(){var e,r,a,s;return p(this,(function(i){return e=n.metadata,r=e.name,a=e.resolves,this._destroy(r,!0),a[r]({}),o&&(s={name:r,resource:this.resourcesMap[r],success:!1,errMsg:t},this.progress.onProgress(s)),[2]}))}))},t}(a)),z={IDEProp:X,componentObserver:G};console.log("Eva.js version: 1.2.7"),exports.Component=d,exports.Game=V,exports.GameObject=w,exports.IDEProp=X,exports.RESOURCE_TYPE_STRATEGY=B,exports.Scene=I,exports.System=P,exports.Transform=T,exports.componentObserver=G,exports.decorators=z,exports.resource=H,exports.resourceLoader=q,exports.version="1.2.7";
15
+ ***************************************************************************** */function s(e,t){function r(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function c(e,t,r,o){var n,a=arguments.length,i=a<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,o);else for(var s=e.length-1;s>=0;s--)(n=e[s])&&(i=(a<3?n(i):a>3?n(t,r,i):n(t,r))||i);return a>3&&i&&Object.defineProperty(t,r,i),i}function u(e,t,r,o){return new(r||(r=Promise))((function(n,a){function i(e){try{c(o.next(e))}catch(e){a(e)}}function s(e){try{c(o.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):new r((function(t){t(e.value)})).then(i,s)}c((o=o.apply(e,t||[])).next())}))}function p(e,t){var r,o,n,a,i={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,o&&(n=2&a[0]?o.return:a[0]?o.throw||((n=o.return)&&n.call(o),0):o.next)&&!(n=n.call(o,a[1])).done)return n;switch(o=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,o=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(n=i.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){i.label=a[1];break}if(6===a[0]&&i.label<n[1]){i.label=n[1],n=a;break}if(n&&i.label<n[2]){i.label=n[2],i.ops.push(a);break}n[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],o=0}finally{r=n=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}function l(e){var t="function"==typeof Symbol&&e[Symbol.iterator],r=0;return t?t.call(e):{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}function f(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var o,n,a=r.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(o=a.next()).done;)i.push(o.value)}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return i}function h(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(f(arguments[t]));return e}var y,m=function(e){function t(t){var r=e.call(this)||this;return r.started=!1,r.name=r.constructor.componentName,r.__componentDefaultParams=t,r}return s(t,e),t}(a),d=m;exports.OBSERVER_TYPE=void 0,(y=exports.OBSERVER_TYPE||(exports.OBSERVER_TYPE={})).ADD="ADD",y.REMOVE="REMOVE",y.CHANGE="CHANGE";var v={},g={},b={},E={};function _(e,t){v[e.gameObject.id]||(v[e.gameObject.id]={});var r=v[e.gameObject.id],o=e.name+"_"+t.join(",");if(r[o])return r[o];for(var n=t.length-1,a=e,i=0;i<n;i++)a=a[t[i]];return r[o]={property:a,key:t[n]},r[o]}function O(e){var t,r,o=e.systemName,n=e.componentName,a=e.component,i=e.prop,s=e.type;null===(r=null===(t=g[o])||void 0===t?void 0:t.componentObserver)||void 0===r||r.add({component:a,prop:i,type:s,componentName:n})}function x(e){var r,o,n=e.obj,a=e.key,i=e.prop,s=e.component,c=e.componentName;if(void 0!==n)if(a in n){if(Object.defineProperty(n,"_"+a,{enumerable:!1,writable:!0,value:n[a]}),i.deep&&t.isObject(n[a]))try{for(var u=l(Object.keys(n[a])),p=u.next();!p.done;p=u.next()){var f=p.value;x({obj:n[a],key:f,prop:i,component:s,componentName:c})}}catch(e){r={error:e}}finally{try{p&&!p.done&&(o=u.return)&&o.call(u)}finally{if(r)throw r.error}}Object.defineProperty(n,a,{enumerable:!0,set:function(e){n["_"+a]!==e&&(n["_"+a]=e,function(e){var r=e.prop,o=e.component,n=e.componentName;for(var a in b){var i=(b[a]||{})[n];i&&i.findIndex((function(e){return t.isEqual(e,r)}))>-1&&O({systemName:a,componentName:n,component:o,prop:r,type:exports.OBSERVER_TYPE.CHANGE})}}({prop:i,component:s,componentName:c}))},get:function(){return n["_"+a]}})}else console.error("prop "+a+" not in component: "+c+", Can not observer")}function R(e,t){var r,o;for(var n in void 0===t&&(t=e.name),b){(b[n]||{})[t]&&(null===(o=null===(r=g[n])||void 0===r?void 0:r.componentObserver)||void 0===o||o.add({component:e,type:exports.OBSERVER_TYPE.REMOVE,componentName:t}))}!function(e){e.gameObject&&delete v[e.gameObject.id]}(e)}var T=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.name="Transform",t._parent=null,t.inScene=!1,t.children=[],t.position={x:0,y:0},t.size={width:0,height:0},t.origin={x:0,y:0},t.anchor={x:0,y:0},t.scale={x:1,y:1},t.skew={x:0,y:0},t.rotation=0,t}return s(t,e),t.prototype.init=function(e){var t,r;void 0===e&&(e={});try{for(var o=l(["position","size","origin","anchor","scale","skew"]),n=o.next();!n.done;n=o.next()){var a=n.value;Object.assign(this[a],e[a])}}catch(e){t={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}this.rotation=e.rotation||this.rotation},Object.defineProperty(t.prototype,"parent",{get:function(){return this._parent},set:function(e){e?e.addChild(this):this.parent&&this.parent.removeChild(this)},enumerable:!1,configurable:!0}),t.prototype.addChild=function(e){if(e.parent===this){var t=this.children.findIndex((function(t){return t===e}));this.children.splice(t,1)}else e.parent&&e.parent.removeChild(e);e._parent=this,this.children.push(e)},t.prototype.removeChild=function(e){var t=this.children.findIndex((function(t){return t===e}));t>-1&&(this.children.splice(t,1),e._parent=null)},t.prototype.clearChildren=function(){this.children.length=0},t.componentName="Transform",c([r.type("vector2"),r.step(1)],t.prototype,"position",void 0),c([r.type("size"),r.step(1)],t.prototype,"size",void 0),c([r.type("vector2"),r.step(.1)],t.prototype,"origin",void 0),c([r.type("vector2"),r.step(.1)],t.prototype,"anchor",void 0),c([r.type("vector2"),r.step(.1)],t.prototype,"scale",void 0),c([r.type("vector2"),r.step(.1)],t.prototype,"skew",void 0),c([r.type("number"),r.step(.1)],t.prototype,"rotation",void 0),t}(d),S=0;var w=function(){function e(e,t){this._componentCache={},this.components=[],this.destroyed=!1,this._name=e,this.id=++S,this.addComponent(T,t)}return Object.defineProperty(e.prototype,"transform",{get:function(){return this.getComponent(T)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this.transform&&this.transform.parent&&this.transform.parent.gameObject},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"name",{get:function(){return this._name},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"scene",{get:function(){return this._scene},set:function(e){var t,r;if(this._scene!==e){var o=this._scene;if(this._scene=e,this.transform&&this.transform.children)try{for(var n=l(this.transform.children),a=n.next();!a.done;a=n.next()){a.value.gameObject.scene=e}}catch(e){t={error:e}}finally{try{a&&!a.done&&(r=n.return)&&r.call(n)}finally{if(t)throw t.error}}e?e.addGameObject(this):o&&o.removeGameObject(this)}},enumerable:!1,configurable:!0}),e.prototype.addChild=function(t){if(t&&t.transform&&t!==this){if(!(t instanceof e))throw new Error("addChild only receive GameObject");if(!this.transform)throw new Error("gameObject '"+this.name+"' has been destroy");t.transform.parent=this.transform,t.scene=this.scene}},e.prototype.removeChild=function(t){return t instanceof e&&t.parent&&t.parent===this?(t.transform.parent=null,t.scene=null,t):t},e.prototype.addComponent=function(e,t){if(!this.destroyed){var r=function(e){return e instanceof m?e.name:e instanceof Function?e.componentName:void 0}(e);if(!this._componentCache[r]){var o;if(e instanceof Function)o=new e(t);else{if(!(e instanceof d))throw new Error("addComponent recieve Component and Component Constructor");o=e}if(o.gameObject)throw new Error("component has been added on gameObject "+o.gameObject.name);return o.gameObject=this,o.init&&o.init(o.__componentDefaultParams),function(e,t){var r,o;for(var n in void 0===t&&(t=e.name),b)(b[n]||{})[t]&&(null===(o=null===(r=g[n])||void 0===r?void 0:r.componentObserver)||void 0===o||o.add({component:e,type:exports.OBSERVER_TYPE.ADD,componentName:t}))}(o,o.name),function(e,t){var r,o;if(void 0===t&&(t=e.name),t&&E[t]){if(!(e&&(n=e,n&&n.constructor&&"componentName"in n.constructor)))throw new Error("component param must be an instance of Component");var n;if(!e.gameObject||!e.gameObject.id)throw new Error("component should be add to a gameObject");try{for(var a=l(E[t]),i=a.next();!i.done;i=a.next()){var s=i.value,c=_(e,s.prop);x({obj:c.property,key:c.key,prop:s,component:e,componentName:t})}}catch(e){r={error:e}}finally{try{i&&!i.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}}}(o,o.name),this.components.push(o),this._componentCache[r]=o,o.awake&&o.awake(),o}}},e.prototype.removeComponent=function(e){var t;if("string"==typeof e?t=e:e instanceof d?t=e.name:e.componentName&&(t=e.componentName),"Transform"===t)throw new Error("Transform can't be removed");return this._removeComponent(t)},e.prototype._removeComponent=function(e){var t=this.components.findIndex((function(t){return t.name===e}));if(-1!==t){var r=this.components.splice(t,1)[0];return delete this._componentCache[e],delete r.__componentDefaultParams,r.onDestroy&&r.onDestroy(),R(r,e),r.gameObject=void 0,r}},e.prototype.getComponent=function(e){var t;return"string"==typeof e?t=e:e instanceof d?t=e.name:e.componentName&&(t=e.componentName),void 0!==this._componentCache[t]?this._componentCache[t]:void 0},e.prototype.remove=function(){if(this.parent)return this.parent.removeChild(this)},e.prototype.destroy=function(){if(this.transform){for(var e in Array.from(this.transform.children).forEach((function(e){e.gameObject.destroy()})),this.remove(),this.transform.clearChildren(),this._componentCache)this._removeComponent(e);this.components.length=0,this.destroyed=!0}else console.error("Cannot destroy gameObject that have already been destroyed.")},e}(),k=function(){function e(){this.events=[]}return e.prototype.add=function(e){var r=e.component,o=e.prop,n=e.type,a=e.componentName;if(n===exports.OBSERVER_TYPE.REMOVE){if(this.events.find((function(e){return e.component===r&&e.type===exports.OBSERVER_TYPE.ADD})))return void(this.events=this.events.filter((function(e){return e.component!==r})));this.events=this.events.filter((function(e){return e.component!==r}))}var i=this.events.findIndex((function(e){return e.component===r&&t.isEqual(e.prop,o)&&e.type===n}));i>-1&&this.events.splice(i,1),this.events.push({gameObject:r.gameObject,component:r,prop:o,type:n,componentName:a})},e.prototype.getChanged=function(){return this.events},Object.defineProperty(e.prototype,"changed",{get:function(){return this.events},enumerable:!1,configurable:!0}),e.prototype.clear=function(){var e=this.events;return this.events=[],e},e}(),P=function(){function e(e){this.started=!1,this.componentObserver=new k,this.__systemDefaultParams=e,this.name=this.constructor.systemName}return e.prototype.destroy=function(){var e;this.componentObserver=null,this.__systemDefaultParams=null,null===(e=this.onDestroy)||void 0===e||e.call(this)},e}();var j,L=Date.now?Date.now:function(){return(new Date).getTime()},C={originTime:0,playbackRate:1},M=function(){function e(t,r){t instanceof e&&(r=t,t={}),t=Object.assign({},C,t),r&&(this._parent=r),this._createTime=L(),this._timeMark=[{globalTime:this.globalTime,localTime:-t.originTime,entropy:-t.originTime,playbackRate:t.playbackRate,globalEntropy:0}],this._parent&&(this._timeMark[0].globalEntropy=this._parent.entropy),this._playbackRate=t.playbackRate}return Object.defineProperty(e.prototype,"globalTime",{get:function(){return this.parent?this.parent.currentTime:L()-this._createTime},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"lastTimeMark",{get:function(){return this._timeMark[this._timeMark.length-1]},enumerable:!1,configurable:!0}),e.prototype.markTime=function(e){var t=void 0===e?{}:e,r=t.time,o=void 0===r?this.currentTime:r,n=t.entropy,a=void 0===n?this.entropy:n,i=t.playbackRate,s=void 0===i?this.playbackRate:i,c={globalTime:this.globalTime,localTime:o,entropy:a,playbackRate:s,globalEntropy:this.globalEntropy};this._timeMark.push(c)},Object.defineProperty(e.prototype,"currentTime",{get:function(){var e=this.lastTimeMark,t=e.localTime,r=e.globalTime;return t+(this.globalTime-r)*this.playbackRate},set:function(e){this.markTime({time:e})},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"globalEntropy",{get:function(){return this._parent?this._parent.entropy:this.globalTime},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"entropy",{get:function(){var e=this.lastTimeMark,t=e.entropy,r=e.globalEntropy;return t+Math.abs((this.globalEntropy-r)*this.playbackRate)},set:function(e){if(this.entropy>e){var t=this.seekTimeMark(e);this._timeMark.length=t+1}this.markTime({entropy:e})},enumerable:!1,configurable:!0}),e.prototype.fork=function(t){return new e(t,this)},e.prototype.seekGlobalTime=function(e){var t=this.seekTimeMark(e),r=this._timeMark[t],o=r.entropy,n=r.playbackRate;return r.globalTime+(e-o)/Math.abs(n)},e.prototype.seekLocalTime=function(e){var t=this.seekTimeMark(e),r=this._timeMark[t],o=r.localTime,n=r.entropy;return r.playbackRate>0?o+(e-n):o-(e-n)},e.prototype.seekTimeMark=function(e){var t=this._timeMark,r=0,o=t.length-1;if(e<=t[r].entropy)return r;if(e>=t[o].entropy)return o;for(var n=Math.floor((r+o)/2);n>r&&n<o;){if(e===t[n].entropy)return n;e<t[n].entropy?o=n:e>t[n].entropy&&(r=n),n=Math.floor((r+o)/2)}return r},Object.defineProperty(e.prototype,"playbackRate",{get:function(){return this._playbackRate},set:function(e){e!==this.playbackRate&&(this.markTime({playbackRate:e}),this._playbackRate=e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"paused",{get:function(){if(0===this.playbackRate)return!0;for(var e=this.parent;e;){if(0===e.playbackRate)return!0;e=e.parent}return!1},enumerable:!1,configurable:!0}),e}(),N={autoStart:!0,frameRate:60},A=function(){function e(e){var t=this;e=Object.assign({},N,e),this._frameCount=0,this._frameDuration=1e3/e.frameRate,this.autoStart=e.autoStart,this.frameRate=e.frameRate,this.timeline=new M({originTime:0,playbackRate:1}),this._lastFrameTime=this.timeline.currentTime,this._tickers=new Set,this._requestId=null,this._ticker=function(){t._started&&(t._requestId=requestAnimationFrame(t._ticker),t.update())},this.autoStart&&this.start()}return e.prototype.update=function(){var e,t,r=this.timeline.currentTime,o=r-this._lastFrameTime;if(o>=this._frameDuration){var n=r-o%this._frameDuration,a=n-this._lastFrameTime;this._lastFrameTime=n;var i={deltaTime:a,time:n,currentTime:n,frameCount:++this._frameCount,fps:Math.round(1e3/a)};try{for(var s=l(this._tickers),c=s.next();!c.done;c=s.next()){var u=c.value;"function"==typeof u&&u(i)}}catch(t){e={error:t}}finally{try{c&&!c.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}}},e.prototype.add=function(e){this._tickers.add(e)},e.prototype.remove=function(e){this._tickers.delete(e)},e.prototype.start=function(){this._started||(this._started=!0,this.timeline.playbackRate=1,this._requestId=requestAnimationFrame(this._ticker))},e.prototype.pause=function(){this._started=!1,this.timeline.playbackRate=0},e.prototype.setPlaybackRate=function(e){this.timeline.playbackRate=e},e}(),I=function(e){function t(t,r){var o=e.call(this,t,r)||this;return o.gameObjects=[],o.scene=o,o}return s(t,e),t.prototype.addGameObject=function(e){this.gameObjects.push(e),e.transform&&(e.transform.inScene=!0)},t.prototype.removeGameObject=function(e){var t=this.gameObjects.indexOf(e);-1!==t&&(e.transform&&(e.transform.inScene=!1),this.gameObjects.splice(t,1))},t.prototype.destroy=function(){this.scene=null,e.prototype.destroy.call(this),this.gameObjects=null,this.canvas=null},t}(w);exports.LOAD_SCENE_MODE=void 0,(j=exports.LOAD_SCENE_MODE||(exports.LOAD_SCENE_MODE={})).SINGLE="SINGLE",j.MULTI_CANVAS="MULTI_CANVAS";var D=function(e){if((e instanceof P||e instanceof d)&&!e.started){e.started=!0;try{e.start&&e.start()}catch(t){e instanceof d?console.error(e.constructor.componentName+" start error",t):console.error(e.constructor.systemName+" start error",t)}}},V=function(e){function r(t){var r,o,n=void 0===t?{}:t,a=n.systems,i=n.frameRate,s=void 0===i?60:i,c=n.autoStart,u=void 0===c||c,p=n.needScene,f=void 0===p||p,h=e.call(this)||this;if(h.playing=!1,h.started=!1,h.multiScenes=[],h.systems=[],window.__EVA_INSPECTOR_ENV__&&(window.__EVA_GAME_INSTANCE__=h),h.ticker=new A({autoStart:!1,frameRate:s}),h.initTicker(),a&&a.length)try{for(var y=l(a),m=y.next();!m.done;m=y.next()){var d=m.value;h.addSystem(d)}}catch(e){r={error:e}}finally{try{m&&!m.done&&(o=y.return)&&o.call(y)}finally{if(r)throw r.error}}return f&&h.loadScene(new I("scene")),u&&h.start(),h}return s(r,e),Object.defineProperty(r.prototype,"scene",{get:function(){return this._scene},set:function(e){this._scene=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"gameObjects",{get:function(){return function(e){var t,r,o,n=(null===(o=null==e?void 0:e.scene)||void 0===o?void 0:o.gameObjects)||[],a=null==e?void 0:e.multiScenes.map((function(e){return e.gameObjects})),i=[];try{for(var s=l(a),c=s.next();!c.done;c=s.next())i=h(i,c.value)}catch(e){t={error:e}}finally{try{c&&!c.done&&(r=s.return)&&r.call(s)}finally{if(t)throw t.error}}return h(n,i)}(this)},enumerable:!1,configurable:!0}),r.prototype.addSystem=function(e,r){var o;if(e instanceof Function)o=new e(r);else{if(!(e instanceof P))return void console.warn("can only add System");o=e}if(!this.systems.find((function(e){return e.constructor===o.constructor}))){o.game=this,o.init&&o.init(o.__systemDefaultParams),function(e,t){b[t.systemName]=t.observerInfo,g[t.systemName]=e}(o,o.constructor),function(e){var r,o,n,a,i=[];e instanceof Array?i.push.apply(i,h(e)):i.push(e);try{for(var s=l(i),c=s.next();!c.done;c=s.next()){var u=c.value;for(var p in u.observerInfo){E[p]=E[p]||[];var f=E[p],y=function(e){-1===f.findIndex((function(r){return t.isEqual(r,e)}))&&E[p].push(e)};try{for(var m=(n=void 0,l(u.observerInfo[p])),d=m.next();!d.done;d=m.next())y(d.value)}catch(e){n={error:e}}finally{try{d&&!d.done&&(a=m.return)&&a.call(m)}finally{if(n)throw n.error}}}}}catch(e){r={error:e}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}finally{if(r)throw r.error}}}(o.constructor);try{o.awake&&o.awake()}catch(e){console.error(o.constructor.systemName+" awake error",e)}return this.systems.push(o),o}console.warn(o.constructor.systemName+" System has been added")},r.prototype.removeSystem=function(e){if(e){var t=-1;"string"==typeof e?t=this.systems.findIndex((function(t){return t.name===e})):e instanceof Function?t=this.systems.findIndex((function(t){return t.constructor===e})):e instanceof P&&(t=this.systems.findIndex((function(t){return t===e}))),t>-1&&(this.systems[t].destroy&&this.systems[t].destroy(),this.systems.splice(t,1))}},r.prototype.getSystem=function(e){return this.systems.find((function(t){return"string"==typeof e?t.name===e:t instanceof e}))},r.prototype.pause=function(){this.playing&&(this.playing=!1,this.ticker.pause(),this.triggerPause())},r.prototype.start=function(){this.playing||(this.playing=!0,this.started=!0,this.ticker.start())},r.prototype.resume=function(){this.playing||(this.playing=!0,this.ticker.start(),this.triggerResume())},r.prototype.initTicker=function(){var e=this;this.ticker.add((function(t){var r,o,n,a;e.scene&&function(e,t){var r,o,n,a,i,s,c,u;void 0===t&&(t=[]);try{for(var p=l(t),f=p.next();!f.done;f=p.next()){var h=f.value;try{for(var y=(n=void 0,l(h.components)),m=y.next();!m.done;m=y.next()){var d=m.value;try{D(d),d.update&&d.update(e)}catch(e){console.error("gameObject: "+h.name+" "+d.name+" update error",e)}}}catch(e){n={error:e}}finally{try{m&&!m.done&&(a=y.return)&&a.call(y)}finally{if(n)throw n.error}}}}catch(e){r={error:e}}finally{try{f&&!f.done&&(o=p.return)&&o.call(p)}finally{if(r)throw r.error}}try{for(var v=l(t),g=v.next();!g.done;g=v.next()){h=g.value;try{for(var b=(c=void 0,l(h.components)),E=b.next();!E.done;E=b.next()){d=E.value;try{d.lateUpdate&&d.lateUpdate(e)}catch(e){console.error("gameObject: "+h.name+" "+d.name+" lateUpdate error",e)}}}catch(e){c={error:e}}finally{try{E&&!E.done&&(u=b.return)&&u.call(b)}finally{if(c)throw c.error}}}}catch(e){i={error:e}}finally{try{g&&!g.done&&(s=v.return)&&s.call(v)}finally{if(i)throw i.error}}}(t,e.gameObjects);try{for(var i=l(e.systems),s=i.next();!s.done;s=i.next()){var c=s.value;try{D(c),c.update&&c.update(t)}catch(t){console.error(c.constructor.systemName+" update error",t)}}}catch(e){r={error:e}}finally{try{s&&!s.done&&(o=i.return)&&o.call(i)}finally{if(r)throw r.error}}try{for(var u=l(e.systems),p=u.next();!p.done;p=u.next()){c=p.value;try{c.lateUpdate&&c.lateUpdate(t)}catch(t){console.error(c.constructor.systemName+" lateUpdate error",t)}}}catch(e){n={error:e}}finally{try{p&&!p.done&&(a=u.return)&&a.call(u)}finally{if(n)throw n.error}}}))},r.prototype.triggerResume=function(){var e,t;!function(e){var t,r,o,n;try{for(var a=l(e),i=a.next();!i.done;i=a.next()){var s=i.value;try{for(var c=(o=void 0,l(s.components)),u=c.next();!u.done;u=c.next()){var p=u.value;try{p.onResume&&p.onResume()}catch(e){console.error("gameObject: "+s.name+", "+p.name+", onResume error",e)}}}catch(e){o={error:e}}finally{try{u&&!u.done&&(n=c.return)&&n.call(c)}finally{if(o)throw o.error}}}}catch(e){t={error:e}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}}(this.gameObjects);try{for(var r=l(this.systems),o=r.next();!o.done;o=r.next()){var n=o.value;try{n.onResume&&n.onResume()}catch(e){console.error(n.constructor.systemName+", onResume error",e)}}}catch(t){e={error:t}}finally{try{o&&!o.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}},r.prototype.triggerPause=function(){var e,t;!function(e){var t,r,o,n;try{for(var a=l(e),i=a.next();!i.done;i=a.next()){var s=i.value;try{for(var c=(o=void 0,l(s.components)),u=c.next();!u.done;u=c.next()){var p=u.value;try{p.onPause&&p.onPause()}catch(e){console.error("gameObject: "+s.name+", "+p.name+", onResume error",e)}}}catch(e){o={error:e}}finally{try{u&&!u.done&&(n=c.return)&&n.call(c)}finally{if(o)throw o.error}}}}catch(e){t={error:e}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}}(this.gameObjects);try{for(var r=l(this.systems),o=r.next();!o.done;o=r.next()){var n=o.value;try{n.onPause&&n.onPause()}catch(e){console.error(n.constructor.systemName+", onPause error",e)}}}catch(t){e={error:t}}finally{try{o&&!o.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}},r.prototype.destroySystems=function(){var e,t;try{for(var r=l(h(this.systems)),o=r.next();!o.done;o=r.next()){var n=o.value;this.removeSystem(n)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}this.systems.length=0},r.prototype.destroy=function(){this.removeAllListeners(),this.pause(),this.scene.destroy(),this.destroySystems(),this.ticker=null,this.scene=null,this.canvas=null,this.multiScenes=null},r.prototype.loadScene=function(e){var t=e.scene,r=e.mode,o=void 0===r?exports.LOAD_SCENE_MODE.SINGLE:r,n=e.params,a=void 0===n?{}:n;if(t){switch(o){case exports.LOAD_SCENE_MODE.SINGLE:this.scene=t;break;case exports.LOAD_SCENE_MODE.MULTI_CANVAS:this.multiScenes.push(t)}this.emit("sceneChanged",{scene:t,mode:o,params:a})}},r}(a);function X(e,t){e.constructor.IDEProps||(e.constructor.IDEProps=[]),e.constructor.IDEProps.push(t)}function G(e){return void 0===e&&(e={}),function(t){if(!t.observerInfo){for(var r in e)for(var o in e[r]){"string"==typeof e[r][o]&&(e[r][o]=[e[r][o]]);var n=void 0;Array.isArray(e[r][o])&&(n={prop:e[r][o],deep:!1},e[r][o]=n),"string"==typeof(n=e[r][o]).prop&&(n.prop=[n.prop])}t.observerInfo=e}}}var F,U,Y=function(e){function t(t){var r=t.resource,o=t.resourceTotal,n=e.call(this)||this;return n.progress=0,n.resourceTotal=0,n.resourceLoadedCount=0,n.resource=r,n.resourceTotal=o,0===o&&n.resource.emit(exports.LOAD_EVENT.COMPLETE,n),n}return s(t,e),t.prototype.onStart=function(){this.resource.emit(exports.LOAD_EVENT.START,this)},t.prototype.onProgress=function(e){this.resourceLoadedCount++,this.progress=Math.floor(this.resourceLoadedCount/this.resourceTotal*100)/100,e.success?this.resource.emit(exports.LOAD_EVENT.LOADED,this,e):this.resource.emit(exports.LOAD_EVENT.ERROR,this,e),this.resource.emit(exports.LOAD_EVENT.PROGRESS,this,e),this.resourceLoadedCount===this.resourceTotal&&this.resource.emit(exports.LOAD_EVENT.COMPLETE,this)},t}(a),q=Y,B={AbstractLoadStrategy:o.AbstractLoadStrategy,AudioLoadStrategy:o.AudioLoadStrategy,ImageLoadStrategy:o.ImageLoadStrategy,XhrResponseType:o.XhrResponseType,MediaElementLoadStrategy:o.MediaElementLoadStrategy,VideoLoadStrategy:o.VideoLoadStrategy,XhrLoadStrategy:o.XhrLoadStrategy,Loader:o.Loader,Resource:o.Resource,ResourceType:o.ResourceType,ResourceState:o.ResourceState};exports.LOAD_EVENT=void 0,(F=exports.LOAD_EVENT||(exports.LOAD_EVENT={})).START="start",F.PROGRESS="progress",F.LOADED="loaded",F.COMPLETE="complete",F.ERROR="error",exports.RESOURCE_TYPE=void 0,(U=exports.RESOURCE_TYPE||(exports.RESOURCE_TYPE={})).IMAGE="IMAGE",U.SPRITE="SPRITE",U.SPRITE_ANIMATION="SPRITE_ANIMATION",U.AUDIO="AUDIO",U.VIDEO="VIDEO",o.XhrLoadStrategy.setExtensionXhrType("json",o.XhrResponseType.Json),o.XhrLoadStrategy.setExtensionXhrType("tex",o.XhrResponseType.Json),o.XhrLoadStrategy.setExtensionXhrType("ske",o.XhrResponseType.Json),o.XhrLoadStrategy.setExtensionXhrType("mp3",o.XhrResponseType.Buffer),o.XhrLoadStrategy.setExtensionXhrType("wav",o.XhrResponseType.Buffer),o.XhrLoadStrategy.setExtensionXhrType("aac",o.XhrResponseType.Buffer),o.XhrLoadStrategy.setExtensionXhrType("ogg",o.XhrResponseType.Buffer);var H={png:o.ImageLoadStrategy,jpg:o.ImageLoadStrategy,jpeg:o.ImageLoadStrategy,webp:o.ImageLoadStrategy,json:o.XhrLoadStrategy,tex:o.XhrLoadStrategy,ske:o.XhrLoadStrategy,audio:o.XhrLoadStrategy,video:o.VideoLoadStrategy},z=function(e){function t(t){var r=e.call(this)||this;return r.timeout=6e3,r.preProcessResourceHandlers=[],r.resourcesMap={},r.makeInstanceFunctions={},r.destroyInstanceFunctions={},r.promiseMap={},r.loaders=[],t&&"number"==typeof t.timeout&&(r.timeout=t.timeout),r}return s(t,e),t.prototype.loadConfig=function(e){this.addResource(e),this.preload()},t.prototype.loadSingle=function(e){return this.addResource([e]),this.getResource(e.name)},t.prototype.addResource=function(e){var t,r;if(!e||e.length<1)console.warn("no resources");else try{for(var o=l(e),n=o.next();!n.done;n=o.next()){var a=n.value;this.resourcesMap[a.name]?console.warn(a.name+" was already added"):(this.resourcesMap[a.name]=a,this.resourcesMap[a.name].data={})}}catch(e){t={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}},t.prototype.addPreProcessResourceHandler=function(e){this.preProcessResourceHandlers.push(e)},t.prototype.removePreProcessResourceHandler=function(e){this.preProcessResourceHandlers.splice(this.preProcessResourceHandlers.indexOf(e),1)},t.prototype.preload=function(){var e=[];for(var t in this.resourcesMap){var r=this.resourcesMap[t];!r.preload||r.complete||this.promiseMap[t]||e.push(r.name)}this.progress=new q({resource:this,resourceTotal:e.length}),this.loadResource({names:e,preload:!0})},t.prototype.getResource=function(e){return u(this,void 0,void 0,(function(){return p(this,(function(t){return this.loadResource({names:[e]}),[2,this.promiseMap[e]||Promise.resolve({})]}))}))},t.prototype.instance=function(e){return u(this,void 0,void 0,(function(){var t,r;return p(this,(function(o){switch(o.label){case 0:return t=this.resourcesMap[e],(r=this.makeInstanceFunctions[t.type])?[4,this.makeInstanceFunctions[t.type](t)]:[3,2];case 1:r=o.sent(),o.label=2;case 2:return[2,r]}}))}))},t.prototype.destroy=function(e){return u(this,void 0,void 0,(function(){return p(this,(function(t){switch(t.label){case 0:return[4,this._destroy(e)];case 1:return t.sent(),[2]}}))}))},t.prototype._destroy=function(e,t){return void 0===t&&(t=!1),u(this,void 0,void 0,(function(){var r,o;return p(this,(function(n){switch(n.label){case 0:if(!(r=this.resourcesMap[e]))return[2];if(t)return[3,5];n.label=1;case 1:return n.trys.push([1,4,,5]),this.destroyInstanceFunctions[r.type]?[4,this.destroyInstanceFunctions[r.type](r)]:[3,3];case 2:n.sent(),n.label=3;case 3:return[3,5];case 4:return o=n.sent(),console.warn("destroy resource "+r.name+" error with '"+o.message+"'"),[3,5];case 5:return delete this.promiseMap[e],r.data={},r.complete=!1,r.instance=void 0,[2]}}))}))},t.prototype.registerResourceType=function(e,t){if(void 0===t&&(t=e),exports.RESOURCE_TYPE[e])throw new Error("The type "+e+" already exists in RESOURCE_TYPE");exports.RESOURCE_TYPE[e]=t},t.prototype.registerInstance=function(e,t){this.makeInstanceFunctions[e]=t},t.prototype.registerDestroy=function(e,t){this.destroyInstanceFunctions[e]=t},t.prototype.loadResource=function(e){var t=this,r=e.names,o=void 0===r?[]:r,n=e.preload,a=void 0!==n&&n,i=o.filter((function(e){return!t.promiseMap[e]&&t.resourcesMap[e]}));if(i.length){var s={},c=this.getLoader(a);i.forEach((function(e){var r,o;t.promiseMap[e]=new Promise((function(t){return s[e]=t}));var n=t.resourcesMap[e];try{for(var i=l(t.preProcessResourceHandlers),u=i.next();!u.done;u=i.next()){(0,u.value)(n)}}catch(e){r={error:e}}finally{try{u&&!u.done&&(o=i.return)&&o.call(i)}finally{if(r)throw r.error}}for(var p in n.src){var f=n.src[p].type;"data"===f?(n.data[p]=n.src[p].data,t.doComplete(e,s[e],a)):c.add({url:n.src[p].url,name:n.name+"_"+p,strategy:H[f],metadata:{key:p,name:n.name,resolves:s}})}})),c.load()}},t.prototype.doComplete=function(e,t,r){return void 0===r&&(r=!1),u(this,void 0,void 0,(function(){var o,n,a,i;return p(this,(function(s){switch(s.label){case 0:if(o=this.resourcesMap[e],n={name:e,resource:this.resourcesMap[e],success:!0},!this.checkAllLoaded(e))return[3,4];s.label=1;case 1:return s.trys.push([1,3,,4]),a=o,[4,this.instance(e)];case 2:return a.instance=s.sent(),o.complete=!0,r&&this.progress.onProgress(n),t(o),[3,4];case 3:return i=s.sent(),console.error(i),o.complete=!1,r&&(n.errMsg=i.message,n.success=!1,this.progress.onProgress(n)),t({}),[3,4];case 4:return[2]}}))}))},t.prototype.checkAllLoaded=function(e){var t=this.resourcesMap[e];return Array.from(Object.keys(t.src)).every((function(e){return t.data[e]}))},t.prototype.getLoader=function(e){var t=this;void 0===e&&(e=!1);var r=this.loaders.find((function(e){return!e.loading}));return r||(r=new o.Loader,this.loaders.push(r)),e&&r.onStart.once((function(){t.progress.onStart()})),r.onLoad.add((function(r,o){t.onLoad({preload:e,resource:o})})),r.onError.add((function(r,o,n){t.onError({errMsg:r,resource:n,preload:e})})),r.onComplete.once((function(){r.onLoad.detachAll(),r.onError.detachAll(),r.reset()})),r},t.prototype.onLoad=function(e){var t=e.preload,r=void 0!==t&&t,o=e.resource;return u(this,void 0,void 0,(function(){var e,t,n,a,i;return p(this,(function(s){return e=o.metadata,t=e.key,n=e.name,a=e.resolves,i=o.data,this.resourcesMap[n].data[t]=i,this.doComplete(n,a[n],r),[2]}))}))},t.prototype.onError=function(e){var t=e.errMsg,r=e.preload,o=void 0!==r&&r,n=e.resource;return u(this,void 0,void 0,(function(){var e,r,a,i;return p(this,(function(s){return e=n.metadata,r=e.name,a=e.resolves,this._destroy(r,!0),a[r]({}),o&&(i={name:r,resource:this.resourcesMap[r],success:!1,errMsg:t},this.progress.onProgress(i)),[2]}))}))},t}(a),J=new z,K={IDEProp:X,componentObserver:G};console.log("Eva.js version: 1.2.7-fix.2"),exports.Component=d,exports.Game=V,exports.GameObject=w,exports.IDEProp=X,exports.RESOURCE_TYPE_STRATEGY=H,exports.Scene=I,exports.System=P,exports.Transform=T,exports.componentObserver=G,exports.decorators=K,exports.resource=J,exports.resourceLoader=B,exports.version="1.2.7-fix.2";
package/dist/eva.js.d.ts CHANGED
@@ -1,5 +1,16 @@
1
+ import { AbstractLoadStrategy } from 'resource-loader';
2
+ import { AudioLoadStrategy } from 'resource-loader';
1
3
  import EE from 'eventemitter3';
2
4
  import EventEmitter from 'eventemitter3';
5
+ import { ImageLoadStrategy } from 'resource-loader';
6
+ import { Loader } from 'resource-loader';
7
+ import { MediaElementLoadStrategy } from 'resource-loader';
8
+ import { Resource as Resource_2 } from 'resource-loader';
9
+ import { ResourceState } from 'resource-loader';
10
+ import { ResourceType } from 'resource-loader';
11
+ import { VideoLoadStrategy } from 'resource-loader';
12
+ import { XhrLoadStrategy } from 'resource-loader';
13
+ import { XhrResponseType } from 'resource-loader';
3
14
 
4
15
  export declare class Component<T extends ComponentParams = {}> extends EventEmitter {
5
16
  static componentName: string;
@@ -68,9 +79,9 @@ export declare class Game extends EventEmitter {
68
79
  set scene(scene: Scene);
69
80
  get gameObjects(): any[];
70
81
  addSystem<T extends System>(S: T): T;
71
- addSystem<T extends SystemType>(S: T, obj?: any): InstanceType<T>;
72
- removeSystem(system: System | SystemType | string): void;
73
- getSystem(S: SystemType | string): System;
82
+ addSystem<T extends System>(S: SystemConstructor<T>, obj?: ConstructorParameters<SystemConstructor<T>>): T;
83
+ removeSystem<S extends System>(system: S | SystemConstructor<S> | string): void;
84
+ getSystem<T extends System>(S: SystemConstructor<T> | string): T;
74
85
  pause(): void;
75
86
  start(): void;
76
87
  resume(): void;
@@ -88,6 +99,7 @@ export declare class GameObject {
88
99
  private _componentCache;
89
100
  id: number;
90
101
  components: Component<ComponentParams>[];
102
+ destroyed: boolean;
91
103
  constructor(name: string, obj?: TransformParams);
92
104
  get transform(): Transform;
93
105
  get parent(): GameObject;
@@ -133,7 +145,26 @@ export declare enum LOAD_SCENE_MODE {
133
145
  declare interface LoadSceneParams {
134
146
  scene: Scene;
135
147
  mode?: LOAD_SCENE_MODE;
136
- params?: any;
148
+ params?: {
149
+ width?: number;
150
+ height?: number;
151
+ canvas?: HTMLCanvasElement;
152
+ renderType?: number;
153
+ autoStart?: boolean;
154
+ sharedTicker?: boolean;
155
+ sharedLoader?: boolean;
156
+ transparent?: boolean;
157
+ antialias?: boolean;
158
+ preserveDrawingBuffer?: boolean;
159
+ resolution?: number;
160
+ backgroundColor?: number;
161
+ clearBeforeRender?: boolean;
162
+ roundPixels?: boolean;
163
+ forceFXAA?: boolean;
164
+ legacy?: boolean;
165
+ autoResize?: boolean;
166
+ powerPreference?: "high-performance";
167
+ };
137
168
  }
138
169
 
139
170
  declare type observableKeys = string | string[];
@@ -165,6 +196,8 @@ export declare interface PluginStruct {
165
196
  Systems?: typeof System[];
166
197
  }
167
198
 
199
+ declare type PreProcessResourceHandler = (res: ResourceBase) => void;
200
+
168
201
  declare class Progress extends EE {
169
202
  progress: number;
170
203
  resourceTotal: number;
@@ -187,7 +220,8 @@ declare interface PureObserverProp {
187
220
 
188
221
  declare class Resource extends EE {
189
222
  timeout: number;
190
- private resourcesMap;
223
+ private preProcessResourceHandlers;
224
+ resourcesMap: Record<ResourceName, ResourceStruct>;
191
225
  private makeInstanceFunctions;
192
226
  private destroyInstanceFunctions;
193
227
  private promiseMap;
@@ -199,17 +233,20 @@ declare class Resource extends EE {
199
233
  loadConfig(resources: ResourceBase[]): void;
200
234
  loadSingle(resource: ResourceBase): Promise<ResourceStruct>;
201
235
  addResource(resources: ResourceBase[]): void;
236
+ addPreProcessResourceHandler(handler: PreProcessResourceHandler): void;
237
+ removePreProcessResourceHandler(handler: PreProcessResourceHandler): void;
202
238
  preload(): void;
203
239
  getResource(name: string): Promise<ResourceStruct>;
204
240
  private instance;
205
241
  destroy(name: string): Promise<void>;
206
242
  private _destroy;
243
+ registerResourceType(type: string, value?: string): void;
207
244
  registerInstance(type: RESOURCE_TYPE | string, callback: ResourceProcessFn): void;
208
245
  registerDestroy(type: RESOURCE_TYPE | string, callback: ResourceProcessFn): void;
209
246
  private loadResource;
210
247
  doComplete(name: any, resolve: any, preload?: boolean): Promise<void>;
211
248
  checkAllLoaded(name: any): boolean;
212
- getLoader(preload?: boolean): any;
249
+ getLoader(preload?: boolean): Loader;
213
250
  private onLoad;
214
251
  private onError;
215
252
  }
@@ -220,16 +257,18 @@ export declare enum RESOURCE_TYPE {
220
257
  'IMAGE' = "IMAGE",
221
258
  'SPRITE' = "SPRITE",
222
259
  'SPRITE_ANIMATION' = "SPRITE_ANIMATION",
223
- 'DRAGONBONE' = "DRAGONBONE",
224
- 'SPINE' = "SPINE",
225
260
  'AUDIO' = "AUDIO",
226
261
  'VIDEO' = "VIDEO"
227
262
  }
228
263
 
264
+ export declare const RESOURCE_TYPE_STRATEGY: {
265
+ [type: string]: new (...args: any[]) => AbstractLoadStrategy;
266
+ };
267
+
229
268
  export declare interface ResourceBase {
230
- name?: string;
231
- type?: RESOURCE_TYPE;
232
- src?: {
269
+ name: string;
270
+ type: RESOURCE_TYPE;
271
+ src: {
233
272
  json?: SrcBase;
234
273
  image?: SrcBase;
235
274
  tex?: SrcBase;
@@ -242,6 +281,22 @@ export declare interface ResourceBase {
242
281
  preload?: boolean;
243
282
  }
244
283
 
284
+ export declare const resourceLoader: {
285
+ AbstractLoadStrategy: typeof AbstractLoadStrategy;
286
+ AudioLoadStrategy: typeof AudioLoadStrategy;
287
+ ImageLoadStrategy: typeof ImageLoadStrategy;
288
+ XhrResponseType: typeof XhrResponseType;
289
+ MediaElementLoadStrategy: typeof MediaElementLoadStrategy;
290
+ VideoLoadStrategy: typeof VideoLoadStrategy;
291
+ XhrLoadStrategy: typeof XhrLoadStrategy;
292
+ Loader: typeof Loader;
293
+ Resource: typeof Resource_2;
294
+ ResourceType: typeof ResourceType;
295
+ ResourceState: typeof ResourceState;
296
+ };
297
+
298
+ declare type ResourceName = string;
299
+
245
300
  declare type ResourceProcessFn = (resource: ResourceStruct) => any;
246
301
 
247
302
  declare interface ResourceStruct extends ResourceBase {
@@ -271,22 +326,29 @@ declare interface Size2 {
271
326
  height: number;
272
327
  }
273
328
 
329
+ declare interface Size2_2 {
330
+ width: number;
331
+ height: number;
332
+ }
333
+
274
334
  declare interface SrcBase {
275
335
  type: string;
276
336
  url?: string;
277
337
  data?: any;
338
+ size?: Size2_2;
339
+ texture?: TextureBase[] | TextureBase;
278
340
  }
279
341
 
280
- export declare class System {
342
+ export declare class System<T extends {} = {}> {
281
343
  static systemName: string;
282
344
  name: string;
283
345
  static observerInfo: PureObserverInfo;
284
346
  componentObserver: ComponentObserver;
285
347
  game: Game;
286
348
  started: boolean;
287
- __systemDefaultParams: any;
288
- constructor(params?: any);
289
- init?(param?: any): void;
349
+ __systemDefaultParams: T;
350
+ constructor(params?: T);
351
+ init?(param?: T): void;
290
352
  awake?(): void;
291
353
  start?(): void;
292
354
  update?(e: UpdateParams): void;
@@ -297,7 +359,17 @@ export declare class System {
297
359
  destroy(): void;
298
360
  }
299
361
 
300
- declare type SystemType = typeof System;
362
+ export declare interface SystemConstructor<T extends System = System> {
363
+ systemName: string;
364
+ observerInfo: PureObserverInfo;
365
+ new (params?: any): T;
366
+ }
367
+
368
+ declare interface TextureBase {
369
+ type: string;
370
+ url: string;
371
+ size?: Size2_2;
372
+ }
301
373
 
302
374
  declare class Ticker {
303
375
  autoStart: boolean;
@@ -310,12 +382,24 @@ declare class Ticker {
310
382
  private _frameCount;
311
383
  private _ticker;
312
384
  private _started;
385
+ private _timeoutList;
386
+ private _timeoutId;
387
+ private _frameDelayList;
388
+ private _frameDelayId;
389
+ time: UpdateParams;
313
390
  constructor(options?: TickerOptions);
391
+ setFrameDelay(callback: any, frameCount: number): number;
392
+ resolveFrameDelay(): void;
393
+ clearFrameDelay(frameDelayId: number): void;
394
+ setTimeout(callback: any, delay: any, ...args: any[]): number;
395
+ clearTimeout(timeoutId: number): void;
396
+ private resolveSetTimeout;
314
397
  update(): void;
315
398
  add(fn: any): void;
316
399
  remove(fn: any): void;
317
400
  start(): void;
318
401
  pause(): void;
402
+ setPlaybackRate(rate: number): void;
319
403
  }
320
404
 
321
405
  declare interface TickerOptions {
@@ -378,4 +462,6 @@ declare interface Vector2 {
378
462
  y: number;
379
463
  }
380
464
 
465
+ export declare const version = "1.3.0";
466
+
381
467
  export { }
@@ -904,6 +904,17 @@ var defaultOptions = {
904
904
  var Ticker = (function () {
905
905
  function Ticker(options) {
906
906
  var _this = this;
907
+ this._timeoutList = [];
908
+ this._timeoutId = 0;
909
+ this._frameDelayList = [];
910
+ this._frameDelayId = 0;
911
+ this.time = {
912
+ deltaTime: 0,
913
+ time: 0,
914
+ currentTime: 0,
915
+ frameCount: 0,
916
+ fps: 0,
917
+ };
907
918
  options = Object.assign({}, defaultOptions, options);
908
919
  this._frameCount = 0;
909
920
  this._frameDuration = 1000 / options.frameRate;
@@ -923,8 +934,101 @@ var Ticker = (function () {
923
934
  this.start();
924
935
  }
925
936
  }
926
- Ticker.prototype.update = function () {
937
+ Ticker.prototype.setFrameDelay = function (callback, frameCount) {
938
+ if (frameCount < 1 || !frameCount) {
939
+ throw 'frameCount must greater than 0';
940
+ }
941
+ var frameDelayInfo = {
942
+ frameDelayId: this._frameDelayId++,
943
+ callback: callback,
944
+ execFrameNumber: this.time.frameCount + frameCount
945
+ };
946
+ this._frameDelayList.push(frameDelayInfo);
947
+ return frameDelayInfo.frameDelayId;
948
+ };
949
+ Ticker.prototype.resolveFrameDelay = function () {
927
950
  var e_1, _a;
951
+ var _this = this;
952
+ var index = this._frameDelayList.findIndex(function (event) { return event.execFrameNumber <= _this.time.frameCount; });
953
+ if (index === -1)
954
+ return;
955
+ var needResolve = this._frameDelayList.splice(0, index + 1);
956
+ try {
957
+ for (var needResolve_1 = __values(needResolve), needResolve_1_1 = needResolve_1.next(); !needResolve_1_1.done; needResolve_1_1 = needResolve_1.next()) {
958
+ var delayInfo = needResolve_1_1.value;
959
+ try {
960
+ delayInfo.callback();
961
+ }
962
+ catch (e) {
963
+ throw e;
964
+ }
965
+ }
966
+ }
967
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
968
+ finally {
969
+ try {
970
+ if (needResolve_1_1 && !needResolve_1_1.done && (_a = needResolve_1.return)) _a.call(needResolve_1);
971
+ }
972
+ finally { if (e_1) throw e_1.error; }
973
+ }
974
+ };
975
+ Ticker.prototype.clearFrameDelay = function (frameDelayId) {
976
+ var index = this._frameDelayList.findIndex(function (event) { return event.frameDelayId === frameDelayId; });
977
+ if (index === -1)
978
+ return;
979
+ this._frameDelayList.splice(index, 1);
980
+ };
981
+ Ticker.prototype.setTimeout = function (callback, delay) {
982
+ var args = [];
983
+ for (var _i = 2; _i < arguments.length; _i++) {
984
+ args[_i - 2] = arguments[_i];
985
+ }
986
+ var delayInfo = {
987
+ timeoutId: this._timeoutId++,
988
+ startTime: this.time.currentTime,
989
+ endTime: this.time.currentTime + delay,
990
+ callback: callback,
991
+ delay: delay,
992
+ args: args
993
+ };
994
+ var index = this._timeoutList.findIndex(function (event) { return delayInfo.endTime >= event.endTime; });
995
+ this._timeoutList.splice(index + 1, 0, delayInfo);
996
+ return delayInfo.timeoutId;
997
+ };
998
+ Ticker.prototype.clearTimeout = function (timeoutId) {
999
+ var index = this._timeoutList.findIndex(function (event) { return event.timeoutId === timeoutId; });
1000
+ if (index === -1)
1001
+ return;
1002
+ this._timeoutList.splice(index, 1);
1003
+ };
1004
+ Ticker.prototype.resolveSetTimeout = function () {
1005
+ var e_2, _a;
1006
+ var _this = this;
1007
+ var index = this._timeoutList.findIndex(function (event) { return event.endTime <= _this.time.currentTime + 0.0001; });
1008
+ if (index === -1)
1009
+ return;
1010
+ var needResolve = this._timeoutList.splice(0, index + 1);
1011
+ try {
1012
+ for (var needResolve_2 = __values(needResolve), needResolve_2_1 = needResolve_2.next(); !needResolve_2_1.done; needResolve_2_1 = needResolve_2.next()) {
1013
+ var delayInfo = needResolve_2_1.value;
1014
+ try {
1015
+ delayInfo.callback.apply(delayInfo, __spread(delayInfo.args));
1016
+ }
1017
+ catch (e) {
1018
+ throw e;
1019
+ }
1020
+ }
1021
+ }
1022
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1023
+ finally {
1024
+ try {
1025
+ if (needResolve_2_1 && !needResolve_2_1.done && (_a = needResolve_2.return)) _a.call(needResolve_2);
1026
+ }
1027
+ finally { if (e_2) throw e_2.error; }
1028
+ }
1029
+ };
1030
+ Ticker.prototype.update = function () {
1031
+ var e_3, _a;
928
1032
  var currentTime = this.timeline.currentTime;
929
1033
  var durationTime = currentTime - this._lastFrameTime;
930
1034
  if (durationTime >= this._frameDuration) {
@@ -938,6 +1042,7 @@ var Ticker = (function () {
938
1042
  frameCount: ++this._frameCount,
939
1043
  fps: Math.round(1000 / deltaTime),
940
1044
  };
1045
+ this.time = options;
941
1046
  try {
942
1047
  for (var _b = __values(this._tickers), _c = _b.next(); !_c.done; _c = _b.next()) {
943
1048
  var func = _c.value;
@@ -946,13 +1051,15 @@ var Ticker = (function () {
946
1051
  }
947
1052
  }
948
1053
  }
949
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1054
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
950
1055
  finally {
951
1056
  try {
952
1057
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
953
1058
  }
954
- finally { if (e_1) throw e_1.error; }
1059
+ finally { if (e_3) throw e_3.error; }
955
1060
  }
1061
+ this.resolveFrameDelay();
1062
+ this.resolveSetTimeout();
956
1063
  }
957
1064
  };
958
1065
  Ticker.prototype.add = function (fn) {
@@ -1898,7 +2005,7 @@ var decorators = {
1898
2005
  IDEProp: IDEProp,
1899
2006
  componentObserver: componentObserver,
1900
2007
  };
1901
- var version = '1.2.7';
2008
+ var version = '1.3.0';
1902
2009
  console.log("Eva.js version: " + version);
1903
2010
 
1904
2011
  export { Component$1 as Component, Game$1 as Game, GameObject$1 as GameObject, IDEProp, LOAD_EVENT, LOAD_SCENE_MODE, ObserverType as OBSERVER_TYPE, RESOURCE_TYPE, RESOURCE_TYPE_STRATEGY, Scene$1 as Scene, System$1 as System, Transform$1 as Transform, componentObserver, decorators, resource, resourceLoader, version };