@eva/eva.js
Advanced tools
@@ -1,1 +0,1 @@ | ||
| "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("eventemitter3"),t=require("@eva/inspector-decorator"),s=require("lodash-es"),o=require("pixi.js");function r(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var n=r(e);function a(e={}){return t.Field(e)}class i extends n{static getInspectorMetadata(){return t.getPropertiesOf(this)}constructor(e){super(),this.started=!1,this.name=this.constructor.componentName,this.__componentDefaultParams=e}getInspectorMetadata(){return this.constructor.getInspectorMetadata()}}var c,l=i;function m(e,t){const s=[];t&&s.push(t);const o=e&&"string"==typeof e.name?e.name:void 0;if(!t||t===o){let t=null==e?void 0:e.constructor;for(t&&(t=Object.getPrototypeOf(t));t&&t!==Function.prototype;){const e=t.componentName;"string"==typeof e&&e&&!s.includes(e)&&s.push(e),t=Object.getPrototypeOf(t)}}return s}exports.OBSERVER_TYPE=void 0,(c=exports.OBSERVER_TYPE||(exports.OBSERVER_TYPE={})).ADD="ADD",c.REMOVE="REMOVE",c.CHANGE="CHANGE";const p={},u={},d={},h={};function f(e,t){p[e.gameObject.id]||(p[e.gameObject.id]={});const s=p[e.gameObject.id],o=e.name+"_"+t.join(",");if(s[o])return s[o];const r=t.length-1;let n=e;for(let e=0;e<r;e++)n=n[t[e]];return s[o]={property:n,key:t[r]},s[o]}function y({systemName:e,componentName:t,component:s,prop:o,type:r}){var n,a;null===(a=null===(n=u[e])||void 0===n?void 0:n.componentObserver)||void 0===a||a.add({component:s,prop:o,type:r,componentName:t})}function g({obj:e,key:t,prop:o,component:r,componentName:n}){if(void 0!==e)if(t in e){if(Object.defineProperty(e,`_${t}`,{enumerable:!1,writable:!0,value:e[t]}),o.deep&&s.isObject(e[t]))for(const s of Object.keys(e[t]))g({obj:e[t],key:s,prop:o,component:r,componentName:n});Object.defineProperty(e,t,{enumerable:!0,set(a){e[`_${t}`]!==a&&(e[`_${t}`]=a,function({prop:e,component:t,componentName:o}){const r=m(t,o);for(const n in d){const a=d[n]||{};let i;for(const e of r)if(a[e]){i=a[e];break}i&&(i.findIndex(t=>s.isEqual(t,e))>-1&&y({systemName:n,componentName:o,component:t,prop:e,type:exports.OBSERVER_TYPE.CHANGE}))}}({prop:o,component:r,componentName:n}))},get:()=>e[`_${t}`]})}else console.error(`prop ${t} not in component: ${n}, Can not observer`)}function v(e,t=e.name){var s,o;const r=m(e,t);for(const n in d){const a=d[n]||{};let i=!1;for(const e of r)if(a[e]){i=!0;break}i&&(null===(o=null===(s=u[n])||void 0===s?void 0:s.componentObserver)||void 0===o||o.add({component:e,type:exports.OBSERVER_TYPE.REMOVE,componentName:t}))}!function(e){e.gameObject&&delete p[e.gameObject.id]}(e)}function E(e,t,s,o){var r,n=arguments.length,a=n<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,s):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,s,o);else for(var i=e.length-1;i>=0;i--)(r=e[i])&&(a=(n<3?r(a):n>3?r(t,s,a):r(t,s))||a);return n>3&&a&&Object.defineProperty(t,s,a),a}function b(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function _(e,t,s,o){return new(s||(s=Promise))(function(r,n){function a(e){try{c(o.next(e))}catch(e){n(e)}}function i(e){try{c(o.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(a,i)}c((o=o.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class O extends l{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}}O.componentName="Transform",E([t.type("vector2"),t.step(1),b("design:type",Object)],O.prototype,"position",void 0),E([t.type("size"),t.step(1),b("design:type",Object)],O.prototype,"size",void 0),E([t.type("vector2"),t.step(.1),b("design:type",Object)],O.prototype,"origin",void 0),E([t.type("vector2"),t.step(.1),b("design:type",Object)],O.prototype,"anchor",void 0),E([t.type("vector2"),t.step(.1),b("design:type",Object)],O.prototype,"scale",void 0),E([t.type("vector2"),t.step(.1),b("design:type",Object)],O.prototype,"skew",void 0),E([t.type("number"),t.step(.1),b("design:type",Number)],O.prototype,"rotation",void 0);var M=O;let R=0;class T{constructor(e,t){this._componentCache={},this.components=[],this.destroyed=!1,this._name=e,this.id=++R,this.addComponent(M,t)}get transform(){return this.getComponent(M)}get parent(){return this.transform&&this.transform.parent&&this.transform.parent.gameObject}get children(){return this.transform.children.map(e=>e.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 T))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 T&&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 i?e.name:e instanceof Function?e.componentName:void 0}(e);if(this._componentCache[s])return;let o;if(e instanceof Function)o=new e(t);else{if(!(e instanceof l))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=e.name){var s,o;const r=m(e,t);for(const n in d){const a=d[n]||{};let i=!1;for(const e of r)if(a[e]){i=!0;break}i&&(null===(o=null===(s=u[n])||void 0===s?void 0:s.componentObserver)||void 0===o||o.add({component:e,type:exports.OBSERVER_TYPE.ADD,componentName:t}))}}(o,o.name),function(e,t=e.name){const s=m(e,t);let o,r="";for(const e of s)if(h[e]){r=e,o=h[e];break}if(o){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");for(const t of o){const{property:s,key:o}=f(e,t.prop);g({obj:s,key:o,prop:t,component:e,componentName:r})}}}(o,o.name),this.components.push(o),this._componentCache[s]=o,o.awake&&o.awake(),o}removeComponent(e){let t;if("string"==typeof e?t=e:e instanceof l?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(),v(s,e),s.gameObject=void 0,s}getComponent(e){let t;return"string"==typeof e?t=e:e instanceof l?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}}}var x=T;var k=class{constructor(){this.events=[]}add({component:e,prop:t,type:o,componentName:r}){if(o===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(r=>r.component===e&&s.isEqual(r.prop,t)&&r.type===o);n>-1&&this.events.splice(n,1),this.events.push({gameObject:e.gameObject,component:e,prop:t,type:o,componentName:r})}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 j=function(){let e=null;return e=Date.now?Date.now:()=>(new Date).getTime(),e}(),P={originTime:0,playbackRate:1};class C{constructor(e,t){e instanceof C&&(t=e,e={}),e=Object.assign({},P,e),t&&(this._parent=t),this._createTime=j(),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:j()-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 o={globalTime:this.globalTime,localTime:e,entropy:t,playbackRate:s,globalEntropy:this.globalEntropy};this._timeMark.push(o)}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 C(e,this)}seekGlobalTime(e){const t=this.seekTimeMark(e),s=this._timeMark[t],{entropy:o,playbackRate:r,globalTime:n}=s;return n+(e-o)/Math.abs(r)}seekLocalTime(e){const t=this.seekTimeMark(e),s=this._timeMark[t],{localTime:o,entropy:r,playbackRate:n}=s;return n>0?o+(e-r):o-(e-r)}seekTimeMark(e){const t=this._timeMark;let s=0,o=t.length-1;if(e<=t[s].entropy)return s;if(e>=t[o].entropy)return o;let r=Math.floor((s+o)/2);for(;r>s&&r<o;){if(e===t[r].entropy)return r;e<t[r].entropy?o=r:e>t[r].entropy&&(s=r),r=Math.floor((s+o)/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=C;const I={autoStart:!0,frameRate:60};var w=class{constructor(e){e=Object.assign({},I,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;let t=0;for(;e-this._lastFrameTime>=this._frameDuration&&t<5;){this._lastFrameTime+=this._frameDuration,t++;const e={deltaTime:this._frameDuration,time:this._lastFrameTime,currentTime:this._lastFrameTime,frameCount:++this._frameCount,fps:this.frameRate};for(const t of this._tickers)"function"==typeof t&&t(e)}e-this._lastFrameTime>=this._frameDuration&&(this._lastFrameTime=e)}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,null!==this._requestId&&(cancelAnimationFrame(this._requestId),this._requestId=null),this.timeline.playbackRate=0}setPlaybackRate(e){this.timeline.playbackRate=e}};var A,D=class extends x{constructor(e,t){super(e,t),this.gameObjects=[],this._nameIndex=new Map,this.scene=this}addGameObject(e){if(this.gameObjects.push(e),e.transform&&(e.transform.inScene=!0),e.name){let t=this._nameIndex.get(e.name);t||(t=new Set,this._nameIndex.set(e.name,t)),t.add(e)}}removeGameObject(e){const t=this.gameObjects.indexOf(e);if(-1!==t&&(e.transform&&(e.transform.inScene=!1),this.gameObjects.splice(t,1),e.name)){const t=this._nameIndex.get(e.name);t&&(t.delete(e),0===t.size&&this._nameIndex.delete(e.name))}}findByName(e){const t=this._nameIndex.get(e);if(!t)return null;for(const e of t)if(!e.destroyed)return e;return null}findAllByName(e){const t=this._nameIndex.get(e);if(!t)return[];const s=[];for(const e of t)e.destroyed||s.push(e);return s}destroy(){this.scene=null,super.destroy(),this.gameObjects=null,this.canvas=null,this._nameIndex=null}};exports.LOAD_SCENE_MODE=void 0,(A=exports.LOAD_SCENE_MODE||(exports.LOAD_SCENE_MODE={})).SINGLE="SINGLE",A.MULTI_CANVAS="MULTI_CANVAS";const U=e=>{if((e instanceof S||e instanceof l)&&!e.started){e.started=!0;try{e.start&&e.start()}catch(t){e instanceof l?console.error(`${e.constructor.componentName} start error`,t):console.error(`${e.constructor.systemName} start error`,t)}}};var F,L,$=class extends n{constructor(){super(...arguments),this.playing=!1,this.started=!1,this.multiScenes=[],this.systems=[]}init({systems:e,frameRate:t=60,autoStart:s=!0,needScene:o=!0}={}){return _(this,void 0,void 0,function*(){if("undefined"!=typeof window&&window.__EVA_INSPECTOR_ENV__&&(window.__EVA_GAME_INSTANCE__=this),this.ticker=new w({autoStart:!1,frameRate:t}),this.initTicker(),e&&e.length)for(const t of e)yield this.addSystem(t);o&&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)||[],o=null==e?void 0:e.multiScenes.map(({gameObjects:e})=>e);let r=[];for(const e of o)r=[...r,...e];return[...s,...r]})(this)}findByName(e){var t;const s=null===(t=this._scene)||void 0===t?void 0:t.findByName(e);if(s)return s;for(const t of this.multiScenes){const s=t.findByName(e);if(s)return s}return null}findAllByName(e){var t;const s=(null===(t=this._scene)||void 0===t?void 0:t.findAllByName(e))||[];for(const t of this.multiScenes){const o=t.findAllByName(e);for(const e of o)s.push(e)}return s}addSystem(e,t){return _(this,void 0,void 0,function*(){let o;if(e instanceof Function)o=new e(t);else{if(!(e instanceof S))return void console.warn("can only add System");o=e}if(!this.systems.find(e=>e.constructor===o.constructor)){o.game=this,o.init&&(yield o.init(o.__systemDefaultParams)),function(e,t){d[t.systemName]=t.observerInfo,u[t.systemName]=e}(o,o.constructor),function(e){const t=[];e instanceof Array?t.push(...e):t.push(e);for(const e of t)for(const t in e.observerInfo){h[t]=h[t]||[];const o=h[t];for(const r of e.observerInfo[t])-1===o.findIndex(e=>s.isEqual(e,r))&&h[t].push(r)}}(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`)})}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{U(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{U(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(){var e,t;this.removeAllListeners(),this.playing?this.pause():null===(e=this.ticker)||void 0===e||e.pause(),null===(t=this.scene)||void 0===t||t.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})}}pauseScene({scene:e}){this.emit("pauseScene",{scene:e})}startScene({scene:e}){this.emit("startScene",{scene:e})}destroyScene({scene:e}){const t=this.multiScenes.findIndex(t=>t===e);if(t>-1){const e=this.multiScenes.splice(t,1)[0];this.emit("sceneDestroyed",{scene:e})}}};function V(e,t){e.constructor.IDEProps||(e.constructor.IDEProps=[]),e.constructor.IDEProps.push(t)}function G(e={}){return function(t){if(!t.observerInfo){for(const t in e)for(const s in e[t]){let o;"string"==typeof e[t][s]&&(e[t][s]=[e[t][s]]),Array.isArray(e[t][s])&&(o={prop:e[t][s],deep:!1},e[t][s]=o),o=e[t][s],"string"==typeof o.prop&&(o.prop=[o.prop])}t.observerInfo=e}}}class Y extends n{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)}}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,(L=exports.RESOURCE_TYPE||(exports.RESOURCE_TYPE={})).IMAGE="IMAGE",L.SPRITE="SPRITE",L.SPRITE_ANIMATION="SPRITE_ANIMATION",L.AUDIO="AUDIO",L.VIDEO="VIDEO",L.FONT="FONT";const B=new class extends n{constructor(e){super(),this.timeout=6e3,this.preProcessResourceHandlers=[],this.resourcesMap={},this.makeInstanceFunctions={},this.destroyInstanceFunctions={},this.promiseMap={},this.resourceUrlsMap={},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"):t&&(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 Y({resource:this,resourceTotal:e.length}),this.loadResource({names:e,preload:!0})}getResource(e){return _(this,void 0,void 0,function*(){return this.loadResource({names:[e]}),this.promiseMap[e]||Promise.resolve({})})}instance(e){return _(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 _(this,void 0,void 0,function*(){yield this._destroy(e)})}_destroy(e,t=!1){var s;return _(this,void 0,void 0,function*(){const r=this.resourcesMap[e];if(!r)return;if(!t)try{this.destroyInstanceFunctions[r.type]&&(yield this.destroyInstanceFunctions[r.type](r))}catch(e){console.warn(`destroy resource ${r.name} error with '${e.message}'`)}const n=this.resourceUrlsMap[e]||[];if(0===n.length&&r.src)for(const e in r.src){let t=null===(s=r.src[e])||void 0===s?void 0:s.url;t&&("string"==typeof t&&t.startsWith("//")&&(t=`https:${t}`),n.push(t))}if(n.length>0)try{yield o.Assets.unload(n);for(const e of n)try{const t=o.Assets.resolver||o.Assets._resolver;t&&t._assetMap&&(delete t._assetMap[e],delete t._resolverHash[e])}catch(e){}}catch(t){console.warn(`Failed to unload assets for ${e}: ${t.message}`)}delete this.promiseMap[e],delete this.resourceUrlsMap[e],r.data={},r.complete=!1,r.instance=void 0,delete this.resourcesMap[e]})}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 r={};s.forEach(e=>_(this,void 0,void 0,function*(){var s;this.promiseMap[e]=new Promise(t=>r[e]=t);const n=this.resourcesMap[e];this.resourceUrlsMap[e]||(this.resourceUrlsMap[e]=[]);for(const e of this.preProcessResourceHandlers)e(n);for(const a in n.src){if("data"===n.src[a].type)n.data[a]=n.src[a].data,this.doComplete(e,r[e],t);else{let i=null===(s=n.src[a])||void 0===s?void 0:s.url;if("string"==typeof i&&i.startsWith("//")&&(i=`https:${n.src[a].url}`),i&&this.resourceUrlsMap[e]&&!this.resourceUrlsMap[e].includes(i)&&this.resourceUrlsMap[e].push(i),"atlas"===a){const s=o.Assets.load(n.src.image.url).catch(s=>{this.onError({preload:t,errMsg:s.message,resource:{metadata:{key:a,name:e,resolves:r}}})});o.Assets.add({alias:i,src:i,loadParser:n.src[a].loadParser,data:{resolve:()=>s,imageTexture:yield s}})}else{const s={alias:i,src:i};if(n.src[a].loadParser&&(s.loadParser=n.src[a].loadParser),n.type===exports.RESOURCE_TYPE.SPRITE||n.type===exports.RESOURCE_TYPE.SPRITE_ANIMATION){if("json"===n.src[a].type)try{const e=yield o.Assets.load(n.src.image.url);s.data={texture:e}}catch(s){console.log(">>>E",s),this.onError({preload:t,errMsg:s.message,resource:{metadata:{key:a,name:e,resolves:r}}})}}else n.type===exports.RESOURCE_TYPE.FONT&&(s.data={family:e});o.Assets.add(s)}o.Assets.load(i).then(s=>{this.onLoad({preload:t,resource:{metadata:{key:a,name:e,resolves:r},data:s}})}).catch(s=>{console.log(">>>E",s),this.onError({preload:t,errMsg:s.message,resource:{metadata:{key:a,name:e,resolves:r}}})})}}}))}doComplete(e,t,s=!1){return _(this,void 0,void 0,function*(){const o=this.resourcesMap[e],r={name:e,resource:this.resourcesMap[e],success:!0};if(this.checkAllLoaded(e))try{o.instance=yield this.instance(e),o.complete=!0,s&&this.progress.onProgress(r),t(o)}catch(e){console.error(e),o.complete=!1,s&&(r.errMsg=e.message,r.success=!1,this.progress.onProgress(r)),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 _(this,void 0,void 0,function*(){const{metadata:{key:s,name:o,resolves:r},data:n}=t,a=this.resourcesMap[o];a?(a.data[s]=n,this.doComplete(o,r[o],e)):console.warn("no resource data found")})}onError({errMsg:e,preload:t=!1,resource:s}){return _(this,void 0,void 0,function*(){const{metadata:{name:o,resolves:r}}=s;if(delete this.promiseMap[o],delete this.resourceUrlsMap[o],r[o]({}),t){const t={name:o,resource:this.resourcesMap[o],success:!1,errMsg:e};this.progress.onProgress(t)}})}},q=(()=>{const e=globalThis.performance;return e&&"function"==typeof e.now?e.now.bind(e):()=>Date.now()})();const H={IDEProp:V,componentObserver:G,ExecuteInEditMode:t.ExecuteInEditMode,Field:t.Field,getPropertiesOf:t.getPropertiesOf,inspectorField:a,shouldExecuteInEditMode:t.shouldExecuteInEditMode,step:t.step,type:t.type},z="2.1.0-beta.6";console.log(`Eva.js version: ${z}`);exports.ExecuteInEditMode=t.ExecuteInEditMode,exports.Field=t.Field,exports.getPropertiesOf=t.getPropertiesOf,exports.shouldExecuteInEditMode=t.shouldExecuteInEditMode,exports.step=t.step,exports.type=t.type,exports.Component=l,exports.Game=$,exports.GameObject=x,exports.IDEProp=V,exports.RESOURCE_TYPE_STRATEGY={},exports.Scene=D,exports.System=S,exports.Transform=M,exports.componentObserver=G,exports.decorators=H,exports.inspectorField=a,exports.installPerfProbes=function(e,t={}){var s,o,r,n,a,i,c,l,m,p,u;const d=null!==(s=t.sampleSize)&&void 0!==s?s:60,h=null===(o=t.warnOnViolation)||void 0===o||o,f={maxFrameMs:null!==(n=null===(r=t.budget)||void 0===r?void 0:r.maxFrameMs)&&void 0!==n?n:16.67,minFps:null!==(i=null===(a=t.budget)||void 0===a?void 0:a.minFps)&&void 0!==i?i:30,sustainedFrames:null!==(l=null===(c=t.budget)||void 0===c?void 0:c.sustainedFrames)&&void 0!==l?l:60,maxSystemMs:null===(m=t.budget)||void 0===m?void 0:m.maxSystemMs,maxGameObjects:null===(p=t.budget)||void 0===p?void 0:p.maxGameObjects},y=new Map;let g=0;const v=[];let E=null;const b=new Map,_=new Set,O=new Set,M=new Map;let R=!1;function T(e){var t,s,o;if(b.has(e))return;const r=null!==(t=Object.getPrototypeOf(e))&&void 0!==t?t:{},n=Object.prototype.hasOwnProperty.call(e,"update"),a=Object.prototype.hasOwnProperty.call(e,"lateUpdate"),i=null!==(s=e.update)&&void 0!==s?s:r.update,c=null!==(o=e.lateUpdate)&&void 0!==o?o:r.lateUpdate;if("function"==typeof i){const t=i;e.update=function(s){var o;const r=q();try{return t.call(this,s)}finally{const t=q()-r,s=null!==(o=y.get(e))&&void 0!==o?o:{updateMs:0,lateUpdateMs:0};s.updateMs+=t,y.set(e,s)}}}if("function"==typeof c){const t=c;e.lateUpdate=function(s){var o;const r=q();try{return t.call(this,s)}finally{const t=q()-r,s=null!==(o=y.get(e))&&void 0!==o?o:{updateMs:0,lateUpdateMs:0};s.lateUpdateMs+=t,y.set(e,s)}}}b.set(e,{system:e,origUpdate:i,origLateUpdate:c,hadOwnUpdate:n,hadOwnLateUpdate:a})}function x(e){const{system:t,origUpdate:s,origLateUpdate:o,hadOwnUpdate:r,hadOwnLateUpdate:n}=e;"function"==typeof s&&(r?t.update=s:delete t.update),"function"==typeof o&&(n?t.lateUpdate=o:delete t.lateUpdate)}const k=t=>{var s;g=q(),y.clear();for(const t of null!==(s=e.systems)&&void 0!==s?s:[])b.has(t)||T(t)},S=t=>{var s,o;const r=q(),n=Math.max(0,r-g),a=(null!==(s=e.systems)&&void 0!==s?s:[]).map(e=>{var t,s,o;const r=null!==(t=y.get(e))&&void 0!==t?t:{updateMs:0,lateUpdateMs:0};return{name:e.name||(null===(s=e.constructor)||void 0===s?void 0:s.systemName)||(null===(o=e.constructor)||void 0===o?void 0:o.name)||"UnknownSystem",updateMs:r.updateMs,lateUpdateMs:r.lateUpdateMs}}),i=a.reduce((e,t)=>e+t.updateMs+t.lateUpdateMs,0),c=Math.max(0,n-i),l=(null!==(o=e.gameObjects)&&void 0!==o?o:[]).length,m=t&&"number"==typeof t.frameCount?t.frameCount:0;v.push({frameCount:m,fps:0,frameMs:n,systems:a,gameObjectsMs:c,gameObjectCount:l}),v.length>d&&v.shift();const p=v.reduce((e,t)=>e+t.frameMs,0),u=p>0?Math.min(1e3,1e3*v.length/p):1e3,b=v[v.length-1];if(b.fps=u,E=b,_.size)for(const e of Array.from(_))try{e(b)}catch(e){console.error("[perf-probes] onFrame callback error",e)}!function(e){var t;const s=[];"number"==typeof f.maxFrameMs&&s.push({name:"frameMs",actual:e.frameMs,threshold:f.maxFrameMs,over:e.frameMs>f.maxFrameMs});"number"==typeof f.minFps&&s.push({name:"fps",actual:e.fps,threshold:f.minFps,over:e.fps<f.minFps});"number"==typeof f.maxGameObjects&&s.push({name:"gameObjects",actual:e.gameObjectCount,threshold:f.maxGameObjects,over:e.gameObjectCount>f.maxGameObjects});if(f.maxSystemMs)for(const t of e.systems){const e=f.maxSystemMs[t.name];if("number"==typeof e){const o=t.updateMs+t.lateUpdateMs;s.push({name:`system:${t.name}`,actual:o,threshold:e,over:o>e})}}for(const o of s){let s=M.get(o.name);if(s||(s={consec:0,count:0,last:o.actual},M.set(o.name,s)),s.last=o.actual,o.over){if(s.consec+=1,s.consec>=(null!==(t=f.sustainedFrames)&&void 0!==t?t:60)){s.count+=1,s.consec=0;const t={name:o.name,actual:o.actual,threshold:o.threshold,frame:e};if(h&&console.warn(`[perf-probes] sustained violation ${o.name}: actual=${o.actual.toFixed(2)} threshold=${o.threshold}`),O.size)for(const e of Array.from(O))try{e(t)}catch(e){console.error("[perf-probes] onViolation callback error",e)}}}else s.consec=0}}(b)},j=(()=>{const t=e.ticker;return t?t._tickers:null})();let P=[];if(j){P=Array.from(j),j.clear(),j.add(k);for(const e of P)j.add(e);j.add(S)}for(const t of null!==(u=e.systems)&&void 0!==u?u:[])T(t);return{current:()=>E,average:function(){var e;if(0===v.length)return null;const t=v.length;let s=0,o=0,r=0,n=0,a=0;const i=v[t-1],c=new Map;for(const t of v){s+=t.frameMs,o+=t.fps,r+=t.gameObjectsMs,n+=t.gameObjectCount,a=t.frameCount;for(const s of t.systems){const t=null!==(e=c.get(s.name))&&void 0!==e?e:{updateMs:0,lateUpdateMs:0,n:0};t.updateMs+=s.updateMs,t.lateUpdateMs+=s.lateUpdateMs,t.n+=1,c.set(s.name,t)}}const l=i.systems.map(e=>{var t;const s=null!==(t=c.get(e.name))&&void 0!==t?t:{updateMs:0,lateUpdateMs:0,n:1};return{name:e.name,updateMs:s.updateMs/s.n,lateUpdateMs:s.lateUpdateMs/s.n}});return{frameCount:a,fps:o/t,frameMs:s/t,systems:l,gameObjectsMs:r/t,gameObjectCount:n/t}},violations(){const e=[];for(const[t,s]of M)0!==s.count&&e.push({name:t,count:s.count,last:s.last});return e},onFrame:e=>(_.add(e),()=>{_.delete(e)}),onViolation:e=>(O.add(e),()=>{O.delete(e)}),uninstall(){if(!R){if(R=!0,j){const e=Array.from(j).filter(e=>e!==k&&e!==S&&!P.includes(e));j.clear();for(const e of P)j.add(e);for(const t of e)j.add(t)}for(const e of b.values())x(e);b.clear(),v.length=0,E=null,_.clear(),O.clear(),M.clear(),y.clear()}}}},exports.resource=B,exports.version=z; | ||
| "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("eventemitter3"),t=require("@eva/inspector-decorator"),s=require("lodash-es"),r=require("pixi.js");function o(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var n=o(e);function a(e={}){return t.Field(e)}class i extends n{static getInspectorMetadata(){return t.getPropertiesOf(this)}constructor(e){super(),this.started=!1,this.name=this.constructor.componentName,this.__componentDefaultParams=e}getInspectorMetadata(){return this.constructor.getInspectorMetadata()}}var c,m=i;function l(e,t){const s=[];t&&s.push(t);const r=e&&"string"==typeof e.name?e.name:void 0;if(!t||t===r){let t=null==e?void 0:e.constructor;for(t&&(t=Object.getPrototypeOf(t));t&&t!==Function.prototype;){const e=t.componentName;"string"==typeof e&&e&&!s.includes(e)&&s.push(e),t=Object.getPrototypeOf(t)}}return s}exports.OBSERVER_TYPE=void 0,(c=exports.OBSERVER_TYPE||(exports.OBSERVER_TYPE={})).ADD="ADD",c.REMOVE="REMOVE",c.CHANGE="CHANGE";const p={},d={},h={},u={};function f(e,t){p[e.gameObject.id]||(p[e.gameObject.id]={});const s=p[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 y({systemName:e,componentName:t,component:s,prop:r,type:o}){var n,a;null===(a=null===(n=d[e])||void 0===n?void 0:n.componentObserver)||void 0===a||a.add({component:s,prop:r,type:o,componentName:t})}function v({obj:e,key:t,prop:r,component:o,componentName:n}){if(void 0!==e)if(t in e){if(Object.defineProperty(e,`_${t}`,{enumerable:!1,writable:!0,value:e[t]}),r.deep&&s.isObject(e[t]))for(const s of Object.keys(e[t]))v({obj:e[t],key:s,prop:r,component:o,componentName:n});Object.defineProperty(e,t,{enumerable:!0,set(a){e[`_${t}`]!==a&&(e[`_${t}`]=a,function({prop:e,component:t,componentName:r}){const o=l(t,r);for(const n in h){const a=h[n]||{};let i;for(const e of o)if(a[e]){i=a[e];break}i&&(i.findIndex(t=>s.isEqual(t,e))>-1&&y({systemName:n,componentName:r,component:t,prop:e,type:exports.OBSERVER_TYPE.CHANGE}))}}({prop:r,component:o,componentName:n}))},get:()=>e[`_${t}`]})}else console.error(`prop ${t} not in component: ${n}, Can not observer`)}function _(e,t=e.name){var s,r;const o=l(e,t);for(const n in h){const a=h[n]||{};let i=!1;for(const e of o)if(a[e]){i=!0;break}i&&(null===(r=null===(s=d[n])||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 p[e.gameObject.id]}(e)}function g(e,t,s,r){var o,n=arguments.length,a=n<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,s):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,s,r);else for(var i=e.length-1;i>=0;i--)(o=e[i])&&(a=(n<3?o(a):n>3?o(t,s,a):o(t,s))||a);return n>3&&a&&Object.defineProperty(t,s,a),a}function E(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function O(e,t,s,r){return new(s||(s=Promise))(function(o,n){function a(e){try{c(r.next(e))}catch(e){n(e)}}function i(e){try{c(r.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(a,i)}c((r=r.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class b 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}}b.componentName="Transform",g([t.type("vector2"),t.step(1),E("design:type",Object)],b.prototype,"position",void 0),g([t.type("size"),t.step(1),E("design:type",Object)],b.prototype,"size",void 0),g([t.type("vector2"),t.step(.1),E("design:type",Object)],b.prototype,"origin",void 0),g([t.type("vector2"),t.step(.1),E("design:type",Object)],b.prototype,"anchor",void 0),g([t.type("vector2"),t.step(.1),E("design:type",Object)],b.prototype,"scale",void 0),g([t.type("vector2"),t.step(.1),E("design:type",Object)],b.prototype,"skew",void 0),g([t.type("number"),t.step(.1),E("design:type",Number)],b.prototype,"rotation",void 0);var M=b;let S=0;class x{constructor(e,t){this._componentCache={},this.components=[],this.destroyed=!1,this._name=e,this.id=++S,this.addComponent(M,t)}get transform(){return this.getComponent(M)}get parent(){return this.transform&&this.transform.parent&&this.transform.parent.gameObject}get children(){return this.transform.children.map(e=>e.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 x))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 x&&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 i?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;const o=l(e,t);for(const n in h){const a=h[n]||{};let i=!1;for(const e of o)if(a[e]){i=!0;break}i&&(null===(r=null===(s=d[n])||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){const s=l(e,t);let r,o="";for(const e of s)if(u[e]){o=e,r=u[e];break}if(r){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");for(const t of r){const{property:s,key:r}=f(e,t.prop);v({obj:s,key:r,prop:t,component:e,componentName:o})}}}(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(),_(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}}}var R=x;var T=class{constructor(){this.events=[]}add({component:e,prop:t,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&&s.isEqual(o.prop,t)&&o.type===r);n>-1&&this.events.splice(n,1),this.events.push({gameObject:e.gameObject,component:e,prop:t,type:r,componentName:o})}getChanged(){return this.events}get changed(){return this.events}clear(){const e=this.events;return this.events=[],e}};var C=class{constructor(e){this.started=!1,this.componentObserver=new T,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 j={autoStart:!0,frameRate:60};var N=class{constructor(e){e=Object.assign({},j,e),this._frameCount=0,this._rafFrameCount=0,this._frameDuration=1e3/e.frameRate,this.autoStart=e.autoStart,this.frameRate=e.frameRate,this._lastRafTime=null,this._accumulator=0,this._simulationTime=0,this._playbackRate=1,this._now=function(){let e=Number.NEGATIVE_INFINITY;return()=>{const t="undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now?Date.now():(new Date).getTime();return e=Math.max(e,t),e}}(),this._tickers=new Set,this._frameStartCallbacks=new Map,this._frameCallbacks=new Map,this._frameStartSnapshot=[],this._frameSnapshot=[],this._frameStartSnapshotDirty=!1,this._frameSnapshotDirty=!1,this._frameCallbackOrder=0,this._requestId=null,this._started=!1,this._ticker=e=>{this._started&&(this._requestId=requestAnimationFrame(this._ticker),this.update(e))},this.autoStart&&this.start()}update(e){const t=void 0===e?this._now():e,s=null===this._lastRafTime?t:Math.max(this._lastRafTime,t),r=null===this._lastRafTime?0:s-this._lastRafTime;this._lastRafTime=s,this._rafFrameCount++,this._accumulator+=Math.max(0,r*this._playbackRate);const o=1e-9*this._frameDuration,n=Math.floor((this._accumulator+o)/this._frameDuration),a=Math.min(n,5),i=n-a;this._accumulator-=n*this._frameDuration,Math.abs(this._accumulator)<o&&(this._accumulator=0);const c={rafTime:s,rafDeltaTime:r,rafFps:r>0?1e3/r:0,rafFrameCount:this._rafFrameCount,updatesThisFrame:a,interpolationAlpha:this._accumulator/this._frameDuration,playbackRate:this._playbackRate},m=Object.assign(Object.assign({},c),{simulationTime:this._simulationTime});this._callFrameCallbacks(this._getFrameStartSnapshot(),m);for(let e=0;e<a;e++){this._simulationTime+=this._frameDuration;const e={deltaTime:this._frameDuration,time:this._simulationTime,currentTime:this._simulationTime,frameCount:++this._frameCount,fps:this.frameRate};for(const t of this._tickers)"function"==typeof t&&t(e)}this._simulationTime+=i*this._frameDuration;const l=Object.assign(Object.assign({},c),{simulationTime:this._simulationTime});this._callFrameCallbacks(this._getFrameSnapshot(),l)}add(e){this._tickers.add(e)}remove(e){this._tickers.delete(e)}addFrameStart(e,t=0){this._addFrameCallback(this._frameStartCallbacks,e,t),this._frameStartSnapshotDirty=!0}removeFrameStart(e){this._frameStartCallbacks.delete(e)&&(this._frameStartSnapshotDirty=!0)}addFrame(e,t=0){this._addFrameCallback(this._frameCallbacks,e,t),this._frameSnapshotDirty=!0}removeFrame(e){this._frameCallbacks.delete(e)&&(this._frameSnapshotDirty=!0)}_addFrameCallback(e,t,s){const r=e.get(t);r?r.priority=s:e.set(t,{fn:t,priority:s,order:this._frameCallbackOrder++})}_getFrameStartSnapshot(){return this._frameStartSnapshotDirty&&(this._frameStartSnapshot=this._createFrameSnapshot(this._frameStartCallbacks),this._frameStartSnapshotDirty=!1),this._frameStartSnapshot}_getFrameSnapshot(){return this._frameSnapshotDirty&&(this._frameSnapshot=this._createFrameSnapshot(this._frameCallbacks),this._frameSnapshotDirty=!1),this._frameSnapshot}_createFrameSnapshot(e){return Array.from(e.values()).sort((e,t)=>e.priority-t.priority||e.order-t.order).map(e=>e.fn)}_callFrameCallbacks(e,t){for(const s of e)s(t)}start(){this._started||(this._started=!0,this._lastRafTime=null,this._requestId=requestAnimationFrame(this._ticker))}pause(){this._started=!1,null!==this._requestId&&(cancelAnimationFrame(this._requestId),this._requestId=null),this._lastRafTime=null}setPlaybackRate(e){if(!Number.isFinite(e)||e<0)throw new RangeError("playback rate must be a finite, non-negative number");this._playbackRate=e}};var w,D=class extends R{constructor(e,t){super(e,t),this.gameObjects=[],this._nameIndex=new Map,this.scene=this}addGameObject(e){if(this.gameObjects.push(e),e.transform&&(e.transform.inScene=!0),e.name){let t=this._nameIndex.get(e.name);t||(t=new Set,this._nameIndex.set(e.name,t)),t.add(e)}}removeGameObject(e){const t=this.gameObjects.indexOf(e);if(-1!==t&&(e.transform&&(e.transform.inScene=!1),this.gameObjects.splice(t,1),e.name)){const t=this._nameIndex.get(e.name);t&&(t.delete(e),0===t.size&&this._nameIndex.delete(e.name))}}findByName(e){const t=this._nameIndex.get(e);if(!t)return null;for(const e of t)if(!e.destroyed)return e;return null}findAllByName(e){const t=this._nameIndex.get(e);if(!t)return[];const s=[];for(const e of t)e.destroyed||s.push(e);return s}destroy(){this.scene=null,super.destroy(),this.gameObjects=null,this.canvas=null,this._nameIndex=null}};exports.LOAD_SCENE_MODE=void 0,(w=exports.LOAD_SCENE_MODE||(exports.LOAD_SCENE_MODE={})).SINGLE="SINGLE",w.MULTI_CANVAS="MULTI_CANVAS";const I=e=>{if((e instanceof C||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)}}},P=(e,t,s)=>{for(const r of t)try{const t=r[s];if(!t)continue;I(r),t.call(r,e)}catch(e){console.error(`${r.constructor.systemName} ${s} error`,e)}};var F,A,k=class extends n{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 O(this,void 0,void 0,function*(){if("undefined"!=typeof window&&window.__EVA_INSPECTOR_ENV__&&(window.__EVA_GAME_INSTANCE__=this),this.ticker=new N({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)}findByName(e){var t;const s=null===(t=this._scene)||void 0===t?void 0:t.findByName(e);if(s)return s;for(const t of this.multiScenes){const s=t.findByName(e);if(s)return s}return null}findAllByName(e){var t;const s=(null===(t=this._scene)||void 0===t?void 0:t.findAllByName(e))||[];for(const t of this.multiScenes){const r=t.findAllByName(e);for(const e of r)s.push(e)}return s}addSystem(e,t){return O(this,void 0,void 0,function*(){let r;if(e instanceof Function)r=new e(t);else{if(!(e instanceof C))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){h[t.systemName]=t.observerInfo,d[t.systemName]=e}(r,r.constructor),function(e){const t=[];e instanceof Array?t.push(...e):t.push(e);for(const e of t)for(const t in e.observerInfo){u[t]=u[t]||[];const r=u[t];for(const o of e.observerInfo[t])-1===r.findIndex(e=>s.isEqual(e,o))&&u[t].push(o)}}(r.constructor);try{r.awake&&r.awake()}catch(e){console.error(`${r.constructor.systemName} awake error`,e)}return this.systems.push(r),this.emit("systemAdded",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 C&&(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.addFrameStart(e=>{P(e,this.systems,"frameStart")}),this.ticker.add(e=>{this.scene&&((e,t=[])=>{for(const s of t)for(const t of s.components)try{I(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{I(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)}}),this.ticker.addFrame(e=>{P(e,this.systems,"frameUpdate")})}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(){var e,t;this.removeAllListeners(),this.playing?this.pause():null===(e=this.ticker)||void 0===e||e.pause(),null===(t=this.scene)||void 0===t||t.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})}}pauseScene({scene:e}){this.emit("pauseScene",{scene:e})}startScene({scene:e}){this.emit("startScene",{scene:e})}destroyScene({scene:e}){const t=this.multiScenes.findIndex(t=>t===e);if(t>-1){const e=this.multiScenes.splice(t,1)[0];this.emit("sceneDestroyed",{scene:e})}}};function U(e,t){e.constructor.IDEProps||(e.constructor.IDEProps=[]),e.constructor.IDEProps.push(t)}function $(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 L extends n{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)}}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,(A=exports.RESOURCE_TYPE||(exports.RESOURCE_TYPE={})).IMAGE="IMAGE",A.SPRITE="SPRITE",A.SPRITE_ANIMATION="SPRITE_ANIMATION",A.AUDIO="AUDIO",A.VIDEO="VIDEO",A.FONT="FONT";const V=new class extends n{constructor(e){super(),this.timeout=6e3,this.preProcessResourceHandlers=[],this.resourcesMap={},this.makeInstanceFunctions={},this.destroyInstanceFunctions={},this.promiseMap={},this.resourceUrlsMap={},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"):t&&(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 L({resource:this,resourceTotal:e.length}),this.loadResource({names:e,preload:!0})}getResource(e){return O(this,void 0,void 0,function*(){return this.loadResource({names:[e]}),this.promiseMap[e]||Promise.resolve({})})}instance(e){return O(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 O(this,void 0,void 0,function*(){yield this._destroy(e)})}_destroy(e,t=!1){var s;return O(this,void 0,void 0,function*(){const o=this.resourcesMap[e];if(!o)return;if(!t)try{this.destroyInstanceFunctions[o.type]&&(yield this.destroyInstanceFunctions[o.type](o))}catch(e){console.warn(`destroy resource ${o.name} error with '${e.message}'`)}const n=this.resourceUrlsMap[e]||[];if(0===n.length&&o.src)for(const e in o.src){let t=null===(s=o.src[e])||void 0===s?void 0:s.url;t&&("string"==typeof t&&t.startsWith("//")&&(t=`https:${t}`),n.push(t))}if(n.length>0)try{yield r.Assets.unload(n);for(const e of n)try{const t=r.Assets.resolver||r.Assets._resolver;t&&t._assetMap&&(delete t._assetMap[e],delete t._resolverHash[e])}catch(e){}}catch(t){console.warn(`Failed to unload assets for ${e}: ${t.message}`)}delete this.promiseMap[e],delete this.resourceUrlsMap[e],o.data={},o.complete=!1,o.instance=void 0,delete this.resourcesMap[e]})}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=>O(this,void 0,void 0,function*(){var s;this.promiseMap[e]=new Promise(t=>o[e]=t);const n=this.resourcesMap[e];this.resourceUrlsMap[e]||(this.resourceUrlsMap[e]=[]);for(const e of this.preProcessResourceHandlers)e(n);for(const a in n.src){if("data"===n.src[a].type)n.data[a]=n.src[a].data,this.doComplete(e,o[e],t);else{let i=null===(s=n.src[a])||void 0===s?void 0:s.url;if("string"==typeof i&&i.startsWith("//")&&(i=`https:${n.src[a].url}`),i&&this.resourceUrlsMap[e]&&!this.resourceUrlsMap[e].includes(i)&&this.resourceUrlsMap[e].push(i),"atlas"===a){const s=r.Assets.load(n.src.image.url).catch(s=>{this.onError({preload:t,errMsg:s.message,resource:{metadata:{key:a,name:e,resolves:o}}})});r.Assets.add({alias:i,src:i,loadParser:n.src[a].loadParser,data:{resolve:()=>s,imageTexture:yield s}})}else{const s={alias:i,src:i};if(n.src[a].loadParser&&(s.loadParser=n.src[a].loadParser),n.type===exports.RESOURCE_TYPE.SPRITE||n.type===exports.RESOURCE_TYPE.SPRITE_ANIMATION){if("json"===n.src[a].type)try{const e=yield r.Assets.load(n.src.image.url);s.data={texture:e}}catch(s){console.log(">>>E",s),this.onError({preload:t,errMsg:s.message,resource:{metadata:{key:a,name:e,resolves:o}}})}}else n.type===exports.RESOURCE_TYPE.FONT&&(s.data={family:e});r.Assets.add(s)}r.Assets.load(i).then(s=>{this.onLoad({preload:t,resource:{metadata:{key:a,name:e,resolves:o},data:s}})}).catch(s=>{console.log(">>>E",s),this.onError({preload:t,errMsg:s.message,resource:{metadata:{key:a,name:e,resolves:o}}})})}}}))}doComplete(e,t,s=!1){return O(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 O(this,void 0,void 0,function*(){const{metadata:{key:s,name:r,resolves:o},data:n}=t,a=this.resourcesMap[r];a?(a.data[s]=n,this.doComplete(r,o[r],e)):console.warn("no resource data found")})}onError({errMsg:e,preload:t=!1,resource:s}){return O(this,void 0,void 0,function*(){const{metadata:{name:r,resolves:o}}=s;if(delete this.promiseMap[r],delete this.resourceUrlsMap[r],o[r]({}),t){const t={name:r,resource:this.resourcesMap[r],success:!1,errMsg:e};this.progress.onProgress(t)}})}},G=()=>{const e=globalThis.performance;return e&&"function"==typeof e.now?e.now():Date.now()};const Y={IDEProp:U,componentObserver:$,ExecuteInEditMode:t.ExecuteInEditMode,Field:t.Field,getPropertiesOf:t.getPropertiesOf,inspectorField:a,shouldExecuteInEditMode:t.shouldExecuteInEditMode,step:t.step,type:t.type},B="2.1.0-beta.7";console.log(`Eva.js version: ${B}`);exports.ExecuteInEditMode=t.ExecuteInEditMode,exports.Field=t.Field,exports.getPropertiesOf=t.getPropertiesOf,exports.shouldExecuteInEditMode=t.shouldExecuteInEditMode,exports.step=t.step,exports.type=t.type,exports.Component=m,exports.Game=k,exports.GameObject=R,exports.IDEProp=U,exports.RESOURCE_TYPE_STRATEGY={},exports.Scene=D,exports.System=C,exports.Transform=M,exports.componentObserver=$,exports.decorators=Y,exports.inspectorField=a,exports.installPerfProbes=function(e,t={}){var s,r,o,n,a,i,c,m,l,p,d;const h=null!==(s=t.sampleSize)&&void 0!==s?s:60,u=null===(r=t.warnOnViolation)||void 0===r||r,f={maxFrameMs:null!==(n=null===(o=t.budget)||void 0===o?void 0:o.maxFrameMs)&&void 0!==n?n:16.67,minFps:null!==(i=null===(a=t.budget)||void 0===a?void 0:a.minFps)&&void 0!==i?i:30,sustainedFrames:null!==(m=null===(c=t.budget)||void 0===c?void 0:c.sustainedFrames)&&void 0!==m?m:60,maxSystemMs:null===(l=t.budget)||void 0===l?void 0:l.maxSystemMs,maxGameObjects:null===(p=t.budget)||void 0===p?void 0:p.maxGameObjects},y=new Map;let v=0;const _=[];let g=null;const E=new Map,O=new Set,b=new Set,M=new Map;let S=!1;function x(e,t,s){const r=Object.prototype.hasOwnProperty.call(e,t),o=e[t];if("function"!=typeof o)return{original:void 0,wrapper:void 0,hadOwn:r};const n=function(...t){if(!s)return o.apply(this,t);const r=G();try{return o.apply(this,t)}finally{const t=`${s}Ms`;(function(e){let t=y.get(e);return t||(t={updateMs:0,lateUpdateMs:0,frameUpdateMs:0},y.set(e,t)),t}(e))[t]+=Math.max(0,G()-r)}};return e[t]=n,{original:o,wrapper:n,hadOwn:r}}function R(e){E.has(e)||E.set(e,{system:e,methods:{update:x(e,"update","update"),lateUpdate:x(e,"lateUpdate","lateUpdate"),frameStart:x(e,"frameStart"),frameUpdate:x(e,"frameUpdate","frameUpdate")}})}function T(e){const{system:t,methods:s}=e;for(const e of Object.keys(s)){const{original:r,wrapper:o,hadOwn:n}=s[e];o&&t[e]===o&&(n?t[e]=r:delete t[e])}}const C=e=>{S||R(e)},j=t=>{var s;v=G(),y.clear();for(const t of null!==(s=e.systems)&&void 0!==s?s:[])E.has(t)||R(t)},N=t=>{var s,r,o;const n=G(),a=Math.max(0,n-v),i=(null!==(s=e.systems)&&void 0!==s?s:[]).map(e=>{var t,s,r;const o=null!==(t=y.get(e))&&void 0!==t?t:{updateMs:0,lateUpdateMs:0,frameUpdateMs:0};return{name:e.name||(null===(s=e.constructor)||void 0===s?void 0:s.systemName)||(null===(r=e.constructor)||void 0===r?void 0:r.name)||"UnknownSystem",updateMs:o.updateMs,lateUpdateMs:o.lateUpdateMs,frameUpdateMs:o.frameUpdateMs}}),c=i.reduce((e,t)=>{var s;return e+(null!==(s=t.frameUpdateMs)&&void 0!==s?s:0)},0),m=i.reduce((e,t)=>{var s;return e+t.updateMs+t.lateUpdateMs+(null!==(s=t.frameUpdateMs)&&void 0!==s?s:0)},0),l=Math.max(0,a-m),p=(null!==(r=e.gameObjects)&&void 0!==r?r:[]).length,d=t&&"number"==typeof t.rafFrameCount?t.rafFrameCount:0,E=t&&"number"==typeof t.rafDeltaTime?t.rafDeltaTime:0,S={frameCount:d,fps:E>0?Number.isFinite(t.rafFps)?t.rafFps:1e3/E:0,frameMs:a,systems:i,frameUpdateMs:c,gameObjectsMs:l,gameObjectCount:p,rafDeltaTime:E,updatesThisFrame:null!==(o=null==t?void 0:t.updatesThisFrame)&&void 0!==o?o:0};if(_.push(S),_.length>h&&_.shift(),g=S,O.size)for(const e of Array.from(O))try{e(S)}catch(e){console.error("[perf-probes] onFrame callback error",e)}!function(e){var t,s,r;const o=[];"number"==typeof f.maxFrameMs&&o.push({name:"frameMs",actual:e.frameMs,threshold:f.maxFrameMs,over:e.frameMs>f.maxFrameMs});"number"==typeof f.minFps&&(null!==(t=e.rafDeltaTime)&&void 0!==t?t:0)>0&&o.push({name:"fps",actual:e.fps,threshold:f.minFps,over:e.fps<f.minFps});"number"==typeof f.maxGameObjects&&o.push({name:"gameObjects",actual:e.gameObjectCount,threshold:f.maxGameObjects,over:e.gameObjectCount>f.maxGameObjects});if(f.maxSystemMs)for(const t of e.systems){const e=f.maxSystemMs[t.name];if("number"==typeof e){const r=t.updateMs+t.lateUpdateMs+(null!==(s=t.frameUpdateMs)&&void 0!==s?s:0);o.push({name:`system:${t.name}`,actual:r,threshold:e,over:r>e})}}for(const t of o){let s=M.get(t.name);if(s||(s={consec:0,count:0,last:t.actual},M.set(t.name,s)),s.last=t.actual,t.over){if(s.consec+=1,s.consec>=(null!==(r=f.sustainedFrames)&&void 0!==r?r:60)){s.count+=1,s.consec=0;const r={name:t.name,actual:t.actual,threshold:t.threshold,frame:e};if(u&&console.warn(`[perf-probes] sustained violation ${t.name}: actual=${t.actual.toFixed(2)} threshold=${t.threshold}`),b.size)for(const e of Array.from(b))try{e(r)}catch(e){console.error("[perf-probes] onViolation callback error",e)}}}else s.consec=0}}(S)},w=e.ticker;w&&(w.addFrameStart(j,-1/0),w.addFrame(N,1/0)),e.on("systemAdded",C);for(const t of null!==(d=e.systems)&&void 0!==d?d:[])R(t);return{current:()=>g,average:function(){var e,t,s,r;if(0===_.length)return null;const o=_.length;let n=0,a=0,i=0,c=0,m=0,l=0,p=0,d=0,h=0,u=0;const f=_[o-1],y=new Map;for(const o of _){n+=o.frameMs,a+=o.gameObjectsMs,i+=o.gameObjectCount,c+=null!==(e=o.frameUpdateMs)&&void 0!==e?e:0,h+=null!==(t=o.updatesThisFrame)&&void 0!==t?t:0,u=o.frameCount,"number"==typeof o.rafDeltaTime?o.rafDeltaTime>0&&(m+=o.rafDeltaTime,l++):(p+=o.fps,d++);for(const e of o.systems){const t=null!==(s=y.get(e.name))&&void 0!==s?s:{updateMs:0,lateUpdateMs:0,frameUpdateMs:0,n:0};t.updateMs+=e.updateMs,t.lateUpdateMs+=e.lateUpdateMs,t.frameUpdateMs+=null!==(r=e.frameUpdateMs)&&void 0!==r?r:0,t.n+=1,y.set(e.name,t)}}const v=f.systems.map(e=>{var t;const s=null!==(t=y.get(e.name))&&void 0!==t?t:{updateMs:0,lateUpdateMs:0,frameUpdateMs:0,n:1};return{name:e.name,updateMs:s.updateMs/s.n,lateUpdateMs:s.lateUpdateMs/s.n,frameUpdateMs:s.frameUpdateMs/s.n}});return{frameCount:u,fps:l>0?1e3*l/m:d>0?p/d:0,frameMs:n/o,systems:v,frameUpdateMs:c/o,gameObjectsMs:a/o,gameObjectCount:i/o,rafDeltaTime:m/Math.max(1,l),updatesThisFrame:h/o}},violations(){const e=[];for(const[t,s]of M)0!==s.count&&e.push({name:t,count:s.count,last:s.last});return e},onFrame:e=>(O.add(e),()=>{O.delete(e)}),onViolation:e=>(b.add(e),()=>{b.delete(e)}),uninstall(){if(!S){S=!0,w&&(w.removeFrameStart(j),w.removeFrame(N)),e.off("systemAdded",C);for(const e of E.values())T(e);E.clear(),_.length=0,g=null,O.clear(),b.clear(),M.clear(),y.clear()}}}},exports.resource=V,exports.version=B; |
+72
-15
@@ -237,2 +237,15 @@ import type { ClassType } from '@eva/inspector-decorator'; | ||
| export declare type FrameCallback = (frame: FrameParams) => void; | ||
| export declare interface FrameParams { | ||
| readonly rafTime: number; | ||
| readonly rafDeltaTime: number; | ||
| readonly rafFps: number; | ||
| readonly rafFrameCount: number; | ||
| readonly updatesThisFrame: number; | ||
| readonly interpolationAlpha: number; | ||
| readonly simulationTime: number; | ||
| readonly playbackRate: number; | ||
| } | ||
| /** | ||
@@ -537,3 +550,3 @@ * 游戏实例类,EVA.js 的核心管理类 | ||
| * - 必须在 game 已经 init 之后调用(否则 game.ticker 还没有,会拒绝并打 warn)。 | ||
| * - install 之后再 addSystem 的 system,probes 会在每帧 epilogue 自动 patch。 | ||
| * - install 之后再 addSystem 的 System 会在 systemAdded 事件中同步 patch;prologue 仍作兜底。 | ||
| * - 同一 game 多次 install:旧 handle 应先 uninstall;否则两套 hook 会串扰。 | ||
@@ -640,9 +653,9 @@ * - uninstall 后 install 必须能正常工作。 | ||
| export declare interface PerfFrame { | ||
| /** Ticker 给出的 frameCount */ | ||
| /** Ticker 给出的物理帧计数 */ | ||
| frameCount: number; | ||
| /** 滑动窗口估算的真实 FPS(基于 frameMs 累计) */ | ||
| /** 当前物理帧的 RAF FPS */ | ||
| fps: number; | ||
| /** 本帧总耗时(systems update+lateUpdate + gameObjects 循环),毫秒 */ | ||
| frameMs: number; | ||
| /** 各 system 本帧的 update / lateUpdate 时长,毫秒 */ | ||
| /** 各 System 本帧的逻辑阶段与一次物理 frameUpdate 时长,毫秒 */ | ||
| systems: { | ||
@@ -652,3 +665,6 @@ name: string; | ||
| lateUpdateMs: number; | ||
| frameUpdateMs?: number; | ||
| }[]; | ||
| /** 所有 System 的 frameUpdate 时长之和,毫秒 */ | ||
| frameUpdateMs?: number; | ||
| /** 本帧 gameObjects 循环耗时,毫秒(估算 = frameMs - sum(systems)) */ | ||
@@ -658,2 +674,6 @@ gameObjectsMs: number; | ||
| gameObjectCount: number; | ||
| /** 当前 RAF 间隔;baseline 帧为 0 */ | ||
| rafDeltaTime?: number; | ||
| /** 当前物理帧执行的固定逻辑更新次数 */ | ||
| updatesThisFrame?: number; | ||
| } | ||
@@ -688,3 +708,3 @@ | ||
| onViolation(fn: (v: PerfViolation) => void): () => void; | ||
| /** 卸载所有 hook,把 system update 和 ticker._tickers 还原 */ | ||
| /** 卸载所有 hook,并按 ownership 还原 System 方法 */ | ||
| uninstall(): void; | ||
@@ -1099,2 +1119,14 @@ } | ||
| /** | ||
| * 每个物理 RAF 开始时调用一次,先于本帧的所有固定逻辑更新。 | ||
| * | ||
| * @param frame - 当前物理帧的时间与逻辑步数信息 | ||
| */ | ||
| frameStart?(frame: FrameParams): void; | ||
| /** | ||
| * 每个物理 RAF 结束时调用一次,晚于本帧的所有固定逻辑更新。 | ||
| * | ||
| * @param frame - 当前物理帧的时间与逻辑步数信息 | ||
| */ | ||
| frameUpdate?(frame: FrameParams): void; | ||
| /** | ||
| * 游戏开始运行前或游戏暂停后恢复时调用 | ||
@@ -1158,7 +1190,5 @@ * | ||
| autoStart: boolean; | ||
| /** 目标帧率,表示每秒调用 RAF 的次数 */ | ||
| /** 目标逻辑帧率 */ | ||
| frameRate: number; | ||
| /** 全局时间线管理器 */ | ||
| private timeline; | ||
| /** 两帧之间的时间间隔(毫秒) */ | ||
| /** 固定逻辑步长(毫秒) */ | ||
| private _frameDuration; | ||
@@ -1169,4 +1199,21 @@ /** 每帧调用的回调函数集合 */ | ||
| _requestId: number | null; | ||
| /** 上一帧的渲染时间 */ | ||
| private _lastFrameTime; | ||
| /** 上一次物理帧时间;null 表示下一帧仅建立 baseline */ | ||
| private _lastRafTime; | ||
| /** 尚未消费的缩放游戏时间 */ | ||
| private _accumulator; | ||
| /** 已执行的固定逻辑时间 */ | ||
| private _simulationTime; | ||
| /** 物理帧计数 */ | ||
| private _rafFrameCount; | ||
| /** 配置的逻辑播放速率 */ | ||
| private _playbackRate; | ||
| /** 手动 update() 使用的单调时钟 */ | ||
| private _now; | ||
| private _frameStartCallbacks; | ||
| private _frameCallbacks; | ||
| private _frameStartSnapshot; | ||
| private _frameSnapshot; | ||
| private _frameStartSnapshotDirty; | ||
| private _frameSnapshotDirty; | ||
| private _frameCallbackOrder; | ||
| /** 从时钟开始以来的帧计数 */ | ||
@@ -1195,3 +1242,3 @@ private _frameCount; | ||
| */ | ||
| update(): void; | ||
| update(rafTime?: number): void; | ||
| /** | ||
@@ -1207,6 +1254,15 @@ * 添加每帧执行的回调函数 | ||
| remove(fn: any): void; | ||
| addFrameStart(fn: FrameCallback, priority?: number): void; | ||
| removeFrameStart(fn: FrameCallback): void; | ||
| addFrame(fn: FrameCallback, priority?: number): void; | ||
| removeFrame(fn: FrameCallback): void; | ||
| private _addFrameCallback; | ||
| private _getFrameStartSnapshot; | ||
| private _getFrameSnapshot; | ||
| private _createFrameSnapshot; | ||
| private _callFrameCallbacks; | ||
| /** | ||
| * 启动主循环 | ||
| * | ||
| * 如果已经启动则忽略。启动后时间线播放速率设为 1.0。 | ||
| * 如果已经启动则忽略。恢复时下一物理帧重建墙钟 baseline。 | ||
| */ | ||
@@ -1217,3 +1273,3 @@ start(): void; | ||
| * | ||
| * 将时间线播放速率设为 0,停止帧更新。 | ||
| * 取消 RAF,但保留已配置的播放速率。 | ||
| */ | ||
@@ -1224,2 +1280,3 @@ pause(): void; | ||
| * @param rate - 播放速率(1.0 为正常速度) | ||
| * @throws RangeError 当播放速率不是有限非负数时抛出 | ||
| */ | ||
@@ -1380,4 +1437,4 @@ setPlaybackRate(rate: number): void; | ||
| export declare const version = "2.1.0-beta.6"; | ||
| export declare const version = "2.1.0-beta.7"; | ||
| export { } |
+1
-1
@@ -1,1 +0,1 @@ | ||
| function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},_extends.apply(null,arguments)}var _EVA_IIFE_EVA=function(e,t){"use strict";var r=function(e){var t={exports:{}};return e(t,t.exports),t.exports}(function(e){var t=Object.prototype.hasOwnProperty,r="~";function n(){}function o(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function s(e,t,n,s,a){if("function"!=typeof n)throw new TypeError("The listener must be a function");var i=new o(n,s||e,a),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],i]:e._events[c].push(i):(e._events[c]=i,e._eventsCount++),e}function a(e,t){0===--e._eventsCount?e._events=new n:delete e._events[t]}function i(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),i.prototype.eventNames=function(){var e,n,o=[];if(0===this._eventsCount)return o;for(n in e=this._events)t.call(e,n)&&o.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},i.prototype.listeners=function(e){var t=r?r+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,a=new Array(s);o<s;o++)a[o]=n[o].fn;return a},i.prototype.listenerCount=function(e){var t=r?r+e:e,n=this._events[t];return n?n.fn?1:n.length:0},i.prototype.emit=function(e,t,n,o,s,a){var i=r?r+e:e;if(!this._events[i])return!1;var c,u,l=this._events[i],p=arguments.length;if(l.fn){switch(l.once&&this.removeListener(e,l.fn,void 0,!0),p){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,t),!0;case 3:return l.fn.call(l.context,t,n),!0;case 4:return l.fn.call(l.context,t,n,o),!0;case 5:return l.fn.call(l.context,t,n,o,s),!0;case 6:return l.fn.call(l.context,t,n,o,s,a),!0}for(u=1,c=new Array(p-1);u<p;u++)c[u-1]=arguments[u];l.fn.apply(l.context,c)}else{var h,f=l.length;for(u=0;u<f;u++)switch(l[u].once&&this.removeListener(e,l[u].fn,void 0,!0),p){case 1:l[u].fn.call(l[u].context);break;case 2:l[u].fn.call(l[u].context,t);break;case 3:l[u].fn.call(l[u].context,t,n);break;case 4:l[u].fn.call(l[u].context,t,n,o);break;default:if(!c)for(h=1,c=new Array(p-1);h<p;h++)c[h-1]=arguments[h];l[u].fn.apply(l[u].context,c)}}return!0},i.prototype.on=function(e,t,r){return s(this,e,t,r,!1)},i.prototype.once=function(e,t,r){return s(this,e,t,r,!0)},i.prototype.removeListener=function(e,t,n,o){var s=r?r+e:e;if(!this._events[s])return this;if(!t)return a(this,s),this;var i=this._events[s];if(i.fn)i.fn!==t||o&&!i.once||n&&i.context!==n||a(this,s);else{for(var c=0,u=[],l=i.length;c<l;c++)(i[c].fn!==t||o&&!i[c].once||n&&i[c].context!==n)&&u.push(i[c]);u.length?this._events[s]=1===u.length?u[0]:u:a(this,s)}return this},i.prototype.removeAllListeners=function(e){var t;return e?(t=r?r+e:e,this._events[t]&&a(this,t)):(this._events=new n,this._eventsCount=0),this},i.prototype.off=i.prototype.removeListener,i.prototype.addListener=i.prototype.on,i.prefixed=r,i.EventEmitter=i,e.exports=i}),n=r;"function"==typeof SuppressedError&&SuppressedError;class o extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const s="IDE_PROPERTY_METADATA",a="COMPONENT_EXECUTE_MODE_METADATA";function i(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}function c(e,t,r,n){let o=Reflect.getMetadata("design:type",e,t),a=o===Array;const c=i(o);if("unknown"!==c&&(o=c),n){const e=n();Array.isArray(e)?(a=!0,o=e[0]):o=e}const u=Reflect.getMetadata(s,e.constructor)||{},l=_extends(_extends(_extends({},u[t]||{}),{type:o,isArray:a}),r);u[t]=l,Reflect.defineMetadata(s,u,e.constructor);!function(e,t,r){const n=e.constructor,o=n.IDEProps||{};o[t]=_extends(_extends({key:t},o[t]),r),n.IDEProps=o}(e,t,function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}(l,["isArray"]))}function u(e){return p({type:e})}function l(e){return p({step:e})}function p(e,t){return(r,n)=>{if("symbol"==typeof n)throw new o;const{options:s,returnTypeFunc:a}=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(e,t);c(r,n,s,a)}}function h(e,t=!0){const r=Reflect.getMetadata(s,e)||{},n=e.componentName,o={name:n,type:n,isArray:!1};return t&&(o.isFolder=!0),!Object.keys(r).length&&e.componentName||(o.type="object",o.children=[],Object.keys(r).forEach(e=>{if("function"==typeof r[e].type){const t=i(r[e].type);if("unknown"!==t)r[e].type=t;else{const t=h(r[e].type,!1);r[e].type="object",r[e].children||(r[e].children=[]),r[e].children.push(...t.children)}}r[e].name||(r[e].name=e),r[e].isArray&&(r[e].addable=!0),o.children.push(r[e])})),o}var f;!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(f||(f={}));const d=e=>{Reflect.defineMetadata(a,f.Edit,e)},m=e=>!!(Reflect.getMetadata(a,e)&f.Edit);function y(e={}){return p(e)}class v extends n{static getInspectorMetadata(){return h(this)}constructor(e){super(),this.started=!1,this.name=this.constructor.componentName,this.__componentDefaultParams=e}getInspectorMetadata(){return this.constructor.getInspectorMetadata()}}var _=v,b="object"==typeof global&&global&&global.Object===Object&&global,g="object"==typeof self&&self&&self.Object===Object&&self,O=b||g||Function("return this")(),E=O.Symbol,j=Object.prototype,M=j.hasOwnProperty,w=j.toString,T=E?E.toStringTag:void 0;var R=Object.prototype.toString;var k=E?E.toStringTag:void 0;function A(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":k&&k in Object(e)?function(e){var t=M.call(e,T),r=e[T];try{e[T]=void 0;var n=!0}catch(e){}var o=w.call(e);return n&&(t?e[T]=r:delete e[T]),o}(e):function(e){return R.call(e)}(e)}function S(e){return null!=e&&"object"==typeof e}var P=Array.isArray;function x(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function C(e){if(!x(e))return!1;var t=A(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t}var I,N=O["__core-js_shared__"],D=(I=/[^.]+$/.exec(N&&N.keys&&N.keys.IE_PROTO||""))?"Symbol(src)_1."+I:"";var U=Function.prototype.toString;function F(e){if(null!=e){try{return U.call(e)}catch(e){}try{return e+""}catch(e){}}return""}var L=/^\[object .+?Constructor\]$/,$=Function.prototype,V=Object.prototype,z=$.toString,G=V.hasOwnProperty,B=RegExp("^"+z.call(G).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Y(e){return!(!x(e)||(t=e,D&&D in t))&&(C(e)?B:L).test(F(e));var t}function H(e,t){var r=function(e,t){return null==e?void 0:e[t]}(e,t);return Y(r)?r:void 0}var q=H(O,"WeakMap"),W=/^(?:0|[1-9]\d*)$/;function X(e,t){var r=typeof e;return!!(t=null==t?9007199254740991:t)&&("number"==r||"symbol"!=r&&W.test(e))&&e>-1&&e%1==0&&e<t}function J(e,t){return e===t||e!=e&&t!=t}function K(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991}var Q=Object.prototype;function Z(e){return S(e)&&"[object Arguments]"==A(e)}var ee=Object.prototype,te=ee.hasOwnProperty,re=ee.propertyIsEnumerable,ne=Z(function(){return arguments}())?Z:function(e){return S(e)&&te.call(e,"callee")&&!re.call(e,"callee")},oe=ne;var se="object"==typeof e&&e&&!e.nodeType&&e,ae=se&&"object"==typeof module&&module&&!module.nodeType&&module,ie=ae&&ae.exports===se?O.Buffer:void 0,ce=(ie?ie.isBuffer:void 0)||function(){return!1},ue={};ue["[object Float32Array]"]=ue["[object Float64Array]"]=ue["[object Int8Array]"]=ue["[object Int16Array]"]=ue["[object Int32Array]"]=ue["[object Uint8Array]"]=ue["[object Uint8ClampedArray]"]=ue["[object Uint16Array]"]=ue["[object Uint32Array]"]=!0,ue["[object Arguments]"]=ue["[object Array]"]=ue["[object ArrayBuffer]"]=ue["[object Boolean]"]=ue["[object DataView]"]=ue["[object Date]"]=ue["[object Error]"]=ue["[object Function]"]=ue["[object Map]"]=ue["[object Number]"]=ue["[object Object]"]=ue["[object RegExp]"]=ue["[object Set]"]=ue["[object String]"]=ue["[object WeakMap]"]=!1;var le,pe="object"==typeof e&&e&&!e.nodeType&&e,he=pe&&"object"==typeof module&&module&&!module.nodeType&&module,fe=he&&he.exports===pe&&b.process,de=function(){try{var e=he&&he.require&&he.require("util").types;return e||fe&&fe.binding&&fe.binding("util")}catch(e){}}(),me=de&&de.isTypedArray,ye=me?(le=me,function(e){return le(e)}):function(e){return S(e)&&K(e.length)&&!!ue[A(e)]},ve=Object.prototype.hasOwnProperty;function _e(e,t){var r=P(e),n=!r&&oe(e),o=!r&&!n&&ce(e),s=!r&&!n&&!o&&ye(e),a=r||n||o||s,i=a?function(e,t){for(var r=-1,n=Array(e);++r<e;)n[r]=t(r);return n}(e.length,String):[],c=i.length;for(var u in e)!t&&!ve.call(e,u)||a&&("length"==u||o&&("offset"==u||"parent"==u)||s&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||X(u,c))||i.push(u);return i}var be=function(e,t){return function(r){return e(t(r))}}(Object.keys,Object),ge=be,Oe=Object.prototype.hasOwnProperty;function Ee(e){if(r=(t=e)&&t.constructor,t!==("function"==typeof r&&r.prototype||Q))return ge(e);var t,r,n=[];for(var o in Object(e))Oe.call(e,o)&&"constructor"!=o&&n.push(o);return n}function je(e){return null!=(t=e)&&K(t.length)&&!C(t)?_e(e):Ee(e);var t}var Me=H(Object,"create");var we=Object.prototype.hasOwnProperty;var Te=Object.prototype.hasOwnProperty;function Re(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function ke(e,t){for(var r=e.length;r--;)if(J(e[r][0],t))return r;return-1}Re.prototype.clear=function(){this.__data__=Me?Me(null):{},this.size=0},Re.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},Re.prototype.get=function(e){var t=this.__data__;if(Me){var r=t[e];return"__lodash_hash_undefined__"===r?void 0:r}return we.call(t,e)?t[e]:void 0},Re.prototype.has=function(e){var t=this.__data__;return Me?void 0!==t[e]:Te.call(t,e)},Re.prototype.set=function(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=Me&&void 0===t?"__lodash_hash_undefined__":t,this};var Ae=Array.prototype.splice;function Se(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}Se.prototype.clear=function(){this.__data__=[],this.size=0},Se.prototype.delete=function(e){var t=this.__data__,r=ke(t,e);return!(r<0)&&(r==t.length-1?t.pop():Ae.call(t,r,1),--this.size,!0)},Se.prototype.get=function(e){var t=this.__data__,r=ke(t,e);return r<0?void 0:t[r][1]},Se.prototype.has=function(e){return ke(this.__data__,e)>-1},Se.prototype.set=function(e,t){var r=this.__data__,n=ke(r,e);return n<0?(++this.size,r.push([e,t])):r[n][1]=t,this};var Pe=H(O,"Map");function xe(e,t){var r=e.__data__;return function(e){var t=typeof e;return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e}(t)?r["string"==typeof t?"string":"hash"]:r.map}function Ce(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}Ce.prototype.clear=function(){this.size=0,this.__data__={hash:new Re,map:new(Pe||Se),string:new Re}},Ce.prototype.delete=function(e){var t=xe(this,e).delete(e);return this.size-=t?1:0,t},Ce.prototype.get=function(e){return xe(this,e).get(e)},Ce.prototype.has=function(e){return xe(this,e).has(e)},Ce.prototype.set=function(e,t){var r=xe(this,e),n=r.size;return r.set(e,t),this.size+=r.size==n?0:1,this};function Ie(e){var t=this.__data__=new Se(e);this.size=t.size}Ie.prototype.clear=function(){this.__data__=new Se,this.size=0},Ie.prototype.delete=function(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r},Ie.prototype.get=function(e){return this.__data__.get(e)},Ie.prototype.has=function(e){return this.__data__.has(e)},Ie.prototype.set=function(e,t){var r=this.__data__;if(r instanceof Se){var n=r.__data__;if(!Pe||n.length<199)return n.push([e,t]),this.size=++r.size,this;r=this.__data__=new Ce(n)}return r.set(e,t),this.size=r.size,this};var Ne=Object.prototype.propertyIsEnumerable,De=Object.getOwnPropertySymbols,Ue=De?function(e){return null==e?[]:(e=Object(e),function(e,t){for(var r=-1,n=null==e?0:e.length,o=0,s=[];++r<n;){var a=e[r];t(a,r,e)&&(s[o++]=a)}return s}(De(e),function(t){return Ne.call(e,t)}))}:function(){return[]};function Fe(e){return function(e,t,r){var n=t(e);return P(e)?n:function(e,t){for(var r=-1,n=t.length,o=e.length;++r<n;)e[o+r]=t[r];return e}(n,r(e))}(e,je,Ue)}var Le=H(O,"DataView"),$e=H(O,"Promise"),Ve=H(O,"Set"),ze="[object Map]",Ge="[object Promise]",Be="[object Set]",Ye="[object WeakMap]",He="[object DataView]",qe=F(Le),We=F(Pe),Xe=F($e),Je=F(Ve),Ke=F(q),Qe=A;(Le&&Qe(new Le(new ArrayBuffer(1)))!=He||Pe&&Qe(new Pe)!=ze||$e&&Qe($e.resolve())!=Ge||Ve&&Qe(new Ve)!=Be||q&&Qe(new q)!=Ye)&&(Qe=function(e){var t=A(e),r="[object Object]"==t?e.constructor:void 0,n=r?F(r):"";if(n)switch(n){case qe:return He;case We:return ze;case Xe:return Ge;case Je:return Be;case Ke:return Ye}return t});var Ze=Qe,et=O.Uint8Array;function tt(e){var t=-1,r=null==e?0:e.length;for(this.__data__=new Ce;++t<r;)this.add(e[t])}function rt(e,t){for(var r=-1,n=null==e?0:e.length;++r<n;)if(t(e[r],r,e))return!0;return!1}tt.prototype.add=tt.prototype.push=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},tt.prototype.has=function(e){return this.__data__.has(e)};function nt(e,t,r,n,o,s){var a=1&r,i=e.length,c=t.length;if(i!=c&&!(a&&c>i))return!1;var u=s.get(e),l=s.get(t);if(u&&l)return u==t&&l==e;var p=-1,h=!0,f=2&r?new tt:void 0;for(s.set(e,t),s.set(t,e);++p<i;){var d=e[p],m=t[p];if(n)var y=a?n(m,d,p,t,e,s):n(d,m,p,e,t,s);if(void 0!==y){if(y)continue;h=!1;break}if(f){if(!rt(t,function(e,t){if(a=t,!f.has(a)&&(d===e||o(d,e,r,n,s)))return f.push(t);var a})){h=!1;break}}else if(d!==m&&!o(d,m,r,n,s)){h=!1;break}}return s.delete(e),s.delete(t),h}function ot(e){var t=-1,r=Array(e.size);return e.forEach(function(e,n){r[++t]=[n,e]}),r}function st(e){var t=-1,r=Array(e.size);return e.forEach(function(e){r[++t]=e}),r}var at=E?E.prototype:void 0,it=at?at.valueOf:void 0;var ct=Object.prototype.hasOwnProperty;var ut,lt="[object Arguments]",pt="[object Array]",ht="[object Object]",ft=Object.prototype.hasOwnProperty;function dt(e,t,r,n,o,s){var a=P(e),i=P(t),c=a?pt:Ze(e),u=i?pt:Ze(t),l=(c=c==lt?ht:c)==ht,p=(u=u==lt?ht:u)==ht,h=c==u;if(h&&ce(e)){if(!ce(t))return!1;a=!0,l=!1}if(h&&!l)return s||(s=new Ie),a||ye(e)?nt(e,t,r,n,o,s):function(e,t,r,n,o,s,a){switch(r){case"[object DataView]":if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case"[object ArrayBuffer]":return!(e.byteLength!=t.byteLength||!s(new et(e),new et(t)));case"[object Boolean]":case"[object Date]":case"[object Number]":return J(+e,+t);case"[object Error]":return e.name==t.name&&e.message==t.message;case"[object RegExp]":case"[object String]":return e==t+"";case"[object Map]":var i=ot;case"[object Set]":var c=1&n;if(i||(i=st),e.size!=t.size&&!c)return!1;var u=a.get(e);if(u)return u==t;n|=2,a.set(e,t);var l=nt(i(e),i(t),n,o,s,a);return a.delete(e),l;case"[object Symbol]":if(it)return it.call(e)==it.call(t)}return!1}(e,t,c,r,n,o,s);if(!(1&r)){var f=l&&ft.call(e,"__wrapped__"),d=p&&ft.call(t,"__wrapped__");if(f||d){var m=f?e.value():e,y=d?t.value():t;return s||(s=new Ie),o(m,y,r,n,s)}}return!!h&&(s||(s=new Ie),function(e,t,r,n,o,s){var a=1&r,i=Fe(e),c=i.length;if(c!=Fe(t).length&&!a)return!1;for(var u=c;u--;){var l=i[u];if(!(a?l in t:ct.call(t,l)))return!1}var p=s.get(e),h=s.get(t);if(p&&h)return p==t&&h==e;var f=!0;s.set(e,t),s.set(t,e);for(var d=a;++u<c;){var m=e[l=i[u]],y=t[l];if(n)var v=a?n(y,m,l,t,e,s):n(m,y,l,e,t,s);if(!(void 0===v?m===y||o(m,y,r,n,s):v)){f=!1;break}d||(d="constructor"==l)}if(f&&!d){var _=e.constructor,b=t.constructor;_==b||!("constructor"in e)||!("constructor"in t)||"function"==typeof _&&_ instanceof _&&"function"==typeof b&&b instanceof b||(f=!1)}return s.delete(e),s.delete(t),f}(e,t,r,n,o,s))}function mt(e,t,r,n,o){return e===t||(null==e||null==t||!S(e)&&!S(t)?e!=e&&t!=t:dt(e,t,r,n,mt,o))}function yt(e,t){return mt(e,t)}function vt(e,t){const r=[];t&&r.push(t);const n=e&&"string"==typeof e.name?e.name:void 0;if(!t||t===n){let t=null==e?void 0:e.constructor;for(t&&(t=Object.getPrototypeOf(t));t&&t!==Function.prototype;){const e=t.componentName;"string"==typeof e&&e&&!r.includes(e)&&r.push(e),t=Object.getPrototypeOf(t)}}return r}e.OBSERVER_TYPE=void 0,(ut=e.OBSERVER_TYPE||(e.OBSERVER_TYPE={})).ADD="ADD",ut.REMOVE="REMOVE",ut.CHANGE="CHANGE";const _t={},bt={},gt={},Ot={};function Et(e,t){_t[e.gameObject.id]||(_t[e.gameObject.id]={});const r=_t[e.gameObject.id],n=e.name+"_"+t.join(",");if(r[n])return r[n];const o=t.length-1;let s=e;for(let e=0;e<o;e++)s=s[t[e]];return r[n]={property:s,key:t[o]},r[n]}function jt({systemName:e,componentName:t,component:r,prop:n,type:o}){var s,a;null===(a=null===(s=bt[e])||void 0===s?void 0:s.componentObserver)||void 0===a||a.add({component:r,prop:n,type:o,componentName:t})}function Mt({obj:t,key:r,prop:n,component:o,componentName:s}){if(void 0!==t)if(r in t){if(Object.defineProperty(t,`_${r}`,{enumerable:!1,writable:!0,value:t[r]}),n.deep&&x(t[r]))for(const e of Object.keys(t[r]))Mt({obj:t[r],key:e,prop:n,component:o,componentName:s});Object.defineProperty(t,r,{enumerable:!0,set(a){t[`_${r}`]!==a&&(t[`_${r}`]=a,function({prop:t,component:r,componentName:n}){const o=vt(r,n);for(const s in gt){const a=gt[s]||{};let i;for(const e of o)if(a[e]){i=a[e];break}i&&(i.findIndex(e=>yt(e,t))>-1&&jt({systemName:s,componentName:n,component:r,prop:t,type:e.OBSERVER_TYPE.CHANGE}))}}({prop:n,component:o,componentName:s}))},get:()=>t[`_${r}`]})}else console.error(`prop ${r} not in component: ${s}, Can not observer`)}function wt(t,r=t.name){var n,o;const s=vt(t,r);for(const a in gt){const i=gt[a]||{};let c=!1;for(const e of s)if(i[e]){c=!0;break}c&&(null===(o=null===(n=bt[a])||void 0===n?void 0:n.componentObserver)||void 0===o||o.add({component:t,type:e.OBSERVER_TYPE.REMOVE,componentName:r}))}!function(e){e.gameObject&&delete _t[e.gameObject.id]}(t)}function Tt(e,t,r,n){var o,s=arguments.length,a=s<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var i=e.length-1;i>=0;i--)(o=e[i])&&(a=(s<3?o(a):s>3?o(t,r,a):o(t,r))||a);return s>3&&a&&Object.defineProperty(t,r,a),a}function Rt(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function kt(e,t,r,n){return new(r||(r=Promise))(function(o,s){function a(e){try{c(n.next(e))}catch(e){s(e)}}function i(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(a,i)}c((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class At extends _{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 r of t)_extends(this[r],e[r]);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}}At.componentName="Transform",Tt([u("vector2"),l(1),Rt("design:type",Object)],At.prototype,"position",void 0),Tt([u("size"),l(1),Rt("design:type",Object)],At.prototype,"size",void 0),Tt([u("vector2"),l(.1),Rt("design:type",Object)],At.prototype,"origin",void 0),Tt([u("vector2"),l(.1),Rt("design:type",Object)],At.prototype,"anchor",void 0),Tt([u("vector2"),l(.1),Rt("design:type",Object)],At.prototype,"scale",void 0),Tt([u("vector2"),l(.1),Rt("design:type",Object)],At.prototype,"skew",void 0),Tt([u("number"),l(.1),Rt("design:type",Number)],At.prototype,"rotation",void 0);var St=At;let Pt=0;class xt{constructor(e,t){this._componentCache={},this.components=[],this.destroyed=!1,this._name=e,this.id=++Pt,this.addComponent(St,t)}get transform(){return this.getComponent(St)}get parent(){return this.transform&&this.transform.parent&&this.transform.parent.gameObject}get children(){return this.transform.children.map(e=>e.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 xt))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 xt&&e.parent&&e.parent===this?(e.transform.parent=null,e.scene=null,e):e}addComponent(t,r){if(this.destroyed)return;const n=function(e){return e instanceof v?e.name:e instanceof Function?e.componentName:void 0}(t);if(this._componentCache[n])return;let o;if(t instanceof Function)o=new t(r);else{if(!(t instanceof _))throw new Error("addComponent recieve Component and Component Constructor");o=t}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(t,r=t.name){var n,o;const s=vt(t,r);for(const a in gt){const i=gt[a]||{};let c=!1;for(const e of s)if(i[e]){c=!0;break}c&&(null===(o=null===(n=bt[a])||void 0===n?void 0:n.componentObserver)||void 0===o||o.add({component:t,type:e.OBSERVER_TYPE.ADD,componentName:r}))}}(o,o.name),function(e,t=e.name){const r=vt(e,t);let n,o="";for(const e of r)if(Ot[e]){o=e,n=Ot[e];break}if(n){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 t of n){const{property:r,key:n}=Et(e,t.prop);Mt({obj:r,key:n,prop:t,component:e,componentName:o})}}}(o,o.name),this.components.push(o),this._componentCache[n]=o,o.awake&&o.awake(),o}removeComponent(e){let t;if("string"==typeof e?t=e:e instanceof _?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 r=this.components.splice(t,1)[0];return delete this._componentCache[e],delete r.__componentDefaultParams,r.onDestroy&&r.onDestroy(),wt(r,e),r.gameObject=void 0,r}getComponent(e){let t;return"string"==typeof e?t=e:e instanceof _?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}}}var Ct=xt;var It=class{constructor(){this.events=[]}add({component:t,prop:r,type:n,componentName:o}){if(n===e.OBSERVER_TYPE.REMOVE){if(this.events.find(r=>r.component===t&&r.type===e.OBSERVER_TYPE.ADD))return void(this.events=this.events.filter(e=>e.component!==t));this.events=this.events.filter(e=>e.component!==t)}const s=this.events.findIndex(e=>e.component===t&&yt(e.prop,r)&&e.type===n);s>-1&&this.events.splice(s,1),this.events.push({gameObject:t.gameObject,component:t,prop:r,type:n,componentName:o})}getChanged(){return this.events}get changed(){return this.events}clear(){const e=this.events;return this.events=[],e}};var Nt=class{constructor(e){this.started=!1,this.componentObserver=new It,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 Dt=function(){let e=null;return e=Date.now?Date.now:()=>(new Date).getTime(),e}(),Ut={originTime:0,playbackRate:1};class Ft{constructor(e,t){e instanceof Ft&&(t=e,e={}),e=_extends({},Ut,e),t&&(this._parent=t),this._createTime=Dt(),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:Dt()-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:r=this.playbackRate}={}){const n={globalTime:this.globalTime,localTime:e,entropy:t,playbackRate:r,globalEntropy:this.globalEntropy};this._timeMark.push(n)}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 Ft(e,this)}seekGlobalTime(e){const t=this.seekTimeMark(e),r=this._timeMark[t],{entropy:n,playbackRate:o,globalTime:s}=r;return s+(e-n)/Math.abs(o)}seekLocalTime(e){const t=this.seekTimeMark(e),r=this._timeMark[t],{localTime:n,entropy:o,playbackRate:s}=r;return s>0?n+(e-o):n-(e-o)}seekTimeMark(e){const t=this._timeMark;let r=0,n=t.length-1;if(e<=t[r].entropy)return r;if(e>=t[n].entropy)return n;let o=Math.floor((r+n)/2);for(;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}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 Lt=Ft;const $t={autoStart:!0,frameRate:60};var Vt=class{constructor(e){e=_extends({},$t,e),this._frameCount=0,this._frameDuration=1e3/e.frameRate,this.autoStart=e.autoStart,this.frameRate=e.frameRate,this.timeline=new Lt({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;let t=0;for(;e-this._lastFrameTime>=this._frameDuration&&t<5;){this._lastFrameTime+=this._frameDuration,t++;const e={deltaTime:this._frameDuration,time:this._lastFrameTime,currentTime:this._lastFrameTime,frameCount:++this._frameCount,fps:this.frameRate};for(const t of this._tickers)"function"==typeof t&&t(e)}e-this._lastFrameTime>=this._frameDuration&&(this._lastFrameTime=e)}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,null!==this._requestId&&(cancelAnimationFrame(this._requestId),this._requestId=null),this.timeline.playbackRate=0}setPlaybackRate(e){this.timeline.playbackRate=e}};var zt,Gt=class extends Ct{constructor(e,t){super(e,t),this.gameObjects=[],this._nameIndex=new Map,this.scene=this}addGameObject(e){if(this.gameObjects.push(e),e.transform&&(e.transform.inScene=!0),e.name){let t=this._nameIndex.get(e.name);t||(t=new Set,this._nameIndex.set(e.name,t)),t.add(e)}}removeGameObject(e){const t=this.gameObjects.indexOf(e);if(-1!==t&&(e.transform&&(e.transform.inScene=!1),this.gameObjects.splice(t,1),e.name)){const t=this._nameIndex.get(e.name);t&&(t.delete(e),0===t.size&&this._nameIndex.delete(e.name))}}findByName(e){const t=this._nameIndex.get(e);if(!t)return null;for(const e of t)if(!e.destroyed)return e;return null}findAllByName(e){const t=this._nameIndex.get(e);if(!t)return[];const r=[];for(const e of t)e.destroyed||r.push(e);return r}destroy(){this.scene=null,super.destroy(),this.gameObjects=null,this.canvas=null,this._nameIndex=null}};e.LOAD_SCENE_MODE=void 0,(zt=e.LOAD_SCENE_MODE||(e.LOAD_SCENE_MODE={})).SINGLE="SINGLE",zt.MULTI_CANVAS="MULTI_CANVAS";const Bt=e=>{if((e instanceof Nt||e instanceof _)&&!e.started){e.started=!0;try{e.start&&e.start()}catch(t){e instanceof _?console.error(`${e.constructor.componentName} start error`,t):console.error(`${e.constructor.systemName} start error`,t)}}};var Yt,Ht,qt=class extends n{constructor(){super(...arguments),this.playing=!1,this.started=!1,this.multiScenes=[],this.systems=[]}init({systems:e,frameRate:t=60,autoStart:r=!0,needScene:n=!0}={}){return kt(this,void 0,void 0,function*(){if("undefined"!=typeof window&&window.__EVA_INSPECTOR_ENV__&&(window.__EVA_GAME_INSTANCE__=this),this.ticker=new Vt({autoStart:!1,frameRate:t}),this.initTicker(),e&&e.length)for(const t of e)yield this.addSystem(t);n&&this.loadScene(new Gt("scene")),r&&this.start()})}get scene(){return this._scene}set scene(e){this._scene=e}get gameObjects(){return(e=>{var t;const r=(null===(t=null==e?void 0:e.scene)||void 0===t?void 0:t.gameObjects)||[],n=null==e?void 0:e.multiScenes.map(({gameObjects:e})=>e);let o=[];for(const e of n)o=[...o,...e];return[...r,...o]})(this)}findByName(e){var t;const r=null===(t=this._scene)||void 0===t?void 0:t.findByName(e);if(r)return r;for(const t of this.multiScenes){const r=t.findByName(e);if(r)return r}return null}findAllByName(e){var t;const r=(null===(t=this._scene)||void 0===t?void 0:t.findAllByName(e))||[];for(const t of this.multiScenes){const n=t.findAllByName(e);for(const e of n)r.push(e)}return r}addSystem(e,t){return kt(this,void 0,void 0,function*(){let r;if(e instanceof Function)r=new e(t);else{if(!(e instanceof Nt))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){gt[t.systemName]=t.observerInfo,bt[t.systemName]=e}(r,r.constructor),function(e){const t=[];e instanceof Array?t.push(...e):t.push(e);for(const e of t)for(const t in e.observerInfo){Ot[t]=Ot[t]||[];const r=Ot[t];for(const n of e.observerInfo[t])-1===r.findIndex(e=>yt(e,n))&&Ot[t].push(n)}}(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 Nt&&(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 r of t)for(const t of r.components)try{Bt(t),t.update&&t.update(e)}catch(e){console.error(`gameObject: ${r.name} ${t.name} update error`,e)}for(const r of t)for(const t of r.components)try{t.lateUpdate&&t.lateUpdate(e)}catch(e){console.error(`gameObject: ${r.name} ${t.name} lateUpdate error`,e)}})(e,this.gameObjects);for(const t of this.systems)try{Bt(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(r){console.error(`gameObject: ${t.name}, ${e.name}, onResume error`,r)}})(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(r){console.error(`gameObject: ${t.name}, ${e.name}, onResume error`,r)}})(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(){var e,t;this.removeAllListeners(),this.playing?this.pause():null===(e=this.ticker)||void 0===e||e.pause(),null===(t=this.scene)||void 0===t||t.destroy(),this.destroySystems(),this.ticker=null,this.scene=null,this.canvas=null,this.multiScenes=null}loadScene({scene:t,mode:r=e.LOAD_SCENE_MODE.SINGLE,params:n={}}){if(t){switch(r){case e.LOAD_SCENE_MODE.SINGLE:this.scene=t;break;case e.LOAD_SCENE_MODE.MULTI_CANVAS:this.multiScenes.push(t)}this.emit("sceneChanged",{scene:t,mode:r,params:n})}}pauseScene({scene:e}){this.emit("pauseScene",{scene:e})}startScene({scene:e}){this.emit("startScene",{scene:e})}destroyScene({scene:e}){const t=this.multiScenes.findIndex(t=>t===e);if(t>-1){const e=this.multiScenes.splice(t,1)[0];this.emit("sceneDestroyed",{scene:e})}}};function Wt(e,t){e.constructor.IDEProps||(e.constructor.IDEProps=[]),e.constructor.IDEProps.push(t)}function Xt(e={}){return function(t){if(!t.observerInfo){for(const t in e)for(const r in e[t]){let n;"string"==typeof e[t][r]&&(e[t][r]=[e[t][r]]),Array.isArray(e[t][r])&&(n={prop:e[t][r],deep:!1},e[t][r]=n),n=e[t][r],"string"==typeof n.prop&&(n.prop=[n.prop])}t.observerInfo=e}}}class Jt extends n{constructor({resource:t,resourceTotal:r}){super(),this.progress=0,this.resourceTotal=0,this.resourceLoadedCount=0,this.resource=t,this.resourceTotal=r,0===r&&this.resource.emit(e.LOAD_EVENT.COMPLETE,this)}onStart(){this.resource.emit(e.LOAD_EVENT.START,this)}onProgress(t){this.resourceLoadedCount++,this.progress=Math.floor(this.resourceLoadedCount/this.resourceTotal*100)/100,t.success?this.resource.emit(e.LOAD_EVENT.LOADED,this,t):this.resource.emit(e.LOAD_EVENT.ERROR,this,t),this.resource.emit(e.LOAD_EVENT.PROGRESS,this,t),this.resourceLoadedCount===this.resourceTotal&&this.resource.emit(e.LOAD_EVENT.COMPLETE,this)}}e.LOAD_EVENT=void 0,(Yt=e.LOAD_EVENT||(e.LOAD_EVENT={})).START="start",Yt.PROGRESS="progress",Yt.LOADED="loaded",Yt.COMPLETE="complete",Yt.ERROR="error",e.RESOURCE_TYPE=void 0,(Ht=e.RESOURCE_TYPE||(e.RESOURCE_TYPE={})).IMAGE="IMAGE",Ht.SPRITE="SPRITE",Ht.SPRITE_ANIMATION="SPRITE_ANIMATION",Ht.AUDIO="AUDIO",Ht.VIDEO="VIDEO",Ht.FONT="FONT";const Kt=new class extends n{constructor(e){super(),this.timeout=6e3,this.preProcessResourceHandlers=[],this.resourcesMap={},this.makeInstanceFunctions={},this.destroyInstanceFunctions={},this.promiseMap={},this.resourceUrlsMap={},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"):t&&(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 r=this.resourcesMap[t];!r.preload||r.complete||this.promiseMap[t]||e.push(r.name)}this.progress=new Jt({resource:this,resourceTotal:e.length}),this.loadResource({names:e,preload:!0})}getResource(e){return kt(this,void 0,void 0,function*(){return this.loadResource({names:[e]}),this.promiseMap[e]||Promise.resolve({})})}instance(e){return kt(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 kt(this,void 0,void 0,function*(){yield this._destroy(e)})}_destroy(e,r=!1){var n;return kt(this,void 0,void 0,function*(){const o=this.resourcesMap[e];if(!o)return;if(!r)try{this.destroyInstanceFunctions[o.type]&&(yield this.destroyInstanceFunctions[o.type](o))}catch(e){console.warn(`destroy resource ${o.name} error with '${e.message}'`)}const s=this.resourceUrlsMap[e]||[];if(0===s.length&&o.src)for(const e in o.src){let t=null===(n=o.src[e])||void 0===n?void 0:n.url;t&&("string"==typeof t&&t.startsWith("//")&&(t=`https:${t}`),s.push(t))}if(s.length>0)try{yield t.Assets.unload(s);for(const e of s)try{const r=t.Assets.resolver||t.Assets._resolver;r&&r._assetMap&&(delete r._assetMap[e],delete r._resolverHash[e])}catch(e){}}catch(t){console.warn(`Failed to unload assets for ${e}: ${t.message}`)}delete this.promiseMap[e],delete this.resourceUrlsMap[e],o.data={},o.complete=!1,o.instance=void 0,delete this.resourcesMap[e]})}registerResourceType(t,r=t){if(e.RESOURCE_TYPE[t])throw new Error(`The type ${t} already exists in RESOURCE_TYPE`);e.RESOURCE_TYPE[t]=r}registerInstance(e,t){this.makeInstanceFunctions[e]=t}registerDestroy(e,t){this.destroyInstanceFunctions[e]=t}loadResource({names:r=[],preload:n=!1}){const o=r.filter(e=>!this.promiseMap[e]&&this.resourcesMap[e]);if(!o.length)return;const s={};o.forEach(r=>kt(this,void 0,void 0,function*(){var o;this.promiseMap[r]=new Promise(e=>s[r]=e);const a=this.resourcesMap[r];this.resourceUrlsMap[r]||(this.resourceUrlsMap[r]=[]);for(const e of this.preProcessResourceHandlers)e(a);for(const i in a.src){if("data"===a.src[i].type)a.data[i]=a.src[i].data,this.doComplete(r,s[r],n);else{let c=null===(o=a.src[i])||void 0===o?void 0:o.url;if("string"==typeof c&&c.startsWith("//")&&(c=`https:${a.src[i].url}`),c&&this.resourceUrlsMap[r]&&!this.resourceUrlsMap[r].includes(c)&&this.resourceUrlsMap[r].push(c),"atlas"===i){const e=t.Assets.load(a.src.image.url).catch(e=>{this.onError({preload:n,errMsg:e.message,resource:{metadata:{key:i,name:r,resolves:s}}})});t.Assets.add({alias:c,src:c,loadParser:a.src[i].loadParser,data:{resolve:()=>e,imageTexture:yield e}})}else{const o={alias:c,src:c};if(a.src[i].loadParser&&(o.loadParser=a.src[i].loadParser),a.type===e.RESOURCE_TYPE.SPRITE||a.type===e.RESOURCE_TYPE.SPRITE_ANIMATION){if("json"===a.src[i].type)try{const e=yield t.Assets.load(a.src.image.url);o.data={texture:e}}catch(e){console.log(">>>E",e),this.onError({preload:n,errMsg:e.message,resource:{metadata:{key:i,name:r,resolves:s}}})}}else a.type===e.RESOURCE_TYPE.FONT&&(o.data={family:r});t.Assets.add(o)}t.Assets.load(c).then(e=>{this.onLoad({preload:n,resource:{metadata:{key:i,name:r,resolves:s},data:e}})}).catch(e=>{console.log(">>>E",e),this.onError({preload:n,errMsg:e.message,resource:{metadata:{key:i,name:r,resolves:s}}})})}}}))}doComplete(e,t,r=!1){return kt(this,void 0,void 0,function*(){const n=this.resourcesMap[e],o={name:e,resource:this.resourcesMap[e],success:!0};if(this.checkAllLoaded(e))try{n.instance=yield this.instance(e),n.complete=!0,r&&this.progress.onProgress(o),t(n)}catch(e){console.error(e),n.complete=!1,r&&(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 kt(this,void 0,void 0,function*(){const{metadata:{key:r,name:n,resolves:o},data:s}=t,a=this.resourcesMap[n];a?(a.data[r]=s,this.doComplete(n,o[n],e)):console.warn("no resource data found")})}onError({errMsg:e,preload:t=!1,resource:r}){return kt(this,void 0,void 0,function*(){const{metadata:{name:n,resolves:o}}=r;if(delete this.promiseMap[n],delete this.resourceUrlsMap[n],o[n]({}),t){const t={name:n,resource:this.resourcesMap[n],success:!1,errMsg:e};this.progress.onProgress(t)}})}},Qt=(()=>{const e=globalThis.performance;return e&&"function"==typeof e.now?e.now.bind(e):()=>Date.now()})();const Zt={IDEProp:Wt,componentObserver:Xt,ExecuteInEditMode:d,Field:p,getPropertiesOf:h,inspectorField:y,shouldExecuteInEditMode:m,step:l,type:u},er="2.1.0-beta.6";console.log(`Eva.js version: ${er}`);return e.Component=_,e.ExecuteInEditMode=d,e.Field=p,e.Game=qt,e.GameObject=Ct,e.IDEProp=Wt,e.RESOURCE_TYPE_STRATEGY={},e.Scene=Gt,e.System=Nt,e.Transform=St,e.componentObserver=Xt,e.decorators=Zt,e.getPropertiesOf=h,e.inspectorField=y,e.installPerfProbes=function(e,t={}){var r,n,o,s,a,i,c,u,l,p,h;const f=null!==(r=t.sampleSize)&&void 0!==r?r:60,d=null===(n=t.warnOnViolation)||void 0===n||n,m={maxFrameMs:null!==(s=null===(o=t.budget)||void 0===o?void 0:o.maxFrameMs)&&void 0!==s?s:16.67,minFps:null!==(i=null===(a=t.budget)||void 0===a?void 0:a.minFps)&&void 0!==i?i:30,sustainedFrames:null!==(u=null===(c=t.budget)||void 0===c?void 0:c.sustainedFrames)&&void 0!==u?u:60,maxSystemMs:null===(l=t.budget)||void 0===l?void 0:l.maxSystemMs,maxGameObjects:null===(p=t.budget)||void 0===p?void 0:p.maxGameObjects},y=new Map;let v=0;const _=[];let b=null;const g=new Map,O=new Set,E=new Set,j=new Map;let M=!1;function w(e){var t,r,n;if(g.has(e))return;const o=null!==(t=Object.getPrototypeOf(e))&&void 0!==t?t:{},s=Object.prototype.hasOwnProperty.call(e,"update"),a=Object.prototype.hasOwnProperty.call(e,"lateUpdate"),i=null!==(r=e.update)&&void 0!==r?r:o.update,c=null!==(n=e.lateUpdate)&&void 0!==n?n:o.lateUpdate;if("function"==typeof i){const t=i;e.update=function(r){var n;const o=Qt();try{return t.call(this,r)}finally{const t=Qt()-o,r=null!==(n=y.get(e))&&void 0!==n?n:{updateMs:0,lateUpdateMs:0};r.updateMs+=t,y.set(e,r)}}}if("function"==typeof c){const t=c;e.lateUpdate=function(r){var n;const o=Qt();try{return t.call(this,r)}finally{const t=Qt()-o,r=null!==(n=y.get(e))&&void 0!==n?n:{updateMs:0,lateUpdateMs:0};r.lateUpdateMs+=t,y.set(e,r)}}}g.set(e,{system:e,origUpdate:i,origLateUpdate:c,hadOwnUpdate:s,hadOwnLateUpdate:a})}function T(e){const{system:t,origUpdate:r,origLateUpdate:n,hadOwnUpdate:o,hadOwnLateUpdate:s}=e;"function"==typeof r&&(o?t.update=r:delete t.update),"function"==typeof n&&(s?t.lateUpdate=n:delete t.lateUpdate)}const R=t=>{var r;v=Qt(),y.clear();for(const t of null!==(r=e.systems)&&void 0!==r?r:[])g.has(t)||w(t)},k=t=>{var r,n;const o=Qt(),s=Math.max(0,o-v),a=(null!==(r=e.systems)&&void 0!==r?r:[]).map(e=>{var t,r,n;const o=null!==(t=y.get(e))&&void 0!==t?t:{updateMs:0,lateUpdateMs:0};return{name:e.name||(null===(r=e.constructor)||void 0===r?void 0:r.systemName)||(null===(n=e.constructor)||void 0===n?void 0:n.name)||"UnknownSystem",updateMs:o.updateMs,lateUpdateMs:o.lateUpdateMs}}),i=a.reduce((e,t)=>e+t.updateMs+t.lateUpdateMs,0),c=Math.max(0,s-i),u=(null!==(n=e.gameObjects)&&void 0!==n?n:[]).length,l=t&&"number"==typeof t.frameCount?t.frameCount:0;_.push({frameCount:l,fps:0,frameMs:s,systems:a,gameObjectsMs:c,gameObjectCount:u}),_.length>f&&_.shift();const p=_.reduce((e,t)=>e+t.frameMs,0),h=p>0?Math.min(1e3,1e3*_.length/p):1e3,g=_[_.length-1];if(g.fps=h,b=g,O.size)for(const e of Array.from(O))try{e(g)}catch(e){console.error("[perf-probes] onFrame callback error",e)}!function(e){var t;const r=[];"number"==typeof m.maxFrameMs&&r.push({name:"frameMs",actual:e.frameMs,threshold:m.maxFrameMs,over:e.frameMs>m.maxFrameMs});"number"==typeof m.minFps&&r.push({name:"fps",actual:e.fps,threshold:m.minFps,over:e.fps<m.minFps});"number"==typeof m.maxGameObjects&&r.push({name:"gameObjects",actual:e.gameObjectCount,threshold:m.maxGameObjects,over:e.gameObjectCount>m.maxGameObjects});if(m.maxSystemMs)for(const t of e.systems){const e=m.maxSystemMs[t.name];if("number"==typeof e){const n=t.updateMs+t.lateUpdateMs;r.push({name:`system:${t.name}`,actual:n,threshold:e,over:n>e})}}for(const n of r){let r=j.get(n.name);if(r||(r={consec:0,count:0,last:n.actual},j.set(n.name,r)),r.last=n.actual,n.over){if(r.consec+=1,r.consec>=(null!==(t=m.sustainedFrames)&&void 0!==t?t:60)){r.count+=1,r.consec=0;const t={name:n.name,actual:n.actual,threshold:n.threshold,frame:e};if(d&&console.warn(`[perf-probes] sustained violation ${n.name}: actual=${n.actual.toFixed(2)} threshold=${n.threshold}`),E.size)for(const e of Array.from(E))try{e(t)}catch(e){console.error("[perf-probes] onViolation callback error",e)}}}else r.consec=0}}(g)},A=(()=>{const t=e.ticker;return t?t._tickers:null})();let S=[];if(A){S=Array.from(A),A.clear(),A.add(R);for(const e of S)A.add(e);A.add(k)}for(const t of null!==(h=e.systems)&&void 0!==h?h:[])w(t);return{current:()=>b,average:function(){var e;if(0===_.length)return null;const t=_.length;let r=0,n=0,o=0,s=0,a=0;const i=_[t-1],c=new Map;for(const t of _){r+=t.frameMs,n+=t.fps,o+=t.gameObjectsMs,s+=t.gameObjectCount,a=t.frameCount;for(const r of t.systems){const t=null!==(e=c.get(r.name))&&void 0!==e?e:{updateMs:0,lateUpdateMs:0,n:0};t.updateMs+=r.updateMs,t.lateUpdateMs+=r.lateUpdateMs,t.n+=1,c.set(r.name,t)}}const u=i.systems.map(e=>{var t;const r=null!==(t=c.get(e.name))&&void 0!==t?t:{updateMs:0,lateUpdateMs:0,n:1};return{name:e.name,updateMs:r.updateMs/r.n,lateUpdateMs:r.lateUpdateMs/r.n}});return{frameCount:a,fps:n/t,frameMs:r/t,systems:u,gameObjectsMs:o/t,gameObjectCount:s/t}},violations(){const e=[];for(const[t,r]of j)0!==r.count&&e.push({name:t,count:r.count,last:r.last});return e},onFrame:e=>(O.add(e),()=>{O.delete(e)}),onViolation:e=>(E.add(e),()=>{E.delete(e)}),uninstall(){if(!M){if(M=!0,A){const e=Array.from(A).filter(e=>e!==R&&e!==k&&!S.includes(e));A.clear();for(const e of S)A.add(e);for(const t of e)A.add(t)}for(const e of g.values())T(e);g.clear(),_.length=0,b=null,O.clear(),E.clear(),j.clear(),y.clear()}}}},e.resource=Kt,e.shouldExecuteInEditMode=m,e.step=l,e.type=u,e.version=er,Object.defineProperty(e,"__esModule",{value:!0}),e}({},PIXI);globalThis.EVA=globalThis.EVA||_EVA_IIFE_EVA; | ||
| function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},_extends.apply(null,arguments)}var _EVA_IIFE_EVA=function(e,t){"use strict";var r=function(e){var t={exports:{}};return e(t,t.exports),t.exports}(function(e){var t=Object.prototype.hasOwnProperty,r="~";function n(){}function s(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function o(e,t,n,o,a){if("function"!=typeof n)throw new TypeError("The listener must be a function");var i=new s(n,o||e,a),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],i]:e._events[c].push(i):(e._events[c]=i,e._eventsCount++),e}function a(e,t){0===--e._eventsCount?e._events=new n:delete e._events[t]}function i(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),i.prototype.eventNames=function(){var e,n,s=[];if(0===this._eventsCount)return s;for(n in e=this._events)t.call(e,n)&&s.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?s.concat(Object.getOwnPropertySymbols(e)):s},i.prototype.listeners=function(e){var t=r?r+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var s=0,o=n.length,a=new Array(o);s<o;s++)a[s]=n[s].fn;return a},i.prototype.listenerCount=function(e){var t=r?r+e:e,n=this._events[t];return n?n.fn?1:n.length:0},i.prototype.emit=function(e,t,n,s,o,a){var i=r?r+e:e;if(!this._events[i])return!1;var c,u,l=this._events[i],h=arguments.length;if(l.fn){switch(l.once&&this.removeListener(e,l.fn,void 0,!0),h){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,t),!0;case 3:return l.fn.call(l.context,t,n),!0;case 4:return l.fn.call(l.context,t,n,s),!0;case 5:return l.fn.call(l.context,t,n,s,o),!0;case 6:return l.fn.call(l.context,t,n,s,o,a),!0}for(u=1,c=new Array(h-1);u<h;u++)c[u-1]=arguments[u];l.fn.apply(l.context,c)}else{var f,p=l.length;for(u=0;u<p;u++)switch(l[u].once&&this.removeListener(e,l[u].fn,void 0,!0),h){case 1:l[u].fn.call(l[u].context);break;case 2:l[u].fn.call(l[u].context,t);break;case 3:l[u].fn.call(l[u].context,t,n);break;case 4:l[u].fn.call(l[u].context,t,n,s);break;default:if(!c)for(f=1,c=new Array(h-1);f<h;f++)c[f-1]=arguments[f];l[u].fn.apply(l[u].context,c)}}return!0},i.prototype.on=function(e,t,r){return o(this,e,t,r,!1)},i.prototype.once=function(e,t,r){return o(this,e,t,r,!0)},i.prototype.removeListener=function(e,t,n,s){var o=r?r+e:e;if(!this._events[o])return this;if(!t)return a(this,o),this;var i=this._events[o];if(i.fn)i.fn!==t||s&&!i.once||n&&i.context!==n||a(this,o);else{for(var c=0,u=[],l=i.length;c<l;c++)(i[c].fn!==t||s&&!i[c].once||n&&i[c].context!==n)&&u.push(i[c]);u.length?this._events[o]=1===u.length?u[0]:u:a(this,o)}return this},i.prototype.removeAllListeners=function(e){var t;return e?(t=r?r+e:e,this._events[t]&&a(this,t)):(this._events=new n,this._eventsCount=0),this},i.prototype.off=i.prototype.removeListener,i.prototype.addListener=i.prototype.on,i.prefixed=r,i.EventEmitter=i,e.exports=i}),n=r;"function"==typeof SuppressedError&&SuppressedError;class s extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const o="IDE_PROPERTY_METADATA",a="COMPONENT_EXECUTE_MODE_METADATA";function i(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}function c(e,t,r,n){let s=Reflect.getMetadata("design:type",e,t),a=s===Array;const c=i(s);if("unknown"!==c&&(s=c),n){const e=n();Array.isArray(e)?(a=!0,s=e[0]):s=e}const u=Reflect.getMetadata(o,e.constructor)||{},l=_extends(_extends(_extends({},u[t]||{}),{type:s,isArray:a}),r);u[t]=l,Reflect.defineMetadata(o,u,e.constructor);!function(e,t,r){const n=e.constructor,s=n.IDEProps||{};s[t]=_extends(_extends({key:t},s[t]),r),n.IDEProps=s}(e,t,function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(e);s<n.length;s++)t.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(e,n[s])&&(r[n[s]]=e[n[s]])}return r}(l,["isArray"]))}function u(e){return h({type:e})}function l(e){return h({step:e})}function h(e,t){return(r,n)=>{if("symbol"==typeof n)throw new s;const{options:o,returnTypeFunc:a}=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(e,t);c(r,n,o,a)}}function f(e,t=!0){const r=Reflect.getMetadata(o,e)||{},n=e.componentName,s={name:n,type:n,isArray:!1};return t&&(s.isFolder=!0),!Object.keys(r).length&&e.componentName||(s.type="object",s.children=[],Object.keys(r).forEach(e=>{if("function"==typeof r[e].type){const t=i(r[e].type);if("unknown"!==t)r[e].type=t;else{const t=f(r[e].type,!1);r[e].type="object",r[e].children||(r[e].children=[]),r[e].children.push(...t.children)}}r[e].name||(r[e].name=e),r[e].isArray&&(r[e].addable=!0),s.children.push(r[e])})),s}var p;!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(p||(p={}));const m=e=>{Reflect.defineMetadata(a,p.Edit,e)},d=e=>!!(Reflect.getMetadata(a,e)&p.Edit);function y(e={}){return h(e)}class _ extends n{static getInspectorMetadata(){return f(this)}constructor(e){super(),this.started=!1,this.name=this.constructor.componentName,this.__componentDefaultParams=e}getInspectorMetadata(){return this.constructor.getInspectorMetadata()}}var v=_,b="object"==typeof global&&global&&global.Object===Object&&global,g="object"==typeof self&&self&&self.Object===Object&&self,O=b||g||Function("return this")(),E=O.Symbol,j=Object.prototype,S=j.hasOwnProperty,M=j.toString,w=E?E.toStringTag:void 0;var A=Object.prototype.toString;var T=E?E.toStringTag:void 0;function R(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":T&&T in Object(e)?function(e){var t=S.call(e,w),r=e[w];try{e[w]=void 0;var n=!0}catch(e){}var s=M.call(e);return n&&(t?e[w]=r:delete e[w]),s}(e):function(e){return A.call(e)}(e)}function C(e){return null!=e&&"object"==typeof e}var P=Array.isArray;function x(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function k(e){if(!x(e))return!1;var t=R(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t}var N,D=O["__core-js_shared__"],I=(N=/[^.]+$/.exec(D&&D.keys&&D.keys.IE_PROTO||""))?"Symbol(src)_1."+N:"";var F=Function.prototype.toString;function U(e){if(null!=e){try{return F.call(e)}catch(e){}try{return e+""}catch(e){}}return""}var L=/^\[object .+?Constructor\]$/,$=Function.prototype,V=Object.prototype,z=$.toString,G=V.hasOwnProperty,B=RegExp("^"+z.call(G).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Y(e){return!(!x(e)||(t=e,I&&I in t))&&(k(e)?B:L).test(U(e));var t}function H(e,t){var r=function(e,t){return null==e?void 0:e[t]}(e,t);return Y(r)?r:void 0}var q=H(O,"WeakMap"),W=/^(?:0|[1-9]\d*)$/;function X(e,t){var r=typeof e;return!!(t=null==t?9007199254740991:t)&&("number"==r||"symbol"!=r&&W.test(e))&&e>-1&&e%1==0&&e<t}function J(e,t){return e===t||e!=e&&t!=t}function K(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991}var Q=Object.prototype;function Z(e){return C(e)&&"[object Arguments]"==R(e)}var ee=Object.prototype,te=ee.hasOwnProperty,re=ee.propertyIsEnumerable,ne=Z(function(){return arguments}())?Z:function(e){return C(e)&&te.call(e,"callee")&&!re.call(e,"callee")},se=ne;var oe="object"==typeof e&&e&&!e.nodeType&&e,ae=oe&&"object"==typeof module&&module&&!module.nodeType&&module,ie=ae&&ae.exports===oe?O.Buffer:void 0,ce=(ie?ie.isBuffer:void 0)||function(){return!1},ue={};ue["[object Float32Array]"]=ue["[object Float64Array]"]=ue["[object Int8Array]"]=ue["[object Int16Array]"]=ue["[object Int32Array]"]=ue["[object Uint8Array]"]=ue["[object Uint8ClampedArray]"]=ue["[object Uint16Array]"]=ue["[object Uint32Array]"]=!0,ue["[object Arguments]"]=ue["[object Array]"]=ue["[object ArrayBuffer]"]=ue["[object Boolean]"]=ue["[object DataView]"]=ue["[object Date]"]=ue["[object Error]"]=ue["[object Function]"]=ue["[object Map]"]=ue["[object Number]"]=ue["[object Object]"]=ue["[object RegExp]"]=ue["[object Set]"]=ue["[object String]"]=ue["[object WeakMap]"]=!1;var le,he="object"==typeof e&&e&&!e.nodeType&&e,fe=he&&"object"==typeof module&&module&&!module.nodeType&&module,pe=fe&&fe.exports===he&&b.process,me=function(){try{var e=fe&&fe.require&&fe.require("util").types;return e||pe&&pe.binding&&pe.binding("util")}catch(e){}}(),de=me&&me.isTypedArray,ye=de?(le=de,function(e){return le(e)}):function(e){return C(e)&&K(e.length)&&!!ue[R(e)]},_e=Object.prototype.hasOwnProperty;function ve(e,t){var r=P(e),n=!r&&se(e),s=!r&&!n&&ce(e),o=!r&&!n&&!s&&ye(e),a=r||n||s||o,i=a?function(e,t){for(var r=-1,n=Array(e);++r<e;)n[r]=t(r);return n}(e.length,String):[],c=i.length;for(var u in e)!t&&!_e.call(e,u)||a&&("length"==u||s&&("offset"==u||"parent"==u)||o&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||X(u,c))||i.push(u);return i}var be=function(e,t){return function(r){return e(t(r))}}(Object.keys,Object),ge=be,Oe=Object.prototype.hasOwnProperty;function Ee(e){if(r=(t=e)&&t.constructor,t!==("function"==typeof r&&r.prototype||Q))return ge(e);var t,r,n=[];for(var s in Object(e))Oe.call(e,s)&&"constructor"!=s&&n.push(s);return n}function je(e){return null!=(t=e)&&K(t.length)&&!k(t)?ve(e):Ee(e);var t}var Se=H(Object,"create");var Me=Object.prototype.hasOwnProperty;var we=Object.prototype.hasOwnProperty;function Ae(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function Te(e,t){for(var r=e.length;r--;)if(J(e[r][0],t))return r;return-1}Ae.prototype.clear=function(){this.__data__=Se?Se(null):{},this.size=0},Ae.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},Ae.prototype.get=function(e){var t=this.__data__;if(Se){var r=t[e];return"__lodash_hash_undefined__"===r?void 0:r}return Me.call(t,e)?t[e]:void 0},Ae.prototype.has=function(e){var t=this.__data__;return Se?void 0!==t[e]:we.call(t,e)},Ae.prototype.set=function(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=Se&&void 0===t?"__lodash_hash_undefined__":t,this};var Re=Array.prototype.splice;function Ce(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}Ce.prototype.clear=function(){this.__data__=[],this.size=0},Ce.prototype.delete=function(e){var t=this.__data__,r=Te(t,e);return!(r<0)&&(r==t.length-1?t.pop():Re.call(t,r,1),--this.size,!0)},Ce.prototype.get=function(e){var t=this.__data__,r=Te(t,e);return r<0?void 0:t[r][1]},Ce.prototype.has=function(e){return Te(this.__data__,e)>-1},Ce.prototype.set=function(e,t){var r=this.__data__,n=Te(r,e);return n<0?(++this.size,r.push([e,t])):r[n][1]=t,this};var Pe=H(O,"Map");function xe(e,t){var r=e.__data__;return function(e){var t=typeof e;return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e}(t)?r["string"==typeof t?"string":"hash"]:r.map}function ke(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}ke.prototype.clear=function(){this.size=0,this.__data__={hash:new Ae,map:new(Pe||Ce),string:new Ae}},ke.prototype.delete=function(e){var t=xe(this,e).delete(e);return this.size-=t?1:0,t},ke.prototype.get=function(e){return xe(this,e).get(e)},ke.prototype.has=function(e){return xe(this,e).has(e)},ke.prototype.set=function(e,t){var r=xe(this,e),n=r.size;return r.set(e,t),this.size+=r.size==n?0:1,this};function Ne(e){var t=this.__data__=new Ce(e);this.size=t.size}Ne.prototype.clear=function(){this.__data__=new Ce,this.size=0},Ne.prototype.delete=function(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r},Ne.prototype.get=function(e){return this.__data__.get(e)},Ne.prototype.has=function(e){return this.__data__.has(e)},Ne.prototype.set=function(e,t){var r=this.__data__;if(r instanceof Ce){var n=r.__data__;if(!Pe||n.length<199)return n.push([e,t]),this.size=++r.size,this;r=this.__data__=new ke(n)}return r.set(e,t),this.size=r.size,this};var De=Object.prototype.propertyIsEnumerable,Ie=Object.getOwnPropertySymbols,Fe=Ie?function(e){return null==e?[]:(e=Object(e),function(e,t){for(var r=-1,n=null==e?0:e.length,s=0,o=[];++r<n;){var a=e[r];t(a,r,e)&&(o[s++]=a)}return o}(Ie(e),function(t){return De.call(e,t)}))}:function(){return[]};function Ue(e){return function(e,t,r){var n=t(e);return P(e)?n:function(e,t){for(var r=-1,n=t.length,s=e.length;++r<n;)e[s+r]=t[r];return e}(n,r(e))}(e,je,Fe)}var Le=H(O,"DataView"),$e=H(O,"Promise"),Ve=H(O,"Set"),ze="[object Map]",Ge="[object Promise]",Be="[object Set]",Ye="[object WeakMap]",He="[object DataView]",qe=U(Le),We=U(Pe),Xe=U($e),Je=U(Ve),Ke=U(q),Qe=R;(Le&&Qe(new Le(new ArrayBuffer(1)))!=He||Pe&&Qe(new Pe)!=ze||$e&&Qe($e.resolve())!=Ge||Ve&&Qe(new Ve)!=Be||q&&Qe(new q)!=Ye)&&(Qe=function(e){var t=R(e),r="[object Object]"==t?e.constructor:void 0,n=r?U(r):"";if(n)switch(n){case qe:return He;case We:return ze;case Xe:return Ge;case Je:return Be;case Ke:return Ye}return t});var Ze=Qe,et=O.Uint8Array;function tt(e){var t=-1,r=null==e?0:e.length;for(this.__data__=new ke;++t<r;)this.add(e[t])}function rt(e,t){for(var r=-1,n=null==e?0:e.length;++r<n;)if(t(e[r],r,e))return!0;return!1}tt.prototype.add=tt.prototype.push=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},tt.prototype.has=function(e){return this.__data__.has(e)};function nt(e,t,r,n,s,o){var a=1&r,i=e.length,c=t.length;if(i!=c&&!(a&&c>i))return!1;var u=o.get(e),l=o.get(t);if(u&&l)return u==t&&l==e;var h=-1,f=!0,p=2&r?new tt:void 0;for(o.set(e,t),o.set(t,e);++h<i;){var m=e[h],d=t[h];if(n)var y=a?n(d,m,h,t,e,o):n(m,d,h,e,t,o);if(void 0!==y){if(y)continue;f=!1;break}if(p){if(!rt(t,function(e,t){if(a=t,!p.has(a)&&(m===e||s(m,e,r,n,o)))return p.push(t);var a})){f=!1;break}}else if(m!==d&&!s(m,d,r,n,o)){f=!1;break}}return o.delete(e),o.delete(t),f}function st(e){var t=-1,r=Array(e.size);return e.forEach(function(e,n){r[++t]=[n,e]}),r}function ot(e){var t=-1,r=Array(e.size);return e.forEach(function(e){r[++t]=e}),r}var at=E?E.prototype:void 0,it=at?at.valueOf:void 0;var ct=Object.prototype.hasOwnProperty;var ut,lt="[object Arguments]",ht="[object Array]",ft="[object Object]",pt=Object.prototype.hasOwnProperty;function mt(e,t,r,n,s,o){var a=P(e),i=P(t),c=a?ht:Ze(e),u=i?ht:Ze(t),l=(c=c==lt?ft:c)==ft,h=(u=u==lt?ft:u)==ft,f=c==u;if(f&&ce(e)){if(!ce(t))return!1;a=!0,l=!1}if(f&&!l)return o||(o=new Ne),a||ye(e)?nt(e,t,r,n,s,o):function(e,t,r,n,s,o,a){switch(r){case"[object DataView]":if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case"[object ArrayBuffer]":return!(e.byteLength!=t.byteLength||!o(new et(e),new et(t)));case"[object Boolean]":case"[object Date]":case"[object Number]":return J(+e,+t);case"[object Error]":return e.name==t.name&&e.message==t.message;case"[object RegExp]":case"[object String]":return e==t+"";case"[object Map]":var i=st;case"[object Set]":var c=1&n;if(i||(i=ot),e.size!=t.size&&!c)return!1;var u=a.get(e);if(u)return u==t;n|=2,a.set(e,t);var l=nt(i(e),i(t),n,s,o,a);return a.delete(e),l;case"[object Symbol]":if(it)return it.call(e)==it.call(t)}return!1}(e,t,c,r,n,s,o);if(!(1&r)){var p=l&&pt.call(e,"__wrapped__"),m=h&&pt.call(t,"__wrapped__");if(p||m){var d=p?e.value():e,y=m?t.value():t;return o||(o=new Ne),s(d,y,r,n,o)}}return!!f&&(o||(o=new Ne),function(e,t,r,n,s,o){var a=1&r,i=Ue(e),c=i.length;if(c!=Ue(t).length&&!a)return!1;for(var u=c;u--;){var l=i[u];if(!(a?l in t:ct.call(t,l)))return!1}var h=o.get(e),f=o.get(t);if(h&&f)return h==t&&f==e;var p=!0;o.set(e,t),o.set(t,e);for(var m=a;++u<c;){var d=e[l=i[u]],y=t[l];if(n)var _=a?n(y,d,l,t,e,o):n(d,y,l,e,t,o);if(!(void 0===_?d===y||s(d,y,r,n,o):_)){p=!1;break}m||(m="constructor"==l)}if(p&&!m){var v=e.constructor,b=t.constructor;v==b||!("constructor"in e)||!("constructor"in t)||"function"==typeof v&&v instanceof v&&"function"==typeof b&&b instanceof b||(p=!1)}return o.delete(e),o.delete(t),p}(e,t,r,n,s,o))}function dt(e,t,r,n,s){return e===t||(null==e||null==t||!C(e)&&!C(t)?e!=e&&t!=t:mt(e,t,r,n,dt,s))}function yt(e,t){return dt(e,t)}function _t(e,t){const r=[];t&&r.push(t);const n=e&&"string"==typeof e.name?e.name:void 0;if(!t||t===n){let t=null==e?void 0:e.constructor;for(t&&(t=Object.getPrototypeOf(t));t&&t!==Function.prototype;){const e=t.componentName;"string"==typeof e&&e&&!r.includes(e)&&r.push(e),t=Object.getPrototypeOf(t)}}return r}e.OBSERVER_TYPE=void 0,(ut=e.OBSERVER_TYPE||(e.OBSERVER_TYPE={})).ADD="ADD",ut.REMOVE="REMOVE",ut.CHANGE="CHANGE";const vt={},bt={},gt={},Ot={};function Et(e,t){vt[e.gameObject.id]||(vt[e.gameObject.id]={});const r=vt[e.gameObject.id],n=e.name+"_"+t.join(",");if(r[n])return r[n];const s=t.length-1;let o=e;for(let e=0;e<s;e++)o=o[t[e]];return r[n]={property:o,key:t[s]},r[n]}function jt({systemName:e,componentName:t,component:r,prop:n,type:s}){var o,a;null===(a=null===(o=bt[e])||void 0===o?void 0:o.componentObserver)||void 0===a||a.add({component:r,prop:n,type:s,componentName:t})}function St({obj:t,key:r,prop:n,component:s,componentName:o}){if(void 0!==t)if(r in t){if(Object.defineProperty(t,`_${r}`,{enumerable:!1,writable:!0,value:t[r]}),n.deep&&x(t[r]))for(const e of Object.keys(t[r]))St({obj:t[r],key:e,prop:n,component:s,componentName:o});Object.defineProperty(t,r,{enumerable:!0,set(a){t[`_${r}`]!==a&&(t[`_${r}`]=a,function({prop:t,component:r,componentName:n}){const s=_t(r,n);for(const o in gt){const a=gt[o]||{};let i;for(const e of s)if(a[e]){i=a[e];break}i&&(i.findIndex(e=>yt(e,t))>-1&&jt({systemName:o,componentName:n,component:r,prop:t,type:e.OBSERVER_TYPE.CHANGE}))}}({prop:n,component:s,componentName:o}))},get:()=>t[`_${r}`]})}else console.error(`prop ${r} not in component: ${o}, Can not observer`)}function Mt(t,r=t.name){var n,s;const o=_t(t,r);for(const a in gt){const i=gt[a]||{};let c=!1;for(const e of o)if(i[e]){c=!0;break}c&&(null===(s=null===(n=bt[a])||void 0===n?void 0:n.componentObserver)||void 0===s||s.add({component:t,type:e.OBSERVER_TYPE.REMOVE,componentName:r}))}!function(e){e.gameObject&&delete vt[e.gameObject.id]}(t)}function wt(e,t,r,n){var s,o=arguments.length,a=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var i=e.length-1;i>=0;i--)(s=e[i])&&(a=(o<3?s(a):o>3?s(t,r,a):s(t,r))||a);return o>3&&a&&Object.defineProperty(t,r,a),a}function At(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function Tt(e,t,r,n){return new(r||(r=Promise))(function(s,o){function a(e){try{c(n.next(e))}catch(e){o(e)}}function i(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(a,i)}c((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class Rt extends v{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 r of t)_extends(this[r],e[r]);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}}Rt.componentName="Transform",wt([u("vector2"),l(1),At("design:type",Object)],Rt.prototype,"position",void 0),wt([u("size"),l(1),At("design:type",Object)],Rt.prototype,"size",void 0),wt([u("vector2"),l(.1),At("design:type",Object)],Rt.prototype,"origin",void 0),wt([u("vector2"),l(.1),At("design:type",Object)],Rt.prototype,"anchor",void 0),wt([u("vector2"),l(.1),At("design:type",Object)],Rt.prototype,"scale",void 0),wt([u("vector2"),l(.1),At("design:type",Object)],Rt.prototype,"skew",void 0),wt([u("number"),l(.1),At("design:type",Number)],Rt.prototype,"rotation",void 0);var Ct=Rt;let Pt=0;class xt{constructor(e,t){this._componentCache={},this.components=[],this.destroyed=!1,this._name=e,this.id=++Pt,this.addComponent(Ct,t)}get transform(){return this.getComponent(Ct)}get parent(){return this.transform&&this.transform.parent&&this.transform.parent.gameObject}get children(){return this.transform.children.map(e=>e.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 xt))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 xt&&e.parent&&e.parent===this?(e.transform.parent=null,e.scene=null,e):e}addComponent(t,r){if(this.destroyed)return;const n=function(e){return e instanceof _?e.name:e instanceof Function?e.componentName:void 0}(t);if(this._componentCache[n])return;let s;if(t instanceof Function)s=new t(r);else{if(!(t instanceof v))throw new Error("addComponent recieve Component and Component Constructor");s=t}if(s.gameObject)throw new Error(`component has been added on gameObject ${s.gameObject.name}`);return s.gameObject=this,s.init&&s.init(s.__componentDefaultParams),function(t,r=t.name){var n,s;const o=_t(t,r);for(const a in gt){const i=gt[a]||{};let c=!1;for(const e of o)if(i[e]){c=!0;break}c&&(null===(s=null===(n=bt[a])||void 0===n?void 0:n.componentObserver)||void 0===s||s.add({component:t,type:e.OBSERVER_TYPE.ADD,componentName:r}))}}(s,s.name),function(e,t=e.name){const r=_t(e,t);let n,s="";for(const e of r)if(Ot[e]){s=e,n=Ot[e];break}if(n){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");for(const t of n){const{property:r,key:n}=Et(e,t.prop);St({obj:r,key:n,prop:t,component:e,componentName:s})}}}(s,s.name),this.components.push(s),this._componentCache[n]=s,s.awake&&s.awake(),s}removeComponent(e){let 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)}_removeComponent(e){const t=this.components.findIndex(({name:t})=>t===e);if(-1===t)return;const r=this.components.splice(t,1)[0];return delete this._componentCache[e],delete r.__componentDefaultParams,r.onDestroy&&r.onDestroy(),Mt(r,e),r.gameObject=void 0,r}getComponent(e){let 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}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}}}var kt=xt;var Nt=class{constructor(){this.events=[]}add({component:t,prop:r,type:n,componentName:s}){if(n===e.OBSERVER_TYPE.REMOVE){if(this.events.find(r=>r.component===t&&r.type===e.OBSERVER_TYPE.ADD))return void(this.events=this.events.filter(e=>e.component!==t));this.events=this.events.filter(e=>e.component!==t)}const o=this.events.findIndex(e=>e.component===t&&yt(e.prop,r)&&e.type===n);o>-1&&this.events.splice(o,1),this.events.push({gameObject:t.gameObject,component:t,prop:r,type:n,componentName:s})}getChanged(){return this.events}get changed(){return this.events}clear(){const e=this.events;return this.events=[],e}};var Dt=class{constructor(e){this.started=!1,this.componentObserver=new Nt,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 It={autoStart:!0,frameRate:60};var Ft=class{constructor(e){e=_extends({},It,e),this._frameCount=0,this._rafFrameCount=0,this._frameDuration=1e3/e.frameRate,this.autoStart=e.autoStart,this.frameRate=e.frameRate,this._lastRafTime=null,this._accumulator=0,this._simulationTime=0,this._playbackRate=1,this._now=function(){let e=Number.NEGATIVE_INFINITY;return()=>{const t="undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now?Date.now():(new Date).getTime();return e=Math.max(e,t),e}}(),this._tickers=new Set,this._frameStartCallbacks=new Map,this._frameCallbacks=new Map,this._frameStartSnapshot=[],this._frameSnapshot=[],this._frameStartSnapshotDirty=!1,this._frameSnapshotDirty=!1,this._frameCallbackOrder=0,this._requestId=null,this._started=!1,this._ticker=e=>{this._started&&(this._requestId=requestAnimationFrame(this._ticker),this.update(e))},this.autoStart&&this.start()}update(e){const t=void 0===e?this._now():e,r=null===this._lastRafTime?t:Math.max(this._lastRafTime,t),n=null===this._lastRafTime?0:r-this._lastRafTime;this._lastRafTime=r,this._rafFrameCount++,this._accumulator+=Math.max(0,n*this._playbackRate);const s=1e-9*this._frameDuration,o=Math.floor((this._accumulator+s)/this._frameDuration),a=Math.min(o,5),i=o-a;this._accumulator-=o*this._frameDuration,Math.abs(this._accumulator)<s&&(this._accumulator=0);const c={rafTime:r,rafDeltaTime:n,rafFps:n>0?1e3/n:0,rafFrameCount:this._rafFrameCount,updatesThisFrame:a,interpolationAlpha:this._accumulator/this._frameDuration,playbackRate:this._playbackRate},u=_extends(_extends({},c),{simulationTime:this._simulationTime});this._callFrameCallbacks(this._getFrameStartSnapshot(),u);for(let e=0;e<a;e++){this._simulationTime+=this._frameDuration;const e={deltaTime:this._frameDuration,time:this._simulationTime,currentTime:this._simulationTime,frameCount:++this._frameCount,fps:this.frameRate};for(const t of this._tickers)"function"==typeof t&&t(e)}this._simulationTime+=i*this._frameDuration;const l=_extends(_extends({},c),{simulationTime:this._simulationTime});this._callFrameCallbacks(this._getFrameSnapshot(),l)}add(e){this._tickers.add(e)}remove(e){this._tickers.delete(e)}addFrameStart(e,t=0){this._addFrameCallback(this._frameStartCallbacks,e,t),this._frameStartSnapshotDirty=!0}removeFrameStart(e){this._frameStartCallbacks.delete(e)&&(this._frameStartSnapshotDirty=!0)}addFrame(e,t=0){this._addFrameCallback(this._frameCallbacks,e,t),this._frameSnapshotDirty=!0}removeFrame(e){this._frameCallbacks.delete(e)&&(this._frameSnapshotDirty=!0)}_addFrameCallback(e,t,r){const n=e.get(t);n?n.priority=r:e.set(t,{fn:t,priority:r,order:this._frameCallbackOrder++})}_getFrameStartSnapshot(){return this._frameStartSnapshotDirty&&(this._frameStartSnapshot=this._createFrameSnapshot(this._frameStartCallbacks),this._frameStartSnapshotDirty=!1),this._frameStartSnapshot}_getFrameSnapshot(){return this._frameSnapshotDirty&&(this._frameSnapshot=this._createFrameSnapshot(this._frameCallbacks),this._frameSnapshotDirty=!1),this._frameSnapshot}_createFrameSnapshot(e){return Array.from(e.values()).sort((e,t)=>e.priority-t.priority||e.order-t.order).map(e=>e.fn)}_callFrameCallbacks(e,t){for(const r of e)r(t)}start(){this._started||(this._started=!0,this._lastRafTime=null,this._requestId=requestAnimationFrame(this._ticker))}pause(){this._started=!1,null!==this._requestId&&(cancelAnimationFrame(this._requestId),this._requestId=null),this._lastRafTime=null}setPlaybackRate(e){if(!Number.isFinite(e)||e<0)throw new RangeError("playback rate must be a finite, non-negative number");this._playbackRate=e}};var Ut,Lt=class extends kt{constructor(e,t){super(e,t),this.gameObjects=[],this._nameIndex=new Map,this.scene=this}addGameObject(e){if(this.gameObjects.push(e),e.transform&&(e.transform.inScene=!0),e.name){let t=this._nameIndex.get(e.name);t||(t=new Set,this._nameIndex.set(e.name,t)),t.add(e)}}removeGameObject(e){const t=this.gameObjects.indexOf(e);if(-1!==t&&(e.transform&&(e.transform.inScene=!1),this.gameObjects.splice(t,1),e.name)){const t=this._nameIndex.get(e.name);t&&(t.delete(e),0===t.size&&this._nameIndex.delete(e.name))}}findByName(e){const t=this._nameIndex.get(e);if(!t)return null;for(const e of t)if(!e.destroyed)return e;return null}findAllByName(e){const t=this._nameIndex.get(e);if(!t)return[];const r=[];for(const e of t)e.destroyed||r.push(e);return r}destroy(){this.scene=null,super.destroy(),this.gameObjects=null,this.canvas=null,this._nameIndex=null}};e.LOAD_SCENE_MODE=void 0,(Ut=e.LOAD_SCENE_MODE||(e.LOAD_SCENE_MODE={})).SINGLE="SINGLE",Ut.MULTI_CANVAS="MULTI_CANVAS";const $t=e=>{if((e instanceof Dt||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)}}},Vt=(e,t,r)=>{for(const n of t)try{const t=n[r];if(!t)continue;$t(n),t.call(n,e)}catch(e){console.error(`${n.constructor.systemName} ${r} error`,e)}};var zt,Gt,Bt=class extends n{constructor(){super(...arguments),this.playing=!1,this.started=!1,this.multiScenes=[],this.systems=[]}init({systems:e,frameRate:t=60,autoStart:r=!0,needScene:n=!0}={}){return Tt(this,void 0,void 0,function*(){if("undefined"!=typeof window&&window.__EVA_INSPECTOR_ENV__&&(window.__EVA_GAME_INSTANCE__=this),this.ticker=new Ft({autoStart:!1,frameRate:t}),this.initTicker(),e&&e.length)for(const t of e)yield this.addSystem(t);n&&this.loadScene(new Lt("scene")),r&&this.start()})}get scene(){return this._scene}set scene(e){this._scene=e}get gameObjects(){return(e=>{var t;const r=(null===(t=null==e?void 0:e.scene)||void 0===t?void 0:t.gameObjects)||[],n=null==e?void 0:e.multiScenes.map(({gameObjects:e})=>e);let s=[];for(const e of n)s=[...s,...e];return[...r,...s]})(this)}findByName(e){var t;const r=null===(t=this._scene)||void 0===t?void 0:t.findByName(e);if(r)return r;for(const t of this.multiScenes){const r=t.findByName(e);if(r)return r}return null}findAllByName(e){var t;const r=(null===(t=this._scene)||void 0===t?void 0:t.findAllByName(e))||[];for(const t of this.multiScenes){const n=t.findAllByName(e);for(const e of n)r.push(e)}return r}addSystem(e,t){return Tt(this,void 0,void 0,function*(){let r;if(e instanceof Function)r=new e(t);else{if(!(e instanceof Dt))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){gt[t.systemName]=t.observerInfo,bt[t.systemName]=e}(r,r.constructor),function(e){const t=[];e instanceof Array?t.push(...e):t.push(e);for(const e of t)for(const t in e.observerInfo){Ot[t]=Ot[t]||[];const r=Ot[t];for(const n of e.observerInfo[t])-1===r.findIndex(e=>yt(e,n))&&Ot[t].push(n)}}(r.constructor);try{r.awake&&r.awake()}catch(e){console.error(`${r.constructor.systemName} awake error`,e)}return this.systems.push(r),this.emit("systemAdded",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 Dt&&(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.addFrameStart(e=>{Vt(e,this.systems,"frameStart")}),this.ticker.add(e=>{this.scene&&((e,t=[])=>{for(const r of t)for(const t of r.components)try{$t(t),t.update&&t.update(e)}catch(e){console.error(`gameObject: ${r.name} ${t.name} update error`,e)}for(const r of t)for(const t of r.components)try{t.lateUpdate&&t.lateUpdate(e)}catch(e){console.error(`gameObject: ${r.name} ${t.name} lateUpdate error`,e)}})(e,this.gameObjects);for(const t of this.systems)try{$t(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)}}),this.ticker.addFrame(e=>{Vt(e,this.systems,"frameUpdate")})}triggerResume(){(e=>{for(const t of e)for(const e of t.components)try{e.onResume&&e.onResume()}catch(r){console.error(`gameObject: ${t.name}, ${e.name}, onResume error`,r)}})(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(r){console.error(`gameObject: ${t.name}, ${e.name}, onResume error`,r)}})(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(){var e,t;this.removeAllListeners(),this.playing?this.pause():null===(e=this.ticker)||void 0===e||e.pause(),null===(t=this.scene)||void 0===t||t.destroy(),this.destroySystems(),this.ticker=null,this.scene=null,this.canvas=null,this.multiScenes=null}loadScene({scene:t,mode:r=e.LOAD_SCENE_MODE.SINGLE,params:n={}}){if(t){switch(r){case e.LOAD_SCENE_MODE.SINGLE:this.scene=t;break;case e.LOAD_SCENE_MODE.MULTI_CANVAS:this.multiScenes.push(t)}this.emit("sceneChanged",{scene:t,mode:r,params:n})}}pauseScene({scene:e}){this.emit("pauseScene",{scene:e})}startScene({scene:e}){this.emit("startScene",{scene:e})}destroyScene({scene:e}){const t=this.multiScenes.findIndex(t=>t===e);if(t>-1){const e=this.multiScenes.splice(t,1)[0];this.emit("sceneDestroyed",{scene:e})}}};function Yt(e,t){e.constructor.IDEProps||(e.constructor.IDEProps=[]),e.constructor.IDEProps.push(t)}function Ht(e={}){return function(t){if(!t.observerInfo){for(const t in e)for(const r in e[t]){let n;"string"==typeof e[t][r]&&(e[t][r]=[e[t][r]]),Array.isArray(e[t][r])&&(n={prop:e[t][r],deep:!1},e[t][r]=n),n=e[t][r],"string"==typeof n.prop&&(n.prop=[n.prop])}t.observerInfo=e}}}class qt extends n{constructor({resource:t,resourceTotal:r}){super(),this.progress=0,this.resourceTotal=0,this.resourceLoadedCount=0,this.resource=t,this.resourceTotal=r,0===r&&this.resource.emit(e.LOAD_EVENT.COMPLETE,this)}onStart(){this.resource.emit(e.LOAD_EVENT.START,this)}onProgress(t){this.resourceLoadedCount++,this.progress=Math.floor(this.resourceLoadedCount/this.resourceTotal*100)/100,t.success?this.resource.emit(e.LOAD_EVENT.LOADED,this,t):this.resource.emit(e.LOAD_EVENT.ERROR,this,t),this.resource.emit(e.LOAD_EVENT.PROGRESS,this,t),this.resourceLoadedCount===this.resourceTotal&&this.resource.emit(e.LOAD_EVENT.COMPLETE,this)}}e.LOAD_EVENT=void 0,(zt=e.LOAD_EVENT||(e.LOAD_EVENT={})).START="start",zt.PROGRESS="progress",zt.LOADED="loaded",zt.COMPLETE="complete",zt.ERROR="error",e.RESOURCE_TYPE=void 0,(Gt=e.RESOURCE_TYPE||(e.RESOURCE_TYPE={})).IMAGE="IMAGE",Gt.SPRITE="SPRITE",Gt.SPRITE_ANIMATION="SPRITE_ANIMATION",Gt.AUDIO="AUDIO",Gt.VIDEO="VIDEO",Gt.FONT="FONT";const Wt=new class extends n{constructor(e){super(),this.timeout=6e3,this.preProcessResourceHandlers=[],this.resourcesMap={},this.makeInstanceFunctions={},this.destroyInstanceFunctions={},this.promiseMap={},this.resourceUrlsMap={},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"):t&&(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 r=this.resourcesMap[t];!r.preload||r.complete||this.promiseMap[t]||e.push(r.name)}this.progress=new qt({resource:this,resourceTotal:e.length}),this.loadResource({names:e,preload:!0})}getResource(e){return Tt(this,void 0,void 0,function*(){return this.loadResource({names:[e]}),this.promiseMap[e]||Promise.resolve({})})}instance(e){return Tt(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 Tt(this,void 0,void 0,function*(){yield this._destroy(e)})}_destroy(e,r=!1){var n;return Tt(this,void 0,void 0,function*(){const s=this.resourcesMap[e];if(!s)return;if(!r)try{this.destroyInstanceFunctions[s.type]&&(yield this.destroyInstanceFunctions[s.type](s))}catch(e){console.warn(`destroy resource ${s.name} error with '${e.message}'`)}const o=this.resourceUrlsMap[e]||[];if(0===o.length&&s.src)for(const e in s.src){let t=null===(n=s.src[e])||void 0===n?void 0:n.url;t&&("string"==typeof t&&t.startsWith("//")&&(t=`https:${t}`),o.push(t))}if(o.length>0)try{yield t.Assets.unload(o);for(const e of o)try{const r=t.Assets.resolver||t.Assets._resolver;r&&r._assetMap&&(delete r._assetMap[e],delete r._resolverHash[e])}catch(e){}}catch(t){console.warn(`Failed to unload assets for ${e}: ${t.message}`)}delete this.promiseMap[e],delete this.resourceUrlsMap[e],s.data={},s.complete=!1,s.instance=void 0,delete this.resourcesMap[e]})}registerResourceType(t,r=t){if(e.RESOURCE_TYPE[t])throw new Error(`The type ${t} already exists in RESOURCE_TYPE`);e.RESOURCE_TYPE[t]=r}registerInstance(e,t){this.makeInstanceFunctions[e]=t}registerDestroy(e,t){this.destroyInstanceFunctions[e]=t}loadResource({names:r=[],preload:n=!1}){const s=r.filter(e=>!this.promiseMap[e]&&this.resourcesMap[e]);if(!s.length)return;const o={};s.forEach(r=>Tt(this,void 0,void 0,function*(){var s;this.promiseMap[r]=new Promise(e=>o[r]=e);const a=this.resourcesMap[r];this.resourceUrlsMap[r]||(this.resourceUrlsMap[r]=[]);for(const e of this.preProcessResourceHandlers)e(a);for(const i in a.src){if("data"===a.src[i].type)a.data[i]=a.src[i].data,this.doComplete(r,o[r],n);else{let c=null===(s=a.src[i])||void 0===s?void 0:s.url;if("string"==typeof c&&c.startsWith("//")&&(c=`https:${a.src[i].url}`),c&&this.resourceUrlsMap[r]&&!this.resourceUrlsMap[r].includes(c)&&this.resourceUrlsMap[r].push(c),"atlas"===i){const e=t.Assets.load(a.src.image.url).catch(e=>{this.onError({preload:n,errMsg:e.message,resource:{metadata:{key:i,name:r,resolves:o}}})});t.Assets.add({alias:c,src:c,loadParser:a.src[i].loadParser,data:{resolve:()=>e,imageTexture:yield e}})}else{const s={alias:c,src:c};if(a.src[i].loadParser&&(s.loadParser=a.src[i].loadParser),a.type===e.RESOURCE_TYPE.SPRITE||a.type===e.RESOURCE_TYPE.SPRITE_ANIMATION){if("json"===a.src[i].type)try{const e=yield t.Assets.load(a.src.image.url);s.data={texture:e}}catch(e){console.log(">>>E",e),this.onError({preload:n,errMsg:e.message,resource:{metadata:{key:i,name:r,resolves:o}}})}}else a.type===e.RESOURCE_TYPE.FONT&&(s.data={family:r});t.Assets.add(s)}t.Assets.load(c).then(e=>{this.onLoad({preload:n,resource:{metadata:{key:i,name:r,resolves:o},data:e}})}).catch(e=>{console.log(">>>E",e),this.onError({preload:n,errMsg:e.message,resource:{metadata:{key:i,name:r,resolves:o}}})})}}}))}doComplete(e,t,r=!1){return Tt(this,void 0,void 0,function*(){const n=this.resourcesMap[e],s={name:e,resource:this.resourcesMap[e],success:!0};if(this.checkAllLoaded(e))try{n.instance=yield this.instance(e),n.complete=!0,r&&this.progress.onProgress(s),t(n)}catch(e){console.error(e),n.complete=!1,r&&(s.errMsg=e.message,s.success=!1,this.progress.onProgress(s)),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 Tt(this,void 0,void 0,function*(){const{metadata:{key:r,name:n,resolves:s},data:o}=t,a=this.resourcesMap[n];a?(a.data[r]=o,this.doComplete(n,s[n],e)):console.warn("no resource data found")})}onError({errMsg:e,preload:t=!1,resource:r}){return Tt(this,void 0,void 0,function*(){const{metadata:{name:n,resolves:s}}=r;if(delete this.promiseMap[n],delete this.resourceUrlsMap[n],s[n]({}),t){const t={name:n,resource:this.resourcesMap[n],success:!1,errMsg:e};this.progress.onProgress(t)}})}},Xt=()=>{const e=globalThis.performance;return e&&"function"==typeof e.now?e.now():Date.now()};const Jt={IDEProp:Yt,componentObserver:Ht,ExecuteInEditMode:m,Field:h,getPropertiesOf:f,inspectorField:y,shouldExecuteInEditMode:d,step:l,type:u},Kt="2.1.0-beta.7";console.log(`Eva.js version: ${Kt}`);return e.Component=v,e.ExecuteInEditMode=m,e.Field=h,e.Game=Bt,e.GameObject=kt,e.IDEProp=Yt,e.RESOURCE_TYPE_STRATEGY={},e.Scene=Lt,e.System=Dt,e.Transform=Ct,e.componentObserver=Ht,e.decorators=Jt,e.getPropertiesOf=f,e.inspectorField=y,e.installPerfProbes=function(e,t={}){var r,n,s,o,a,i,c,u,l,h,f;const p=null!==(r=t.sampleSize)&&void 0!==r?r:60,m=null===(n=t.warnOnViolation)||void 0===n||n,d={maxFrameMs:null!==(o=null===(s=t.budget)||void 0===s?void 0:s.maxFrameMs)&&void 0!==o?o:16.67,minFps:null!==(i=null===(a=t.budget)||void 0===a?void 0:a.minFps)&&void 0!==i?i:30,sustainedFrames:null!==(u=null===(c=t.budget)||void 0===c?void 0:c.sustainedFrames)&&void 0!==u?u:60,maxSystemMs:null===(l=t.budget)||void 0===l?void 0:l.maxSystemMs,maxGameObjects:null===(h=t.budget)||void 0===h?void 0:h.maxGameObjects},y=new Map;let _=0;const v=[];let b=null;const g=new Map,O=new Set,E=new Set,j=new Map;let S=!1;function M(e,t,r){const n=Object.prototype.hasOwnProperty.call(e,t),s=e[t];if("function"!=typeof s)return{original:void 0,wrapper:void 0,hadOwn:n};const o=function(...t){if(!r)return s.apply(this,t);const n=Xt();try{return s.apply(this,t)}finally{const t=`${r}Ms`;(function(e){let t=y.get(e);return t||(t={updateMs:0,lateUpdateMs:0,frameUpdateMs:0},y.set(e,t)),t}(e))[t]+=Math.max(0,Xt()-n)}};return e[t]=o,{original:s,wrapper:o,hadOwn:n}}function w(e){g.has(e)||g.set(e,{system:e,methods:{update:M(e,"update","update"),lateUpdate:M(e,"lateUpdate","lateUpdate"),frameStart:M(e,"frameStart"),frameUpdate:M(e,"frameUpdate","frameUpdate")}})}function A(e){const{system:t,methods:r}=e;for(const e of Object.keys(r)){const{original:n,wrapper:s,hadOwn:o}=r[e];s&&t[e]===s&&(o?t[e]=n:delete t[e])}}const T=e=>{S||w(e)},R=t=>{var r;_=Xt(),y.clear();for(const t of null!==(r=e.systems)&&void 0!==r?r:[])g.has(t)||w(t)},C=t=>{var r,n,s;const o=Xt(),a=Math.max(0,o-_),i=(null!==(r=e.systems)&&void 0!==r?r:[]).map(e=>{var t,r,n;const s=null!==(t=y.get(e))&&void 0!==t?t:{updateMs:0,lateUpdateMs:0,frameUpdateMs:0};return{name:e.name||(null===(r=e.constructor)||void 0===r?void 0:r.systemName)||(null===(n=e.constructor)||void 0===n?void 0:n.name)||"UnknownSystem",updateMs:s.updateMs,lateUpdateMs:s.lateUpdateMs,frameUpdateMs:s.frameUpdateMs}}),c=i.reduce((e,t)=>{var r;return e+(null!==(r=t.frameUpdateMs)&&void 0!==r?r:0)},0),u=i.reduce((e,t)=>{var r;return e+t.updateMs+t.lateUpdateMs+(null!==(r=t.frameUpdateMs)&&void 0!==r?r:0)},0),l=Math.max(0,a-u),h=(null!==(n=e.gameObjects)&&void 0!==n?n:[]).length,f=t&&"number"==typeof t.rafFrameCount?t.rafFrameCount:0,g=t&&"number"==typeof t.rafDeltaTime?t.rafDeltaTime:0,S={frameCount:f,fps:g>0?Number.isFinite(t.rafFps)?t.rafFps:1e3/g:0,frameMs:a,systems:i,frameUpdateMs:c,gameObjectsMs:l,gameObjectCount:h,rafDeltaTime:g,updatesThisFrame:null!==(s=null==t?void 0:t.updatesThisFrame)&&void 0!==s?s:0};if(v.push(S),v.length>p&&v.shift(),b=S,O.size)for(const e of Array.from(O))try{e(S)}catch(e){console.error("[perf-probes] onFrame callback error",e)}!function(e){var t,r,n;const s=[];"number"==typeof d.maxFrameMs&&s.push({name:"frameMs",actual:e.frameMs,threshold:d.maxFrameMs,over:e.frameMs>d.maxFrameMs});"number"==typeof d.minFps&&(null!==(t=e.rafDeltaTime)&&void 0!==t?t:0)>0&&s.push({name:"fps",actual:e.fps,threshold:d.minFps,over:e.fps<d.minFps});"number"==typeof d.maxGameObjects&&s.push({name:"gameObjects",actual:e.gameObjectCount,threshold:d.maxGameObjects,over:e.gameObjectCount>d.maxGameObjects});if(d.maxSystemMs)for(const t of e.systems){const e=d.maxSystemMs[t.name];if("number"==typeof e){const n=t.updateMs+t.lateUpdateMs+(null!==(r=t.frameUpdateMs)&&void 0!==r?r:0);s.push({name:`system:${t.name}`,actual:n,threshold:e,over:n>e})}}for(const t of s){let r=j.get(t.name);if(r||(r={consec:0,count:0,last:t.actual},j.set(t.name,r)),r.last=t.actual,t.over){if(r.consec+=1,r.consec>=(null!==(n=d.sustainedFrames)&&void 0!==n?n:60)){r.count+=1,r.consec=0;const n={name:t.name,actual:t.actual,threshold:t.threshold,frame:e};if(m&&console.warn(`[perf-probes] sustained violation ${t.name}: actual=${t.actual.toFixed(2)} threshold=${t.threshold}`),E.size)for(const e of Array.from(E))try{e(n)}catch(e){console.error("[perf-probes] onViolation callback error",e)}}}else r.consec=0}}(S)},P=e.ticker;P&&(P.addFrameStart(R,-1/0),P.addFrame(C,1/0)),e.on("systemAdded",T);for(const t of null!==(f=e.systems)&&void 0!==f?f:[])w(t);return{current:()=>b,average:function(){var e,t,r,n;if(0===v.length)return null;const s=v.length;let o=0,a=0,i=0,c=0,u=0,l=0,h=0,f=0,p=0,m=0;const d=v[s-1],y=new Map;for(const s of v){o+=s.frameMs,a+=s.gameObjectsMs,i+=s.gameObjectCount,c+=null!==(e=s.frameUpdateMs)&&void 0!==e?e:0,p+=null!==(t=s.updatesThisFrame)&&void 0!==t?t:0,m=s.frameCount,"number"==typeof s.rafDeltaTime?s.rafDeltaTime>0&&(u+=s.rafDeltaTime,l++):(h+=s.fps,f++);for(const e of s.systems){const t=null!==(r=y.get(e.name))&&void 0!==r?r:{updateMs:0,lateUpdateMs:0,frameUpdateMs:0,n:0};t.updateMs+=e.updateMs,t.lateUpdateMs+=e.lateUpdateMs,t.frameUpdateMs+=null!==(n=e.frameUpdateMs)&&void 0!==n?n:0,t.n+=1,y.set(e.name,t)}}const _=d.systems.map(e=>{var t;const r=null!==(t=y.get(e.name))&&void 0!==t?t:{updateMs:0,lateUpdateMs:0,frameUpdateMs:0,n:1};return{name:e.name,updateMs:r.updateMs/r.n,lateUpdateMs:r.lateUpdateMs/r.n,frameUpdateMs:r.frameUpdateMs/r.n}});return{frameCount:m,fps:l>0?1e3*l/u:f>0?h/f:0,frameMs:o/s,systems:_,frameUpdateMs:c/s,gameObjectsMs:a/s,gameObjectCount:i/s,rafDeltaTime:u/Math.max(1,l),updatesThisFrame:p/s}},violations(){const e=[];for(const[t,r]of j)0!==r.count&&e.push({name:t,count:r.count,last:r.last});return e},onFrame:e=>(O.add(e),()=>{O.delete(e)}),onViolation:e=>(E.add(e),()=>{E.delete(e)}),uninstall(){if(!S){S=!0,P&&(P.removeFrameStart(R),P.removeFrame(C)),e.off("systemAdded",T);for(const e of g.values())A(e);g.clear(),v.length=0,b=null,O.clear(),E.clear(),j.clear(),y.clear()}}}},e.resource=Wt,e.shouldExecuteInEditMode=d,e.step=l,e.type=u,e.version=Kt,Object.defineProperty(e,"__esModule",{value:!0}),e}({},PIXI);globalThis.EVA=globalThis.EVA||_EVA_IIFE_EVA; |
+1
-1
| { | ||
| "name": "@eva/eva.js", | ||
| "version": "2.1.0-beta.7", | ||
| "version": "2.1.0-beta.8", | ||
| "description": "@eva/eva.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
427273
1.25%10286
-0.24%