@eva/eva.js 2.0.0-beta.1 → 2.0.0-beta.2

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"),n=require("pixi.js"),o=require("resource-loader");function a(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var i=a(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])},s(e,t)};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("eventemitter3"),t=require("lodash-es"),s=require("@eva/inspector-decorator"),r=require("pixi.js"),o=require("resource-loader");function n(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var i=n(e);class a extends i{constructor(e){super(),this.started=!1,this.name=this.constructor.componentName,this.__componentDefaultParams=e}}var c,m=a;exports.OBSERVER_TYPE=void 0,(c=exports.OBSERVER_TYPE||(exports.OBSERVER_TYPE={})).ADD="ADD",c.REMOVE="REMOVE",c.CHANGE="CHANGE";const h={},p={},l={},u={};function d(e,t){h[e.gameObject.id]||(h[e.gameObject.id]={});const s=h[e.gameObject.id],r=e.name+"_"+t.join(",");if(s[r])return s[r];const o=t.length-1;let n=e;for(let e=0;e<o;e++)n=n[t[e]];return s[r]={property:n,key:t[o]},s[r]}function f({systemName:e,componentName:t,component:s,prop:r,type:o}){var n,i;null===(i=null===(n=p[e])||void 0===n?void 0:n.componentObserver)||void 0===i||i.add({component:s,prop:r,type:o,componentName:t})}function y({obj:e,key:s,prop:r,component:o,componentName:n}){if(void 0!==e)if(s in e){if(Object.defineProperty(e,`_${s}`,{enumerable:!1,writable:!0,value:e[s]}),r.deep&&t.isObject(e[s]))for(const t of Object.keys(e[s]))y({obj:e[s],key:t,prop:r,component:o,componentName:n});Object.defineProperty(e,s,{enumerable:!0,set(i){e[`_${s}`]!==i&&(e[`_${s}`]=i,function({prop:e,component:s,componentName:r}){for(const o in l){const n=(l[o]||{})[r];n&&(n.findIndex((s=>t.isEqual(s,e)))>-1&&f({systemName:o,componentName:r,component:s,prop:e,type:exports.OBSERVER_TYPE.CHANGE}))}}({prop:r,component:o,componentName:n}))},get:()=>e[`_${s}`]})}else console.error(`prop ${s} not in component: ${n}, Can not observer`)}function g(e,t=e.name){var s,r;for(const o in l){(l[o]||{})[t]&&(null===(r=null===(s=p[o])||void 0===s?void 0:s.componentObserver)||void 0===r||r.add({component:e,type:exports.OBSERVER_TYPE.REMOVE,componentName:t}))}!function(e){e.gameObject&&delete h[e.gameObject.id]}(e)}
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,5 @@ 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 c(e,t){function r(){this.constructor=e}s(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function u(e,t,r,n){var o,a=arguments.length,i=a<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(a<3?o(i):a>3?o(t,r,i):o(t,r))||i);return a>3&&i&&Object.defineProperty(t,r,i),i}function p(e,t,r,n){return new(r||(r=Promise))((function(o,a){function i(e){try{c(n.next(e))}catch(e){a(e)}}function s(e){try{c(n.throw(e))}catch(e){a(e)}}function c(e){e.done?o(e.value):new r((function(t){t(e.value)})).then(i,s)}c((n=n.apply(e,t||[])).next())}))}function l(e,t){var r,n,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[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,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}function f(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 h(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,a=r.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(n=a.next()).done;)i.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=a.return)&&r.call(a)}finally{if(o)throw o.error}}return i}function m(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(h(arguments[t]));return e}var y,d=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 c(t,e),t}(i),v=d;exports.OBSERVER_TYPE=void 0,(y=exports.OBSERVER_TYPE||(exports.OBSERVER_TYPE={})).ADD="ADD",y.REMOVE="REMOVE",y.CHANGE="CHANGE";var b={},g={},E={},_={};function O(e,t){b[e.gameObject.id]||(b[e.gameObject.id]={});var r=b[e.gameObject.id],n=e.name+"_"+t.join(",");if(r[n])return r[n];for(var o=t.length-1,a=e,i=0;i<o;i++)a=a[t[i]];return r[n]={property:a,key:t[o]},r[n]}function R(e){var t,r,n=e.systemName,o=e.componentName,a=e.component,i=e.prop,s=e.type;null===(r=null===(t=g[n])||void 0===t?void 0:t.componentObserver)||void 0===r||r.add({component:a,prop:i,type:s,componentName:o})}function x(e){var r,n,o=e.obj,a=e.key,i=e.prop,s=e.component,c=e.componentName;if(void 0!==o)if(a in o){if(Object.defineProperty(o,"_"+a,{enumerable:!1,writable:!0,value:o[a]}),i.deep&&t.isObject(o[a]))try{for(var u=f(Object.keys(o[a])),p=u.next();!p.done;p=u.next()){var l=p.value;x({obj:o[a],key:l,prop:i,component:s,componentName:c})}}catch(e){r={error:e}}finally{try{p&&!p.done&&(n=u.return)&&n.call(u)}finally{if(r)throw r.error}}Object.defineProperty(o,a,{enumerable:!0,set:function(e){o["_"+a]!==e&&(o["_"+a]=e,function(e){var r=e.prop,n=e.component,o=e.componentName;for(var a in E){var i=(E[a]||{})[o];i&&i.findIndex((function(e){return t.isEqual(e,r)}))>-1&&R({systemName:a,componentName:o,component:n,prop:r,type:exports.OBSERVER_TYPE.CHANGE})}}({prop:i,component:s,componentName:c}))},get:function(){return o["_"+a]}})}else console.error("prop "+a+" not in component: "+c+", Can not observer")}function T(e,t){var r,n;for(var o in void 0===t&&(t=e.name),E){(E[o]||{})[t]&&(null===(n=null===(r=g[o])||void 0===r?void 0:r.componentObserver)||void 0===n||n.add({component:e,type:exports.OBSERVER_TYPE.REMOVE,componentName:t}))}!function(e){e.gameObject&&delete b[e.gameObject.id]}(e)}var w=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 c(t,e),t.prototype.init=function(e){var t,r;void 0===e&&(e={});try{for(var n=f(["position","size","origin","anchor","scale","skew"]),o=n.next();!o.done;o=n.next()){var a=o.value;Object.assign(this[a],e[a])}}catch(e){t={error:e}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}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",u([r.type("vector2"),r.step(1)],t.prototype,"position",void 0),u([r.type("size"),r.step(1)],t.prototype,"size",void 0),u([r.type("vector2"),r.step(.1)],t.prototype,"origin",void 0),u([r.type("vector2"),r.step(.1)],t.prototype,"anchor",void 0),u([r.type("vector2"),r.step(.1)],t.prototype,"scale",void 0),u([r.type("vector2"),r.step(.1)],t.prototype,"skew",void 0),u([r.type("number"),r.step(.1)],t.prototype,"rotation",void 0),t}(v),k=0;var S=function(){function e(e,t){this._componentCache={},this.components=[],this.destroyed=!1,this._name=e,this.id=++k,this.addComponent(w,t)}return Object.defineProperty(e.prototype,"transform",{get:function(){return this.getComponent(w)},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 n=this._scene;if(this._scene=e,this.transform&&this.transform.children)try{for(var o=f(this.transform.children),a=o.next();!a.done;a=o.next()){a.value.gameObject.scene=e}}catch(e){t={error:e}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}e?e.addGameObject(this):n&&n.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 d?e.name:e instanceof Function?e.componentName:void 0}(e);if(!this._componentCache[r]){var n;if(e instanceof Function)n=new e(t);else{if(!(e instanceof v))throw new Error("addComponent recieve Component and Component Constructor");n=e}if(n.gameObject)throw new Error("component has been added on gameObject "+n.gameObject.name);return n.gameObject=this,n.init&&n.init(n.__componentDefaultParams),function(e,t){var r,n;for(var o in void 0===t&&(t=e.name),E)(E[o]||{})[t]&&(null===(n=null===(r=g[o])||void 0===r?void 0:r.componentObserver)||void 0===n||n.add({component:e,type:exports.OBSERVER_TYPE.ADD,componentName:t}))}(n,n.name),function(e,t){var r,n;if(void 0===t&&(t=e.name),t&&_[t]){if(!(e&&(o=e,o&&o.constructor&&"componentName"in o.constructor)))throw new Error("component param must be an instance of Component");var o;if(!e.gameObject||!e.gameObject.id)throw new Error("component should be add to a gameObject");try{for(var a=f(_[t]),i=a.next();!i.done;i=a.next()){var s=i.value,c=O(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&&(n=a.return)&&n.call(a)}finally{if(r)throw r.error}}}}(n,n.name),this.components.push(n),this._componentCache[r]=n,n.awake&&n.awake(),n}}},e.prototype.removeComponent=function(e){var t;if("string"==typeof e?t=e:e instanceof v?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(),T(r,e),r.gameObject=void 0,r}},e.prototype.getComponent=function(e){var t;return"string"==typeof e?t=e:e instanceof v?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}(),P=function(){function e(){this.events=[]}return e.prototype.add=function(e){var r=e.component,n=e.prop,o=e.type,a=e.componentName;if(o===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,n)&&e.type===o}));i>-1&&this.events.splice(i,1),this.events.push({gameObject:r.gameObject,component:r,prop:n,type:o,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}(),j=function(){function e(e){this.started=!1,this.componentObserver=new P,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 C,M=Date.now?Date.now:function(){return(new Date).getTime()},N={originTime:0,playbackRate:1},A=function(){function e(t,r){t instanceof e&&(r=t,t={}),t=Object.assign({},N,t),r&&(this._parent=r),this._createTime=M(),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:M()-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,n=void 0===r?this.currentTime:r,o=t.entropy,a=void 0===o?this.entropy:o,i=t.playbackRate,s=void 0===i?this.playbackRate:i,c={globalTime:this.globalTime,localTime:n,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],n=r.entropy,o=r.playbackRate;return r.globalTime+(e-n)/Math.abs(o)},e.prototype.seekLocalTime=function(e){var t=this.seekTimeMark(e),r=this._timeMark[t],n=r.localTime,o=r.entropy;return r.playbackRate>0?n+(e-o):n-(e-o)},e.prototype.seekTimeMark=function(e){var t=this._timeMark,r=0,n=t.length-1;if(e<=t[r].entropy)return r;if(e>=t[n].entropy)return n;for(var o=Math.floor((r+n)/2);o>r&&o<n;){if(e===t[o].entropy)return o;e<t[o].entropy?n=o:e>t[o].entropy&&(r=o),o=Math.floor((r+n)/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}(),D={autoStart:!0,frameRate:60},I=function(){function e(e){var t=this;e=Object.assign({},D,e),this._frameCount=0,this._frameDuration=1e3/e.frameRate,this.autoStart=e.autoStart,this.frameRate=e.frameRate,this.timeline=new A({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,n=r-this._lastFrameTime;if(n>=this._frameDuration){var o=r-n%this._frameDuration,a=o-this._lastFrameTime;this._lastFrameTime=o;var i={deltaTime:a,time:o,currentTime:o,frameCount:++this._frameCount,fps:Math.round(1e3/a)};try{for(var s=f(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}(),L=function(e){function t(t,r){var n=e.call(this,t,r)||this;return n.gameObjects=[],n.scene=n,n}return c(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}(S);exports.LOAD_SCENE_MODE=void 0,(C=exports.LOAD_SCENE_MODE||(exports.LOAD_SCENE_MODE={})).SINGLE="SINGLE",C.MULTI_CANVAS="MULTI_CANVAS";var V=function(e){if((e instanceof j||e instanceof v)&&!e.started){e.started=!0;try{e.start&&e.start()}catch(t){e instanceof v?console.error(e.constructor.componentName+" start error",t):console.error(e.constructor.systemName+" start error",t)}}},G=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.playing=!1,t.started=!1,t.multiScenes=[],t.systems=[],t}return c(r,e),r.prototype.init=function(e){var t=void 0===e?{}:e,r=t.systems,n=t.frameRate,o=void 0===n?60:n,a=t.autoStart,i=void 0===a||a,s=t.needScene,c=void 0===s||s;return p(this,void 0,void 0,(function(){var e,t,n,a,s,u;return l(this,(function(p){switch(p.label){case 0:if(window.__EVA_INSPECTOR_ENV__&&(window.__EVA_GAME_INSTANCE__=this),this.ticker=new I({autoStart:!1,frameRate:o}),this.initTicker(),!r||!r.length)return[3,8];p.label=1;case 1:p.trys.push([1,6,7,8]),e=f(r),t=e.next(),p.label=2;case 2:return t.done?[3,5]:(n=t.value,[4,this.addSystem(n)]);case 3:p.sent(),p.label=4;case 4:return t=e.next(),[3,2];case 5:return[3,8];case 6:return a=p.sent(),s={error:a},[3,8];case 7:try{t&&!t.done&&(u=e.return)&&u.call(e)}finally{if(s)throw s.error}return[7];case 8:return c&&this.loadScene(new L("scene")),i&&this.start(),[2]}}))}))},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,n,o=(null===(n=null==e?void 0:e.scene)||void 0===n?void 0:n.gameObjects)||[],a=null==e?void 0:e.multiScenes.map((function(e){return e.gameObjects})),i=[];try{for(var s=f(a),c=s.next();!c.done;c=s.next())i=m(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 m(o,i)}(this)},enumerable:!1,configurable:!0}),r.prototype.addSystem=function(e,r){return p(this,void 0,void 0,(function(){var n;return l(this,(function(o){switch(o.label){case 0:if(e instanceof Function)n=new e(r);else{if(!(e instanceof j))return console.warn("can only add System"),[2];n=e}return this.systems.find((function(e){return e.constructor===n.constructor}))?(console.warn(n.constructor.systemName+" System has been added"),[2]):(n.game=this,n.init?[4,n.init(n.__systemDefaultParams)]:[3,2]);case 1:o.sent(),o.label=2;case 2:!function(e,t){E[t.systemName]=t.observerInfo,g[t.systemName]=e}(n,n.constructor),function(e){var r,n,o,a,i=[];e instanceof Array?i.push.apply(i,m(e)):i.push(e);try{for(var s=f(i),c=s.next();!c.done;c=s.next()){var u=c.value;for(var p in u.observerInfo){_[p]=_[p]||[];var l=_[p],h=function(e){-1===l.findIndex((function(r){return t.isEqual(r,e)}))&&_[p].push(e)};try{for(var y=(o=void 0,f(u.observerInfo[p])),d=y.next();!d.done;d=y.next())h(d.value)}catch(e){o={error:e}}finally{try{d&&!d.done&&(a=y.return)&&a.call(y)}finally{if(o)throw o.error}}}}}catch(e){r={error:e}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}}(n.constructor);try{n.awake&&n.awake()}catch(e){console.error(n.constructor.systemName+" awake error",e)}return this.systems.push(n),[2,n]}}))}))},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 j&&(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,n,o,a;e.scene&&function(e,t){var r,n,o,a,i,s,c,u;void 0===t&&(t=[]);try{for(var p=f(t),l=p.next();!l.done;l=p.next()){var h=l.value;try{for(var m=(o=void 0,f(h.components)),y=m.next();!y.done;y=m.next()){var d=y.value;try{V(d),d.update&&d.update(e)}catch(e){console.error("gameObject: "+h.name+" "+d.name+" update error",e)}}}catch(e){o={error:e}}finally{try{y&&!y.done&&(a=m.return)&&a.call(m)}finally{if(o)throw o.error}}}}catch(e){r={error:e}}finally{try{l&&!l.done&&(n=p.return)&&n.call(p)}finally{if(r)throw r.error}}try{for(var v=f(t),b=v.next();!b.done;b=v.next()){h=b.value;try{for(var g=(c=void 0,f(h.components)),E=g.next();!E.done;E=g.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=g.return)&&u.call(g)}finally{if(c)throw c.error}}}}catch(e){i={error:e}}finally{try{b&&!b.done&&(s=v.return)&&s.call(v)}finally{if(i)throw i.error}}}(t,e.gameObjects);try{for(var i=f(e.systems),s=i.next();!s.done;s=i.next()){var c=s.value;try{V(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&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}try{for(var u=f(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){o={error:e}}finally{try{p&&!p.done&&(a=u.return)&&a.call(u)}finally{if(o)throw o.error}}}))},r.prototype.triggerResume=function(){var e,t;!function(e){var t,r,n,o;try{for(var a=f(e),i=a.next();!i.done;i=a.next()){var s=i.value;try{for(var c=(n=void 0,f(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){n={error:e}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(n)throw n.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=f(this.systems),n=r.next();!n.done;n=r.next()){var o=n.value;try{o.onResume&&o.onResume()}catch(e){console.error(o.constructor.systemName+", onResume error",e)}}}catch(t){e={error:t}}finally{try{n&&!n.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,n,o;try{for(var a=f(e),i=a.next();!i.done;i=a.next()){var s=i.value;try{for(var c=(n=void 0,f(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){n={error:e}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(n)throw n.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=f(this.systems),n=r.next();!n.done;n=r.next()){var o=n.value;try{o.onPause&&o.onPause()}catch(e){console.error(o.constructor.systemName+", onPause error",e)}}}catch(t){e={error:t}}finally{try{n&&!n.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}},r.prototype.destroySystems=function(){var e,t;try{for(var r=f(m(this.systems)),n=r.next();!n.done;n=r.next()){var o=n.value;this.removeSystem(o)}}catch(t){e={error:t}}finally{try{n&&!n.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,n=void 0===r?exports.LOAD_SCENE_MODE.SINGLE:r,o=e.params,a=void 0===o?{}:o;if(t){switch(n){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:n,params:a})}},r}(i);function F(e,t){e.constructor.IDEProps||(e.constructor.IDEProps=[]),e.constructor.IDEProps.push(t)}function U(e){return void 0===e&&(e={}),function(t){if(!t.observerInfo){for(var r in e)for(var n in e[r]){"string"==typeof e[r][n]&&(e[r][n]=[e[r][n]]);var o=void 0;Array.isArray(e[r][n])&&(o={prop:e[r][n],deep:!1},e[r][n]=o),"string"==typeof(o=e[r][n]).prop&&(o.prop=[o.prop])}t.observerInfo=e}}}var Y,q,H=function(e){function t(t){var r=t.resource,n=t.resourceTotal,o=e.call(this)||this;return o.progress=0,o.resourceTotal=0,o.resourceLoadedCount=0,o.resource=r,o.resourceTotal=n,0===n&&o.resource.emit(exports.LOAD_EVENT.COMPLETE,o),o}return c(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}(i),B=H,z={AbstractLoadStrategy:o.AbstractLoadStrategy,AudioLoadStrategy:o.AudioLoadStrategy,ImageLoadStrategy:o.ImageLoadStrategy,XhrResponseType:o.XhrResponseType,MediaElementLoadStrategy:o.MediaElementLoadStrategy,VideoLoadStrategy:o.VideoLoadStrategy,Loader:o.Loader,Resource:o.Resource,ResourceType:o.ResourceType,ResourceState:o.ResourceState};exports.LOAD_EVENT=void 0,(Y=exports.LOAD_EVENT||(exports.LOAD_EVENT={})).START="start",Y.PROGRESS="progress",Y.LOADED="loaded",Y.COMPLETE="complete",Y.ERROR="error",exports.RESOURCE_TYPE=void 0,(q=exports.RESOURCE_TYPE||(exports.RESOURCE_TYPE={})).IMAGE="IMAGE",q.SPRITE="SPRITE",q.SPRITE_ANIMATION="SPRITE_ANIMATION",q.AUDIO="AUDIO",q.VIDEO="VIDEO";var X=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={},t&&"number"==typeof t.timeout&&(r.timeout=t.timeout),r}return c(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 n=f(e),o=n.next();!o.done;o=n.next()){var a=o.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{o&&!o.done&&(r=n.return)&&r.call(n)}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 B({resource:this,resourceTotal:e.length}),this.loadResource({names:e,preload:!0})},t.prototype.getResource=function(e){return p(this,void 0,void 0,(function(){return l(this,(function(t){return this.loadResource({names:[e]}),[2,this.promiseMap[e]||Promise.resolve({})]}))}))},t.prototype.instance=function(e){return p(this,void 0,void 0,(function(){var t,r;return l(this,(function(n){switch(n.label){case 0:return t=this.resourcesMap[e],(r=this.makeInstanceFunctions[t.type])?[4,this.makeInstanceFunctions[t.type](t)]:[3,2];case 1:r=n.sent(),n.label=2;case 2:return[2,r]}}))}))},t.prototype.destroy=function(e){return p(this,void 0,void 0,(function(){return l(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),p(this,void 0,void 0,(function(){var r,n;return l(this,(function(o){switch(o.label){case 0:if(!(r=this.resourcesMap[e]))return[2];if(t)return[3,5];o.label=1;case 1:return o.trys.push([1,4,,5]),this.destroyInstanceFunctions[r.type]?[4,this.destroyInstanceFunctions[r.type](r)]:[3,3];case 2:o.sent(),o.label=3;case 3:return[3,5];case 4:return n=o.sent(),console.warn("destroy resource "+r.name+" error with '"+n.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,a=e.preload,i=void 0!==a&&a,s=o.filter((function(e){return!t.promiseMap[e]&&t.resourcesMap[e]}));if(s.length){var c={};s.forEach((function(e){var r,o,a;t.promiseMap[e]=new Promise((function(t){return c[e]=t}));var s=t.resourcesMap[e];try{for(var u=f(t.preProcessResourceHandlers),p=u.next();!p.done;p=u.next()){(0,p.value)(s)}}catch(e){r={error:e}}finally{try{p&&!p.done&&(o=u.return)&&o.call(u)}finally{if(r)throw r.error}}var l=function(r){if("data"===s.src[r].type)s.data[r]=s.src[r].data,t.doComplete(e,c[e],i);else{var o=null===(a=s.src[r])||void 0===a?void 0:a.url;"string"==typeof o&&o.startsWith("//")&&(o=""+window.location.protocol+s.src[r].url),"atlas"===r?n.Assets.add({alias:o,src:o,data:{resolve:function(){return n.Assets.load(s.src.image.url)}}}):n.Assets.add({alias:o,src:o}),n.Assets.load(o).then((function(n){t.onLoad({preload:i,resource:{metadata:{key:r,name:e,resolves:c},data:n}})})).catch((function(n){console.log(">>>E",n),t.onError({preload:i,errMsg:n.message,resource:{metadata:{key:r,name:e,resolves:c}}})}))}};for(var h in s.src)l(h)}))}},t.prototype.doComplete=function(e,t,r){return void 0===r&&(r=!1),p(this,void 0,void 0,(function(){var n,o,a,i;return l(this,(function(s){switch(s.label){case 0:if(n=this.resourcesMap[e],o={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=n,[4,this.instance(e)];case 2:return a.instance=s.sent(),n.complete=!0,r&&this.progress.onProgress(o),t(n),[3,4];case 3:return i=s.sent(),console.error(i),n.complete=!1,r&&(o.errMsg=i.message,o.success=!1,this.progress.onProgress(o)),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){},t.prototype.onLoad=function(e){var t=e.preload,r=void 0!==t&&t,n=e.resource;return p(this,void 0,void 0,(function(){var e,t,o,a,i;return l(this,(function(s){return e=n.metadata,t=e.key,o=e.name,a=e.resolves,i=n.data,this.resourcesMap[o].data[t]=i,this.doComplete(o,a[o],r),[2]}))}))},t.prototype.onError=function(e){var t=e.errMsg,r=e.preload,n=void 0!==r&&r,o=e.resource;return p(this,void 0,void 0,(function(){var e,r,a,i;return l(this,(function(s){return e=o.metadata,r=e.name,a=e.resolves,this._destroy(r,!0),a[r]({}),n&&(i={name:r,resource:this.resourcesMap[r],success:!1,errMsg:t},this.progress.onProgress(i)),[2]}))}))},t}(i),W=new X,J={IDEProp:F,componentObserver:U},K="2.0.0-beta.1";console.log("Eva.js version: "+K);exports.Component=v,exports.Game=G,exports.GameObject=S,exports.IDEProp=F,exports.RESOURCE_TYPE_STRATEGY={},exports.Scene=L,exports.System=j,exports.Transform=w,exports.componentObserver=U,exports.decorators=J,exports.resource=W,exports.resourceLoader=z,exports.version=K;
15
+ ***************************************************************************** */
16
+ function E(e,t,s,r){var o,n=arguments.length,i=n<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,s):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,s,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(i=(n<3?o(i):n>3?o(t,s,i):o(t,s))||i);return n>3&&i&&Object.defineProperty(t,s,i),i}function v(e,t,s,r){return new(s||(s=Promise))((function(o,n){function i(e){try{c(r.next(e))}catch(e){n(e)}}function a(e){try{c(r.throw(e))}catch(e){n(e)}}function c(e){e.done?o(e.value):new s((function(t){t(e.value)})).then(i,a)}c((r=r.apply(e,t||[])).next())}))}class _ extends m{constructor(){super(...arguments),this.name="Transform",this._parent=null,this.inScene=!1,this.children=[],this.position={x:0,y:0},this.size={width:0,height:0},this.origin={x:0,y:0},this.anchor={x:0,y:0},this.scale={x:1,y:1},this.skew={x:0,y:0},this.rotation=0}init(e={}){const t=["position","size","origin","anchor","scale","skew"];for(const s of t)Object.assign(this[s],e[s]);this.rotation=e.rotation||this.rotation}set parent(e){e?e.addChild(this):this.parent&&this.parent.removeChild(this)}get parent(){return this._parent}addChild(e){if(e.parent===this){const t=this.children.findIndex((t=>t===e));this.children.splice(t,1)}else e.parent&&e.parent.removeChild(e);e._parent=this,this.children.push(e)}removeChild(e){const t=this.children.findIndex((t=>t===e));t>-1&&(this.children.splice(t,1),e._parent=null)}clearChildren(){this.children.length=0}}_.componentName="Transform",E([s.type("vector2"),s.step(1)],_.prototype,"position",void 0),E([s.type("size"),s.step(1)],_.prototype,"size",void 0),E([s.type("vector2"),s.step(.1)],_.prototype,"origin",void 0),E([s.type("vector2"),s.step(.1)],_.prototype,"anchor",void 0),E([s.type("vector2"),s.step(.1)],_.prototype,"scale",void 0),E([s.type("vector2"),s.step(.1)],_.prototype,"skew",void 0),E([s.type("number"),s.step(.1)],_.prototype,"rotation",void 0);var b=_;let R=0;class O{constructor(e,t){this._componentCache={},this.components=[],this.destroyed=!1,this._name=e,this.id=++R,this.addComponent(b,t)}get transform(){return this.getComponent(b)}get parent(){return this.transform&&this.transform.parent&&this.transform.parent.gameObject}get name(){return this._name}set scene(e){if(this._scene===e)return;const t=this._scene;if(this._scene=e,this.transform&&this.transform.children)for(const t of this.transform.children)t.gameObject.scene=e;e?e.addGameObject(this):t&&t.removeGameObject(this)}get scene(){return this._scene}addChild(e){if(e&&e.transform&&e!==this){if(!(e instanceof O))throw new Error("addChild only receive GameObject");if(!this.transform)throw new Error(`gameObject '${this.name}' has been destroy`);e.transform.parent=this.transform,e.scene=this.scene}}removeChild(e){return e instanceof O&&e.parent&&e.parent===this?(e.transform.parent=null,e.scene=null,e):e}addComponent(e,t){if(this.destroyed)return;const s=function(e){return e instanceof a?e.name:e instanceof Function?e.componentName:void 0}(e);if(this._componentCache[s])return;let r;if(e instanceof Function)r=new e(t);else{if(!(e instanceof m))throw new Error("addComponent recieve Component and Component Constructor");r=e}if(r.gameObject)throw new Error(`component has been added on gameObject ${r.gameObject.name}`);return r.gameObject=this,r.init&&r.init(r.__componentDefaultParams),function(e,t=e.name){var s,r;for(const o in l)(l[o]||{})[t]&&(null===(r=null===(s=p[o])||void 0===s?void 0:s.componentObserver)||void 0===r||r.add({component:e,type:exports.OBSERVER_TYPE.ADD,componentName:t}))}(r,r.name),function(e,t=e.name){if(t&&u[t]){if(!(e&&(s=e,s&&s.constructor&&"componentName"in s.constructor)))throw new Error("component param must be an instance of Component");var s;if(!e.gameObject||!e.gameObject.id)throw new Error("component should be add to a gameObject");for(const s of u[t]){const{property:r,key:o}=d(e,s.prop);y({obj:r,key:o,prop:s,component:e,componentName:t})}}}(r,r.name),this.components.push(r),this._componentCache[s]=r,r.awake&&r.awake(),r}removeComponent(e){let t;if("string"==typeof e?t=e:e instanceof m?t=e.name:e.componentName&&(t=e.componentName),"Transform"===t)throw new Error("Transform can't be removed");return this._removeComponent(t)}_removeComponent(e){const t=this.components.findIndex((({name:t})=>t===e));if(-1===t)return;const s=this.components.splice(t,1)[0];return delete this._componentCache[e],delete s.__componentDefaultParams,s.onDestroy&&s.onDestroy(),g(s,e),s.gameObject=void 0,s}getComponent(e){let t;return"string"==typeof e?t=e:e instanceof m?t=e.name:e.componentName&&(t=e.componentName),void 0!==this._componentCache[t]?this._componentCache[t]:void 0}remove(){if(this.parent)return this.parent.removeChild(this)}destroy(){if(this.transform){Array.from(this.transform.children).forEach((({gameObject:e})=>{e.destroy()})),this.remove(),this.transform.clearChildren();for(const e in this._componentCache)this._removeComponent(e);this.components.length=0,this.destroyed=!0}else console.error("Cannot destroy gameObject that have already been destroyed.")}}var T=O;var k=class{constructor(){this.events=[]}add({component:e,prop:s,type:r,componentName:o}){if(r===exports.OBSERVER_TYPE.REMOVE){if(this.events.find((t=>t.component===e&&t.type===exports.OBSERVER_TYPE.ADD)))return void(this.events=this.events.filter((t=>t.component!==e)));this.events=this.events.filter((t=>t.component!==e))}const n=this.events.findIndex((o=>o.component===e&&t.isEqual(o.prop,s)&&o.type===r));n>-1&&this.events.splice(n,1),this.events.push({gameObject:e.gameObject,component:e,prop:s,type:r,componentName:o})}getChanged(){return this.events}get changed(){return this.events}clear(){const e=this.events;return this.events=[],e}};var S=class{constructor(e){this.started=!1,this.componentObserver=new k,this.__systemDefaultParams=e,this.name=this.constructor.systemName}destroy(){var e;this.componentObserver=null,this.__systemDefaultParams=null,null===(e=this.onDestroy)||void 0===e||e.call(this)}};const C=function(){let e=null;return e=Date.now?Date.now:()=>(new Date).getTime(),e}(),M={originTime:0,playbackRate:1};class x{constructor(e,t){e instanceof x&&(t=e,e={}),e=Object.assign({},M,e),t&&(this._parent=t),this._createTime=C(),this._timeMark=[{globalTime:this.globalTime,localTime:-e.originTime,entropy:-e.originTime,playbackRate:e.playbackRate,globalEntropy:0}],this._parent&&(this._timeMark[0].globalEntropy=this._parent.entropy),this._playbackRate=e.playbackRate}get globalTime(){return this.parent?this.parent.currentTime:C()-this._createTime}get parent(){return this._parent}get lastTimeMark(){return this._timeMark[this._timeMark.length-1]}markTime({time:e=this.currentTime,entropy:t=this.entropy,playbackRate:s=this.playbackRate}={}){const r={globalTime:this.globalTime,localTime:e,entropy:t,playbackRate:s,globalEntropy:this.globalEntropy};this._timeMark.push(r)}get currentTime(){const{localTime:e,globalTime:t}=this.lastTimeMark;return e+(this.globalTime-t)*this.playbackRate}set currentTime(e){this.markTime({time:e})}get globalEntropy(){return this._parent?this._parent.entropy:this.globalTime}get entropy(){const{entropy:e,globalEntropy:t}=this.lastTimeMark;return e+Math.abs((this.globalEntropy-t)*this.playbackRate)}set entropy(e){if(this.entropy>e){const t=this.seekTimeMark(e);this._timeMark.length=t+1}this.markTime({entropy:e})}fork(e){return new x(e,this)}seekGlobalTime(e){const t=this.seekTimeMark(e),s=this._timeMark[t],{entropy:r,playbackRate:o,globalTime:n}=s;return n+(e-r)/Math.abs(o)}seekLocalTime(e){const t=this.seekTimeMark(e),s=this._timeMark[t],{localTime:r,entropy:o,playbackRate:n}=s;return n>0?r+(e-o):r-(e-o)}seekTimeMark(e){const t=this._timeMark;let s=0,r=t.length-1;if(e<=t[s].entropy)return s;if(e>=t[r].entropy)return r;let o=Math.floor((s+r)/2);for(;o>s&&o<r;){if(e===t[o].entropy)return o;e<t[o].entropy?r=o:e>t[o].entropy&&(s=o),o=Math.floor((s+r)/2)}return s}get playbackRate(){return this._playbackRate}set playbackRate(e){e!==this.playbackRate&&(this.markTime({playbackRate:e}),this._playbackRate=e)}get paused(){if(0===this.playbackRate)return!0;let e=this.parent;for(;e;){if(0===e.playbackRate)return!0;e=e.parent}return!1}}var N=x;const P={autoStart:!0,frameRate:60};var A=class{constructor(e){e=Object.assign({},P,e),this._frameCount=0,this._frameDuration=1e3/e.frameRate,this.autoStart=e.autoStart,this.frameRate=e.frameRate,this.timeline=new N({originTime:0,playbackRate:1}),this._lastFrameTime=this.timeline.currentTime,this._tickers=new Set,this._requestId=null,this._ticker=()=>{this._started&&(this._requestId=requestAnimationFrame(this._ticker),this.update())},this.autoStart&&this.start()}update(){const e=this.timeline.currentTime,t=e-this._lastFrameTime;if(t>=this._frameDuration){const s=e-t%this._frameDuration,r=s-this._lastFrameTime;this._lastFrameTime=s;const o={deltaTime:r,time:s,currentTime:s,frameCount:++this._frameCount,fps:Math.round(1e3/r)};for(const e of this._tickers)"function"==typeof e&&e(o)}}add(e){this._tickers.add(e)}remove(e){this._tickers.delete(e)}start(){this._started||(this._started=!0,this.timeline.playbackRate=1,this._requestId=requestAnimationFrame(this._ticker))}pause(){this._started=!1,this.timeline.playbackRate=0}setPlaybackRate(e){this.timeline.playbackRate=e}};var j,D=class extends T{constructor(e,t){super(e,t),this.gameObjects=[],this.scene=this}addGameObject(e){this.gameObjects.push(e),e.transform&&(e.transform.inScene=!0)}removeGameObject(e){const t=this.gameObjects.indexOf(e);-1!==t&&(e.transform&&(e.transform.inScene=!1),this.gameObjects.splice(t,1))}destroy(){this.scene=null,super.destroy(),this.gameObjects=null,this.canvas=null}};exports.LOAD_SCENE_MODE=void 0,(j=exports.LOAD_SCENE_MODE||(exports.LOAD_SCENE_MODE={})).SINGLE="SINGLE",j.MULTI_CANVAS="MULTI_CANVAS";const w=e=>{if((e instanceof S||e instanceof m)&&!e.started){e.started=!0;try{e.start&&e.start()}catch(t){e instanceof m?console.error(`${e.constructor.componentName} start error`,t):console.error(`${e.constructor.systemName} start error`,t)}}};var I=class extends i{constructor(){super(...arguments),this.playing=!1,this.started=!1,this.multiScenes=[],this.systems=[]}init({systems:e,frameRate:t=60,autoStart:s=!0,needScene:r=!0}={}){return v(this,void 0,void 0,(function*(){if(window.__EVA_INSPECTOR_ENV__&&(window.__EVA_GAME_INSTANCE__=this),this.ticker=new A({autoStart:!1,frameRate:t}),this.initTicker(),e&&e.length)for(const t of e)yield this.addSystem(t);r&&this.loadScene(new D("scene")),s&&this.start()}))}get scene(){return this._scene}set scene(e){this._scene=e}get gameObjects(){return(e=>{var t;const s=(null===(t=null==e?void 0:e.scene)||void 0===t?void 0:t.gameObjects)||[],r=null==e?void 0:e.multiScenes.map((({gameObjects:e})=>e));let o=[];for(const e of r)o=[...o,...e];return[...s,...o]})(this)}addSystem(e,s){return v(this,void 0,void 0,(function*(){let r;if(e instanceof Function)r=new e(s);else{if(!(e instanceof S))return void console.warn("can only add System");r=e}if(!this.systems.find((e=>e.constructor===r.constructor))){r.game=this,r.init&&(yield r.init(r.__systemDefaultParams)),function(e,t){l[t.systemName]=t.observerInfo,p[t.systemName]=e}(r,r.constructor),function(e){const s=[];e instanceof Array?s.push(...e):s.push(e);for(const e of s)for(const s in e.observerInfo){u[s]=u[s]||[];const r=u[s];for(const o of e.observerInfo[s])-1===r.findIndex((e=>t.isEqual(e,o)))&&u[s].push(o)}}(r.constructor);try{r.awake&&r.awake()}catch(e){console.error(`${r.constructor.systemName} awake error`,e)}return this.systems.push(r),r}console.warn(`${r.constructor.systemName} System has been added`)}))}removeSystem(e){if(!e)return;let t=-1;"string"==typeof e?t=this.systems.findIndex((t=>t.name===e)):e instanceof Function?t=this.systems.findIndex((t=>t.constructor===e)):e instanceof S&&(t=this.systems.findIndex((t=>t===e))),t>-1&&(this.systems[t].destroy&&this.systems[t].destroy(),this.systems.splice(t,1))}getSystem(e){return this.systems.find((t=>"string"==typeof e?t.name===e:t instanceof e))}pause(){this.playing&&(this.playing=!1,this.ticker.pause(),this.triggerPause())}start(){this.playing||(this.playing=!0,this.started=!0,this.ticker.start())}resume(){this.playing||(this.playing=!0,this.ticker.start(),this.triggerResume())}initTicker(){this.ticker.add((e=>{this.scene&&((e,t=[])=>{for(const s of t)for(const t of s.components)try{w(t),t.update&&t.update(e)}catch(e){console.error(`gameObject: ${s.name} ${t.name} update error`,e)}for(const s of t)for(const t of s.components)try{t.lateUpdate&&t.lateUpdate(e)}catch(e){console.error(`gameObject: ${s.name} ${t.name} lateUpdate error`,e)}})(e,this.gameObjects);for(const t of this.systems)try{w(t),t.update&&t.update(e)}catch(e){console.error(`${t.constructor.systemName} update error`,e)}for(const t of this.systems)try{t.lateUpdate&&t.lateUpdate(e)}catch(e){console.error(`${t.constructor.systemName} lateUpdate error`,e)}}))}triggerResume(){(e=>{for(const t of e)for(const e of t.components)try{e.onResume&&e.onResume()}catch(s){console.error(`gameObject: ${t.name}, ${e.name}, onResume error`,s)}})(this.gameObjects);for(const e of this.systems)try{e.onResume&&e.onResume()}catch(t){console.error(`${e.constructor.systemName}, onResume error`,t)}}triggerPause(){(e=>{for(const t of e)for(const e of t.components)try{e.onPause&&e.onPause()}catch(s){console.error(`gameObject: ${t.name}, ${e.name}, onResume error`,s)}})(this.gameObjects);for(const e of this.systems)try{e.onPause&&e.onPause()}catch(t){console.error(`${e.constructor.systemName}, onPause error`,t)}}destroySystems(){for(const e of[...this.systems])this.removeSystem(e);this.systems.length=0}destroy(){this.removeAllListeners(),this.pause(),this.scene.destroy(),this.destroySystems(),this.ticker=null,this.scene=null,this.canvas=null,this.multiScenes=null}loadScene({scene:e,mode:t=exports.LOAD_SCENE_MODE.SINGLE,params:s={}}){if(e){switch(t){case exports.LOAD_SCENE_MODE.SINGLE:this.scene=e;break;case exports.LOAD_SCENE_MODE.MULTI_CANVAS:this.multiScenes.push(e)}this.emit("sceneChanged",{scene:e,mode:t,params:s})}}};function L(e,t){e.constructor.IDEProps||(e.constructor.IDEProps=[]),e.constructor.IDEProps.push(t)}function V(e={}){return function(t){if(!t.observerInfo){for(const t in e)for(const s in e[t]){let r;"string"==typeof e[t][s]&&(e[t][s]=[e[t][s]]),Array.isArray(e[t][s])&&(r={prop:e[t][s],deep:!1},e[t][s]=r),r=e[t][s],"string"==typeof r.prop&&(r.prop=[r.prop])}t.observerInfo=e}}}class $ extends i{constructor({resource:e,resourceTotal:t}){super(),this.progress=0,this.resourceTotal=0,this.resourceLoadedCount=0,this.resource=e,this.resourceTotal=t,0===t&&this.resource.emit(exports.LOAD_EVENT.COMPLETE,this)}onStart(){this.resource.emit(exports.LOAD_EVENT.START,this)}onProgress(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)}}const G={AbstractLoadStrategy:o.AbstractLoadStrategy,AudioLoadStrategy:o.AudioLoadStrategy,ImageLoadStrategy:o.ImageLoadStrategy,XhrResponseType:o.XhrResponseType,MediaElementLoadStrategy:o.MediaElementLoadStrategy,VideoLoadStrategy:o.VideoLoadStrategy,Loader:o.Loader,Resource:o.Resource,ResourceType:o.ResourceType,ResourceState:o.ResourceState};var F,U;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";const Y=new class extends i{constructor(e){super(),this.timeout=6e3,this.preProcessResourceHandlers=[],this.resourcesMap={},this.makeInstanceFunctions={},this.destroyInstanceFunctions={},this.promiseMap={},e&&"number"==typeof e.timeout&&(this.timeout=e.timeout)}loadConfig(e){this.addResource(e),this.preload()}loadSingle(e){return this.addResource([e]),this.getResource(e.name)}addResource(e){if(!e||e.length<1)console.warn("no resources");else for(const t of e)this.resourcesMap[t.name]?console.warn(t.name+" was already added"):(this.resourcesMap[t.name]=t,this.resourcesMap[t.name].data={})}addPreProcessResourceHandler(e){this.preProcessResourceHandlers.push(e)}removePreProcessResourceHandler(e){this.preProcessResourceHandlers.splice(this.preProcessResourceHandlers.indexOf(e),1)}preload(){const e=[];for(const t in this.resourcesMap){const s=this.resourcesMap[t];!s.preload||s.complete||this.promiseMap[t]||e.push(s.name)}this.progress=new $({resource:this,resourceTotal:e.length}),this.loadResource({names:e,preload:!0})}getResource(e){return v(this,void 0,void 0,(function*(){return this.loadResource({names:[e]}),this.promiseMap[e]||Promise.resolve({})}))}instance(e){return v(this,void 0,void 0,(function*(){const t=this.resourcesMap[e];return this.makeInstanceFunctions[t.type]&&(yield this.makeInstanceFunctions[t.type](t))}))}destroy(e){return v(this,void 0,void 0,(function*(){yield this._destroy(e)}))}_destroy(e,t=!1){return v(this,void 0,void 0,(function*(){const s=this.resourcesMap[e];if(s){if(!t)try{this.destroyInstanceFunctions[s.type]&&(yield this.destroyInstanceFunctions[s.type](s))}catch(e){console.warn(`destroy resource ${s.name} error with '${e.message}'`)}delete this.promiseMap[e],s.data={},s.complete=!1,s.instance=void 0}}))}registerResourceType(e,t=e){if(exports.RESOURCE_TYPE[e])throw new Error(`The type ${e} already exists in RESOURCE_TYPE`);exports.RESOURCE_TYPE[e]=t}registerInstance(e,t){this.makeInstanceFunctions[e]=t}registerDestroy(e,t){this.destroyInstanceFunctions[e]=t}loadResource({names:e=[],preload:t=!1}){const s=e.filter((e=>!this.promiseMap[e]&&this.resourcesMap[e]));if(!s.length)return;const o={};s.forEach((e=>{var s;this.promiseMap[e]=new Promise((t=>o[e]=t));const n=this.resourcesMap[e];for(const e of this.preProcessResourceHandlers)e(n);for(const i in n.src){if("data"===n.src[i].type)n.data[i]=n.src[i].data,this.doComplete(e,o[e],t);else{let a=null===(s=n.src[i])||void 0===s?void 0:s.url;"string"==typeof a&&a.startsWith("//")&&(a=`${window.location.protocol}${n.src[i].url}`),"atlas"===i?r.Assets.add({alias:a,src:a,data:{resolve:()=>r.Assets.load(n.src.image.url)}}):r.Assets.add({alias:a,src:a}),r.Assets.load(a).then((s=>{this.onLoad({preload:t,resource:{metadata:{key:i,name:e,resolves:o},data:s}})})).catch((s=>{console.log(">>>E",s),this.onError({preload:t,errMsg:s.message,resource:{metadata:{key:i,name:e,resolves:o}}})}))}}}))}doComplete(e,t,s=!1){return v(this,void 0,void 0,(function*(){const r=this.resourcesMap[e],o={name:e,resource:this.resourcesMap[e],success:!0};if(this.checkAllLoaded(e))try{r.instance=yield this.instance(e),r.complete=!0,s&&this.progress.onProgress(o),t(r)}catch(e){console.error(e),r.complete=!1,s&&(o.errMsg=e.message,o.success=!1,this.progress.onProgress(o)),t({})}}))}checkAllLoaded(e){const t=this.resourcesMap[e];return Array.from(Object.keys(t.src)).every((e=>t.data[e]))}getLoader(e=!1){}onLoad({preload:e=!1,resource:t}){return v(this,void 0,void 0,(function*(){const{metadata:{key:s,name:r,resolves:o},data:n}=t;this.resourcesMap[r].data[s]=n,this.doComplete(r,o[r],e)}))}onError({errMsg:e,preload:t=!1,resource:s}){return v(this,void 0,void 0,(function*(){const{metadata:{name:r,resolves:o}}=s;if(this._destroy(r,!0),o[r]({}),t){const t={name:r,resource:this.resourcesMap[r],success:!1,errMsg:e};this.progress.onProgress(t)}}))}},q={IDEProp:L,componentObserver:V},H="2.0.0-beta.2";console.log(`Eva.js version: ${H}`);exports.Component=m,exports.Game=I,exports.GameObject=T,exports.IDEProp=L,exports.RESOURCE_TYPE_STRATEGY={},exports.Scene=D,exports.System=S,exports.Transform=b,exports.componentObserver=V,exports.decorators=q,exports.resource=Y,exports.resourceLoader=G,exports.version=H;
package/dist/eva.js.d.ts CHANGED
@@ -448,6 +448,6 @@ declare interface Vector2 {
448
448
  y: number;
449
449
  }
450
450
 
451
- export declare const version = "2.0.0-beta.1";
451
+ export declare const version = "2.0.0-beta.2";
452
452
 
453
453
  export { }