@eva/eva.js 2.0.1-beta.19 → 2.0.1-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EVA.js +21 -1
- package/dist/EVA.min.js +1 -1
- package/dist/eva.js.cjs.js +22 -1
- package/dist/eva.js.cjs.prod.js +2 -2
- package/dist/eva.js.d.ts +1 -1
- package/dist/eva.js.esm.js +22 -1
- package/package.json +1 -1
package/dist/EVA.js
CHANGED
|
@@ -2260,6 +2260,7 @@ var _EVA_IIFE_EVA = function (exports, pixi_js) {
|
|
|
2260
2260
|
});
|
|
2261
2261
|
}
|
|
2262
2262
|
_destroy(name, loadError = false) {
|
|
2263
|
+
var _a;
|
|
2263
2264
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2264
2265
|
const resource = this.resourcesMap[name];
|
|
2265
2266
|
if (!resource) return;
|
|
@@ -2272,6 +2273,25 @@ var _EVA_IIFE_EVA = function (exports, pixi_js) {
|
|
|
2272
2273
|
console.warn(`destroy resource ${resource.name} error with '${e.message}'`);
|
|
2273
2274
|
}
|
|
2274
2275
|
}
|
|
2276
|
+
if (resource.src) {
|
|
2277
|
+
const urlsToUnload = [];
|
|
2278
|
+
for (const key in resource.src) {
|
|
2279
|
+
let url = (_a = resource.src[key]) === null || _a === void 0 ? void 0 : _a.url;
|
|
2280
|
+
if (url) {
|
|
2281
|
+
if (typeof url === 'string' && url.startsWith('//')) {
|
|
2282
|
+
url = `https:${url}`;
|
|
2283
|
+
}
|
|
2284
|
+
urlsToUnload.push(url);
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
if (urlsToUnload.length > 0) {
|
|
2288
|
+
try {
|
|
2289
|
+
yield pixi_js.Assets.unload(urlsToUnload);
|
|
2290
|
+
} catch (e) {
|
|
2291
|
+
console.warn(`Failed to unload assets for ${name}: ${e.message}`);
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2275
2295
|
delete this.promiseMap[name];
|
|
2276
2296
|
resource.data = {};
|
|
2277
2297
|
resource.complete = false;
|
|
@@ -2489,7 +2509,7 @@ var _EVA_IIFE_EVA = function (exports, pixi_js) {
|
|
|
2489
2509
|
IDEProp,
|
|
2490
2510
|
componentObserver
|
|
2491
2511
|
};
|
|
2492
|
-
const version = '2.0.1-beta.
|
|
2512
|
+
const version = '2.0.1-beta.19';
|
|
2493
2513
|
console.log(`Eva.js version: ${version}`);
|
|
2494
2514
|
const RESOURCE_TYPE_STRATEGY = {};
|
|
2495
2515
|
exports.Component = Component$1;
|
package/dist/EVA.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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,i){if("function"!=typeof n)throw new TypeError("The listener must be a function");var a=new o(n,s||e,i),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],a]:e._events[c].push(a):(e._events[c]=a,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new n:delete e._events[t]}function a(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),a.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},a.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,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i},a.prototype.listenerCount=function(e){var t=r?r+e:e,n=this._events[t];return n?n.fn?1:n.length:0},a.prototype.emit=function(e,t,n,o,s,i){var a=r?r+e:e;if(!this._events[a])return!1;var c,u,h=this._events[a],l=arguments.length;if(h.fn){switch(h.once&&this.removeListener(e,h.fn,void 0,!0),l){case 1:return h.fn.call(h.context),!0;case 2:return h.fn.call(h.context,t),!0;case 3:return h.fn.call(h.context,t,n),!0;case 4:return h.fn.call(h.context,t,n,o),!0;case 5:return h.fn.call(h.context,t,n,o,s),!0;case 6:return h.fn.call(h.context,t,n,o,s,i),!0}for(u=1,c=new Array(l-1);u<l;u++)c[u-1]=arguments[u];h.fn.apply(h.context,c)}else{var p,f=h.length;for(u=0;u<f;u++)switch(h[u].once&&this.removeListener(e,h[u].fn,void 0,!0),l){case 1:h[u].fn.call(h[u].context);break;case 2:h[u].fn.call(h[u].context,t);break;case 3:h[u].fn.call(h[u].context,t,n);break;case 4:h[u].fn.call(h[u].context,t,n,o);break;default:if(!c)for(p=1,c=new Array(l-1);p<l;p++)c[p-1]=arguments[p];h[u].fn.apply(h[u].context,c)}}return!0},a.prototype.on=function(e,t,r){return s(this,e,t,r,!1)},a.prototype.once=function(e,t,r){return s(this,e,t,r,!0)},a.prototype.removeListener=function(e,t,n,o){var s=r?r+e:e;if(!this._events[s])return this;if(!t)return i(this,s),this;var a=this._events[s];if(a.fn)a.fn!==t||o&&!a.once||n&&a.context!==n||i(this,s);else{for(var c=0,u=[],h=a.length;c<h;c++)(a[c].fn!==t||o&&!a[c].once||n&&a[c].context!==n)&&u.push(a[c]);u.length?this._events[s]=1===u.length?u[0]:u:i(this,s)}return this},a.prototype.removeAllListeners=function(e){var t;return e?(t=r?r+e:e,this._events[t]&&i(this,t)):(this._events=new n,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=r,a.EventEmitter=a,e.exports=a})),n=r;class o extends n{constructor(e){super(),this.started=!1,this.name=this.constructor.componentName,this.__componentDefaultParams=e}}var s=o,i="object"==typeof global&&global&&global.Object===Object&&global,a="object"==typeof self&&self&&self.Object===Object&&self,c=i||a||Function("return this")(),u=c.Symbol,h=Object.prototype,l=h.hasOwnProperty,p=h.toString,f=u?u.toStringTag:void 0;var m=Object.prototype.toString;var d=u?u.toStringTag:void 0;function y(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":d&&d in Object(e)?function(e){var t=l.call(e,f),r=e[f];try{e[f]=void 0;var n=!0}catch(e){}var o=p.call(e);return n&&(t?e[f]=r:delete e[f]),o}(e):function(e){return m.call(e)}(e)}function _(e){return null!=e&&"object"==typeof e}var v=Array.isArray;function b(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function g(e){if(!b(e))return!1;var t=y(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t}var E,O=c["__core-js_shared__"],j=(E=/[^.]+$/.exec(O&&O.keys&&O.keys.IE_PROTO||""))?"Symbol(src)_1."+E:"";var T=Function.prototype.toString;function R(e){if(null!=e){try{return T.call(e)}catch(e){}try{return e+""}catch(e){}}return""}var w=/^\[object .+?Constructor\]$/,k=Function.prototype,S=Object.prototype,A=k.toString,P=S.hasOwnProperty,C=RegExp("^"+A.call(P).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function M(e){return!(!b(e)||(t=e,j&&j in t))&&(g(e)?C:w).test(R(e));var t}function I(e,t){var r=function(e,t){return null==e?void 0:e[t]}(e,t);return M(r)?r:void 0}var N=I(c,"WeakMap"),D=/^(?:0|[1-9]\d*)$/;function x(e,t){var r=typeof e;return!!(t=null==t?9007199254740991:t)&&("number"==r||"symbol"!=r&&D.test(e))&&e>-1&&e%1==0&&e<t}function L(e,t){return e===t||e!=e&&t!=t}function V(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991}var $=Object.prototype;function F(e){return _(e)&&"[object Arguments]"==y(e)}var z=Object.prototype,U=z.hasOwnProperty,G=z.propertyIsEnumerable,Y=F(function(){return arguments}())?F:function(e){return _(e)&&U.call(e,"callee")&&!G.call(e,"callee")},B=Y;var H="object"==typeof e&&e&&!e.nodeType&&e,q=H&&"object"==typeof module&&module&&!module.nodeType&&module,W=q&&q.exports===H?c.Buffer:void 0,X=(W?W.isBuffer:void 0)||function(){return!1},J={};J["[object Float32Array]"]=J["[object Float64Array]"]=J["[object Int8Array]"]=J["[object Int16Array]"]=J["[object Int32Array]"]=J["[object Uint8Array]"]=J["[object Uint8ClampedArray]"]=J["[object Uint16Array]"]=J["[object Uint32Array]"]=!0,J["[object Arguments]"]=J["[object Array]"]=J["[object ArrayBuffer]"]=J["[object Boolean]"]=J["[object DataView]"]=J["[object Date]"]=J["[object Error]"]=J["[object Function]"]=J["[object Map]"]=J["[object Number]"]=J["[object Object]"]=J["[object RegExp]"]=J["[object Set]"]=J["[object String]"]=J["[object WeakMap]"]=!1;var K,Q="object"==typeof e&&e&&!e.nodeType&&e,Z=Q&&"object"==typeof module&&module&&!module.nodeType&&module,ee=Z&&Z.exports===Q&&i.process,te=function(){try{var e=Z&&Z.require&&Z.require("util").types;return e||ee&&ee.binding&&ee.binding("util")}catch(e){}}(),re=te&&te.isTypedArray,ne=re?(K=re,function(e){return K(e)}):function(e){return _(e)&&V(e.length)&&!!J[y(e)]},oe=Object.prototype.hasOwnProperty;function se(e,t){var r=v(e),n=!r&&B(e),o=!r&&!n&&X(e),s=!r&&!n&&!o&&ne(e),i=r||n||o||s,a=i?function(e,t){for(var r=-1,n=Array(e);++r<e;)n[r]=t(r);return n}(e.length,String):[],c=a.length;for(var u in e)!t&&!oe.call(e,u)||i&&("length"==u||o&&("offset"==u||"parent"==u)||s&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||x(u,c))||a.push(u);return a}var ie=function(e,t){return function(r){return e(t(r))}}(Object.keys,Object),ae=ie,ce=Object.prototype.hasOwnProperty;function ue(e){if(r=(t=e)&&t.constructor,t!==("function"==typeof r&&r.prototype||$))return ae(e);var t,r,n=[];for(var o in Object(e))ce.call(e,o)&&"constructor"!=o&&n.push(o);return n}function he(e){return null!=(t=e)&&V(t.length)&&!g(t)?se(e):ue(e);var t}var le=I(Object,"create");var pe=Object.prototype.hasOwnProperty;var fe=Object.prototype.hasOwnProperty;function me(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 de(e,t){for(var r=e.length;r--;)if(L(e[r][0],t))return r;return-1}me.prototype.clear=function(){this.__data__=le?le(null):{},this.size=0},me.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},me.prototype.get=function(e){var t=this.__data__;if(le){var r=t[e];return"__lodash_hash_undefined__"===r?void 0:r}return pe.call(t,e)?t[e]:void 0},me.prototype.has=function(e){var t=this.__data__;return le?void 0!==t[e]:fe.call(t,e)},me.prototype.set=function(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=le&&void 0===t?"__lodash_hash_undefined__":t,this};var ye=Array.prototype.splice;function _e(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])}}_e.prototype.clear=function(){this.__data__=[],this.size=0},_e.prototype.delete=function(e){var t=this.__data__,r=de(t,e);return!(r<0)&&(r==t.length-1?t.pop():ye.call(t,r,1),--this.size,!0)},_e.prototype.get=function(e){var t=this.__data__,r=de(t,e);return r<0?void 0:t[r][1]},_e.prototype.has=function(e){return de(this.__data__,e)>-1},_e.prototype.set=function(e,t){var r=this.__data__,n=de(r,e);return n<0?(++this.size,r.push([e,t])):r[n][1]=t,this};var ve=I(c,"Map");function be(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 ge(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])}}ge.prototype.clear=function(){this.size=0,this.__data__={hash:new me,map:new(ve||_e),string:new me}},ge.prototype.delete=function(e){var t=be(this,e).delete(e);return this.size-=t?1:0,t},ge.prototype.get=function(e){return be(this,e).get(e)},ge.prototype.has=function(e){return be(this,e).has(e)},ge.prototype.set=function(e,t){var r=be(this,e),n=r.size;return r.set(e,t),this.size+=r.size==n?0:1,this};function Ee(e){var t=this.__data__=new _e(e);this.size=t.size}Ee.prototype.clear=function(){this.__data__=new _e,this.size=0},Ee.prototype.delete=function(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r},Ee.prototype.get=function(e){return this.__data__.get(e)},Ee.prototype.has=function(e){return this.__data__.has(e)},Ee.prototype.set=function(e,t){var r=this.__data__;if(r instanceof _e){var n=r.__data__;if(!ve||n.length<199)return n.push([e,t]),this.size=++r.size,this;r=this.__data__=new ge(n)}return r.set(e,t),this.size=r.size,this};var Oe=Object.prototype.propertyIsEnumerable,je=Object.getOwnPropertySymbols,Te=je?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 i=e[r];t(i,r,e)&&(s[o++]=i)}return s}(je(e),(function(t){return Oe.call(e,t)})))}:function(){return[]};function Re(e){return function(e,t,r){var n=t(e);return v(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,he,Te)}var we=I(c,"DataView"),ke=I(c,"Promise"),Se=I(c,"Set"),Ae="[object Map]",Pe="[object Promise]",Ce="[object Set]",Me="[object WeakMap]",Ie="[object DataView]",Ne=R(we),De=R(ve),xe=R(ke),Le=R(Se),Ve=R(N),$e=y;(we&&$e(new we(new ArrayBuffer(1)))!=Ie||ve&&$e(new ve)!=Ae||ke&&$e(ke.resolve())!=Pe||Se&&$e(new Se)!=Ce||N&&$e(new N)!=Me)&&($e=function(e){var t=y(e),r="[object Object]"==t?e.constructor:void 0,n=r?R(r):"";if(n)switch(n){case Ne:return Ie;case De:return Ae;case xe:return Pe;case Le:return Ce;case Ve:return Me}return t});var Fe=$e,ze=c.Uint8Array;function Ue(e){var t=-1,r=null==e?0:e.length;for(this.__data__=new ge;++t<r;)this.add(e[t])}function Ge(e,t){for(var r=-1,n=null==e?0:e.length;++r<n;)if(t(e[r],r,e))return!0;return!1}Ue.prototype.add=Ue.prototype.push=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},Ue.prototype.has=function(e){return this.__data__.has(e)};function Ye(e,t,r,n,o,s){var i=1&r,a=e.length,c=t.length;if(a!=c&&!(i&&c>a))return!1;var u=s.get(e),h=s.get(t);if(u&&h)return u==t&&h==e;var l=-1,p=!0,f=2&r?new Ue:void 0;for(s.set(e,t),s.set(t,e);++l<a;){var m=e[l],d=t[l];if(n)var y=i?n(d,m,l,t,e,s):n(m,d,l,e,t,s);if(void 0!==y){if(y)continue;p=!1;break}if(f){if(!Ge(t,(function(e,t){if(i=t,!f.has(i)&&(m===e||o(m,e,r,n,s)))return f.push(t);var i}))){p=!1;break}}else if(m!==d&&!o(m,d,r,n,s)){p=!1;break}}return s.delete(e),s.delete(t),p}function Be(e){var t=-1,r=Array(e.size);return e.forEach((function(e,n){r[++t]=[n,e]})),r}function He(e){var t=-1,r=Array(e.size);return e.forEach((function(e){r[++t]=e})),r}var qe=u?u.prototype:void 0,We=qe?qe.valueOf:void 0;var Xe=Object.prototype.hasOwnProperty;var Je,Ke="[object Arguments]",Qe="[object Array]",Ze="[object Object]",et=Object.prototype.hasOwnProperty;function tt(e,t,r,n,o,s){var i=v(e),a=v(t),c=i?Qe:Fe(e),u=a?Qe:Fe(t),h=(c=c==Ke?Ze:c)==Ze,l=(u=u==Ke?Ze:u)==Ze,p=c==u;if(p&&X(e)){if(!X(t))return!1;i=!0,h=!1}if(p&&!h)return s||(s=new Ee),i||ne(e)?Ye(e,t,r,n,o,s):function(e,t,r,n,o,s,i){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 ze(e),new ze(t)));case"[object Boolean]":case"[object Date]":case"[object Number]":return L(+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 a=Be;case"[object Set]":var c=1&n;if(a||(a=He),e.size!=t.size&&!c)return!1;var u=i.get(e);if(u)return u==t;n|=2,i.set(e,t);var h=Ye(a(e),a(t),n,o,s,i);return i.delete(e),h;case"[object Symbol]":if(We)return We.call(e)==We.call(t)}return!1}(e,t,c,r,n,o,s);if(!(1&r)){var f=h&&et.call(e,"__wrapped__"),m=l&&et.call(t,"__wrapped__");if(f||m){var d=f?e.value():e,y=m?t.value():t;return s||(s=new Ee),o(d,y,r,n,s)}}return!!p&&(s||(s=new Ee),function(e,t,r,n,o,s){var i=1&r,a=Re(e),c=a.length;if(c!=Re(t).length&&!i)return!1;for(var u=c;u--;){var h=a[u];if(!(i?h in t:Xe.call(t,h)))return!1}var l=s.get(e),p=s.get(t);if(l&&p)return l==t&&p==e;var f=!0;s.set(e,t),s.set(t,e);for(var m=i;++u<c;){var d=e[h=a[u]],y=t[h];if(n)var _=i?n(y,d,h,t,e,s):n(d,y,h,e,t,s);if(!(void 0===_?d===y||o(d,y,r,n,s):_)){f=!1;break}m||(m="constructor"==h)}if(f&&!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||(f=!1)}return s.delete(e),s.delete(t),f}(e,t,r,n,o,s))}function rt(e,t,r,n,o){return e===t||(null==e||null==t||!_(e)&&!_(t)?e!=e&&t!=t:tt(e,t,r,n,rt,o))}function nt(e,t){return rt(e,t)}e.OBSERVER_TYPE=void 0,(Je=e.OBSERVER_TYPE||(e.OBSERVER_TYPE={})).ADD="ADD",Je.REMOVE="REMOVE",Je.CHANGE="CHANGE";const ot={},st={},it={},at={};function ct(e,t){ot[e.gameObject.id]||(ot[e.gameObject.id]={});const r=ot[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 ut({systemName:e,componentName:t,component:r,prop:n,type:o}){var s,i;null===(i=null===(s=st[e])||void 0===s?void 0:s.componentObserver)||void 0===i||i.add({component:r,prop:n,type:o,componentName:t})}function ht({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&&b(t[r]))for(const e of Object.keys(t[r]))ht({obj:t[r],key:e,prop:n,component:o,componentName:s});Object.defineProperty(t,r,{enumerable:!0,set(i){t[`_${r}`]!==i&&(t[`_${r}`]=i,function({prop:t,component:r,componentName:n}){for(const o in it){const s=(it[o]||{})[n];s&&(s.findIndex((e=>nt(e,t)))>-1&&ut({systemName:o,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 lt(t,r=t.name){var n,o;for(const s in it){(it[s]||{})[r]&&(null===(o=null===(n=st[s])||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 ot[e.gameObject.id]}(t)}function pt(e,t,r,n){var o,s=arguments.length,i=s<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(i=(s<3?o(i):s>3?o(t,r,i):o(t,r))||i);return s>3&&i&&Object.defineProperty(t,r,i),i}function ft(e,t,r,n){return new(r||(r=Promise))((function(o,s){function i(e){try{c(n.next(e))}catch(e){s(e)}}function a(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(i,a)}c((n=n.apply(e,t||[])).next())}))}function mt(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}function dt(e){return function(t,r){var n=mt(t,r);n.key=r,n.type=e}}function yt(e){return function(t,r){mt(t,r).step=e}}class _t extends s{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}}_t.componentName="Transform",pt([dt("vector2"),yt(1)],_t.prototype,"position",void 0),pt([dt("size"),yt(1)],_t.prototype,"size",void 0),pt([dt("vector2"),yt(.1)],_t.prototype,"origin",void 0),pt([dt("vector2"),yt(.1)],_t.prototype,"anchor",void 0),pt([dt("vector2"),yt(.1)],_t.prototype,"scale",void 0),pt([dt("vector2"),yt(.1)],_t.prototype,"skew",void 0),pt([dt("number"),yt(.1)],_t.prototype,"rotation",void 0);var vt=_t;let bt=0;class gt{constructor(e,t){this._componentCache={},this.components=[],this.destroyed=!1,this._name=e,this.id=++bt,this.addComponent(vt,t)}get transform(){return this.getComponent(vt)}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 gt))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 gt&&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 o?e.name:e instanceof Function?e.componentName:void 0}(t);if(this._componentCache[n])return;let i;if(t instanceof Function)i=new t(r);else{if(!(t instanceof s))throw new Error("addComponent recieve Component and Component Constructor");i=t}if(i.gameObject)throw new Error(`component has been added on gameObject ${i.gameObject.name}`);return i.gameObject=this,i.init&&i.init(i.__componentDefaultParams),function(t,r=t.name){var n,o;for(const s in it)(it[s]||{})[r]&&(null===(o=null===(n=st[s])||void 0===n?void 0:n.componentObserver)||void 0===o||o.add({component:t,type:e.OBSERVER_TYPE.ADD,componentName:r}))}(i,i.name),function(e,t=e.name){if(t&&at[t]){if(!(e&&(r=e,r&&r.constructor&&"componentName"in r.constructor)))throw new Error("component param must be an instance of Component");var r;if(!e.gameObject||!e.gameObject.id)throw new Error("component should be add to a gameObject");for(const r of at[t]){const{property:n,key:o}=ct(e,r.prop);ht({obj:n,key:o,prop:r,component:e,componentName:t})}}}(i,i.name),this.components.push(i),this._componentCache[n]=i,i.awake&&i.awake(),i}removeComponent(e){let t;if("string"==typeof e?t=e:e instanceof s?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(),lt(r,e),r.gameObject=void 0,r}getComponent(e){let t;return"string"==typeof e?t=e:e instanceof s?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 Et=gt;var Ot=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&&nt(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 jt=class{constructor(e){this.started=!1,this.componentObserver=new Ot,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 Tt=function(){let e=null;return e=Date.now?Date.now:()=>(new Date).getTime(),e}(),Rt={originTime:0,playbackRate:1};class wt{constructor(e,t){e instanceof wt&&(t=e,e={}),e=_extends({},Rt,e),t&&(this._parent=t),this._createTime=Tt(),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:Tt()-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 wt(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 kt=wt;const St={autoStart:!0,frameRate:60};var At=class{constructor(e){e=_extends({},St,e),this._frameCount=0,this._frameDuration=1e3/e.frameRate,this.autoStart=e.autoStart,this.frameRate=e.frameRate,this.timeline=new kt({originTime:0,playbackRate:1}),this._lastFrameTime=this.timeline.currentTime,this._tickers=new Set,this._requestId=null,this._ticker=()=>{this._started&&(this._requestId=requestAnimationFrame(this._ticker),this.update())},this.autoStart&&this.start()}update(){const e=this.timeline.currentTime,t=e-this._lastFrameTime;if(t>=this._frameDuration){const r=e-t%this._frameDuration,n=r-this._lastFrameTime;this._lastFrameTime=r;const o={deltaTime:n,time:r,currentTime:r,frameCount:++this._frameCount,fps:Math.round(1e3/n)};for(const e of this._tickers)"function"==typeof e&&e(o)}}add(e){this._tickers.add(e)}remove(e){this._tickers.delete(e)}start(){this._started||(this._started=!0,this.timeline.playbackRate=1,this._requestId=requestAnimationFrame(this._ticker))}pause(){this._started=!1,this.timeline.playbackRate=0}setPlaybackRate(e){this.timeline.playbackRate=e}};var Pt,Ct=class extends Et{constructor(e,t){super(e,t),this.gameObjects=[],this.scene=this}addGameObject(e){this.gameObjects.push(e),e.transform&&(e.transform.inScene=!0)}removeGameObject(e){const t=this.gameObjects.indexOf(e);-1!==t&&(e.transform&&(e.transform.inScene=!1),this.gameObjects.splice(t,1))}destroy(){this.scene=null,super.destroy(),this.gameObjects=null,this.canvas=null}};e.LOAD_SCENE_MODE=void 0,(Pt=e.LOAD_SCENE_MODE||(e.LOAD_SCENE_MODE={})).SINGLE="SINGLE",Pt.MULTI_CANVAS="MULTI_CANVAS";const Mt=e=>{if((e instanceof jt||e instanceof s)&&!e.started){e.started=!0;try{e.start&&e.start()}catch(t){e instanceof s?console.error(`${e.constructor.componentName} start error`,t):console.error(`${e.constructor.systemName} start error`,t)}}};var It,Nt,Dt=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 ft(this,void 0,void 0,(function*(){if("undefined"!=typeof window&&window.__EVA_INSPECTOR_ENV__&&(window.__EVA_GAME_INSTANCE__=this),this.ticker=new At({autoStart:!1,frameRate:t}),this.initTicker(),e&&e.length)for(const t of e)yield this.addSystem(t);n&&this.loadScene(new Ct("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)}addSystem(e,t){return ft(this,void 0,void 0,(function*(){let r;if(e instanceof Function)r=new e(t);else{if(!(e instanceof jt))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){it[t.systemName]=t.observerInfo,st[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){at[t]=at[t]||[];const r=at[t];for(const n of e.observerInfo[t])-1===r.findIndex((e=>nt(e,n)))&&at[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 jt&&(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{Mt(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{Mt(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(){this.removeAllListeners(),this.pause(),this.scene.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 xt(e,t){e.constructor.IDEProps||(e.constructor.IDEProps=[]),e.constructor.IDEProps.push(t)}function Lt(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 Vt 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,(It=e.LOAD_EVENT||(e.LOAD_EVENT={})).START="start",It.PROGRESS="progress",It.LOADED="loaded",It.COMPLETE="complete",It.ERROR="error",e.RESOURCE_TYPE=void 0,(Nt=e.RESOURCE_TYPE||(e.RESOURCE_TYPE={})).IMAGE="IMAGE",Nt.SPRITE="SPRITE",Nt.SPRITE_ANIMATION="SPRITE_ANIMATION",Nt.AUDIO="AUDIO",Nt.VIDEO="VIDEO",Nt.FONT="FONT";const $t=new class extends n{constructor(e){super(),this.timeout=6e3,this.preProcessResourceHandlers=[],this.resourcesMap={},this.makeInstanceFunctions={},this.destroyInstanceFunctions={},this.promiseMap={},e&&"number"==typeof e.timeout&&(this.timeout=e.timeout)}loadConfig(e){this.addResource(e),this.preload()}loadSingle(e){return this.addResource([e]),this.getResource(e.name)}addResource(e){if(!e||e.length<1)console.warn("no resources");else for(const t of e)this.resourcesMap[t.name]?console.warn(t.name+" was already added"):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 Vt({resource:this,resourceTotal:e.length}),this.loadResource({names:e,preload:!0})}getResource(e){return ft(this,void 0,void 0,(function*(){return this.loadResource({names:[e]}),this.promiseMap[e]||Promise.resolve({})}))}instance(e){return ft(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 ft(this,void 0,void 0,(function*(){yield this._destroy(e)}))}_destroy(e,t=!1){return ft(this,void 0,void 0,(function*(){const r=this.resourcesMap[e];if(r){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}'`)}delete this.promiseMap[e],r.data={},r.complete=!1,r.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=>ft(this,void 0,void 0,(function*(){var o;this.promiseMap[r]=new Promise((e=>s[r]=e));const i=this.resourcesMap[r];for(const e of this.preProcessResourceHandlers)e(i);for(const a in i.src){if("data"===i.src[a].type)i.data[a]=i.src[a].data,this.doComplete(r,s[r],n);else{let c=null===(o=i.src[a])||void 0===o?void 0:o.url;if(console.log(c),"string"==typeof c&&c.startsWith("//")&&(c=`https:${i.src[a].url}`),"atlas"===a){const e=t.Assets.load(i.src.image.url).catch((e=>{this.onError({preload:n,errMsg:e.message,resource:{metadata:{key:a,name:r,resolves:s}}})}));t.Assets.add({alias:c,src:c,data:{resolve:()=>e,imageTexture:yield e}})}else{const o={alias:c,src:c};if(i.type===e.RESOURCE_TYPE.SPRITE||i.type===e.RESOURCE_TYPE.SPRITE_ANIMATION){if("json"===i.src[a].type)try{const e=yield t.Assets.load(i.src.image.url);o.data={texture:e}}catch(e){console.log(">>>E",e),this.onError({preload:n,errMsg:e.message,resource:{metadata:{key:a,name:r,resolves:s}}})}}else i.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:a,name:r,resolves:s},data:e}})})).catch((e=>{console.log(">>>E",e),this.onError({preload:n,errMsg:e.message,resource:{metadata:{key:a,name:r,resolves:s}}})}))}}}))))}doComplete(e,t,r=!1){return ft(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 ft(this,void 0,void 0,(function*(){const{metadata:{key:r,name:n,resolves:o},data:s}=t,i=this.resourcesMap[n];i?(i.data[r]=s,this.doComplete(n,o[n],e)):console.warn("no resource data found")}))}onError({errMsg:e,preload:t=!1,resource:r}){return ft(this,void 0,void 0,(function*(){const{metadata:{name:n,resolves:o}}=r;if(this._destroy(n,!0),o[n]({}),t){const t={name:n,resource:this.resourcesMap[n],success:!1,errMsg:e};this.progress.onProgress(t)}}))}},Ft={IDEProp:xt,componentObserver:Lt},zt="2.0.1-beta.18";console.log(`Eva.js version: ${zt}`);return e.Component=s,e.Game=Dt,e.GameObject=Et,e.IDEProp=xt,e.RESOURCE_TYPE_STRATEGY={},e.Scene=Ct,e.System=jt,e.Transform=vt,e.componentObserver=Lt,e.decorators=Ft,e.resource=$t,e.version=zt,Object.defineProperty(e,"__esModule",{value:!0}),e}({},PIXI);globalThis.EVA=globalThis.EVA||_EVA_IIFE_EVA;
|
|
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,i){if("function"!=typeof n)throw new TypeError("The listener must be a function");var a=new o(n,s||e,i),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],a]:e._events[c].push(a):(e._events[c]=a,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new n:delete e._events[t]}function a(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),a.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},a.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,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i},a.prototype.listenerCount=function(e){var t=r?r+e:e,n=this._events[t];return n?n.fn?1:n.length:0},a.prototype.emit=function(e,t,n,o,s,i){var a=r?r+e:e;if(!this._events[a])return!1;var c,u,h=this._events[a],l=arguments.length;if(h.fn){switch(h.once&&this.removeListener(e,h.fn,void 0,!0),l){case 1:return h.fn.call(h.context),!0;case 2:return h.fn.call(h.context,t),!0;case 3:return h.fn.call(h.context,t,n),!0;case 4:return h.fn.call(h.context,t,n,o),!0;case 5:return h.fn.call(h.context,t,n,o,s),!0;case 6:return h.fn.call(h.context,t,n,o,s,i),!0}for(u=1,c=new Array(l-1);u<l;u++)c[u-1]=arguments[u];h.fn.apply(h.context,c)}else{var p,f=h.length;for(u=0;u<f;u++)switch(h[u].once&&this.removeListener(e,h[u].fn,void 0,!0),l){case 1:h[u].fn.call(h[u].context);break;case 2:h[u].fn.call(h[u].context,t);break;case 3:h[u].fn.call(h[u].context,t,n);break;case 4:h[u].fn.call(h[u].context,t,n,o);break;default:if(!c)for(p=1,c=new Array(l-1);p<l;p++)c[p-1]=arguments[p];h[u].fn.apply(h[u].context,c)}}return!0},a.prototype.on=function(e,t,r){return s(this,e,t,r,!1)},a.prototype.once=function(e,t,r){return s(this,e,t,r,!0)},a.prototype.removeListener=function(e,t,n,o){var s=r?r+e:e;if(!this._events[s])return this;if(!t)return i(this,s),this;var a=this._events[s];if(a.fn)a.fn!==t||o&&!a.once||n&&a.context!==n||i(this,s);else{for(var c=0,u=[],h=a.length;c<h;c++)(a[c].fn!==t||o&&!a[c].once||n&&a[c].context!==n)&&u.push(a[c]);u.length?this._events[s]=1===u.length?u[0]:u:i(this,s)}return this},a.prototype.removeAllListeners=function(e){var t;return e?(t=r?r+e:e,this._events[t]&&i(this,t)):(this._events=new n,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=r,a.EventEmitter=a,e.exports=a})),n=r;class o extends n{constructor(e){super(),this.started=!1,this.name=this.constructor.componentName,this.__componentDefaultParams=e}}var s=o,i="object"==typeof global&&global&&global.Object===Object&&global,a="object"==typeof self&&self&&self.Object===Object&&self,c=i||a||Function("return this")(),u=c.Symbol,h=Object.prototype,l=h.hasOwnProperty,p=h.toString,f=u?u.toStringTag:void 0;var m=Object.prototype.toString;var d=u?u.toStringTag:void 0;function y(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":d&&d in Object(e)?function(e){var t=l.call(e,f),r=e[f];try{e[f]=void 0;var n=!0}catch(e){}var o=p.call(e);return n&&(t?e[f]=r:delete e[f]),o}(e):function(e){return m.call(e)}(e)}function v(e){return null!=e&&"object"==typeof e}var _=Array.isArray;function b(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function g(e){if(!b(e))return!1;var t=y(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t}var E,O=c["__core-js_shared__"],j=(E=/[^.]+$/.exec(O&&O.keys&&O.keys.IE_PROTO||""))?"Symbol(src)_1."+E:"";var T=Function.prototype.toString;function R(e){if(null!=e){try{return T.call(e)}catch(e){}try{return e+""}catch(e){}}return""}var w=/^\[object .+?Constructor\]$/,k=Function.prototype,S=Object.prototype,A=k.toString,P=S.hasOwnProperty,C=RegExp("^"+A.call(P).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function M(e){return!(!b(e)||(t=e,j&&j in t))&&(g(e)?C:w).test(R(e));var t}function I(e,t){var r=function(e,t){return null==e?void 0:e[t]}(e,t);return M(r)?r:void 0}var N=I(c,"WeakMap"),D=/^(?:0|[1-9]\d*)$/;function x(e,t){var r=typeof e;return!!(t=null==t?9007199254740991:t)&&("number"==r||"symbol"!=r&&D.test(e))&&e>-1&&e%1==0&&e<t}function L(e,t){return e===t||e!=e&&t!=t}function V(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991}var $=Object.prototype;function F(e){return v(e)&&"[object Arguments]"==y(e)}var z=Object.prototype,U=z.hasOwnProperty,G=z.propertyIsEnumerable,Y=F(function(){return arguments}())?F:function(e){return v(e)&&U.call(e,"callee")&&!G.call(e,"callee")},B=Y;var H="object"==typeof e&&e&&!e.nodeType&&e,q=H&&"object"==typeof module&&module&&!module.nodeType&&module,W=q&&q.exports===H?c.Buffer:void 0,X=(W?W.isBuffer:void 0)||function(){return!1},J={};J["[object Float32Array]"]=J["[object Float64Array]"]=J["[object Int8Array]"]=J["[object Int16Array]"]=J["[object Int32Array]"]=J["[object Uint8Array]"]=J["[object Uint8ClampedArray]"]=J["[object Uint16Array]"]=J["[object Uint32Array]"]=!0,J["[object Arguments]"]=J["[object Array]"]=J["[object ArrayBuffer]"]=J["[object Boolean]"]=J["[object DataView]"]=J["[object Date]"]=J["[object Error]"]=J["[object Function]"]=J["[object Map]"]=J["[object Number]"]=J["[object Object]"]=J["[object RegExp]"]=J["[object Set]"]=J["[object String]"]=J["[object WeakMap]"]=!1;var K,Q="object"==typeof e&&e&&!e.nodeType&&e,Z=Q&&"object"==typeof module&&module&&!module.nodeType&&module,ee=Z&&Z.exports===Q&&i.process,te=function(){try{var e=Z&&Z.require&&Z.require("util").types;return e||ee&&ee.binding&&ee.binding("util")}catch(e){}}(),re=te&&te.isTypedArray,ne=re?(K=re,function(e){return K(e)}):function(e){return v(e)&&V(e.length)&&!!J[y(e)]},oe=Object.prototype.hasOwnProperty;function se(e,t){var r=_(e),n=!r&&B(e),o=!r&&!n&&X(e),s=!r&&!n&&!o&&ne(e),i=r||n||o||s,a=i?function(e,t){for(var r=-1,n=Array(e);++r<e;)n[r]=t(r);return n}(e.length,String):[],c=a.length;for(var u in e)!t&&!oe.call(e,u)||i&&("length"==u||o&&("offset"==u||"parent"==u)||s&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||x(u,c))||a.push(u);return a}var ie=function(e,t){return function(r){return e(t(r))}}(Object.keys,Object),ae=ie,ce=Object.prototype.hasOwnProperty;function ue(e){if(r=(t=e)&&t.constructor,t!==("function"==typeof r&&r.prototype||$))return ae(e);var t,r,n=[];for(var o in Object(e))ce.call(e,o)&&"constructor"!=o&&n.push(o);return n}function he(e){return null!=(t=e)&&V(t.length)&&!g(t)?se(e):ue(e);var t}var le=I(Object,"create");var pe=Object.prototype.hasOwnProperty;var fe=Object.prototype.hasOwnProperty;function me(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 de(e,t){for(var r=e.length;r--;)if(L(e[r][0],t))return r;return-1}me.prototype.clear=function(){this.__data__=le?le(null):{},this.size=0},me.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},me.prototype.get=function(e){var t=this.__data__;if(le){var r=t[e];return"__lodash_hash_undefined__"===r?void 0:r}return pe.call(t,e)?t[e]:void 0},me.prototype.has=function(e){var t=this.__data__;return le?void 0!==t[e]:fe.call(t,e)},me.prototype.set=function(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=le&&void 0===t?"__lodash_hash_undefined__":t,this};var ye=Array.prototype.splice;function ve(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])}}ve.prototype.clear=function(){this.__data__=[],this.size=0},ve.prototype.delete=function(e){var t=this.__data__,r=de(t,e);return!(r<0)&&(r==t.length-1?t.pop():ye.call(t,r,1),--this.size,!0)},ve.prototype.get=function(e){var t=this.__data__,r=de(t,e);return r<0?void 0:t[r][1]},ve.prototype.has=function(e){return de(this.__data__,e)>-1},ve.prototype.set=function(e,t){var r=this.__data__,n=de(r,e);return n<0?(++this.size,r.push([e,t])):r[n][1]=t,this};var _e=I(c,"Map");function be(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 ge(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])}}ge.prototype.clear=function(){this.size=0,this.__data__={hash:new me,map:new(_e||ve),string:new me}},ge.prototype.delete=function(e){var t=be(this,e).delete(e);return this.size-=t?1:0,t},ge.prototype.get=function(e){return be(this,e).get(e)},ge.prototype.has=function(e){return be(this,e).has(e)},ge.prototype.set=function(e,t){var r=be(this,e),n=r.size;return r.set(e,t),this.size+=r.size==n?0:1,this};function Ee(e){var t=this.__data__=new ve(e);this.size=t.size}Ee.prototype.clear=function(){this.__data__=new ve,this.size=0},Ee.prototype.delete=function(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r},Ee.prototype.get=function(e){return this.__data__.get(e)},Ee.prototype.has=function(e){return this.__data__.has(e)},Ee.prototype.set=function(e,t){var r=this.__data__;if(r instanceof ve){var n=r.__data__;if(!_e||n.length<199)return n.push([e,t]),this.size=++r.size,this;r=this.__data__=new ge(n)}return r.set(e,t),this.size=r.size,this};var Oe=Object.prototype.propertyIsEnumerable,je=Object.getOwnPropertySymbols,Te=je?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 i=e[r];t(i,r,e)&&(s[o++]=i)}return s}(je(e),(function(t){return Oe.call(e,t)})))}:function(){return[]};function Re(e){return function(e,t,r){var n=t(e);return _(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,he,Te)}var we=I(c,"DataView"),ke=I(c,"Promise"),Se=I(c,"Set"),Ae="[object Map]",Pe="[object Promise]",Ce="[object Set]",Me="[object WeakMap]",Ie="[object DataView]",Ne=R(we),De=R(_e),xe=R(ke),Le=R(Se),Ve=R(N),$e=y;(we&&$e(new we(new ArrayBuffer(1)))!=Ie||_e&&$e(new _e)!=Ae||ke&&$e(ke.resolve())!=Pe||Se&&$e(new Se)!=Ce||N&&$e(new N)!=Me)&&($e=function(e){var t=y(e),r="[object Object]"==t?e.constructor:void 0,n=r?R(r):"";if(n)switch(n){case Ne:return Ie;case De:return Ae;case xe:return Pe;case Le:return Ce;case Ve:return Me}return t});var Fe=$e,ze=c.Uint8Array;function Ue(e){var t=-1,r=null==e?0:e.length;for(this.__data__=new ge;++t<r;)this.add(e[t])}function Ge(e,t){for(var r=-1,n=null==e?0:e.length;++r<n;)if(t(e[r],r,e))return!0;return!1}Ue.prototype.add=Ue.prototype.push=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},Ue.prototype.has=function(e){return this.__data__.has(e)};function Ye(e,t,r,n,o,s){var i=1&r,a=e.length,c=t.length;if(a!=c&&!(i&&c>a))return!1;var u=s.get(e),h=s.get(t);if(u&&h)return u==t&&h==e;var l=-1,p=!0,f=2&r?new Ue:void 0;for(s.set(e,t),s.set(t,e);++l<a;){var m=e[l],d=t[l];if(n)var y=i?n(d,m,l,t,e,s):n(m,d,l,e,t,s);if(void 0!==y){if(y)continue;p=!1;break}if(f){if(!Ge(t,(function(e,t){if(i=t,!f.has(i)&&(m===e||o(m,e,r,n,s)))return f.push(t);var i}))){p=!1;break}}else if(m!==d&&!o(m,d,r,n,s)){p=!1;break}}return s.delete(e),s.delete(t),p}function Be(e){var t=-1,r=Array(e.size);return e.forEach((function(e,n){r[++t]=[n,e]})),r}function He(e){var t=-1,r=Array(e.size);return e.forEach((function(e){r[++t]=e})),r}var qe=u?u.prototype:void 0,We=qe?qe.valueOf:void 0;var Xe=Object.prototype.hasOwnProperty;var Je,Ke="[object Arguments]",Qe="[object Array]",Ze="[object Object]",et=Object.prototype.hasOwnProperty;function tt(e,t,r,n,o,s){var i=_(e),a=_(t),c=i?Qe:Fe(e),u=a?Qe:Fe(t),h=(c=c==Ke?Ze:c)==Ze,l=(u=u==Ke?Ze:u)==Ze,p=c==u;if(p&&X(e)){if(!X(t))return!1;i=!0,h=!1}if(p&&!h)return s||(s=new Ee),i||ne(e)?Ye(e,t,r,n,o,s):function(e,t,r,n,o,s,i){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 ze(e),new ze(t)));case"[object Boolean]":case"[object Date]":case"[object Number]":return L(+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 a=Be;case"[object Set]":var c=1&n;if(a||(a=He),e.size!=t.size&&!c)return!1;var u=i.get(e);if(u)return u==t;n|=2,i.set(e,t);var h=Ye(a(e),a(t),n,o,s,i);return i.delete(e),h;case"[object Symbol]":if(We)return We.call(e)==We.call(t)}return!1}(e,t,c,r,n,o,s);if(!(1&r)){var f=h&&et.call(e,"__wrapped__"),m=l&&et.call(t,"__wrapped__");if(f||m){var d=f?e.value():e,y=m?t.value():t;return s||(s=new Ee),o(d,y,r,n,s)}}return!!p&&(s||(s=new Ee),function(e,t,r,n,o,s){var i=1&r,a=Re(e),c=a.length;if(c!=Re(t).length&&!i)return!1;for(var u=c;u--;){var h=a[u];if(!(i?h in t:Xe.call(t,h)))return!1}var l=s.get(e),p=s.get(t);if(l&&p)return l==t&&p==e;var f=!0;s.set(e,t),s.set(t,e);for(var m=i;++u<c;){var d=e[h=a[u]],y=t[h];if(n)var v=i?n(y,d,h,t,e,s):n(d,y,h,e,t,s);if(!(void 0===v?d===y||o(d,y,r,n,s):v)){f=!1;break}m||(m="constructor"==h)}if(f&&!m){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 rt(e,t,r,n,o){return e===t||(null==e||null==t||!v(e)&&!v(t)?e!=e&&t!=t:tt(e,t,r,n,rt,o))}function nt(e,t){return rt(e,t)}e.OBSERVER_TYPE=void 0,(Je=e.OBSERVER_TYPE||(e.OBSERVER_TYPE={})).ADD="ADD",Je.REMOVE="REMOVE",Je.CHANGE="CHANGE";const ot={},st={},it={},at={};function ct(e,t){ot[e.gameObject.id]||(ot[e.gameObject.id]={});const r=ot[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 ut({systemName:e,componentName:t,component:r,prop:n,type:o}){var s,i;null===(i=null===(s=st[e])||void 0===s?void 0:s.componentObserver)||void 0===i||i.add({component:r,prop:n,type:o,componentName:t})}function ht({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&&b(t[r]))for(const e of Object.keys(t[r]))ht({obj:t[r],key:e,prop:n,component:o,componentName:s});Object.defineProperty(t,r,{enumerable:!0,set(i){t[`_${r}`]!==i&&(t[`_${r}`]=i,function({prop:t,component:r,componentName:n}){for(const o in it){const s=(it[o]||{})[n];s&&(s.findIndex((e=>nt(e,t)))>-1&&ut({systemName:o,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 lt(t,r=t.name){var n,o;for(const s in it){(it[s]||{})[r]&&(null===(o=null===(n=st[s])||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 ot[e.gameObject.id]}(t)}function pt(e,t,r,n){var o,s=arguments.length,i=s<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(i=(s<3?o(i):s>3?o(t,r,i):o(t,r))||i);return s>3&&i&&Object.defineProperty(t,r,i),i}function ft(e,t,r,n){return new(r||(r=Promise))((function(o,s){function i(e){try{c(n.next(e))}catch(e){s(e)}}function a(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(i,a)}c((n=n.apply(e,t||[])).next())}))}function mt(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}function dt(e){return function(t,r){var n=mt(t,r);n.key=r,n.type=e}}function yt(e){return function(t,r){mt(t,r).step=e}}class vt extends s{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}}vt.componentName="Transform",pt([dt("vector2"),yt(1)],vt.prototype,"position",void 0),pt([dt("size"),yt(1)],vt.prototype,"size",void 0),pt([dt("vector2"),yt(.1)],vt.prototype,"origin",void 0),pt([dt("vector2"),yt(.1)],vt.prototype,"anchor",void 0),pt([dt("vector2"),yt(.1)],vt.prototype,"scale",void 0),pt([dt("vector2"),yt(.1)],vt.prototype,"skew",void 0),pt([dt("number"),yt(.1)],vt.prototype,"rotation",void 0);var _t=vt;let bt=0;class gt{constructor(e,t){this._componentCache={},this.components=[],this.destroyed=!1,this._name=e,this.id=++bt,this.addComponent(_t,t)}get transform(){return this.getComponent(_t)}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 gt))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 gt&&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 o?e.name:e instanceof Function?e.componentName:void 0}(t);if(this._componentCache[n])return;let i;if(t instanceof Function)i=new t(r);else{if(!(t instanceof s))throw new Error("addComponent recieve Component and Component Constructor");i=t}if(i.gameObject)throw new Error(`component has been added on gameObject ${i.gameObject.name}`);return i.gameObject=this,i.init&&i.init(i.__componentDefaultParams),function(t,r=t.name){var n,o;for(const s in it)(it[s]||{})[r]&&(null===(o=null===(n=st[s])||void 0===n?void 0:n.componentObserver)||void 0===o||o.add({component:t,type:e.OBSERVER_TYPE.ADD,componentName:r}))}(i,i.name),function(e,t=e.name){if(t&&at[t]){if(!(e&&(r=e,r&&r.constructor&&"componentName"in r.constructor)))throw new Error("component param must be an instance of Component");var r;if(!e.gameObject||!e.gameObject.id)throw new Error("component should be add to a gameObject");for(const r of at[t]){const{property:n,key:o}=ct(e,r.prop);ht({obj:n,key:o,prop:r,component:e,componentName:t})}}}(i,i.name),this.components.push(i),this._componentCache[n]=i,i.awake&&i.awake(),i}removeComponent(e){let t;if("string"==typeof e?t=e:e instanceof s?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(),lt(r,e),r.gameObject=void 0,r}getComponent(e){let t;return"string"==typeof e?t=e:e instanceof s?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 Et=gt;var Ot=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&&nt(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 jt=class{constructor(e){this.started=!1,this.componentObserver=new Ot,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 Tt=function(){let e=null;return e=Date.now?Date.now:()=>(new Date).getTime(),e}(),Rt={originTime:0,playbackRate:1};class wt{constructor(e,t){e instanceof wt&&(t=e,e={}),e=_extends({},Rt,e),t&&(this._parent=t),this._createTime=Tt(),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:Tt()-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 wt(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 kt=wt;const St={autoStart:!0,frameRate:60};var At=class{constructor(e){e=_extends({},St,e),this._frameCount=0,this._frameDuration=1e3/e.frameRate,this.autoStart=e.autoStart,this.frameRate=e.frameRate,this.timeline=new kt({originTime:0,playbackRate:1}),this._lastFrameTime=this.timeline.currentTime,this._tickers=new Set,this._requestId=null,this._ticker=()=>{this._started&&(this._requestId=requestAnimationFrame(this._ticker),this.update())},this.autoStart&&this.start()}update(){const e=this.timeline.currentTime,t=e-this._lastFrameTime;if(t>=this._frameDuration){const r=e-t%this._frameDuration,n=r-this._lastFrameTime;this._lastFrameTime=r;const o={deltaTime:n,time:r,currentTime:r,frameCount:++this._frameCount,fps:Math.round(1e3/n)};for(const e of this._tickers)"function"==typeof e&&e(o)}}add(e){this._tickers.add(e)}remove(e){this._tickers.delete(e)}start(){this._started||(this._started=!0,this.timeline.playbackRate=1,this._requestId=requestAnimationFrame(this._ticker))}pause(){this._started=!1,this.timeline.playbackRate=0}setPlaybackRate(e){this.timeline.playbackRate=e}};var Pt,Ct=class extends Et{constructor(e,t){super(e,t),this.gameObjects=[],this.scene=this}addGameObject(e){this.gameObjects.push(e),e.transform&&(e.transform.inScene=!0)}removeGameObject(e){const t=this.gameObjects.indexOf(e);-1!==t&&(e.transform&&(e.transform.inScene=!1),this.gameObjects.splice(t,1))}destroy(){this.scene=null,super.destroy(),this.gameObjects=null,this.canvas=null}};e.LOAD_SCENE_MODE=void 0,(Pt=e.LOAD_SCENE_MODE||(e.LOAD_SCENE_MODE={})).SINGLE="SINGLE",Pt.MULTI_CANVAS="MULTI_CANVAS";const Mt=e=>{if((e instanceof jt||e instanceof s)&&!e.started){e.started=!0;try{e.start&&e.start()}catch(t){e instanceof s?console.error(`${e.constructor.componentName} start error`,t):console.error(`${e.constructor.systemName} start error`,t)}}};var It,Nt,Dt=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 ft(this,void 0,void 0,(function*(){if("undefined"!=typeof window&&window.__EVA_INSPECTOR_ENV__&&(window.__EVA_GAME_INSTANCE__=this),this.ticker=new At({autoStart:!1,frameRate:t}),this.initTicker(),e&&e.length)for(const t of e)yield this.addSystem(t);n&&this.loadScene(new Ct("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)}addSystem(e,t){return ft(this,void 0,void 0,(function*(){let r;if(e instanceof Function)r=new e(t);else{if(!(e instanceof jt))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){it[t.systemName]=t.observerInfo,st[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){at[t]=at[t]||[];const r=at[t];for(const n of e.observerInfo[t])-1===r.findIndex((e=>nt(e,n)))&&at[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 jt&&(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{Mt(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{Mt(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(){this.removeAllListeners(),this.pause(),this.scene.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 xt(e,t){e.constructor.IDEProps||(e.constructor.IDEProps=[]),e.constructor.IDEProps.push(t)}function Lt(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 Vt 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,(It=e.LOAD_EVENT||(e.LOAD_EVENT={})).START="start",It.PROGRESS="progress",It.LOADED="loaded",It.COMPLETE="complete",It.ERROR="error",e.RESOURCE_TYPE=void 0,(Nt=e.RESOURCE_TYPE||(e.RESOURCE_TYPE={})).IMAGE="IMAGE",Nt.SPRITE="SPRITE",Nt.SPRITE_ANIMATION="SPRITE_ANIMATION",Nt.AUDIO="AUDIO",Nt.VIDEO="VIDEO",Nt.FONT="FONT";const $t=new class extends n{constructor(e){super(),this.timeout=6e3,this.preProcessResourceHandlers=[],this.resourcesMap={},this.makeInstanceFunctions={},this.destroyInstanceFunctions={},this.promiseMap={},e&&"number"==typeof e.timeout&&(this.timeout=e.timeout)}loadConfig(e){this.addResource(e),this.preload()}loadSingle(e){return this.addResource([e]),this.getResource(e.name)}addResource(e){if(!e||e.length<1)console.warn("no resources");else for(const t of e)this.resourcesMap[t.name]?console.warn(t.name+" was already added"):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 Vt({resource:this,resourceTotal:e.length}),this.loadResource({names:e,preload:!0})}getResource(e){return ft(this,void 0,void 0,(function*(){return this.loadResource({names:[e]}),this.promiseMap[e]||Promise.resolve({})}))}instance(e){return ft(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 ft(this,void 0,void 0,(function*(){yield this._destroy(e)}))}_destroy(e,r=!1){var n;return ft(this,void 0,void 0,(function*(){const o=this.resourcesMap[e];if(o){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}'`)}if(o.src){const r=[];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}`),r.push(t))}if(r.length>0)try{yield t.Assets.unload(r)}catch(t){console.warn(`Failed to unload assets for ${e}: ${t.message}`)}}delete this.promiseMap[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=>ft(this,void 0,void 0,(function*(){var o;this.promiseMap[r]=new Promise((e=>s[r]=e));const i=this.resourcesMap[r];for(const e of this.preProcessResourceHandlers)e(i);for(const a in i.src){if("data"===i.src[a].type)i.data[a]=i.src[a].data,this.doComplete(r,s[r],n);else{let c=null===(o=i.src[a])||void 0===o?void 0:o.url;if(console.log(c),"string"==typeof c&&c.startsWith("//")&&(c=`https:${i.src[a].url}`),"atlas"===a){const e=t.Assets.load(i.src.image.url).catch((e=>{this.onError({preload:n,errMsg:e.message,resource:{metadata:{key:a,name:r,resolves:s}}})}));t.Assets.add({alias:c,src:c,data:{resolve:()=>e,imageTexture:yield e}})}else{const o={alias:c,src:c};if(i.type===e.RESOURCE_TYPE.SPRITE||i.type===e.RESOURCE_TYPE.SPRITE_ANIMATION){if("json"===i.src[a].type)try{const e=yield t.Assets.load(i.src.image.url);o.data={texture:e}}catch(e){console.log(">>>E",e),this.onError({preload:n,errMsg:e.message,resource:{metadata:{key:a,name:r,resolves:s}}})}}else i.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:a,name:r,resolves:s},data:e}})})).catch((e=>{console.log(">>>E",e),this.onError({preload:n,errMsg:e.message,resource:{metadata:{key:a,name:r,resolves:s}}})}))}}}))))}doComplete(e,t,r=!1){return ft(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 ft(this,void 0,void 0,(function*(){const{metadata:{key:r,name:n,resolves:o},data:s}=t,i=this.resourcesMap[n];i?(i.data[r]=s,this.doComplete(n,o[n],e)):console.warn("no resource data found")}))}onError({errMsg:e,preload:t=!1,resource:r}){return ft(this,void 0,void 0,(function*(){const{metadata:{name:n,resolves:o}}=r;if(this._destroy(n,!0),o[n]({}),t){const t={name:n,resource:this.resourcesMap[n],success:!1,errMsg:e};this.progress.onProgress(t)}}))}},Ft={IDEProp:xt,componentObserver:Lt},zt="2.0.1-beta.19";console.log(`Eva.js version: ${zt}`);return e.Component=s,e.Game=Dt,e.GameObject=Et,e.IDEProp=xt,e.RESOURCE_TYPE_STRATEGY={},e.Scene=Ct,e.System=jt,e.Transform=_t,e.componentObserver=Lt,e.decorators=Ft,e.resource=$t,e.version=zt,Object.defineProperty(e,"__esModule",{value:!0}),e}({},PIXI);globalThis.EVA=globalThis.EVA||_EVA_IIFE_EVA;
|
package/dist/eva.js.cjs.js
CHANGED
|
@@ -1230,6 +1230,7 @@ class Resource extends EventEmitter__default {
|
|
|
1230
1230
|
});
|
|
1231
1231
|
}
|
|
1232
1232
|
_destroy(name, loadError = false) {
|
|
1233
|
+
var _a;
|
|
1233
1234
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1234
1235
|
const resource = this.resourcesMap[name];
|
|
1235
1236
|
if (!resource)
|
|
@@ -1244,6 +1245,26 @@ class Resource extends EventEmitter__default {
|
|
|
1244
1245
|
console.warn(`destroy resource ${resource.name} error with '${e.message}'`);
|
|
1245
1246
|
}
|
|
1246
1247
|
}
|
|
1248
|
+
if (resource.src) {
|
|
1249
|
+
const urlsToUnload = [];
|
|
1250
|
+
for (const key in resource.src) {
|
|
1251
|
+
let url = (_a = resource.src[key]) === null || _a === void 0 ? void 0 : _a.url;
|
|
1252
|
+
if (url) {
|
|
1253
|
+
if (typeof url === 'string' && url.startsWith('//')) {
|
|
1254
|
+
url = `https:${url}`;
|
|
1255
|
+
}
|
|
1256
|
+
urlsToUnload.push(url);
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
if (urlsToUnload.length > 0) {
|
|
1260
|
+
try {
|
|
1261
|
+
yield pixi_js.Assets.unload(urlsToUnload);
|
|
1262
|
+
}
|
|
1263
|
+
catch (e) {
|
|
1264
|
+
console.warn(`Failed to unload assets for ${name}: ${e.message}`);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1247
1268
|
delete this.promiseMap[name];
|
|
1248
1269
|
resource.data = {};
|
|
1249
1270
|
resource.complete = false;
|
|
@@ -1433,7 +1454,7 @@ const decorators = {
|
|
|
1433
1454
|
IDEProp,
|
|
1434
1455
|
componentObserver,
|
|
1435
1456
|
};
|
|
1436
|
-
const version = '2.0.1-beta.
|
|
1457
|
+
const version = '2.0.1-beta.19';
|
|
1437
1458
|
console.log(`Eva.js version: ${version}`);
|
|
1438
1459
|
const RESOURCE_TYPE_STRATEGY = {};
|
|
1439
1460
|
|
package/dist/eva.js.cjs.prod.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("eventemitter3"),t=require("lodash-es"),s=require("@eva/inspector-decorator"),r=require("pixi.js");function o(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var n=o(e);class i extends n{constructor(e){super(),this.started=!1,this.name=this.constructor.componentName,this.__componentDefaultParams=e}}var a,c=i;exports.OBSERVER_TYPE=void 0,(a=exports.OBSERVER_TYPE||(exports.OBSERVER_TYPE={})).ADD="ADD",a.REMOVE="REMOVE",a.CHANGE="CHANGE";const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("eventemitter3"),t=require("lodash-es"),s=require("@eva/inspector-decorator"),r=require("pixi.js");function o(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var n=o(e);class i extends n{constructor(e){super(),this.started=!1,this.name=this.constructor.componentName,this.__componentDefaultParams=e}}var a,c=i;exports.OBSERVER_TYPE=void 0,(a=exports.OBSERVER_TYPE||(exports.OBSERVER_TYPE={})).ADD="ADD",a.REMOVE="REMOVE",a.CHANGE="CHANGE";const h={},m={},p={},l={};function u(e,t){h[e.gameObject.id]||(h[e.gameObject.id]={});const s=h[e.gameObject.id],r=e.name+"_"+t.join(",");if(s[r])return s[r];const o=t.length-1;let n=e;for(let e=0;e<o;e++)n=n[t[e]];return s[r]={property:n,key:t[o]},s[r]}function d({systemName:e,componentName:t,component:s,prop:r,type:o}){var n,i;null===(i=null===(n=m[e])||void 0===n?void 0:n.componentObserver)||void 0===i||i.add({component:s,prop:r,type:o,componentName:t})}function f({obj:e,key:s,prop:r,component:o,componentName:n}){if(void 0!==e)if(s in e){if(Object.defineProperty(e,`_${s}`,{enumerable:!1,writable:!0,value:e[s]}),r.deep&&t.isObject(e[s]))for(const t of Object.keys(e[s]))f({obj:e[s],key:t,prop:r,component:o,componentName:n});Object.defineProperty(e,s,{enumerable:!0,set(i){e[`_${s}`]!==i&&(e[`_${s}`]=i,function({prop:e,component:s,componentName:r}){for(const o in p){const n=(p[o]||{})[r];n&&(n.findIndex((s=>t.isEqual(s,e)))>-1&&d({systemName:o,componentName:r,component:s,prop:e,type:exports.OBSERVER_TYPE.CHANGE}))}}({prop:r,component:o,componentName:n}))},get:()=>e[`_${s}`]})}else console.error(`prop ${s} not in component: ${n}, Can not observer`)}function y(e,t=e.name){var s,r;for(const o in p){(p[o]||{})[t]&&(null===(r=null===(s=m[o])||void 0===s?void 0:s.componentObserver)||void 0===r||r.add({component:e,type:exports.OBSERVER_TYPE.REMOVE,componentName:t}))}!function(e){e.gameObject&&delete h[e.gameObject.id]}(e)}
|
|
2
2
|
/*! *****************************************************************************
|
|
3
3
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
@@ -13,4 +13,4 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
|
13
13
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
14
|
and limitations under the License.
|
|
15
15
|
***************************************************************************** */
|
|
16
|
-
function E(e,t,s,r){var o,n=arguments.length,i=n<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,s):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,s,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(i=(n<3?o(i):n>3?o(t,s,i):o(t,s))||i);return n>3&&i&&Object.defineProperty(t,s,i),i}function g(e,t,s,r){return new(s||(s=Promise))((function(o,n){function i(e){try{c(r.next(e))}catch(e){n(e)}}function a(e){try{c(r.throw(e))}catch(e){n(e)}}function c(e){e.done?o(e.value):new s((function(t){t(e.value)})).then(i,a)}c((r=r.apply(e,t||[])).next())}))}class v extends c{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}}v.componentName="Transform",E([s.type("vector2"),s.step(1)],v.prototype,"position",void 0),E([s.type("size"),s.step(1)],v.prototype,"size",void 0),E([s.type("vector2"),s.step(.1)],v.prototype,"origin",void 0),E([s.type("vector2"),s.step(.1)],v.prototype,"anchor",void 0),E([s.type("vector2"),s.step(.1)],v.prototype,"scale",void 0),E([s.type("vector2"),s.step(.1)],v.prototype,"skew",void 0),E([s.type("number"),s.step(.1)],v.prototype,"rotation",void 0);var _=v;let b=0;class O{constructor(e,t){this._componentCache={},this.components=[],this.destroyed=!1,this._name=e,this.id=++b,this.addComponent(_,t)}get transform(){return this.getComponent(_)}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 O))throw new Error("addChild only receive GameObject");if(!this.transform)throw new Error(`gameObject '${this.name}' has been destroy`);e.transform.parent=this.transform,e.scene=this.scene}}removeChild(e){return e instanceof O&&e.parent&&e.parent===this?(e.transform.parent=null,e.scene=null,e):e}addComponent(e,t){if(this.destroyed)return;const s=function(e){return e instanceof 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 c))throw new Error("addComponent recieve Component and Component Constructor");r=e}if(r.gameObject)throw new Error(`component has been added on gameObject ${r.gameObject.name}`);return r.gameObject=this,r.init&&r.init(r.__componentDefaultParams),function(e,t=e.name){var s,r;for(const o in p)(p[o]||{})[t]&&(null===(r=null===(s=h[o])||void 0===s?void 0:s.componentObserver)||void 0===r||r.add({component:e,type:exports.OBSERVER_TYPE.ADD,componentName:t}))}(r,r.name),function(e,t=e.name){if(t&&l[t]){if(!(e&&(s=e,s&&s.constructor&&"componentName"in s.constructor)))throw new Error("component param must be an instance of Component");var s;if(!e.gameObject||!e.gameObject.id)throw new Error("component should be add to a gameObject");for(const s of l[t]){const{property:r,key:o}=u(e,s.prop);f({obj:r,key:o,prop:s,component:e,componentName:t})}}}(r,r.name),this.components.push(r),this._componentCache[s]=r,r.awake&&r.awake(),r}removeComponent(e){let t;if("string"==typeof e?t=e:e instanceof c?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(),y(s,e),s.gameObject=void 0,s}getComponent(e){let t;return"string"==typeof e?t=e:e instanceof c?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=O;var T=class{constructor(){this.events=[]}add({component:e,prop:s,type:r,componentName:o}){if(r===exports.OBSERVER_TYPE.REMOVE){if(this.events.find((t=>t.component===e&&t.type===exports.OBSERVER_TYPE.ADD)))return void(this.events=this.events.filter((t=>t.component!==e)));this.events=this.events.filter((t=>t.component!==e))}const n=this.events.findIndex((o=>o.component===e&&t.isEqual(o.prop,s)&&o.type===r));n>-1&&this.events.splice(n,1),this.events.push({gameObject:e.gameObject,component:e,prop:s,type:r,componentName:o})}getChanged(){return this.events}get changed(){return this.events}clear(){const e=this.events;return this.events=[],e}};var k=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 S=function(){let e=null;return e=Date.now?Date.now:()=>(new Date).getTime(),e}(),x={originTime:0,playbackRate:1};class C{constructor(e,t){e instanceof C&&(t=e,e={}),e=Object.assign({},x,e),t&&(this._parent=t),this._createTime=S(),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:S()-this._createTime}get parent(){return this._parent}get lastTimeMark(){return this._timeMark[this._timeMark.length-1]}markTime({time:e=this.currentTime,entropy:t=this.entropy,playbackRate:s=this.playbackRate}={}){const r={globalTime:this.globalTime,localTime:e,entropy:t,playbackRate:s,globalEntropy:this.globalEntropy};this._timeMark.push(r)}get currentTime(){const{localTime:e,globalTime:t}=this.lastTimeMark;return e+(this.globalTime-t)*this.playbackRate}set currentTime(e){this.markTime({time:e})}get globalEntropy(){return this._parent?this._parent.entropy:this.globalTime}get entropy(){const{entropy:e,globalEntropy:t}=this.lastTimeMark;return e+Math.abs((this.globalEntropy-t)*this.playbackRate)}set entropy(e){if(this.entropy>e){const t=this.seekTimeMark(e);this._timeMark.length=t+1}this.markTime({entropy:e})}fork(e){return new C(e,this)}seekGlobalTime(e){const t=this.seekTimeMark(e),s=this._timeMark[t],{entropy:r,playbackRate:o,globalTime:n}=s;return n+(e-r)/Math.abs(o)}seekLocalTime(e){const t=this.seekTimeMark(e),s=this._timeMark[t],{localTime:r,entropy:o,playbackRate:n}=s;return n>0?r+(e-o):r-(e-o)}seekTimeMark(e){const t=this._timeMark;let s=0,r=t.length-1;if(e<=t[s].entropy)return s;if(e>=t[r].entropy)return r;let o=Math.floor((s+r)/2);for(;o>s&&o<r;){if(e===t[o].entropy)return o;e<t[o].entropy?r=o:e>t[o].entropy&&(s=o),o=Math.floor((s+r)/2)}return s}get playbackRate(){return this._playbackRate}set playbackRate(e){e!==this.playbackRate&&(this.markTime({playbackRate:e}),this._playbackRate=e)}get paused(){if(0===this.playbackRate)return!0;let e=this.parent;for(;e;){if(0===e.playbackRate)return!0;e=e.parent}return!1}}var M=C;const N={autoStart:!0,frameRate:60};var P=class{constructor(e){e=Object.assign({},N,e),this._frameCount=0,this._frameDuration=1e3/e.frameRate,this.autoStart=e.autoStart,this.frameRate=e.frameRate,this.timeline=new M({originTime:0,playbackRate:1}),this._lastFrameTime=this.timeline.currentTime,this._tickers=new Set,this._requestId=null,this._ticker=()=>{this._started&&(this._requestId=requestAnimationFrame(this._ticker),this.update())},this.autoStart&&this.start()}update(){const e=this.timeline.currentTime,t=e-this._lastFrameTime;if(t>=this._frameDuration){const s=e-t%this._frameDuration,r=s-this._lastFrameTime;this._lastFrameTime=s;const o={deltaTime:r,time:s,currentTime:s,frameCount:++this._frameCount,fps:Math.round(1e3/r)};for(const e of this._tickers)"function"==typeof e&&e(o)}}add(e){this._tickers.add(e)}remove(e){this._tickers.delete(e)}start(){this._started||(this._started=!0,this.timeline.playbackRate=1,this._requestId=requestAnimationFrame(this._ticker))}pause(){this._started=!1,this.timeline.playbackRate=0}setPlaybackRate(e){this.timeline.playbackRate=e}};var A,j=class extends R{constructor(e,t){super(e,t),this.gameObjects=[],this.scene=this}addGameObject(e){this.gameObjects.push(e),e.transform&&(e.transform.inScene=!0)}removeGameObject(e){const t=this.gameObjects.indexOf(e);-1!==t&&(e.transform&&(e.transform.inScene=!1),this.gameObjects.splice(t,1))}destroy(){this.scene=null,super.destroy(),this.gameObjects=null,this.canvas=null}};exports.LOAD_SCENE_MODE=void 0,(A=exports.LOAD_SCENE_MODE||(exports.LOAD_SCENE_MODE={})).SINGLE="SINGLE",A.MULTI_CANVAS="MULTI_CANVAS";const D=e=>{if((e instanceof k||e instanceof c)&&!e.started){e.started=!0;try{e.start&&e.start()}catch(t){e instanceof c?console.error(`${e.constructor.componentName} start error`,t):console.error(`${e.constructor.systemName} start error`,t)}}};var w,I,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:r=!0}={}){return g(this,void 0,void 0,(function*(){if("undefined"!=typeof window&&window.__EVA_INSPECTOR_ENV__&&(window.__EVA_GAME_INSTANCE__=this),this.ticker=new P({autoStart:!1,frameRate:t}),this.initTicker(),e&&e.length)for(const t of e)yield this.addSystem(t);r&&this.loadScene(new j("scene")),s&&this.start()}))}get scene(){return this._scene}set scene(e){this._scene=e}get gameObjects(){return(e=>{var t;const s=(null===(t=null==e?void 0:e.scene)||void 0===t?void 0:t.gameObjects)||[],r=null==e?void 0:e.multiScenes.map((({gameObjects:e})=>e));let o=[];for(const e of r)o=[...o,...e];return[...s,...o]})(this)}addSystem(e,s){return g(this,void 0,void 0,(function*(){let r;if(e instanceof Function)r=new e(s);else{if(!(e instanceof k))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){p[t.systemName]=t.observerInfo,h[t.systemName]=e}(r,r.constructor),function(e){const s=[];e instanceof Array?s.push(...e):s.push(e);for(const e of s)for(const s in e.observerInfo){l[s]=l[s]||[];const r=l[s];for(const o of e.observerInfo[s])-1===r.findIndex((e=>t.isEqual(e,o)))&&l[s].push(o)}}(r.constructor);try{r.awake&&r.awake()}catch(e){console.error(`${r.constructor.systemName} awake error`,e)}return this.systems.push(r),r}console.warn(`${r.constructor.systemName} System has been added`)}))}removeSystem(e){if(!e)return;let t=-1;"string"==typeof e?t=this.systems.findIndex((t=>t.name===e)):e instanceof Function?t=this.systems.findIndex((t=>t.constructor===e)):e instanceof k&&(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{D(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{D(t),t.update&&t.update(e)}catch(e){console.error(`${t.constructor.systemName} update error`,e)}for(const t of this.systems)try{t.lateUpdate&&t.lateUpdate(e)}catch(e){console.error(`${t.constructor.systemName} lateUpdate error`,e)}}))}triggerResume(){(e=>{for(const t of e)for(const e of t.components)try{e.onResume&&e.onResume()}catch(s){console.error(`gameObject: ${t.name}, ${e.name}, onResume error`,s)}})(this.gameObjects);for(const e of this.systems)try{e.onResume&&e.onResume()}catch(t){console.error(`${e.constructor.systemName}, onResume error`,t)}}triggerPause(){(e=>{for(const t of e)for(const e of t.components)try{e.onPause&&e.onPause()}catch(s){console.error(`gameObject: ${t.name}, ${e.name}, onResume error`,s)}})(this.gameObjects);for(const e of this.systems)try{e.onPause&&e.onPause()}catch(t){console.error(`${e.constructor.systemName}, onPause error`,t)}}destroySystems(){for(const e of[...this.systems])this.removeSystem(e);this.systems.length=0}destroy(){this.removeAllListeners(),this.pause(),this.scene.destroy(),this.destroySystems(),this.ticker=null,this.scene=null,this.canvas=null,this.multiScenes=null}loadScene({scene:e,mode:t=exports.LOAD_SCENE_MODE.SINGLE,params:s={}}){if(e){switch(t){case exports.LOAD_SCENE_MODE.SINGLE:this.scene=e;break;case exports.LOAD_SCENE_MODE.MULTI_CANVAS:this.multiScenes.push(e)}this.emit("sceneChanged",{scene:e,mode:t,params:s})}}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 $(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 F 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,(w=exports.LOAD_EVENT||(exports.LOAD_EVENT={})).START="start",w.PROGRESS="progress",w.LOADED="loaded",w.COMPLETE="complete",w.ERROR="error",exports.RESOURCE_TYPE=void 0,(I=exports.RESOURCE_TYPE||(exports.RESOURCE_TYPE={})).IMAGE="IMAGE",I.SPRITE="SPRITE",I.SPRITE_ANIMATION="SPRITE_ANIMATION",I.AUDIO="AUDIO",I.VIDEO="VIDEO",I.FONT="FONT";const G=new class extends n{constructor(e){super(),this.timeout=6e3,this.preProcessResourceHandlers=[],this.resourcesMap={},this.makeInstanceFunctions={},this.destroyInstanceFunctions={},this.promiseMap={},e&&"number"==typeof e.timeout&&(this.timeout=e.timeout)}loadConfig(e){this.addResource(e),this.preload()}loadSingle(e){return this.addResource([e]),this.getResource(e.name)}addResource(e){if(!e||e.length<1)console.warn("no resources");else for(const t of e)this.resourcesMap[t.name]?console.warn(t.name+" was already added"):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 F({resource:this,resourceTotal:e.length}),this.loadResource({names:e,preload:!0})}getResource(e){return g(this,void 0,void 0,(function*(){return this.loadResource({names:[e]}),this.promiseMap[e]||Promise.resolve({})}))}instance(e){return g(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 g(this,void 0,void 0,(function*(){yield this._destroy(e)}))}_destroy(e,t=!1){return g(this,void 0,void 0,(function*(){const s=this.resourcesMap[e];if(s){if(!t)try{this.destroyInstanceFunctions[s.type]&&(yield this.destroyInstanceFunctions[s.type](s))}catch(e){console.warn(`destroy resource ${s.name} error with '${e.message}'`)}delete this.promiseMap[e],s.data={},s.complete=!1,s.instance=void 0,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=>g(this,void 0,void 0,(function*(){var s;this.promiseMap[e]=new Promise((t=>o[e]=t));const n=this.resourcesMap[e];for(const e of this.preProcessResourceHandlers)e(n);for(const i in n.src){if("data"===n.src[i].type)n.data[i]=n.src[i].data,this.doComplete(e,o[e],t);else{let a=null===(s=n.src[i])||void 0===s?void 0:s.url;if(console.log(a),"string"==typeof a&&a.startsWith("//")&&(a=`https:${n.src[i].url}`),"atlas"===i){const s=r.Assets.load(n.src.image.url).catch((s=>{this.onError({preload:t,errMsg:s.message,resource:{metadata:{key:i,name:e,resolves:o}}})}));r.Assets.add({alias:a,src:a,data:{resolve:()=>s,imageTexture:yield s}})}else{const s={alias:a,src:a};if(n.type===exports.RESOURCE_TYPE.SPRITE||n.type===exports.RESOURCE_TYPE.SPRITE_ANIMATION){if("json"===n.src[i].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:i,name:e,resolves:o}}})}}else n.type===exports.RESOURCE_TYPE.FONT&&(s.data={family:e});r.Assets.add(s)}r.Assets.load(a).then((s=>{this.onLoad({preload:t,resource:{metadata:{key:i,name:e,resolves:o},data:s}})})).catch((s=>{console.log(">>>E",s),this.onError({preload:t,errMsg:s.message,resource:{metadata:{key:i,name:e,resolves:o}}})}))}}}))))}doComplete(e,t,s=!1){return g(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 g(this,void 0,void 0,(function*(){const{metadata:{key:s,name:r,resolves:o},data:n}=t,i=this.resourcesMap[r];i?(i.data[s]=n,this.doComplete(r,o[r],e)):console.warn("no resource data found")}))}onError({errMsg:e,preload:t=!1,resource:s}){return g(this,void 0,void 0,(function*(){const{metadata:{name:r,resolves:o}}=s;if(this._destroy(r,!0),o[r]({}),t){const t={name:r,resource:this.resourcesMap[r],success:!1,errMsg:e};this.progress.onProgress(t)}}))}},U={IDEProp:V,componentObserver:$},Y="2.0.1-beta.18";console.log(`Eva.js version: ${Y}`);exports.Component=c,exports.Game=L,exports.GameObject=R,exports.IDEProp=V,exports.RESOURCE_TYPE_STRATEGY={},exports.Scene=j,exports.System=k,exports.Transform=_,exports.componentObserver=$,exports.decorators=U,exports.resource=G,exports.version=Y;
|
|
16
|
+
function E(e,t,s,r){var o,n=arguments.length,i=n<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,s):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,s,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(i=(n<3?o(i):n>3?o(t,s,i):o(t,s))||i);return n>3&&i&&Object.defineProperty(t,s,i),i}function g(e,t,s,r){return new(s||(s=Promise))((function(o,n){function i(e){try{c(r.next(e))}catch(e){n(e)}}function a(e){try{c(r.throw(e))}catch(e){n(e)}}function c(e){e.done?o(e.value):new s((function(t){t(e.value)})).then(i,a)}c((r=r.apply(e,t||[])).next())}))}class v extends c{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}}v.componentName="Transform",E([s.type("vector2"),s.step(1)],v.prototype,"position",void 0),E([s.type("size"),s.step(1)],v.prototype,"size",void 0),E([s.type("vector2"),s.step(.1)],v.prototype,"origin",void 0),E([s.type("vector2"),s.step(.1)],v.prototype,"anchor",void 0),E([s.type("vector2"),s.step(.1)],v.prototype,"scale",void 0),E([s.type("vector2"),s.step(.1)],v.prototype,"skew",void 0),E([s.type("number"),s.step(.1)],v.prototype,"rotation",void 0);var _=v;let b=0;class O{constructor(e,t){this._componentCache={},this.components=[],this.destroyed=!1,this._name=e,this.id=++b,this.addComponent(_,t)}get transform(){return this.getComponent(_)}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 O))throw new Error("addChild only receive GameObject");if(!this.transform)throw new Error(`gameObject '${this.name}' has been destroy`);e.transform.parent=this.transform,e.scene=this.scene}}removeChild(e){return e instanceof O&&e.parent&&e.parent===this?(e.transform.parent=null,e.scene=null,e):e}addComponent(e,t){if(this.destroyed)return;const s=function(e){return e instanceof 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 c))throw new Error("addComponent recieve Component and Component Constructor");r=e}if(r.gameObject)throw new Error(`component has been added on gameObject ${r.gameObject.name}`);return r.gameObject=this,r.init&&r.init(r.__componentDefaultParams),function(e,t=e.name){var s,r;for(const o in p)(p[o]||{})[t]&&(null===(r=null===(s=m[o])||void 0===s?void 0:s.componentObserver)||void 0===r||r.add({component:e,type:exports.OBSERVER_TYPE.ADD,componentName:t}))}(r,r.name),function(e,t=e.name){if(t&&l[t]){if(!(e&&(s=e,s&&s.constructor&&"componentName"in s.constructor)))throw new Error("component param must be an instance of Component");var s;if(!e.gameObject||!e.gameObject.id)throw new Error("component should be add to a gameObject");for(const s of l[t]){const{property:r,key:o}=u(e,s.prop);f({obj:r,key:o,prop:s,component:e,componentName:t})}}}(r,r.name),this.components.push(r),this._componentCache[s]=r,r.awake&&r.awake(),r}removeComponent(e){let t;if("string"==typeof e?t=e:e instanceof c?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(),y(s,e),s.gameObject=void 0,s}getComponent(e){let t;return"string"==typeof e?t=e:e instanceof c?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=O;var T=class{constructor(){this.events=[]}add({component:e,prop:s,type:r,componentName:o}){if(r===exports.OBSERVER_TYPE.REMOVE){if(this.events.find((t=>t.component===e&&t.type===exports.OBSERVER_TYPE.ADD)))return void(this.events=this.events.filter((t=>t.component!==e)));this.events=this.events.filter((t=>t.component!==e))}const n=this.events.findIndex((o=>o.component===e&&t.isEqual(o.prop,s)&&o.type===r));n>-1&&this.events.splice(n,1),this.events.push({gameObject:e.gameObject,component:e,prop:s,type:r,componentName:o})}getChanged(){return this.events}get changed(){return this.events}clear(){const e=this.events;return this.events=[],e}};var k=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 S=function(){let e=null;return e=Date.now?Date.now:()=>(new Date).getTime(),e}(),x={originTime:0,playbackRate:1};class C{constructor(e,t){e instanceof C&&(t=e,e={}),e=Object.assign({},x,e),t&&(this._parent=t),this._createTime=S(),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:S()-this._createTime}get parent(){return this._parent}get lastTimeMark(){return this._timeMark[this._timeMark.length-1]}markTime({time:e=this.currentTime,entropy:t=this.entropy,playbackRate:s=this.playbackRate}={}){const r={globalTime:this.globalTime,localTime:e,entropy:t,playbackRate:s,globalEntropy:this.globalEntropy};this._timeMark.push(r)}get currentTime(){const{localTime:e,globalTime:t}=this.lastTimeMark;return e+(this.globalTime-t)*this.playbackRate}set currentTime(e){this.markTime({time:e})}get globalEntropy(){return this._parent?this._parent.entropy:this.globalTime}get entropy(){const{entropy:e,globalEntropy:t}=this.lastTimeMark;return e+Math.abs((this.globalEntropy-t)*this.playbackRate)}set entropy(e){if(this.entropy>e){const t=this.seekTimeMark(e);this._timeMark.length=t+1}this.markTime({entropy:e})}fork(e){return new C(e,this)}seekGlobalTime(e){const t=this.seekTimeMark(e),s=this._timeMark[t],{entropy:r,playbackRate:o,globalTime:n}=s;return n+(e-r)/Math.abs(o)}seekLocalTime(e){const t=this.seekTimeMark(e),s=this._timeMark[t],{localTime:r,entropy:o,playbackRate:n}=s;return n>0?r+(e-o):r-(e-o)}seekTimeMark(e){const t=this._timeMark;let s=0,r=t.length-1;if(e<=t[s].entropy)return s;if(e>=t[r].entropy)return r;let o=Math.floor((s+r)/2);for(;o>s&&o<r;){if(e===t[o].entropy)return o;e<t[o].entropy?r=o:e>t[o].entropy&&(s=o),o=Math.floor((s+r)/2)}return s}get playbackRate(){return this._playbackRate}set playbackRate(e){e!==this.playbackRate&&(this.markTime({playbackRate:e}),this._playbackRate=e)}get paused(){if(0===this.playbackRate)return!0;let e=this.parent;for(;e;){if(0===e.playbackRate)return!0;e=e.parent}return!1}}var M=C;const N={autoStart:!0,frameRate:60};var P=class{constructor(e){e=Object.assign({},N,e),this._frameCount=0,this._frameDuration=1e3/e.frameRate,this.autoStart=e.autoStart,this.frameRate=e.frameRate,this.timeline=new M({originTime:0,playbackRate:1}),this._lastFrameTime=this.timeline.currentTime,this._tickers=new Set,this._requestId=null,this._ticker=()=>{this._started&&(this._requestId=requestAnimationFrame(this._ticker),this.update())},this.autoStart&&this.start()}update(){const e=this.timeline.currentTime,t=e-this._lastFrameTime;if(t>=this._frameDuration){const s=e-t%this._frameDuration,r=s-this._lastFrameTime;this._lastFrameTime=s;const o={deltaTime:r,time:s,currentTime:s,frameCount:++this._frameCount,fps:Math.round(1e3/r)};for(const e of this._tickers)"function"==typeof e&&e(o)}}add(e){this._tickers.add(e)}remove(e){this._tickers.delete(e)}start(){this._started||(this._started=!0,this.timeline.playbackRate=1,this._requestId=requestAnimationFrame(this._ticker))}pause(){this._started=!1,this.timeline.playbackRate=0}setPlaybackRate(e){this.timeline.playbackRate=e}};var A,j=class extends R{constructor(e,t){super(e,t),this.gameObjects=[],this.scene=this}addGameObject(e){this.gameObjects.push(e),e.transform&&(e.transform.inScene=!0)}removeGameObject(e){const t=this.gameObjects.indexOf(e);-1!==t&&(e.transform&&(e.transform.inScene=!1),this.gameObjects.splice(t,1))}destroy(){this.scene=null,super.destroy(),this.gameObjects=null,this.canvas=null}};exports.LOAD_SCENE_MODE=void 0,(A=exports.LOAD_SCENE_MODE||(exports.LOAD_SCENE_MODE={})).SINGLE="SINGLE",A.MULTI_CANVAS="MULTI_CANVAS";const w=e=>{if((e instanceof k||e instanceof c)&&!e.started){e.started=!0;try{e.start&&e.start()}catch(t){e instanceof c?console.error(`${e.constructor.componentName} start error`,t):console.error(`${e.constructor.systemName} start error`,t)}}};var D,I,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:r=!0}={}){return g(this,void 0,void 0,(function*(){if("undefined"!=typeof window&&window.__EVA_INSPECTOR_ENV__&&(window.__EVA_GAME_INSTANCE__=this),this.ticker=new P({autoStart:!1,frameRate:t}),this.initTicker(),e&&e.length)for(const t of e)yield this.addSystem(t);r&&this.loadScene(new j("scene")),s&&this.start()}))}get scene(){return this._scene}set scene(e){this._scene=e}get gameObjects(){return(e=>{var t;const s=(null===(t=null==e?void 0:e.scene)||void 0===t?void 0:t.gameObjects)||[],r=null==e?void 0:e.multiScenes.map((({gameObjects:e})=>e));let o=[];for(const e of r)o=[...o,...e];return[...s,...o]})(this)}addSystem(e,s){return g(this,void 0,void 0,(function*(){let r;if(e instanceof Function)r=new e(s);else{if(!(e instanceof k))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){p[t.systemName]=t.observerInfo,m[t.systemName]=e}(r,r.constructor),function(e){const s=[];e instanceof Array?s.push(...e):s.push(e);for(const e of s)for(const s in e.observerInfo){l[s]=l[s]||[];const r=l[s];for(const o of e.observerInfo[s])-1===r.findIndex((e=>t.isEqual(e,o)))&&l[s].push(o)}}(r.constructor);try{r.awake&&r.awake()}catch(e){console.error(`${r.constructor.systemName} awake error`,e)}return this.systems.push(r),r}console.warn(`${r.constructor.systemName} System has been added`)}))}removeSystem(e){if(!e)return;let t=-1;"string"==typeof e?t=this.systems.findIndex((t=>t.name===e)):e instanceof Function?t=this.systems.findIndex((t=>t.constructor===e)):e instanceof k&&(t=this.systems.findIndex((t=>t===e))),t>-1&&(this.systems[t].destroy&&this.systems[t].destroy(),this.systems.splice(t,1))}getSystem(e){return this.systems.find((t=>"string"==typeof e?t.name===e:t instanceof e))}pause(){this.playing&&(this.playing=!1,this.ticker.pause(),this.triggerPause())}start(){this.playing||(this.playing=!0,this.started=!0,this.ticker.start())}resume(){this.playing||(this.playing=!0,this.ticker.start(),this.triggerResume())}initTicker(){this.ticker.add((e=>{this.scene&&((e,t=[])=>{for(const s of t)for(const t of s.components)try{w(t),t.update&&t.update(e)}catch(e){console.error(`gameObject: ${s.name} ${t.name} update error`,e)}for(const s of t)for(const t of s.components)try{t.lateUpdate&&t.lateUpdate(e)}catch(e){console.error(`gameObject: ${s.name} ${t.name} lateUpdate error`,e)}})(e,this.gameObjects);for(const t of this.systems)try{w(t),t.update&&t.update(e)}catch(e){console.error(`${t.constructor.systemName} update error`,e)}for(const t of this.systems)try{t.lateUpdate&&t.lateUpdate(e)}catch(e){console.error(`${t.constructor.systemName} lateUpdate error`,e)}}))}triggerResume(){(e=>{for(const t of e)for(const e of t.components)try{e.onResume&&e.onResume()}catch(s){console.error(`gameObject: ${t.name}, ${e.name}, onResume error`,s)}})(this.gameObjects);for(const e of this.systems)try{e.onResume&&e.onResume()}catch(t){console.error(`${e.constructor.systemName}, onResume error`,t)}}triggerPause(){(e=>{for(const t of e)for(const e of t.components)try{e.onPause&&e.onPause()}catch(s){console.error(`gameObject: ${t.name}, ${e.name}, onResume error`,s)}})(this.gameObjects);for(const e of this.systems)try{e.onPause&&e.onPause()}catch(t){console.error(`${e.constructor.systemName}, onPause error`,t)}}destroySystems(){for(const e of[...this.systems])this.removeSystem(e);this.systems.length=0}destroy(){this.removeAllListeners(),this.pause(),this.scene.destroy(),this.destroySystems(),this.ticker=null,this.scene=null,this.canvas=null,this.multiScenes=null}loadScene({scene:e,mode:t=exports.LOAD_SCENE_MODE.SINGLE,params:s={}}){if(e){switch(t){case exports.LOAD_SCENE_MODE.SINGLE:this.scene=e;break;case exports.LOAD_SCENE_MODE.MULTI_CANVAS:this.multiScenes.push(e)}this.emit("sceneChanged",{scene:e,mode:t,params:s})}}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 $(e,t){e.constructor.IDEProps||(e.constructor.IDEProps=[]),e.constructor.IDEProps.push(t)}function V(e={}){return function(t){if(!t.observerInfo){for(const t in e)for(const s in e[t]){let r;"string"==typeof e[t][s]&&(e[t][s]=[e[t][s]]),Array.isArray(e[t][s])&&(r={prop:e[t][s],deep:!1},e[t][s]=r),r=e[t][s],"string"==typeof r.prop&&(r.prop=[r.prop])}t.observerInfo=e}}}class F 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,(D=exports.LOAD_EVENT||(exports.LOAD_EVENT={})).START="start",D.PROGRESS="progress",D.LOADED="loaded",D.COMPLETE="complete",D.ERROR="error",exports.RESOURCE_TYPE=void 0,(I=exports.RESOURCE_TYPE||(exports.RESOURCE_TYPE={})).IMAGE="IMAGE",I.SPRITE="SPRITE",I.SPRITE_ANIMATION="SPRITE_ANIMATION",I.AUDIO="AUDIO",I.VIDEO="VIDEO",I.FONT="FONT";const G=new class extends n{constructor(e){super(),this.timeout=6e3,this.preProcessResourceHandlers=[],this.resourcesMap={},this.makeInstanceFunctions={},this.destroyInstanceFunctions={},this.promiseMap={},e&&"number"==typeof e.timeout&&(this.timeout=e.timeout)}loadConfig(e){this.addResource(e),this.preload()}loadSingle(e){return this.addResource([e]),this.getResource(e.name)}addResource(e){if(!e||e.length<1)console.warn("no resources");else for(const t of e)this.resourcesMap[t.name]?console.warn(t.name+" was already added"):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 F({resource:this,resourceTotal:e.length}),this.loadResource({names:e,preload:!0})}getResource(e){return g(this,void 0,void 0,(function*(){return this.loadResource({names:[e]}),this.promiseMap[e]||Promise.resolve({})}))}instance(e){return g(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 g(this,void 0,void 0,(function*(){yield this._destroy(e)}))}_destroy(e,t=!1){var s;return g(this,void 0,void 0,(function*(){const o=this.resourcesMap[e];if(o){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}'`)}if(o.src){const t=[];for(const e in o.src){let r=null===(s=o.src[e])||void 0===s?void 0:s.url;r&&("string"==typeof r&&r.startsWith("//")&&(r=`https:${r}`),t.push(r))}if(t.length>0)try{yield r.Assets.unload(t)}catch(t){console.warn(`Failed to unload assets for ${e}: ${t.message}`)}}delete this.promiseMap[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=>g(this,void 0,void 0,(function*(){var s;this.promiseMap[e]=new Promise((t=>o[e]=t));const n=this.resourcesMap[e];for(const e of this.preProcessResourceHandlers)e(n);for(const i in n.src){if("data"===n.src[i].type)n.data[i]=n.src[i].data,this.doComplete(e,o[e],t);else{let a=null===(s=n.src[i])||void 0===s?void 0:s.url;if(console.log(a),"string"==typeof a&&a.startsWith("//")&&(a=`https:${n.src[i].url}`),"atlas"===i){const s=r.Assets.load(n.src.image.url).catch((s=>{this.onError({preload:t,errMsg:s.message,resource:{metadata:{key:i,name:e,resolves:o}}})}));r.Assets.add({alias:a,src:a,data:{resolve:()=>s,imageTexture:yield s}})}else{const s={alias:a,src:a};if(n.type===exports.RESOURCE_TYPE.SPRITE||n.type===exports.RESOURCE_TYPE.SPRITE_ANIMATION){if("json"===n.src[i].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:i,name:e,resolves:o}}})}}else n.type===exports.RESOURCE_TYPE.FONT&&(s.data={family:e});r.Assets.add(s)}r.Assets.load(a).then((s=>{this.onLoad({preload:t,resource:{metadata:{key:i,name:e,resolves:o},data:s}})})).catch((s=>{console.log(">>>E",s),this.onError({preload:t,errMsg:s.message,resource:{metadata:{key:i,name:e,resolves:o}}})}))}}}))))}doComplete(e,t,s=!1){return g(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 g(this,void 0,void 0,(function*(){const{metadata:{key:s,name:r,resolves:o},data:n}=t,i=this.resourcesMap[r];i?(i.data[s]=n,this.doComplete(r,o[r],e)):console.warn("no resource data found")}))}onError({errMsg:e,preload:t=!1,resource:s}){return g(this,void 0,void 0,(function*(){const{metadata:{name:r,resolves:o}}=s;if(this._destroy(r,!0),o[r]({}),t){const t={name:r,resource:this.resourcesMap[r],success:!1,errMsg:e};this.progress.onProgress(t)}}))}},U={IDEProp:$,componentObserver:V},Y="2.0.1-beta.19";console.log(`Eva.js version: ${Y}`);exports.Component=c,exports.Game=L,exports.GameObject=R,exports.IDEProp=$,exports.RESOURCE_TYPE_STRATEGY={},exports.Scene=j,exports.System=k,exports.Transform=_,exports.componentObserver=V,exports.decorators=U,exports.resource=G,exports.version=Y;
|
package/dist/eva.js.d.ts
CHANGED
package/dist/eva.js.esm.js
CHANGED
|
@@ -1222,6 +1222,7 @@ class Resource extends EventEmitter {
|
|
|
1222
1222
|
});
|
|
1223
1223
|
}
|
|
1224
1224
|
_destroy(name, loadError = false) {
|
|
1225
|
+
var _a;
|
|
1225
1226
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1226
1227
|
const resource = this.resourcesMap[name];
|
|
1227
1228
|
if (!resource)
|
|
@@ -1236,6 +1237,26 @@ class Resource extends EventEmitter {
|
|
|
1236
1237
|
console.warn(`destroy resource ${resource.name} error with '${e.message}'`);
|
|
1237
1238
|
}
|
|
1238
1239
|
}
|
|
1240
|
+
if (resource.src) {
|
|
1241
|
+
const urlsToUnload = [];
|
|
1242
|
+
for (const key in resource.src) {
|
|
1243
|
+
let url = (_a = resource.src[key]) === null || _a === void 0 ? void 0 : _a.url;
|
|
1244
|
+
if (url) {
|
|
1245
|
+
if (typeof url === 'string' && url.startsWith('//')) {
|
|
1246
|
+
url = `https:${url}`;
|
|
1247
|
+
}
|
|
1248
|
+
urlsToUnload.push(url);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
if (urlsToUnload.length > 0) {
|
|
1252
|
+
try {
|
|
1253
|
+
yield Assets.unload(urlsToUnload);
|
|
1254
|
+
}
|
|
1255
|
+
catch (e) {
|
|
1256
|
+
console.warn(`Failed to unload assets for ${name}: ${e.message}`);
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1239
1260
|
delete this.promiseMap[name];
|
|
1240
1261
|
resource.data = {};
|
|
1241
1262
|
resource.complete = false;
|
|
@@ -1425,7 +1446,7 @@ const decorators = {
|
|
|
1425
1446
|
IDEProp,
|
|
1426
1447
|
componentObserver,
|
|
1427
1448
|
};
|
|
1428
|
-
const version = '2.0.1-beta.
|
|
1449
|
+
const version = '2.0.1-beta.19';
|
|
1429
1450
|
console.log(`Eva.js version: ${version}`);
|
|
1430
1451
|
const RESOURCE_TYPE_STRATEGY = {};
|
|
1431
1452
|
|