@eva/eva.js 2.0.1-beta.0 → 2.0.1-beta.10
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 +39 -3
- package/dist/EVA.min.js +1 -1
- package/dist/eva.js.cjs.js +28 -3
- package/dist/eva.js.cjs.prod.js +1 -1
- package/dist/eva.js.d.ts +14 -2
- package/dist/eva.js.esm.js +28 -3
- package/package.json +1 -1
package/dist/EVA.js
CHANGED
|
@@ -2070,6 +2070,31 @@ var _EVA_IIFE_EVA = function (exports, pixi_js) {
|
|
|
2070
2070
|
params
|
|
2071
2071
|
});
|
|
2072
2072
|
}
|
|
2073
|
+
pauseScene({
|
|
2074
|
+
scene
|
|
2075
|
+
}) {
|
|
2076
|
+
this.emit('pauseScene', {
|
|
2077
|
+
scene
|
|
2078
|
+
});
|
|
2079
|
+
}
|
|
2080
|
+
startScene({
|
|
2081
|
+
scene
|
|
2082
|
+
}) {
|
|
2083
|
+
this.emit('startScene', {
|
|
2084
|
+
scene
|
|
2085
|
+
});
|
|
2086
|
+
}
|
|
2087
|
+
destroyScene({
|
|
2088
|
+
scene
|
|
2089
|
+
}) {
|
|
2090
|
+
const index = this.multiScenes.findIndex(item => item === scene);
|
|
2091
|
+
if (index > -1) {
|
|
2092
|
+
const scene = this.multiScenes.splice(index, 1)[0];
|
|
2093
|
+
this.emit('sceneDestroyed', {
|
|
2094
|
+
scene
|
|
2095
|
+
});
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2073
2098
|
}
|
|
2074
2099
|
var Game$1 = Game;
|
|
2075
2100
|
function IDEProp(target, propertyKey) {
|
|
@@ -2151,6 +2176,7 @@ var _EVA_IIFE_EVA = function (exports, pixi_js) {
|
|
|
2151
2176
|
RESOURCE_TYPE["SPRITE_ANIMATION"] = "SPRITE_ANIMATION";
|
|
2152
2177
|
RESOURCE_TYPE["AUDIO"] = "AUDIO";
|
|
2153
2178
|
RESOURCE_TYPE["VIDEO"] = "VIDEO";
|
|
2179
|
+
RESOURCE_TYPE["FONT"] = "FONT";
|
|
2154
2180
|
})(exports.RESOURCE_TYPE || (exports.RESOURCE_TYPE = {}));
|
|
2155
2181
|
class Resource extends EE {
|
|
2156
2182
|
constructor(options) {
|
|
@@ -2183,8 +2209,10 @@ var _EVA_IIFE_EVA = function (exports, pixi_js) {
|
|
|
2183
2209
|
console.warn(res.name + ' was already added');
|
|
2184
2210
|
continue;
|
|
2185
2211
|
}
|
|
2186
|
-
|
|
2187
|
-
|
|
2212
|
+
if (res) {
|
|
2213
|
+
this.resourcesMap[res.name] = res;
|
|
2214
|
+
this.resourcesMap[res.name].data = {};
|
|
2215
|
+
}
|
|
2188
2216
|
}
|
|
2189
2217
|
}
|
|
2190
2218
|
addPreProcessResourceHandler(handler) {
|
|
@@ -2335,6 +2363,10 @@ var _EVA_IIFE_EVA = function (exports, pixi_js) {
|
|
|
2335
2363
|
});
|
|
2336
2364
|
}
|
|
2337
2365
|
}
|
|
2366
|
+
} else if (res.type === exports.RESOURCE_TYPE.FONT) {
|
|
2367
|
+
options.data = {
|
|
2368
|
+
family: name
|
|
2369
|
+
};
|
|
2338
2370
|
}
|
|
2339
2371
|
pixi_js.Assets.add(options);
|
|
2340
2372
|
}
|
|
@@ -2416,6 +2448,10 @@ var _EVA_IIFE_EVA = function (exports, pixi_js) {
|
|
|
2416
2448
|
data
|
|
2417
2449
|
} = resource;
|
|
2418
2450
|
const res = this.resourcesMap[name];
|
|
2451
|
+
if (!res) {
|
|
2452
|
+
console.warn('no resource data found');
|
|
2453
|
+
return;
|
|
2454
|
+
}
|
|
2419
2455
|
res.data[key] = data;
|
|
2420
2456
|
this.doComplete(name, resolves[name], preload);
|
|
2421
2457
|
});
|
|
@@ -2451,7 +2487,7 @@ var _EVA_IIFE_EVA = function (exports, pixi_js) {
|
|
|
2451
2487
|
IDEProp,
|
|
2452
2488
|
componentObserver
|
|
2453
2489
|
};
|
|
2454
|
-
const version = '2.0.
|
|
2490
|
+
const version = '2.0.1-beta.9';
|
|
2455
2491
|
console.log(`Eva.js version: ${version}`);
|
|
2456
2492
|
const RESOURCE_TYPE_STRATEGY = {};
|
|
2457
2493
|
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 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,A=Object.prototype,P=k.toString,S=A.hasOwnProperty,C=RegExp("^"+P.call(S).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"),Ae=I(c,"Set"),Pe="[object Map]",Se="[object Promise]",Ce="[object Set]",Me="[object WeakMap]",Ie="[object DataView]",Ne=R(we),De=R(_e),xe=R(ke),Le=R(Ae),Ve=R(N),$e=y;(we&&$e(new we(new ArrayBuffer(1)))!=Ie||_e&&$e(new _e)!=Pe||ke&&$e(ke.resolve())!=Se||Ae&&$e(new Ae)!=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 Pe;case xe:return Se;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 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}else console.error("Cannot destroy gameObject that have already been destroyed.")}}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 At={autoStart:!0,frameRate:60};var Pt=class{constructor(e){e=_extends({},At,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 St,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,(St=e.LOAD_SCENE_MODE||(e.LOAD_SCENE_MODE={})).SINGLE="SINGLE",St.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 Pt({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})}}};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";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"):(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)&&"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}}})}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;this.resourcesMap[n].data[r]=s,this.doComplete(n,o[n],e)}))}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.0";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;
|
|
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 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}else console.error("Cannot destroy gameObject that have already been destroyed.")}}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.9";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;
|
package/dist/eva.js.cjs.js
CHANGED
|
@@ -1055,6 +1055,19 @@ class Game extends EventEmitter__default {
|
|
|
1055
1055
|
}
|
|
1056
1056
|
this.emit('sceneChanged', { scene, mode, params });
|
|
1057
1057
|
}
|
|
1058
|
+
pauseScene({ scene }) {
|
|
1059
|
+
this.emit('pauseScene', { scene });
|
|
1060
|
+
}
|
|
1061
|
+
startScene({ scene }) {
|
|
1062
|
+
this.emit('startScene', { scene });
|
|
1063
|
+
}
|
|
1064
|
+
destroyScene({ scene }) {
|
|
1065
|
+
const index = this.multiScenes.findIndex(item => item === scene);
|
|
1066
|
+
if (index > -1) {
|
|
1067
|
+
const scene = this.multiScenes.splice(index, 1)[0];
|
|
1068
|
+
this.emit('sceneDestroyed', { scene });
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1058
1071
|
}
|
|
1059
1072
|
var Game$1 = Game;
|
|
1060
1073
|
|
|
@@ -1138,6 +1151,7 @@ exports.RESOURCE_TYPE = void 0;
|
|
|
1138
1151
|
RESOURCE_TYPE["SPRITE_ANIMATION"] = "SPRITE_ANIMATION";
|
|
1139
1152
|
RESOURCE_TYPE["AUDIO"] = "AUDIO";
|
|
1140
1153
|
RESOURCE_TYPE["VIDEO"] = "VIDEO";
|
|
1154
|
+
RESOURCE_TYPE["FONT"] = "FONT";
|
|
1141
1155
|
})(exports.RESOURCE_TYPE || (exports.RESOURCE_TYPE = {}));
|
|
1142
1156
|
class Resource extends EventEmitter__default {
|
|
1143
1157
|
constructor(options) {
|
|
@@ -1170,8 +1184,10 @@ class Resource extends EventEmitter__default {
|
|
|
1170
1184
|
console.warn(res.name + ' was already added');
|
|
1171
1185
|
continue;
|
|
1172
1186
|
}
|
|
1173
|
-
|
|
1174
|
-
|
|
1187
|
+
if (res) {
|
|
1188
|
+
this.resourcesMap[res.name] = res;
|
|
1189
|
+
this.resourcesMap[res.name].data = {};
|
|
1190
|
+
}
|
|
1175
1191
|
}
|
|
1176
1192
|
}
|
|
1177
1193
|
addPreProcessResourceHandler(handler) {
|
|
@@ -1313,6 +1329,11 @@ class Resource extends EventEmitter__default {
|
|
|
1313
1329
|
}
|
|
1314
1330
|
}
|
|
1315
1331
|
}
|
|
1332
|
+
else if (res.type === exports.RESOURCE_TYPE.FONT) {
|
|
1333
|
+
options.data = {
|
|
1334
|
+
family: name,
|
|
1335
|
+
};
|
|
1336
|
+
}
|
|
1316
1337
|
pixi_js.Assets.add(options);
|
|
1317
1338
|
}
|
|
1318
1339
|
pixi_js.Assets.load(url)
|
|
@@ -1379,6 +1400,10 @@ class Resource extends EventEmitter__default {
|
|
|
1379
1400
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1380
1401
|
const { metadata: { key, name, resolves }, data, } = resource;
|
|
1381
1402
|
const res = this.resourcesMap[name];
|
|
1403
|
+
if (!res) {
|
|
1404
|
+
console.warn('no resource data found');
|
|
1405
|
+
return;
|
|
1406
|
+
}
|
|
1382
1407
|
res.data[key] = data;
|
|
1383
1408
|
this.doComplete(name, resolves[name], preload);
|
|
1384
1409
|
});
|
|
@@ -1406,7 +1431,7 @@ const decorators = {
|
|
|
1406
1431
|
IDEProp,
|
|
1407
1432
|
componentObserver,
|
|
1408
1433
|
};
|
|
1409
|
-
const version = '2.0.
|
|
1434
|
+
const version = '2.0.1-beta.9';
|
|
1410
1435
|
console.log(`Eva.js version: ${version}`);
|
|
1411
1436
|
const RESOURCE_TYPE_STRATEGY = {};
|
|
1412
1437
|
|
package/dist/eva.js.cjs.prod.js
CHANGED
|
@@ -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 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}else console.error("Cannot destroy gameObject that have already been destroyed.")}}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}(),C={originTime:0,playbackRate:1};class M{constructor(e,t){e instanceof M&&(t=e,e={}),e=Object.assign({},C,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 M(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 x=M;const P={autoStart:!0,frameRate:60};var N=class{constructor(e){e=Object.assign({},P,e),this._frameCount=0,this._frameDuration=1e3/e.frameRate,this.autoStart=e.autoStart,this.frameRate=e.frameRate,this.timeline=new x({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 N({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})}}};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 G 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";const U=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"):(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 G({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)&&"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}}})}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;this.resourcesMap[r].data[s]=n,this.doComplete(r,o[r],e)}))}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)}}))}},F={IDEProp:V,componentObserver:$},Y="2.0.0";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=F,exports.resource=U,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 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}else console.error("Cannot destroy gameObject that have already been destroyed.")}}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}(),C={originTime:0,playbackRate:1};class x{constructor(e,t){e instanceof x&&(t=e,e={}),e=Object.assign({},C,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 x(e,this)}seekGlobalTime(e){const t=this.seekTimeMark(e),s=this._timeMark[t],{entropy:r,playbackRate:o,globalTime:n}=s;return n+(e-r)/Math.abs(o)}seekLocalTime(e){const t=this.seekTimeMark(e),s=this._timeMark[t],{localTime:r,entropy:o,playbackRate:n}=s;return n>0?r+(e-o):r-(e-o)}seekTimeMark(e){const t=this._timeMark;let s=0,r=t.length-1;if(e<=t[s].entropy)return s;if(e>=t[r].entropy)return r;let o=Math.floor((s+r)/2);for(;o>s&&o<r;){if(e===t[o].entropy)return o;e<t[o].entropy?r=o:e>t[o].entropy&&(s=o),o=Math.floor((s+r)/2)}return s}get playbackRate(){return this._playbackRate}set playbackRate(e){e!==this.playbackRate&&(this.markTime({playbackRate:e}),this._playbackRate=e)}get paused(){if(0===this.playbackRate)return!0;let e=this.parent;for(;e;){if(0===e.playbackRate)return!0;e=e.parent}return!1}}var M=x;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.9";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;
|
package/dist/eva.js.d.ts
CHANGED
|
@@ -48,6 +48,10 @@ export declare const decorators: {
|
|
|
48
48
|
componentObserver: typeof componentObserver;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
+
declare interface DestroySceneParams {
|
|
52
|
+
scene: Scene;
|
|
53
|
+
}
|
|
54
|
+
|
|
51
55
|
declare interface EventParam {
|
|
52
56
|
name: string;
|
|
53
57
|
resource: ResourceStruct;
|
|
@@ -80,6 +84,13 @@ export declare class Game extends EventEmitter {
|
|
|
80
84
|
destroySystems(): void;
|
|
81
85
|
destroy(): void;
|
|
82
86
|
loadScene({ scene, mode, params }: LoadSceneParams): void;
|
|
87
|
+
pauseScene({ scene }: {
|
|
88
|
+
scene: any;
|
|
89
|
+
}): void;
|
|
90
|
+
startScene({ scene }: {
|
|
91
|
+
scene: any;
|
|
92
|
+
}): void;
|
|
93
|
+
destroyScene({ scene }: DestroySceneParams): void;
|
|
83
94
|
}
|
|
84
95
|
|
|
85
96
|
export declare class GameObject {
|
|
@@ -246,7 +257,8 @@ export declare enum RESOURCE_TYPE {
|
|
|
246
257
|
'SPRITE' = "SPRITE",
|
|
247
258
|
'SPRITE_ANIMATION' = "SPRITE_ANIMATION",
|
|
248
259
|
'AUDIO' = "AUDIO",
|
|
249
|
-
'VIDEO' = "VIDEO"
|
|
260
|
+
'VIDEO' = "VIDEO",
|
|
261
|
+
'FONT' = "FONT"
|
|
250
262
|
}
|
|
251
263
|
|
|
252
264
|
export declare const RESOURCE_TYPE_STRATEGY: {};
|
|
@@ -425,6 +437,6 @@ declare interface Vector2 {
|
|
|
425
437
|
y: number;
|
|
426
438
|
}
|
|
427
439
|
|
|
428
|
-
export declare const version = "2.0.
|
|
440
|
+
export declare const version = "2.0.1-beta.9";
|
|
429
441
|
|
|
430
442
|
export { }
|
package/dist/eva.js.esm.js
CHANGED
|
@@ -1047,6 +1047,19 @@ class Game extends EventEmitter {
|
|
|
1047
1047
|
}
|
|
1048
1048
|
this.emit('sceneChanged', { scene, mode, params });
|
|
1049
1049
|
}
|
|
1050
|
+
pauseScene({ scene }) {
|
|
1051
|
+
this.emit('pauseScene', { scene });
|
|
1052
|
+
}
|
|
1053
|
+
startScene({ scene }) {
|
|
1054
|
+
this.emit('startScene', { scene });
|
|
1055
|
+
}
|
|
1056
|
+
destroyScene({ scene }) {
|
|
1057
|
+
const index = this.multiScenes.findIndex(item => item === scene);
|
|
1058
|
+
if (index > -1) {
|
|
1059
|
+
const scene = this.multiScenes.splice(index, 1)[0];
|
|
1060
|
+
this.emit('sceneDestroyed', { scene });
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1050
1063
|
}
|
|
1051
1064
|
var Game$1 = Game;
|
|
1052
1065
|
|
|
@@ -1130,6 +1143,7 @@ var RESOURCE_TYPE;
|
|
|
1130
1143
|
RESOURCE_TYPE["SPRITE_ANIMATION"] = "SPRITE_ANIMATION";
|
|
1131
1144
|
RESOURCE_TYPE["AUDIO"] = "AUDIO";
|
|
1132
1145
|
RESOURCE_TYPE["VIDEO"] = "VIDEO";
|
|
1146
|
+
RESOURCE_TYPE["FONT"] = "FONT";
|
|
1133
1147
|
})(RESOURCE_TYPE || (RESOURCE_TYPE = {}));
|
|
1134
1148
|
class Resource extends EventEmitter {
|
|
1135
1149
|
constructor(options) {
|
|
@@ -1162,8 +1176,10 @@ class Resource extends EventEmitter {
|
|
|
1162
1176
|
console.warn(res.name + ' was already added');
|
|
1163
1177
|
continue;
|
|
1164
1178
|
}
|
|
1165
|
-
|
|
1166
|
-
|
|
1179
|
+
if (res) {
|
|
1180
|
+
this.resourcesMap[res.name] = res;
|
|
1181
|
+
this.resourcesMap[res.name].data = {};
|
|
1182
|
+
}
|
|
1167
1183
|
}
|
|
1168
1184
|
}
|
|
1169
1185
|
addPreProcessResourceHandler(handler) {
|
|
@@ -1305,6 +1321,11 @@ class Resource extends EventEmitter {
|
|
|
1305
1321
|
}
|
|
1306
1322
|
}
|
|
1307
1323
|
}
|
|
1324
|
+
else if (res.type === RESOURCE_TYPE.FONT) {
|
|
1325
|
+
options.data = {
|
|
1326
|
+
family: name,
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1308
1329
|
Assets.add(options);
|
|
1309
1330
|
}
|
|
1310
1331
|
Assets.load(url)
|
|
@@ -1371,6 +1392,10 @@ class Resource extends EventEmitter {
|
|
|
1371
1392
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1372
1393
|
const { metadata: { key, name, resolves }, data, } = resource;
|
|
1373
1394
|
const res = this.resourcesMap[name];
|
|
1395
|
+
if (!res) {
|
|
1396
|
+
console.warn('no resource data found');
|
|
1397
|
+
return;
|
|
1398
|
+
}
|
|
1374
1399
|
res.data[key] = data;
|
|
1375
1400
|
this.doComplete(name, resolves[name], preload);
|
|
1376
1401
|
});
|
|
@@ -1398,7 +1423,7 @@ const decorators = {
|
|
|
1398
1423
|
IDEProp,
|
|
1399
1424
|
componentObserver,
|
|
1400
1425
|
};
|
|
1401
|
-
const version = '2.0.
|
|
1426
|
+
const version = '2.0.1-beta.9';
|
|
1402
1427
|
console.log(`Eva.js version: ${version}`);
|
|
1403
1428
|
const RESOURCE_TYPE_STRATEGY = {};
|
|
1404
1429
|
|