@eva/plugin-renderer 2.0.1-beta.9 → 2.0.2-beta.0
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.
|
@@ -1280,6 +1280,16 @@ var _EVA_IIFE_renderer = function (exports, eva_js, rendererAdapter, pixi_js) {
|
|
|
1280
1280
|
application
|
|
1281
1281
|
});
|
|
1282
1282
|
}));
|
|
1283
|
+
this.game.on('pauseScene', ({
|
|
1284
|
+
scene
|
|
1285
|
+
}) => {
|
|
1286
|
+
this.onPauseScene(scene);
|
|
1287
|
+
});
|
|
1288
|
+
this.game.on('startScene', ({
|
|
1289
|
+
scene
|
|
1290
|
+
}) => {
|
|
1291
|
+
this.onStartScene(scene);
|
|
1292
|
+
});
|
|
1283
1293
|
this.game.on('sceneDestroyed', ({
|
|
1284
1294
|
scene
|
|
1285
1295
|
}) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1343,13 +1353,6 @@ var _EVA_IIFE_renderer = function (exports, eva_js, rendererAdapter, pixi_js) {
|
|
|
1343
1353
|
}
|
|
1344
1354
|
}
|
|
1345
1355
|
lateUpdate(e) {
|
|
1346
|
-
for (const gameObject of this.game.gameObjects) {
|
|
1347
|
-
this.containerManager.updateTransform({
|
|
1348
|
-
name: gameObject.id,
|
|
1349
|
-
transform: gameObject.transform
|
|
1350
|
-
});
|
|
1351
|
-
this.rendererManager.update(gameObject);
|
|
1352
|
-
}
|
|
1353
1356
|
this.transform.update();
|
|
1354
1357
|
this.application.ticker.update(e.time);
|
|
1355
1358
|
}
|
|
@@ -1372,15 +1375,33 @@ var _EVA_IIFE_renderer = function (exports, eva_js, rendererAdapter, pixi_js) {
|
|
|
1372
1375
|
this.params.height = height;
|
|
1373
1376
|
this.application.renderer.resize(width, height);
|
|
1374
1377
|
}
|
|
1375
|
-
|
|
1378
|
+
getApplicationByScene(scene) {
|
|
1376
1379
|
const index = this.multiApps.findIndex(app => app.canvas === scene.canvas);
|
|
1377
1380
|
if (index > -1) {
|
|
1378
1381
|
const application = this.multiApps[index];
|
|
1379
|
-
application
|
|
1382
|
+
return application;
|
|
1380
1383
|
} else {
|
|
1381
1384
|
console.warn('application not found');
|
|
1382
1385
|
}
|
|
1383
1386
|
}
|
|
1387
|
+
onPauseScene(scene) {
|
|
1388
|
+
const app = this.getApplicationByScene(scene);
|
|
1389
|
+
if (app) {
|
|
1390
|
+
app.stop();
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
onStartScene(scene) {
|
|
1394
|
+
const app = this.getApplicationByScene(scene);
|
|
1395
|
+
if (app) {
|
|
1396
|
+
app.start();
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
resizeByScene(scene, width, height) {
|
|
1400
|
+
const app = this.getApplicationByScene(scene);
|
|
1401
|
+
if (app) {
|
|
1402
|
+
app.renderer.resize(width, height);
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1384
1405
|
};
|
|
1385
1406
|
Renderer$1.systemName = 'Renderer';
|
|
1386
1407
|
Renderer$1 = __decorate([eva_js.decorators.componentObserver({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{};var _EVA_IIFE_renderer=function(e,t,n,r){"use strict";function o(e,t,n,r){var o,a=arguments.length,i=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(a<3?o(i):a>3?o(t,n,i):o(t,n))||i);return a>3&&i&&Object.defineProperty(t,n,i),i}function a(e,t,n,r){return new(n||(n=Promise))((function(o,a){function i(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,s)}c((r=r.apply(e,t||[])).next())}))}function i(e,t){return e===t||e!=e&&t!=t}function s(e,t){for(var n=e.length;n--;)if(i(e[n][0],t))return n;return-1}var c=Array.prototype.splice;function u(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}u.prototype.clear=function(){this.__data__=[],this.size=0},u.prototype.delete=function(e){var t=this.__data__,n=s(t,e);return!(n<0)&&(n==t.length-1?t.pop():c.call(t,n,1),--this.size,!0)},u.prototype.get=function(e){var t=this.__data__,n=s(t,e);return n<0?void 0:t[n][1]},u.prototype.has=function(e){return s(this.__data__,e)>-1},u.prototype.set=function(e,t){var n=this.__data__,r=s(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this};var p="object"==typeof global&&global&&global.Object===Object&&global,l="object"==typeof self&&self&&self.Object===Object&&self,f=p||l||Function("return this")(),h=f.Symbol,d=Object.prototype,v=d.hasOwnProperty,_=d.toString,y=h?h.toStringTag:void 0;var g=Object.prototype.toString;var m=h?h.toStringTag:void 0;function b(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":m&&m in Object(e)?function(e){var t=v.call(e,y),n=e[y];try{e[y]=void 0;var r=!0}catch(e){}var o=_.call(e);return r&&(t?e[y]=n:delete e[y]),o}(e):function(e){return g.call(e)}(e)}function j(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function O(e){if(!j(e))return!1;var t=b(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t}var w,E=f["__core-js_shared__"],A=(w=/[^.]+$/.exec(E&&E.keys&&E.keys.IE_PROTO||""))?"Symbol(src)_1."+w:"";var x=Function.prototype.toString;function C(e){if(null!=e){try{return x.call(e)}catch(e){}try{return e+""}catch(e){}}return""}var M=/^\[object .+?Constructor\]$/,S=Function.prototype,T=Object.prototype,P=S.toString,R=T.hasOwnProperty,I=RegExp("^"+P.call(R).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function z(e){return!(!j(e)||(t=e,A&&A in t))&&(O(e)?I:M).test(C(e));var t}function L(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return z(n)?n:void 0}var N=L(f,"Map"),V=L(Object,"create");var B=Object.prototype.hasOwnProperty;var D=Object.prototype.hasOwnProperty;function k(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function W(e,t){var n,r,o=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof t?"string":"hash"]:o.map}function G(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}k.prototype.clear=function(){this.__data__=V?V(null):{},this.size=0},k.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},k.prototype.get=function(e){var t=this.__data__;if(V){var n=t[e];return"__lodash_hash_undefined__"===n?void 0:n}return B.call(t,e)?t[e]:void 0},k.prototype.has=function(e){var t=this.__data__;return V?void 0!==t[e]:D.call(t,e)},k.prototype.set=function(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=V&&void 0===t?"__lodash_hash_undefined__":t,this},G.prototype.clear=function(){this.size=0,this.__data__={hash:new k,map:new(N||u),string:new k}},G.prototype.delete=function(e){var t=W(this,e).delete(e);return this.size-=t?1:0,t},G.prototype.get=function(e){return W(this,e).get(e)},G.prototype.has=function(e){return W(this,e).has(e)},G.prototype.set=function(e,t){var n=W(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this};function U(e){var t=this.__data__=new u(e);this.size=t.size}U.prototype.clear=function(){this.__data__=new u,this.size=0},U.prototype.delete=function(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n},U.prototype.get=function(e){return this.__data__.get(e)},U.prototype.has=function(e){return this.__data__.has(e)},U.prototype.set=function(e,t){var n=this.__data__;if(n instanceof u){var r=n.__data__;if(!N||r.length<199)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new G(r)}return n.set(e,t),this.size=n.size,this};function $(e){var t=-1,n=null==e?0:e.length;for(this.__data__=new G;++t<n;)this.add(e[t])}function F(e,t){for(var n=-1,r=null==e?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}$.prototype.add=$.prototype.push=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},$.prototype.has=function(e){return this.__data__.has(e)};function Y(e,t,n,r,o,a){var i=1&n,s=e.length,c=t.length;if(s!=c&&!(i&&c>s))return!1;var u=a.get(e),p=a.get(t);if(u&&p)return u==t&&p==e;var l=-1,f=!0,h=2&n?new $:void 0;for(a.set(e,t),a.set(t,e);++l<s;){var d=e[l],v=t[l];if(r)var _=i?r(v,d,l,t,e,a):r(d,v,l,e,t,a);if(void 0!==_){if(_)continue;f=!1;break}if(h){if(!F(t,(function(e,t){if(i=t,!h.has(i)&&(d===e||o(d,e,n,r,a)))return h.push(t);var i}))){f=!1;break}}else if(d!==v&&!o(d,v,n,r,a)){f=!1;break}}return a.delete(e),a.delete(t),f}var K=f.Uint8Array;function X(e){var t=-1,n=Array(e.size);return e.forEach((function(e,r){n[++t]=[r,e]})),n}function q(e){var t=-1,n=Array(e.size);return e.forEach((function(e){n[++t]=e})),n}var H=h?h.prototype:void 0,J=H?H.valueOf:void 0;var Q=Array.isArray;var Z=Object.prototype.propertyIsEnumerable,ee=Object.getOwnPropertySymbols,te=ee?function(e){return null==e?[]:(e=Object(e),function(e,t){for(var n=-1,r=null==e?0:e.length,o=0,a=[];++n<r;){var i=e[n];t(i,n,e)&&(a[o++]=i)}return a}(ee(e),(function(t){return Z.call(e,t)})))}:function(){return[]},ne=te;function re(e){return null!=e&&"object"==typeof e}function oe(e){return re(e)&&"[object Arguments]"==b(e)}var ae=Object.prototype,ie=ae.hasOwnProperty,se=ae.propertyIsEnumerable,ce=oe(function(){return arguments}())?oe:function(e){return re(e)&&ie.call(e,"callee")&&!se.call(e,"callee")},ue=ce;var pe="object"==typeof e&&e&&!e.nodeType&&e,le=pe&&"object"==typeof module&&module&&!module.nodeType&&module,fe=le&&le.exports===pe?f.Buffer:void 0,he=(fe?fe.isBuffer:void 0)||function(){return!1},de=/^(?:0|[1-9]\d*)$/;function ve(e,t){var n=typeof e;return!!(t=null==t?9007199254740991:t)&&("number"==n||"symbol"!=n&&de.test(e))&&e>-1&&e%1==0&&e<t}function _e(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991}var ye={};ye["[object Float32Array]"]=ye["[object Float64Array]"]=ye["[object Int8Array]"]=ye["[object Int16Array]"]=ye["[object Int32Array]"]=ye["[object Uint8Array]"]=ye["[object Uint8ClampedArray]"]=ye["[object Uint16Array]"]=ye["[object Uint32Array]"]=!0,ye["[object Arguments]"]=ye["[object Array]"]=ye["[object ArrayBuffer]"]=ye["[object Boolean]"]=ye["[object DataView]"]=ye["[object Date]"]=ye["[object Error]"]=ye["[object Function]"]=ye["[object Map]"]=ye["[object Number]"]=ye["[object Object]"]=ye["[object RegExp]"]=ye["[object Set]"]=ye["[object String]"]=ye["[object WeakMap]"]=!1;var ge,me="object"==typeof e&&e&&!e.nodeType&&e,be=me&&"object"==typeof module&&module&&!module.nodeType&&module,je=be&&be.exports===me&&p.process,Oe=function(){try{var e=be&&be.require&&be.require("util").types;return e||je&&je.binding&&je.binding("util")}catch(e){}}(),we=Oe&&Oe.isTypedArray,Ee=we?(ge=we,function(e){return ge(e)}):function(e){return re(e)&&_e(e.length)&&!!ye[b(e)]},Ae=Object.prototype.hasOwnProperty;function xe(e,t){var n=Q(e),r=!n&&ue(e),o=!n&&!r&&he(e),a=!n&&!r&&!o&&Ee(e),i=n||r||o||a,s=i?function(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}(e.length,String):[],c=s.length;for(var u in e)!t&&!Ae.call(e,u)||i&&("length"==u||o&&("offset"==u||"parent"==u)||a&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||ve(u,c))||s.push(u);return s}var Ce=Object.prototype;var Me=function(e,t){return function(n){return e(t(n))}}(Object.keys,Object),Se=Me,Te=Object.prototype.hasOwnProperty;function Pe(e){if(n=(t=e)&&t.constructor,t!==("function"==typeof n&&n.prototype||Ce))return Se(e);var t,n,r=[];for(var o in Object(e))Te.call(e,o)&&"constructor"!=o&&r.push(o);return r}function Re(e){return null!=(t=e)&&_e(t.length)&&!O(t)?xe(e):Pe(e);var t}function Ie(e){return function(e,t,n){var r=t(e);return Q(e)?r:function(e,t){for(var n=-1,r=t.length,o=e.length;++n<r;)e[o+n]=t[n];return e}(r,n(e))}(e,Re,ne)}var ze=Object.prototype.hasOwnProperty;var Le=L(f,"DataView"),Ne=L(f,"Promise"),Ve=L(f,"Set"),Be=L(f,"WeakMap"),De="[object Map]",ke="[object Promise]",We="[object Set]",Ge="[object WeakMap]",Ue="[object DataView]",$e=C(Le),Fe=C(N),Ye=C(Ne),Ke=C(Ve),Xe=C(Be),qe=b;(Le&&qe(new Le(new ArrayBuffer(1)))!=Ue||N&&qe(new N)!=De||Ne&&qe(Ne.resolve())!=ke||Ve&&qe(new Ve)!=We||Be&&qe(new Be)!=Ge)&&(qe=function(e){var t=b(e),n="[object Object]"==t?e.constructor:void 0,r=n?C(n):"";if(r)switch(r){case $e:return Ue;case Fe:return De;case Ye:return ke;case Ke:return We;case Xe:return Ge}return t});var He=qe,Je="[object Arguments]",Qe="[object Array]",Ze="[object Object]",et=Object.prototype.hasOwnProperty;function tt(e,t,n,r,o,a){var s=Q(e),c=Q(t),u=s?Qe:He(e),p=c?Qe:He(t),l=(u=u==Je?Ze:u)==Ze,f=(p=p==Je?Ze:p)==Ze,h=u==p;if(h&&he(e)){if(!he(t))return!1;s=!0,l=!1}if(h&&!l)return a||(a=new U),s||Ee(e)?Y(e,t,n,r,o,a):function(e,t,n,r,o,a,s){switch(n){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||!a(new K(e),new K(t)));case"[object Boolean]":case"[object Date]":case"[object Number]":return i(+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 c=X;case"[object Set]":var u=1&r;if(c||(c=q),e.size!=t.size&&!u)return!1;var p=s.get(e);if(p)return p==t;r|=2,s.set(e,t);var l=Y(c(e),c(t),r,o,a,s);return s.delete(e),l;case"[object Symbol]":if(J)return J.call(e)==J.call(t)}return!1}(e,t,u,n,r,o,a);if(!(1&n)){var d=l&&et.call(e,"__wrapped__"),v=f&&et.call(t,"__wrapped__");if(d||v){var _=d?e.value():e,y=v?t.value():t;return a||(a=new U),o(_,y,n,r,a)}}return!!h&&(a||(a=new U),function(e,t,n,r,o,a){var i=1&n,s=Ie(e),c=s.length;if(c!=Ie(t).length&&!i)return!1;for(var u=c;u--;){var p=s[u];if(!(i?p in t:ze.call(t,p)))return!1}var l=a.get(e),f=a.get(t);if(l&&f)return l==t&&f==e;var h=!0;a.set(e,t),a.set(t,e);for(var d=i;++u<c;){var v=e[p=s[u]],_=t[p];if(r)var y=i?r(_,v,p,t,e,a):r(v,_,p,e,t,a);if(!(void 0===y?v===_||o(v,_,n,r,a):y)){h=!1;break}d||(d="constructor"==p)}if(h&&!d){var g=e.constructor,m=t.constructor;g==m||!("constructor"in e)||!("constructor"in t)||"function"==typeof g&&g instanceof g&&"function"==typeof m&&m instanceof m||(h=!1)}return a.delete(e),a.delete(t),h}(e,t,n,r,o,a))}function nt(e,t,n,r,o){return e===t||(null==e||null==t||!re(e)&&!re(t)?e!=e&&t!=t:tt(e,t,n,r,nt,o))}var rt=class{constructor({game:e,rendererSystem:t}){this.renderers=[],this.game=e,this.rendererSystem=t}register(...e){for(const t of e)t.game=this.game,t.rendererManager=this.rendererSystem.rendererManager,t.containerManager=this.rendererSystem.containerManager,this.renderers.push(t)}componentChanged(e){for(const n of e)for(const e of this.renderers){const r=e.observerInfo[n.componentName];if(r){if([t.OBSERVER_TYPE.ADD,t.OBSERVER_TYPE.REMOVE].indexOf(n.type)>-1){try{e.componentChanged&&e.componentChanged(n)}catch(e){console.error(`gameObject: ${n.gameObject.name}, ${n.componentName} is error.`,n,e)}continue}if(r.findIndex((e=>{return t=e,r=n.prop,nt(t,r);var t,r}))>-1)try{e.componentChanged&&e.componentChanged(n)}catch(e){console.error(`gameObject: ${n.gameObject&&n.gameObject.name}, ${n.componentName} is componentChanged error.`,n,e)}}}}update(e){for(const t of e.components)for(const n of this.renderers){const r=[];if(n.observerInfo[t.name]&&-1===r.indexOf(e)){r.push(e);try{n.rendererUpdate&&n.rendererUpdate(e)}catch(n){console.info(`gameObject: ${e.name}, ${t.name} is update error`,n)}}}}};class ot{constructor(){this.containerMap={}}addContainer({name:e,container:t,gameObject:n}){this.containerMap[e]=t,t.gName=n.name||e}getContainer(e){return this.containerMap[e]}removeContainer(e){const t=this.containerMap[e];t&&t.destroy({children:!0}),delete this.containerMap[e]}updateTransform({name:e,transform:t}){const n=this.containerMap[e];if(!n||!t)return;const{anchor:r,origin:o,position:a,rotation:i,scale:s,size:c,skew:u}=t;n.rotation=i,n.scale=s,n.pivot.x=c.width*o.x,n.pivot.y=c.height*o.y,n.skew=u;let p=a.x,l=a.y;if(t.parent){const e=t.parent;p+=e.size.width*r.x,l+=e.size.height*r.y}n.position={x:p,y:l}}}var at=function(e){var t={exports:{}};return e(t,t.exports),t.exports}((function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}function o(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function a(e,t,r,a,i){if("function"!=typeof r)throw new TypeError("The listener must be a function");var s=new o(r,a||e,i),c=n?n+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],s]:e._events[c].push(s):(e._events[c]=s,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new r:delete e._events[t]}function s(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),s.prototype.eventNames=function(){var e,r,o=[];if(0===this._eventsCount)return o;for(r in e=this._events)t.call(e,r)&&o.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},s.prototype.listeners=function(e){var t=n?n+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var o=0,a=r.length,i=new Array(a);o<a;o++)i[o]=r[o].fn;return i},s.prototype.listenerCount=function(e){var t=n?n+e:e,r=this._events[t];return r?r.fn?1:r.length:0},s.prototype.emit=function(e,t,r,o,a,i){var s=n?n+e:e;if(!this._events[s])return!1;var c,u,p=this._events[s],l=arguments.length;if(p.fn){switch(p.once&&this.removeListener(e,p.fn,void 0,!0),l){case 1:return p.fn.call(p.context),!0;case 2:return p.fn.call(p.context,t),!0;case 3:return p.fn.call(p.context,t,r),!0;case 4:return p.fn.call(p.context,t,r,o),!0;case 5:return p.fn.call(p.context,t,r,o,a),!0;case 6:return p.fn.call(p.context,t,r,o,a,i),!0}for(u=1,c=new Array(l-1);u<l;u++)c[u-1]=arguments[u];p.fn.apply(p.context,c)}else{var f,h=p.length;for(u=0;u<h;u++)switch(p[u].once&&this.removeListener(e,p[u].fn,void 0,!0),l){case 1:p[u].fn.call(p[u].context);break;case 2:p[u].fn.call(p[u].context,t);break;case 3:p[u].fn.call(p[u].context,t,r);break;case 4:p[u].fn.call(p[u].context,t,r,o);break;default:if(!c)for(f=1,c=new Array(l-1);f<l;f++)c[f-1]=arguments[f];p[u].fn.apply(p[u].context,c)}}return!0},s.prototype.on=function(e,t,n){return a(this,e,t,n,!1)},s.prototype.once=function(e,t,n){return a(this,e,t,n,!0)},s.prototype.removeListener=function(e,t,r,o){var a=n?n+e:e;if(!this._events[a])return this;if(!t)return i(this,a),this;var s=this._events[a];if(s.fn)s.fn!==t||o&&!s.once||r&&s.context!==r||i(this,a);else{for(var c=0,u=[],p=s.length;c<p;c++)(s[c].fn!==t||o&&!s[c].once||r&&s[c].context!==r)&&u.push(s[c]);u.length?this._events[a]=1===u.length?u[0]:u:i(this,a)}return this},s.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&i(this,t)):(this._events=new r,this._eventsCount=0),this},s.prototype.off=s.prototype.removeListener,s.prototype.addListener=s.prototype.on,s.prefixed=n,s.EventEmitter=s,e.exports=s})),it=at;let st=class extends it{constructor({system:e,containerManager:t}){super(),this.name="Transform",this.waitRemoveIds=[],this.waitChangeScenes=[],this.containerManager=t,this.init(e)}init(e){this.system=e,this.on("changeScene",(({scene:e,mode:t,application:n})=>{this.waitChangeScenes.push({scene:e,mode:t,application:n})}))}update(){for(const e of this.waitRemoveIds)this.containerManager.removeContainer(e);this.waitRemoveIds=[];for(const e of this.waitChangeScenes){const t=this.containerManager.getContainer(e.scene.id);t&&(e.application.stage.removeChildren(),e.application.stage.addChild(t))}this.waitChangeScenes=[]}componentChanged(e){e.type===t.OBSERVER_TYPE.ADD?this.addContainer(e):e.type===t.OBSERVER_TYPE.CHANGE?this.change(e):e.type===t.OBSERVER_TYPE.REMOVE&&this.waitRemoveIds.push(e.gameObject.id)}addContainer(e){const t=new n.Container;t.label=e.gameObject.name,this.containerManager.addContainer({name:e.gameObject.id,container:t,gameObject:e.gameObject});const r=e.component;Object.defineProperty(r,"worldTransform",{get:()=>t.renderGroup||t.parentRenderGroup?t.worldTransform:void 0})}change(e){const t=e.component;if(t.parent){this.containerManager.getContainer(t.parent.gameObject.id).addChild(this.containerManager.getContainer(e.gameObject.id));const n=e.gameObject.transform.parent&&e.gameObject.transform.parent.gameObject.getComponent("Render");n&&(n.sortDirty=!0)}else{const t=this.containerManager.getContainer(e.gameObject.id);t.parent&&t.parent.removeChild(t)}}destroy(){this.removeAllListeners(),this.waitRemoveIds=null,this.waitChangeScenes=null,this.system=null,this.containerManager=null}};st=o([t.decorators.componentObserver({Transform:["_parent"]})],st);var ct,ut=st;e.RENDERER_TYPE=void 0,(ct=e.RENDERER_TYPE||(e.RENDERER_TYPE={}))[ct.UNKNOWN=0]="UNKNOWN",ct[ct.WEBGL=1]="WEBGL",ct[ct.CANVAS=2]="CANVAS";let pt=class extends t.System{constructor(){super(...arguments),this.multiApps=[]}init(e){return a(this,void 0,void 0,(function*(){this.params=e,this.application=yield this.createApplication(e),this.containerManager=new ot,this.rendererManager=new rt({game:this.game,rendererSystem:this}),this.game.canvas=this.application.canvas,this.transform=new ut({system:this,containerManager:this.containerManager}),this.game.on("sceneChanged",(({scene:e,mode:n,params:r})=>a(this,void 0,void 0,(function*(){let o;switch(n){case t.LOAD_SCENE_MODE.SINGLE:o=this.application;break;case t.LOAD_SCENE_MODE.MULTI_CANVAS:o=yield this.createMultiApplication({params:r})}e.canvas=o.canvas,this.transform.emit("changeScene",{scene:e,mode:n,application:o})})))),this.game.on("sceneDestroyed",(({scene:e})=>a(this,void 0,void 0,(function*(){const t=this.multiApps.findIndex((t=>t.canvas===e.canvas));if(t>-1){this.multiApps.splice(t,1)[0].destroy(),e.destroy()}}))))}))}registerObserver(e){const t=this.constructor.observerInfo;for(const n in e)t[n]||(t[n]=[]),t[n].push(...e[n])}createMultiApplication({params:e}){return a(this,void 0,void 0,(function*(){const t=yield this.createApplication(e);return this.multiApps.push(t),t}))}createApplication(e){return a(this,void 0,void 0,(function*(){const t=new n.Application;var o;return e.debugMode&&(globalThis.__PIXI_APP__=t),yield t.init(_extends(_extends({sharedTicker:!0},e),{hello:!0})),void 0!==e.enableScroll&&(e.enableScroll?((o=t.renderer).events.autoPreventDefault=!1,o.canvas.style.touchAction="auto"):(e=>{e.events.autoPreventDefault=!0,e.canvas.style.touchAction="none"})(t.renderer)),r.Ticker.shared.stop(),r.Ticker.shared.autoStart=!1,t}))}update(){const e=this.componentObserver.clear();for(const t of e)this.transform.componentChanged(t);for(const e of this.game.gameObjects)this.containerManager.updateTransform({name:e.id,transform:e.transform}),this.rendererManager.update(e)}lateUpdate(e){for(const e of this.game.gameObjects)this.containerManager.updateTransform({name:e.id,transform:e.transform}),this.rendererManager.update(e);this.transform.update(),this.application.ticker.update(e.time)}onDestroy(){this.application.destroy();for(const e of this.multiApps)e&&e.destroy();this.transform.destroy(),this.transform=null,this.params=null,this.rendererManager=null,this.containerManager=null,this.application=null,this.game=null,this.multiApps=null}resize(e,t){this.params.width=e,this.params.height=t,this.application.renderer.resize(e,t)}resizeByScene(e,t,n){const r=this.multiApps.findIndex((t=>t.canvas===e.canvas));if(r>-1){this.multiApps[r].renderer.resize(t,n)}else console.warn("application not found")}};pt.systemName="Renderer",pt=o([t.decorators.componentObserver({Transform:["_parent"]})],pt);var lt=pt;let ft;function ht(e){e.addPreProcessResourceHandler((function(e){var t,n,r;let o=null===(n=null===(t=e.src)||void 0===t?void 0:t.image)||void 0===n?void 0:n.texture;if(!o)return;Array.isArray(o)||(o=[o]);const a=null!==(r=function(){if(ft)return ft;const e=document.createElement("canvas").getContext("webgl2");if(!e)return console.warn("WebGL not available for compressed textures. Silently failing."),{s3tc:!1,etc:!1,etc1:!1,pvrtc:!1,atc:!1,astc:!1};ft={s3tc:!!e.getExtension("WEBGL_compressed_texture_s3tc"),etc:!!e.getExtension("WEBGL_compressed_texture_etc"),etc1:!!e.getExtension("WEBGL_compressed_texture_etc1"),pvrtc:!!e.getExtension("WEBGL_compressed_texture_pvrtc")||!!e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),atc:!!e.getExtension("WEBGL_compressed_texture_atc"),astc:!!e.getExtension("WEBGL_compressed_texture_astc")};try{console.log("Eva.js Supported Compressed Texture Format List: "+Object.keys(ft).filter((e=>ft[e])).join(", "))}catch(e){}return ft}())&&void 0!==r?r:{};let i=o.find((e=>a[e.type]));i&&_extends(e.src.image,i)}))}class dt extends t.System{constructor(e){super(e),this.asyncIdMap={},this.observerInfo=this.constructor.observerInfo}componentChanged(e){}rendererUpdate(e){}update(e){const t=this.componentObserver.clear();for(const e of t)this.componentChanged(e)}increaseAsyncId(e){return this.asyncIdMap[e]=(this.asyncIdMap[e]||0)+1,this.asyncIdMap[e]}validateAsyncId(e,t){return this.asyncIdMap[e]===t}}return e.ContainerManager=ot,e.Renderer=dt,e.RendererManager=rt,e.RendererSystem=lt,e.registerKtx2CompressedTexture=function(e){r.setKTXTranscoderPath(e),r.extensions.add(r.loadKTX2),r.extensions.add(r.resolveCompressedTextureUrl),r.extensions.add(r.detectCompressed),ht(t.resource)},Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.rendererAdapter,PIXI);globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||_EVA_IIFE_renderer;
|
|
1
|
+
function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{};var _EVA_IIFE_renderer=function(e,t,n,r){"use strict";function o(e,t,n,r){var o,a=arguments.length,i=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(a<3?o(i):a>3?o(t,n,i):o(t,n))||i);return a>3&&i&&Object.defineProperty(t,n,i),i}function a(e,t,n,r){return new(n||(n=Promise))(function(o,a){function i(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(i,s)}c((r=r.apply(e,t||[])).next())})}function i(e,t){return e===t||e!=e&&t!=t}function s(e,t){for(var n=e.length;n--;)if(i(e[n][0],t))return n;return-1}var c=Array.prototype.splice;function u(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}u.prototype.clear=function(){this.__data__=[],this.size=0},u.prototype.delete=function(e){var t=this.__data__,n=s(t,e);return!(n<0)&&(n==t.length-1?t.pop():c.call(t,n,1),--this.size,!0)},u.prototype.get=function(e){var t=this.__data__,n=s(t,e);return n<0?void 0:t[n][1]},u.prototype.has=function(e){return s(this.__data__,e)>-1},u.prototype.set=function(e,t){var n=this.__data__,r=s(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this};var p="object"==typeof global&&global&&global.Object===Object&&global,l="object"==typeof self&&self&&self.Object===Object&&self,h=p||l||Function("return this")(),f=h.Symbol,d=Object.prototype,v=d.hasOwnProperty,y=d.toString,_=f?f.toStringTag:void 0;var g=Object.prototype.toString;var m=f?f.toStringTag:void 0;function b(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":m&&m in Object(e)?function(e){var t=v.call(e,_),n=e[_];try{e[_]=void 0;var r=!0}catch(e){}var o=y.call(e);return r&&(t?e[_]=n:delete e[_]),o}(e):function(e){return g.call(e)}(e)}function j(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function O(e){if(!j(e))return!1;var t=b(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t}var w,E=h["__core-js_shared__"],A=(w=/[^.]+$/.exec(E&&E.keys&&E.keys.IE_PROTO||""))?"Symbol(src)_1."+w:"";var x=Function.prototype.toString;function S(e){if(null!=e){try{return x.call(e)}catch(e){}try{return e+""}catch(e){}}return""}var C=/^\[object .+?Constructor\]$/,M=Function.prototype,P=Object.prototype,T=M.toString,R=P.hasOwnProperty,I=RegExp("^"+T.call(R).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function z(e){return!(!j(e)||(t=e,A&&A in t))&&(O(e)?I:C).test(S(e));var t}function B(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return z(n)?n:void 0}var L=B(h,"Map"),N=B(Object,"create");var V=Object.prototype.hasOwnProperty;var D=Object.prototype.hasOwnProperty;function k(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function W(e,t){var n,r,o=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof t?"string":"hash"]:o.map}function G(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}k.prototype.clear=function(){this.__data__=N?N(null):{},this.size=0},k.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},k.prototype.get=function(e){var t=this.__data__;if(N){var n=t[e];return"__lodash_hash_undefined__"===n?void 0:n}return V.call(t,e)?t[e]:void 0},k.prototype.has=function(e){var t=this.__data__;return N?void 0!==t[e]:D.call(t,e)},k.prototype.set=function(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=N&&void 0===t?"__lodash_hash_undefined__":t,this},G.prototype.clear=function(){this.size=0,this.__data__={hash:new k,map:new(L||u),string:new k}},G.prototype.delete=function(e){var t=W(this,e).delete(e);return this.size-=t?1:0,t},G.prototype.get=function(e){return W(this,e).get(e)},G.prototype.has=function(e){return W(this,e).has(e)},G.prototype.set=function(e,t){var n=W(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this};function U(e){var t=this.__data__=new u(e);this.size=t.size}U.prototype.clear=function(){this.__data__=new u,this.size=0},U.prototype.delete=function(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n},U.prototype.get=function(e){return this.__data__.get(e)},U.prototype.has=function(e){return this.__data__.has(e)},U.prototype.set=function(e,t){var n=this.__data__;if(n instanceof u){var r=n.__data__;if(!L||r.length<199)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new G(r)}return n.set(e,t),this.size=n.size,this};function $(e){var t=-1,n=null==e?0:e.length;for(this.__data__=new G;++t<n;)this.add(e[t])}function F(e,t){for(var n=-1,r=null==e?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}$.prototype.add=$.prototype.push=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},$.prototype.has=function(e){return this.__data__.has(e)};function Y(e,t,n,r,o,a){var i=1&n,s=e.length,c=t.length;if(s!=c&&!(i&&c>s))return!1;var u=a.get(e),p=a.get(t);if(u&&p)return u==t&&p==e;var l=-1,h=!0,f=2&n?new $:void 0;for(a.set(e,t),a.set(t,e);++l<s;){var d=e[l],v=t[l];if(r)var y=i?r(v,d,l,t,e,a):r(d,v,l,e,t,a);if(void 0!==y){if(y)continue;h=!1;break}if(f){if(!F(t,function(e,t){if(i=t,!f.has(i)&&(d===e||o(d,e,n,r,a)))return f.push(t);var i})){h=!1;break}}else if(d!==v&&!o(d,v,n,r,a)){h=!1;break}}return a.delete(e),a.delete(t),h}var K=h.Uint8Array;function X(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}function q(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var H=f?f.prototype:void 0,J=H?H.valueOf:void 0;var Q=Array.isArray;var Z=Object.prototype.propertyIsEnumerable,ee=Object.getOwnPropertySymbols,te=ee?function(e){return null==e?[]:(e=Object(e),function(e,t){for(var n=-1,r=null==e?0:e.length,o=0,a=[];++n<r;){var i=e[n];t(i,n,e)&&(a[o++]=i)}return a}(ee(e),function(t){return Z.call(e,t)}))}:function(){return[]},ne=te;function re(e){return null!=e&&"object"==typeof e}function oe(e){return re(e)&&"[object Arguments]"==b(e)}var ae=Object.prototype,ie=ae.hasOwnProperty,se=ae.propertyIsEnumerable,ce=oe(function(){return arguments}())?oe:function(e){return re(e)&&ie.call(e,"callee")&&!se.call(e,"callee")},ue=ce;var pe="object"==typeof e&&e&&!e.nodeType&&e,le=pe&&"object"==typeof module&&module&&!module.nodeType&&module,he=le&&le.exports===pe?h.Buffer:void 0,fe=(he?he.isBuffer:void 0)||function(){return!1},de=/^(?:0|[1-9]\d*)$/;function ve(e,t){var n=typeof e;return!!(t=null==t?9007199254740991:t)&&("number"==n||"symbol"!=n&&de.test(e))&&e>-1&&e%1==0&&e<t}function ye(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991}var _e={};_e["[object Float32Array]"]=_e["[object Float64Array]"]=_e["[object Int8Array]"]=_e["[object Int16Array]"]=_e["[object Int32Array]"]=_e["[object Uint8Array]"]=_e["[object Uint8ClampedArray]"]=_e["[object Uint16Array]"]=_e["[object Uint32Array]"]=!0,_e["[object Arguments]"]=_e["[object Array]"]=_e["[object ArrayBuffer]"]=_e["[object Boolean]"]=_e["[object DataView]"]=_e["[object Date]"]=_e["[object Error]"]=_e["[object Function]"]=_e["[object Map]"]=_e["[object Number]"]=_e["[object Object]"]=_e["[object RegExp]"]=_e["[object Set]"]=_e["[object String]"]=_e["[object WeakMap]"]=!1;var ge,me="object"==typeof e&&e&&!e.nodeType&&e,be=me&&"object"==typeof module&&module&&!module.nodeType&&module,je=be&&be.exports===me&&p.process,Oe=function(){try{var e=be&&be.require&&be.require("util").types;return e||je&&je.binding&&je.binding("util")}catch(e){}}(),we=Oe&&Oe.isTypedArray,Ee=we?(ge=we,function(e){return ge(e)}):function(e){return re(e)&&ye(e.length)&&!!_e[b(e)]},Ae=Object.prototype.hasOwnProperty;function xe(e,t){var n=Q(e),r=!n&&ue(e),o=!n&&!r&&fe(e),a=!n&&!r&&!o&&Ee(e),i=n||r||o||a,s=i?function(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}(e.length,String):[],c=s.length;for(var u in e)!t&&!Ae.call(e,u)||i&&("length"==u||o&&("offset"==u||"parent"==u)||a&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||ve(u,c))||s.push(u);return s}var Se=Object.prototype;var Ce=function(e,t){return function(n){return e(t(n))}}(Object.keys,Object),Me=Ce,Pe=Object.prototype.hasOwnProperty;function Te(e){if(n=(t=e)&&t.constructor,t!==("function"==typeof n&&n.prototype||Se))return Me(e);var t,n,r=[];for(var o in Object(e))Pe.call(e,o)&&"constructor"!=o&&r.push(o);return r}function Re(e){return null!=(t=e)&&ye(t.length)&&!O(t)?xe(e):Te(e);var t}function Ie(e){return function(e,t,n){var r=t(e);return Q(e)?r:function(e,t){for(var n=-1,r=t.length,o=e.length;++n<r;)e[o+n]=t[n];return e}(r,n(e))}(e,Re,ne)}var ze=Object.prototype.hasOwnProperty;var Be=B(h,"DataView"),Le=B(h,"Promise"),Ne=B(h,"Set"),Ve=B(h,"WeakMap"),De="[object Map]",ke="[object Promise]",We="[object Set]",Ge="[object WeakMap]",Ue="[object DataView]",$e=S(Be),Fe=S(L),Ye=S(Le),Ke=S(Ne),Xe=S(Ve),qe=b;(Be&&qe(new Be(new ArrayBuffer(1)))!=Ue||L&&qe(new L)!=De||Le&&qe(Le.resolve())!=ke||Ne&&qe(new Ne)!=We||Ve&&qe(new Ve)!=Ge)&&(qe=function(e){var t=b(e),n="[object Object]"==t?e.constructor:void 0,r=n?S(n):"";if(r)switch(r){case $e:return Ue;case Fe:return De;case Ye:return ke;case Ke:return We;case Xe:return Ge}return t});var He=qe,Je="[object Arguments]",Qe="[object Array]",Ze="[object Object]",et=Object.prototype.hasOwnProperty;function tt(e,t,n,r,o,a){var s=Q(e),c=Q(t),u=s?Qe:He(e),p=c?Qe:He(t),l=(u=u==Je?Ze:u)==Ze,h=(p=p==Je?Ze:p)==Ze,f=u==p;if(f&&fe(e)){if(!fe(t))return!1;s=!0,l=!1}if(f&&!l)return a||(a=new U),s||Ee(e)?Y(e,t,n,r,o,a):function(e,t,n,r,o,a,s){switch(n){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||!a(new K(e),new K(t)));case"[object Boolean]":case"[object Date]":case"[object Number]":return i(+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 c=X;case"[object Set]":var u=1&r;if(c||(c=q),e.size!=t.size&&!u)return!1;var p=s.get(e);if(p)return p==t;r|=2,s.set(e,t);var l=Y(c(e),c(t),r,o,a,s);return s.delete(e),l;case"[object Symbol]":if(J)return J.call(e)==J.call(t)}return!1}(e,t,u,n,r,o,a);if(!(1&n)){var d=l&&et.call(e,"__wrapped__"),v=h&&et.call(t,"__wrapped__");if(d||v){var y=d?e.value():e,_=v?t.value():t;return a||(a=new U),o(y,_,n,r,a)}}return!!f&&(a||(a=new U),function(e,t,n,r,o,a){var i=1&n,s=Ie(e),c=s.length;if(c!=Ie(t).length&&!i)return!1;for(var u=c;u--;){var p=s[u];if(!(i?p in t:ze.call(t,p)))return!1}var l=a.get(e),h=a.get(t);if(l&&h)return l==t&&h==e;var f=!0;a.set(e,t),a.set(t,e);for(var d=i;++u<c;){var v=e[p=s[u]],y=t[p];if(r)var _=i?r(y,v,p,t,e,a):r(v,y,p,e,t,a);if(!(void 0===_?v===y||o(v,y,n,r,a):_)){f=!1;break}d||(d="constructor"==p)}if(f&&!d){var g=e.constructor,m=t.constructor;g==m||!("constructor"in e)||!("constructor"in t)||"function"==typeof g&&g instanceof g&&"function"==typeof m&&m instanceof m||(f=!1)}return a.delete(e),a.delete(t),f}(e,t,n,r,o,a))}function nt(e,t,n,r,o){return e===t||(null==e||null==t||!re(e)&&!re(t)?e!=e&&t!=t:tt(e,t,n,r,nt,o))}var rt=class{constructor({game:e,rendererSystem:t}){this.renderers=[],this.game=e,this.rendererSystem=t}register(...e){for(const t of e)t.game=this.game,t.rendererManager=this.rendererSystem.rendererManager,t.containerManager=this.rendererSystem.containerManager,this.renderers.push(t)}componentChanged(e){for(const n of e)for(const e of this.renderers){const r=e.observerInfo[n.componentName];if(r){if([t.OBSERVER_TYPE.ADD,t.OBSERVER_TYPE.REMOVE].indexOf(n.type)>-1){try{e.componentChanged&&e.componentChanged(n)}catch(e){console.error(`gameObject: ${n.gameObject.name}, ${n.componentName} is error.`,n,e)}continue}if(r.findIndex(e=>{return t=e,r=n.prop,nt(t,r);var t,r})>-1)try{e.componentChanged&&e.componentChanged(n)}catch(e){console.error(`gameObject: ${n.gameObject&&n.gameObject.name}, ${n.componentName} is componentChanged error.`,n,e)}}}}update(e){for(const t of e.components)for(const n of this.renderers){const r=[];if(n.observerInfo[t.name]&&-1===r.indexOf(e)){r.push(e);try{n.rendererUpdate&&n.rendererUpdate(e)}catch(n){console.info(`gameObject: ${e.name}, ${t.name} is update error`,n)}}}}};class ot{constructor(){this.containerMap={}}addContainer({name:e,container:t,gameObject:n}){this.containerMap[e]=t,t.gName=n.name||e}getContainer(e){return this.containerMap[e]}removeContainer(e){const t=this.containerMap[e];t&&t.destroy({children:!0}),delete this.containerMap[e]}updateTransform({name:e,transform:t}){const n=this.containerMap[e];if(!n||!t)return;const{anchor:r,origin:o,position:a,rotation:i,scale:s,size:c,skew:u}=t;n.rotation=i,n.scale=s,n.pivot.x=c.width*o.x,n.pivot.y=c.height*o.y,n.skew=u;let p=a.x,l=a.y;if(t.parent){const e=t.parent;p+=e.size.width*r.x,l+=e.size.height*r.y}n.position={x:p,y:l}}}var at=function(e){var t={exports:{}};return e(t,t.exports),t.exports}(function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}function o(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function a(e,t,r,a,i){if("function"!=typeof r)throw new TypeError("The listener must be a function");var s=new o(r,a||e,i),c=n?n+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],s]:e._events[c].push(s):(e._events[c]=s,e._eventsCount++),e}function i(e,t){0===--e._eventsCount?e._events=new r:delete e._events[t]}function s(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),s.prototype.eventNames=function(){var e,r,o=[];if(0===this._eventsCount)return o;for(r in e=this._events)t.call(e,r)&&o.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},s.prototype.listeners=function(e){var t=n?n+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var o=0,a=r.length,i=new Array(a);o<a;o++)i[o]=r[o].fn;return i},s.prototype.listenerCount=function(e){var t=n?n+e:e,r=this._events[t];return r?r.fn?1:r.length:0},s.prototype.emit=function(e,t,r,o,a,i){var s=n?n+e:e;if(!this._events[s])return!1;var c,u,p=this._events[s],l=arguments.length;if(p.fn){switch(p.once&&this.removeListener(e,p.fn,void 0,!0),l){case 1:return p.fn.call(p.context),!0;case 2:return p.fn.call(p.context,t),!0;case 3:return p.fn.call(p.context,t,r),!0;case 4:return p.fn.call(p.context,t,r,o),!0;case 5:return p.fn.call(p.context,t,r,o,a),!0;case 6:return p.fn.call(p.context,t,r,o,a,i),!0}for(u=1,c=new Array(l-1);u<l;u++)c[u-1]=arguments[u];p.fn.apply(p.context,c)}else{var h,f=p.length;for(u=0;u<f;u++)switch(p[u].once&&this.removeListener(e,p[u].fn,void 0,!0),l){case 1:p[u].fn.call(p[u].context);break;case 2:p[u].fn.call(p[u].context,t);break;case 3:p[u].fn.call(p[u].context,t,r);break;case 4:p[u].fn.call(p[u].context,t,r,o);break;default:if(!c)for(h=1,c=new Array(l-1);h<l;h++)c[h-1]=arguments[h];p[u].fn.apply(p[u].context,c)}}return!0},s.prototype.on=function(e,t,n){return a(this,e,t,n,!1)},s.prototype.once=function(e,t,n){return a(this,e,t,n,!0)},s.prototype.removeListener=function(e,t,r,o){var a=n?n+e:e;if(!this._events[a])return this;if(!t)return i(this,a),this;var s=this._events[a];if(s.fn)s.fn!==t||o&&!s.once||r&&s.context!==r||i(this,a);else{for(var c=0,u=[],p=s.length;c<p;c++)(s[c].fn!==t||o&&!s[c].once||r&&s[c].context!==r)&&u.push(s[c]);u.length?this._events[a]=1===u.length?u[0]:u:i(this,a)}return this},s.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&i(this,t)):(this._events=new r,this._eventsCount=0),this},s.prototype.off=s.prototype.removeListener,s.prototype.addListener=s.prototype.on,s.prefixed=n,s.EventEmitter=s,e.exports=s}),it=at;let st=class extends it{constructor({system:e,containerManager:t}){super(),this.name="Transform",this.waitRemoveIds=[],this.waitChangeScenes=[],this.containerManager=t,this.init(e)}init(e){this.system=e,this.on("changeScene",({scene:e,mode:t,application:n})=>{this.waitChangeScenes.push({scene:e,mode:t,application:n})})}update(){for(const e of this.waitRemoveIds)this.containerManager.removeContainer(e);this.waitRemoveIds=[];for(const e of this.waitChangeScenes){const t=this.containerManager.getContainer(e.scene.id);t&&(e.application.stage.removeChildren(),e.application.stage.addChild(t))}this.waitChangeScenes=[]}componentChanged(e){e.type===t.OBSERVER_TYPE.ADD?this.addContainer(e):e.type===t.OBSERVER_TYPE.CHANGE?this.change(e):e.type===t.OBSERVER_TYPE.REMOVE&&this.waitRemoveIds.push(e.gameObject.id)}addContainer(e){const t=new n.Container;t.label=e.gameObject.name,this.containerManager.addContainer({name:e.gameObject.id,container:t,gameObject:e.gameObject});const r=e.component;Object.defineProperty(r,"worldTransform",{get:()=>t.renderGroup||t.parentRenderGroup?t.worldTransform:void 0})}change(e){const t=e.component;if(t.parent){this.containerManager.getContainer(t.parent.gameObject.id).addChild(this.containerManager.getContainer(e.gameObject.id));const n=e.gameObject.transform.parent&&e.gameObject.transform.parent.gameObject.getComponent("Render");n&&(n.sortDirty=!0)}else{const t=this.containerManager.getContainer(e.gameObject.id);t.parent&&t.parent.removeChild(t)}}destroy(){this.removeAllListeners(),this.waitRemoveIds=null,this.waitChangeScenes=null,this.system=null,this.containerManager=null}};st=o([t.decorators.componentObserver({Transform:["_parent"]})],st);var ct,ut=st;e.RENDERER_TYPE=void 0,(ct=e.RENDERER_TYPE||(e.RENDERER_TYPE={}))[ct.UNKNOWN=0]="UNKNOWN",ct[ct.WEBGL=1]="WEBGL",ct[ct.CANVAS=2]="CANVAS";let pt=class extends t.System{constructor(){super(...arguments),this.multiApps=[]}init(e){return a(this,void 0,void 0,function*(){this.params=e,this.application=yield this.createApplication(e),this.containerManager=new ot,this.rendererManager=new rt({game:this.game,rendererSystem:this}),this.game.canvas=this.application.canvas,this.transform=new ut({system:this,containerManager:this.containerManager}),this.game.on("sceneChanged",({scene:e,mode:n,params:r})=>a(this,void 0,void 0,function*(){let o;switch(n){case t.LOAD_SCENE_MODE.SINGLE:o=this.application;break;case t.LOAD_SCENE_MODE.MULTI_CANVAS:o=yield this.createMultiApplication({params:r})}e.canvas=o.canvas,this.transform.emit("changeScene",{scene:e,mode:n,application:o})})),this.game.on("pauseScene",({scene:e})=>{this.onPauseScene(e)}),this.game.on("startScene",({scene:e})=>{this.onStartScene(e)}),this.game.on("sceneDestroyed",({scene:e})=>a(this,void 0,void 0,function*(){const t=this.multiApps.findIndex(t=>t.canvas===e.canvas);if(t>-1){this.multiApps.splice(t,1)[0].destroy(),e.destroy()}}))})}registerObserver(e){const t=this.constructor.observerInfo;for(const n in e)t[n]||(t[n]=[]),t[n].push(...e[n])}createMultiApplication({params:e}){return a(this,void 0,void 0,function*(){const t=yield this.createApplication(e);return this.multiApps.push(t),t})}createApplication(e){return a(this,void 0,void 0,function*(){const t=new n.Application;var o;return e.debugMode&&(globalThis.__PIXI_APP__=t),yield t.init(_extends(_extends({sharedTicker:!0},e),{hello:!0})),void 0!==e.enableScroll&&(e.enableScroll?((o=t.renderer).events.autoPreventDefault=!1,o.canvas.style.touchAction="auto"):(e=>{e.events.autoPreventDefault=!0,e.canvas.style.touchAction="none"})(t.renderer)),r.Ticker.shared.stop(),r.Ticker.shared.autoStart=!1,t})}update(){const e=this.componentObserver.clear();for(const t of e)this.transform.componentChanged(t);for(const e of this.game.gameObjects)this.containerManager.updateTransform({name:e.id,transform:e.transform}),this.rendererManager.update(e)}lateUpdate(e){this.transform.update(),this.application.ticker.update(e.time)}onDestroy(){this.application.destroy();for(const e of this.multiApps)e&&e.destroy();this.transform.destroy(),this.transform=null,this.params=null,this.rendererManager=null,this.containerManager=null,this.application=null,this.game=null,this.multiApps=null}resize(e,t){this.params.width=e,this.params.height=t,this.application.renderer.resize(e,t)}getApplicationByScene(e){const t=this.multiApps.findIndex(t=>t.canvas===e.canvas);if(t>-1){return this.multiApps[t]}console.warn("application not found")}onPauseScene(e){const t=this.getApplicationByScene(e);t&&t.stop()}onStartScene(e){const t=this.getApplicationByScene(e);t&&t.start()}resizeByScene(e,t,n){const r=this.getApplicationByScene(e);r&&r.renderer.resize(t,n)}};pt.systemName="Renderer",pt=o([t.decorators.componentObserver({Transform:["_parent"]})],pt);var lt=pt;let ht;function ft(e){e.addPreProcessResourceHandler(function(e){var t,n,r;let o=null===(n=null===(t=e.src)||void 0===t?void 0:t.image)||void 0===n?void 0:n.texture;if(!o)return;Array.isArray(o)||(o=[o]);const a=null!==(r=function(){if(ht)return ht;const e=document.createElement("canvas").getContext("webgl2");if(!e)return console.warn("WebGL not available for compressed textures. Silently failing."),{s3tc:!1,etc:!1,etc1:!1,pvrtc:!1,atc:!1,astc:!1};ht={s3tc:!!e.getExtension("WEBGL_compressed_texture_s3tc"),etc:!!e.getExtension("WEBGL_compressed_texture_etc"),etc1:!!e.getExtension("WEBGL_compressed_texture_etc1"),pvrtc:!!e.getExtension("WEBGL_compressed_texture_pvrtc")||!!e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),atc:!!e.getExtension("WEBGL_compressed_texture_atc"),astc:!!e.getExtension("WEBGL_compressed_texture_astc")};try{console.log("Eva.js Supported Compressed Texture Format List: "+Object.keys(ht).filter(e=>ht[e]).join(", "))}catch(e){}return ht}())&&void 0!==r?r:{};let i=o.find(e=>a[e.type]);i&&_extends(e.src.image,i)})}class dt extends t.System{constructor(e){super(e),this.asyncIdMap={},this.observerInfo=this.constructor.observerInfo}componentChanged(e){}rendererUpdate(e){}update(e){const t=this.componentObserver.clear();for(const e of t)this.componentChanged(e)}increaseAsyncId(e){return this.asyncIdMap[e]=(this.asyncIdMap[e]||0)+1,this.asyncIdMap[e]}validateAsyncId(e,t){return this.asyncIdMap[e]===t}}return e.ContainerManager=ot,e.Renderer=dt,e.RendererManager=rt,e.RendererSystem=lt,e.registerKtx2CompressedTexture=function(e){r.setKTXTranscoderPath(e),r.extensions.add(r.loadKTX2),r.extensions.add(r.resolveCompressedTextureUrl),r.extensions.add(r.detectCompressed),ft(t.resource)},Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.rendererAdapter,PIXI);globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||_EVA_IIFE_renderer;
|
|
@@ -13,19 +13,19 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
13
13
|
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
|
14
14
|
var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
Copyright (c) Microsoft Corporation.
|
|
18
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
19
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
20
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
/******************************************************************************
|
|
17
|
+
Copyright (c) Microsoft Corporation.
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
25
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
19
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
20
|
+
purpose with or without fee is hereby granted.
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
23
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
24
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
25
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
26
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
27
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
28
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
29
29
|
***************************************************************************** */
|
|
30
30
|
|
|
31
31
|
function __decorate(decorators, target, key, desc) {
|
|
@@ -36,20 +36,59 @@ function __decorate(decorators, target, key, desc) {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
39
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
39
40
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
40
41
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
41
42
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
42
|
-
function step(result) { result.done ? resolve(result.value) :
|
|
43
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
43
44
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
44
45
|
});
|
|
45
|
-
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
49
|
+
var e = new Error(message);
|
|
50
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
51
|
+
};
|
|
46
52
|
|
|
53
|
+
/**
|
|
54
|
+
* 渲染管理器类
|
|
55
|
+
*
|
|
56
|
+
* RendererManager 负责管理和协调所有渲染器。
|
|
57
|
+
* 它将组件变化事件分发给相应的渲染器,
|
|
58
|
+
* 并在每帧调用渲染器的更新方法。
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const rendererManager = new RendererManager({
|
|
63
|
+
* game,
|
|
64
|
+
* rendererSystem
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* rendererManager.register(
|
|
68
|
+
* new SpriteRenderer(),
|
|
69
|
+
* new TextRenderer()
|
|
70
|
+
* );
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
47
73
|
class RendererManager {
|
|
74
|
+
/**
|
|
75
|
+
* 构造渲染管理器
|
|
76
|
+
* @param game - 游戏实例
|
|
77
|
+
* @param rendererSystem - 渲染系统实例
|
|
78
|
+
*/
|
|
48
79
|
constructor({ game, rendererSystem }) {
|
|
80
|
+
/** 注册的渲染器列表 */
|
|
49
81
|
this.renderers = [];
|
|
50
82
|
this.game = game;
|
|
51
83
|
this.rendererSystem = rendererSystem;
|
|
52
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* 注册渲染器
|
|
87
|
+
*
|
|
88
|
+
* 将渲染器添加到管理器,并为其设置必要的引用。
|
|
89
|
+
*
|
|
90
|
+
* @param renderers - 要注册的渲染器列表
|
|
91
|
+
*/
|
|
53
92
|
register(...renderers) {
|
|
54
93
|
for (const renderer of renderers) {
|
|
55
94
|
renderer.game = this.game;
|
|
@@ -131,9 +170,11 @@ class ContainerManager {
|
|
|
131
170
|
return;
|
|
132
171
|
const { anchor, origin, position, rotation, scale, size, skew } = transform;
|
|
133
172
|
container.rotation = rotation;
|
|
173
|
+
// @ts-ignore
|
|
134
174
|
container.scale = scale;
|
|
135
175
|
container.pivot.x = size.width * origin.x;
|
|
136
176
|
container.pivot.y = size.height * origin.y;
|
|
177
|
+
// @ts-ignore
|
|
137
178
|
container.skew = skew;
|
|
138
179
|
let x = position.x;
|
|
139
180
|
let y = position.y;
|
|
@@ -142,6 +183,7 @@ class ContainerManager {
|
|
|
142
183
|
x = x + parent.size.width * anchor.x;
|
|
143
184
|
y = y + parent.size.height * anchor.y;
|
|
144
185
|
}
|
|
186
|
+
// @ts-ignore
|
|
145
187
|
container.position = { x, y };
|
|
146
188
|
}
|
|
147
189
|
}
|
|
@@ -158,7 +200,12 @@ let Transform = class Transform extends EventEmitter__default {
|
|
|
158
200
|
init(system) {
|
|
159
201
|
this.system = system;
|
|
160
202
|
this.on('changeScene', ({ scene, mode, application }) => {
|
|
203
|
+
// switch (mode) {
|
|
204
|
+
// case LOAD_SCENE_MODE.SINGLE:
|
|
161
205
|
this.waitChangeScenes.push({ scene, mode, application });
|
|
206
|
+
// break;
|
|
207
|
+
// case LOAD_SCENE_MODE.MULTI_CANVAS:
|
|
208
|
+
// }
|
|
162
209
|
});
|
|
163
210
|
}
|
|
164
211
|
update() {
|
|
@@ -167,6 +214,7 @@ let Transform = class Transform extends EventEmitter__default {
|
|
|
167
214
|
}
|
|
168
215
|
this.waitRemoveIds = [];
|
|
169
216
|
for (const sceneInfo of this.waitChangeScenes) {
|
|
217
|
+
// set scene
|
|
170
218
|
const container = this.containerManager.getContainer(sceneInfo.scene.id);
|
|
171
219
|
if (container) {
|
|
172
220
|
sceneInfo.application.stage.removeChildren();
|
|
@@ -282,6 +330,12 @@ let Renderer$1 = class Renderer extends eva_js.System {
|
|
|
282
330
|
application,
|
|
283
331
|
});
|
|
284
332
|
}));
|
|
333
|
+
this.game.on('pauseScene', ({ scene }) => {
|
|
334
|
+
this.onPauseScene(scene);
|
|
335
|
+
});
|
|
336
|
+
this.game.on('startScene', ({ scene }) => {
|
|
337
|
+
this.onStartScene(scene);
|
|
338
|
+
});
|
|
285
339
|
this.game.on('sceneDestroyed', ({ scene }) => __awaiter(this, void 0, void 0, function* () {
|
|
286
340
|
const index = this.multiApps.findIndex(app => app.canvas === scene.canvas);
|
|
287
341
|
if (index > -1) {
|
|
@@ -293,17 +347,20 @@ let Renderer$1 = class Renderer extends eva_js.System {
|
|
|
293
347
|
});
|
|
294
348
|
}
|
|
295
349
|
registerObserver(observerInfo) {
|
|
350
|
+
// @ts-ignore
|
|
296
351
|
const thisObserverInfo = this.constructor.observerInfo;
|
|
297
352
|
for (const key in observerInfo) {
|
|
298
353
|
if (!thisObserverInfo[key]) {
|
|
299
354
|
thisObserverInfo[key] = [];
|
|
300
355
|
}
|
|
356
|
+
//@ts-ignore
|
|
301
357
|
thisObserverInfo[key].push(...observerInfo[key]);
|
|
302
358
|
}
|
|
303
359
|
}
|
|
304
360
|
createMultiApplication({ params }) {
|
|
305
361
|
return __awaiter(this, void 0, void 0, function* () {
|
|
306
362
|
const app = yield this.createApplication(params);
|
|
363
|
+
// @ts-ignore
|
|
307
364
|
this.multiApps.push(app);
|
|
308
365
|
return app;
|
|
309
366
|
});
|
|
@@ -337,13 +394,6 @@ let Renderer$1 = class Renderer extends eva_js.System {
|
|
|
337
394
|
}
|
|
338
395
|
}
|
|
339
396
|
lateUpdate(e) {
|
|
340
|
-
for (const gameObject of this.game.gameObjects) {
|
|
341
|
-
this.containerManager.updateTransform({
|
|
342
|
-
name: gameObject.id,
|
|
343
|
-
transform: gameObject.transform,
|
|
344
|
-
});
|
|
345
|
-
this.rendererManager.update(gameObject);
|
|
346
|
-
}
|
|
347
397
|
this.transform.update();
|
|
348
398
|
this.application.ticker.update(e.time);
|
|
349
399
|
}
|
|
@@ -364,18 +414,38 @@ let Renderer$1 = class Renderer extends eva_js.System {
|
|
|
364
414
|
resize(width, height) {
|
|
365
415
|
this.params.width = width;
|
|
366
416
|
this.params.height = height;
|
|
417
|
+
// @ts-ignore
|
|
367
418
|
this.application.renderer.resize(width, height);
|
|
368
419
|
}
|
|
369
|
-
|
|
420
|
+
getApplicationByScene(scene) {
|
|
370
421
|
const index = this.multiApps.findIndex(app => app.canvas === scene.canvas);
|
|
371
422
|
if (index > -1) {
|
|
372
423
|
const application = this.multiApps[index];
|
|
373
|
-
application
|
|
424
|
+
return application;
|
|
374
425
|
}
|
|
375
426
|
else {
|
|
376
427
|
console.warn('application not found');
|
|
377
428
|
}
|
|
378
429
|
}
|
|
430
|
+
onPauseScene(scene) {
|
|
431
|
+
const app = this.getApplicationByScene(scene);
|
|
432
|
+
if (app) {
|
|
433
|
+
app.stop();
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
onStartScene(scene) {
|
|
437
|
+
const app = this.getApplicationByScene(scene);
|
|
438
|
+
if (app) {
|
|
439
|
+
app.start();
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
resizeByScene(scene, width, height) {
|
|
443
|
+
const app = this.getApplicationByScene(scene);
|
|
444
|
+
if (app) {
|
|
445
|
+
// @ts-ignore
|
|
446
|
+
app.renderer.resize(width, height);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
379
449
|
};
|
|
380
450
|
Renderer$1.systemName = 'Renderer';
|
|
381
451
|
Renderer$1 = __decorate([
|
|
@@ -392,7 +462,9 @@ function getSuportCompressedTextureFormats() {
|
|
|
392
462
|
const canvas = document.createElement('canvas');
|
|
393
463
|
const gl = canvas.getContext('webgl2');
|
|
394
464
|
if (!gl) {
|
|
465
|
+
// #if _DEBUG
|
|
395
466
|
console.warn('WebGL not available for compressed textures. Silently failing.');
|
|
467
|
+
// #endif
|
|
396
468
|
return {
|
|
397
469
|
s3tc: false,
|
|
398
470
|
etc: false,
|
|
@@ -445,14 +517,29 @@ function registerKtx2CompressedTexture(params) {
|
|
|
445
517
|
addPreProcessResourceHandler(eva_js.resource);
|
|
446
518
|
}
|
|
447
519
|
|
|
520
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
448
521
|
class Renderer extends eva_js.System {
|
|
449
522
|
constructor(params) {
|
|
450
523
|
super(params);
|
|
451
524
|
this.asyncIdMap = {};
|
|
525
|
+
// @ts-ignore
|
|
452
526
|
this.observerInfo = this.constructor.observerInfo;
|
|
453
527
|
}
|
|
528
|
+
// init(arg?: any): void;
|
|
529
|
+
/**
|
|
530
|
+
* 当监听的属性变化时候调用
|
|
531
|
+
*
|
|
532
|
+
* called while the observed component props change.
|
|
533
|
+
*/
|
|
454
534
|
componentChanged(_changed) { }
|
|
535
|
+
/**
|
|
536
|
+
* 每帧调用
|
|
537
|
+
*
|
|
538
|
+
* called by every loop
|
|
539
|
+
* @param _gameObject gameObject
|
|
540
|
+
*/
|
|
455
541
|
rendererUpdate(_gameObject) { }
|
|
542
|
+
// @ts-ignore
|
|
456
543
|
update(e) {
|
|
457
544
|
const changes = this.componentObserver.clear();
|
|
458
545
|
for (const changed of changes) {
|
|
@@ -468,7 +555,19 @@ class Renderer extends eva_js.System {
|
|
|
468
555
|
}
|
|
469
556
|
}
|
|
470
557
|
|
|
558
|
+
// import { BaseTexture, utils } from 'pixi.js';
|
|
471
559
|
const mixinPIXI = () => {
|
|
560
|
+
// BaseTexture.prototype.destroy = function () {
|
|
561
|
+
// if (this.imageUrl) {
|
|
562
|
+
// delete utils.TextureCache[this.imageUrl];
|
|
563
|
+
// this.imageUrl = null;
|
|
564
|
+
// }
|
|
565
|
+
// this.source = null;
|
|
566
|
+
// this.dispose();
|
|
567
|
+
// BaseTexture.removeFromCache(this);
|
|
568
|
+
// this.textureCacheIds = null;
|
|
569
|
+
// this._destroyed = true;
|
|
570
|
+
// };
|
|
472
571
|
};
|
|
473
572
|
|
|
474
573
|
mixinPIXI();
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/renderer-adapter"),n=require("lodash-es/isEqual"),r=require("eventemitter3"),s=require("pixi.js");function a(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var o=a(n),i=a(r);
|
|
2
|
-
/*! *****************************************************************************
|
|
3
|
-
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
5
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
6
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
|
|
8
|
-
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
9
|
-
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
10
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
11
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
12
|
-
|
|
13
|
-
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
|
-
and limitations under the License.
|
|
15
|
-
***************************************************************************** */
|
|
16
|
-
function c(e,t,n,r){var s,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var i=e.length-1;i>=0;i--)(s=e[i])&&(o=(a<3?s(o):a>3?s(t,n,o):s(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}function d(e,t,n,r){return new(n||(n=Promise))((function(s,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function i(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?s(e.value):new n((function(t){t(e.value)})).then(o,i)}c((r=r.apply(e,t||[])).next())}))}var p=class{constructor({game:e,rendererSystem:t}){this.renderers=[],this.game=e,this.rendererSystem=t}register(...e){for(const t of e)t.game=this.game,t.rendererManager=this.rendererSystem.rendererManager,t.containerManager=this.rendererSystem.containerManager,this.renderers.push(t)}componentChanged(t){for(const n of t)for(const t of this.renderers){const r=t.observerInfo[n.componentName];if(r){if([e.OBSERVER_TYPE.ADD,e.OBSERVER_TYPE.REMOVE].indexOf(n.type)>-1){try{t.componentChanged&&t.componentChanged(n)}catch(e){console.error(`gameObject: ${n.gameObject.name}, ${n.componentName} is error.`,n,e)}continue}if(r.findIndex((e=>o(e,n.prop)))>-1)try{t.componentChanged&&t.componentChanged(n)}catch(e){console.error(`gameObject: ${n.gameObject&&n.gameObject.name}, ${n.componentName} is componentChanged error.`,n,e)}}}}update(e){for(const t of e.components)for(const n of this.renderers){const r=[];if(n.observerInfo[t.name]&&-1===r.indexOf(e)){r.push(e);try{n.rendererUpdate&&n.rendererUpdate(e)}catch(n){console.info(`gameObject: ${e.name}, ${t.name} is update error`,n)}}}}};class h{constructor(){this.containerMap={}}addContainer({name:e,container:t,gameObject:n}){this.containerMap[e]=t,t.gName=n.name||e}getContainer(e){return this.containerMap[e]}removeContainer(e){const t=this.containerMap[e];t&&t.destroy({children:!0}),delete this.containerMap[e]}updateTransform({name:e,transform:t}){const n=this.containerMap[e];if(!n||!t)return;const{anchor:r,origin:s,position:a,rotation:o,scale:i,size:c,skew:d}=t;n.rotation=o,n.scale=i,n.pivot.x=c.width*s.x,n.pivot.y=c.height*s.y,n.skew=d;let p=a.x,h=a.y;if(t.parent){const e=t.parent;p+=e.size.width*r.x,h+=e.size.height*r.y}n.position={x:p,y:h}}}let m=class extends i{constructor({system:e,containerManager:t}){super(),this.name="Transform",this.waitRemoveIds=[],this.waitChangeScenes=[],this.containerManager=t,this.init(e)}init(e){this.system=e,this.on("changeScene",(({scene:e,mode:t,application:n})=>{this.waitChangeScenes.push({scene:e,mode:t,application:n})}))}update(){for(const e of this.waitRemoveIds)this.containerManager.removeContainer(e);this.waitRemoveIds=[];for(const e of this.waitChangeScenes){const t=this.containerManager.getContainer(e.scene.id);t&&(e.application.stage.removeChildren(),e.application.stage.addChild(t))}this.waitChangeScenes=[]}componentChanged(t){t.type===e.OBSERVER_TYPE.ADD?this.addContainer(t):t.type===e.OBSERVER_TYPE.CHANGE?this.change(t):t.type===e.OBSERVER_TYPE.REMOVE&&this.waitRemoveIds.push(t.gameObject.id)}addContainer(e){const n=new t.Container;n.label=e.gameObject.name,this.containerManager.addContainer({name:e.gameObject.id,container:n,gameObject:e.gameObject});const r=e.component;Object.defineProperty(r,"worldTransform",{get:()=>n.renderGroup||n.parentRenderGroup?n.worldTransform:void 0})}change(e){const t=e.component;if(t.parent){this.containerManager.getContainer(t.parent.gameObject.id).addChild(this.containerManager.getContainer(e.gameObject.id));const n=e.gameObject.transform.parent&&e.gameObject.transform.parent.gameObject.getComponent("Render");n&&(n.sortDirty=!0)}else{const t=this.containerManager.getContainer(e.gameObject.id);t.parent&&t.parent.removeChild(t)}}destroy(){this.removeAllListeners(),this.waitRemoveIds=null,this.waitChangeScenes=null,this.system=null,this.containerManager=null}};m=c([e.decorators.componentObserver({Transform:["_parent"]})],m);var l,u=m;exports.RENDERER_TYPE=void 0,(l=exports.RENDERER_TYPE||(exports.RENDERER_TYPE={}))[l.UNKNOWN=0]="UNKNOWN",l[l.WEBGL=1]="WEBGL",l[l.CANVAS=2]="CANVAS";let g=class extends e.System{constructor(){super(...arguments),this.multiApps=[]}init(t){return d(this,void 0,void 0,(function*(){this.params=t,this.application=yield this.createApplication(t),this.containerManager=new h,this.rendererManager=new p({game:this.game,rendererSystem:this}),this.game.canvas=this.application.canvas,this.transform=new u({system:this,containerManager:this.containerManager}),this.game.on("sceneChanged",(({scene:t,mode:n,params:r})=>d(this,void 0,void 0,(function*(){let s;switch(n){case e.LOAD_SCENE_MODE.SINGLE:s=this.application;break;case e.LOAD_SCENE_MODE.MULTI_CANVAS:s=yield this.createMultiApplication({params:r})}t.canvas=s.canvas,this.transform.emit("changeScene",{scene:t,mode:n,application:s})})))),this.game.on("sceneDestroyed",(({scene:e})=>d(this,void 0,void 0,(function*(){const t=this.multiApps.findIndex((t=>t.canvas===e.canvas));if(t>-1){this.multiApps.splice(t,1)[0].destroy(),e.destroy()}}))))}))}registerObserver(e){const t=this.constructor.observerInfo;for(const n in e)t[n]||(t[n]=[]),t[n].push(...e[n])}createMultiApplication({params:e}){return d(this,void 0,void 0,(function*(){const t=yield this.createApplication(e);return this.multiApps.push(t),t}))}createApplication(e){return d(this,void 0,void 0,(function*(){const n=new t.Application;var r;return e.debugMode&&(globalThis.__PIXI_APP__=n),yield n.init(Object.assign(Object.assign({sharedTicker:!0},e),{hello:!0})),void 0!==e.enableScroll&&(e.enableScroll?((r=n.renderer).events.autoPreventDefault=!1,r.canvas.style.touchAction="auto"):(e=>{e.events.autoPreventDefault=!0,e.canvas.style.touchAction="none"})(n.renderer)),s.Ticker.shared.stop(),s.Ticker.shared.autoStart=!1,n}))}update(){const e=this.componentObserver.clear();for(const t of e)this.transform.componentChanged(t);for(const e of this.game.gameObjects)this.containerManager.updateTransform({name:e.id,transform:e.transform}),this.rendererManager.update(e)}lateUpdate(e){for(const e of this.game.gameObjects)this.containerManager.updateTransform({name:e.id,transform:e.transform}),this.rendererManager.update(e);this.transform.update(),this.application.ticker.update(e.time)}onDestroy(){this.application.destroy();for(const e of this.multiApps)e&&e.destroy();this.transform.destroy(),this.transform=null,this.params=null,this.rendererManager=null,this.containerManager=null,this.application=null,this.game=null,this.multiApps=null}resize(e,t){this.params.width=e,this.params.height=t,this.application.renderer.resize(e,t)}resizeByScene(e,t,n){const r=this.multiApps.findIndex((t=>t.canvas===e.canvas));if(r>-1){this.multiApps[r].renderer.resize(t,n)}else console.warn("application not found")}};g.systemName="Renderer",g=c([e.decorators.componentObserver({Transform:["_parent"]})],g);var f=g;let v;function y(e){e.addPreProcessResourceHandler((function(e){var t,n,r;let s=null===(n=null===(t=e.src)||void 0===t?void 0:t.image)||void 0===n?void 0:n.texture;if(!s)return;Array.isArray(s)||(s=[s]);const a=null!==(r=function(){if(v)return v;const e=document.createElement("canvas").getContext("webgl2");if(!e)return console.warn("WebGL not available for compressed textures. Silently failing."),{s3tc:!1,etc:!1,etc1:!1,pvrtc:!1,atc:!1,astc:!1};v={s3tc:!!e.getExtension("WEBGL_compressed_texture_s3tc"),etc:!!e.getExtension("WEBGL_compressed_texture_etc"),etc1:!!e.getExtension("WEBGL_compressed_texture_etc1"),pvrtc:!!e.getExtension("WEBGL_compressed_texture_pvrtc")||!!e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),atc:!!e.getExtension("WEBGL_compressed_texture_atc"),astc:!!e.getExtension("WEBGL_compressed_texture_astc")};try{console.log("Eva.js Supported Compressed Texture Format List: "+Object.keys(v).filter((e=>v[e])).join(", "))}catch(e){}return v}())&&void 0!==r?r:{};let o=s.find((e=>a[e.type]));o&&Object.assign(e.src.image,o)}))}class E extends e.System{constructor(e){super(e),this.asyncIdMap={},this.observerInfo=this.constructor.observerInfo}componentChanged(e){}rendererUpdate(e){}update(e){const t=this.componentObserver.clear();for(const e of t)this.componentChanged(e)}increaseAsyncId(e){return this.asyncIdMap[e]=(this.asyncIdMap[e]||0)+1,this.asyncIdMap[e]}validateAsyncId(e,t){return this.asyncIdMap[e]===t}}exports.ContainerManager=h,exports.Renderer=E,exports.RendererManager=p,exports.RendererSystem=f,exports.registerKtx2CompressedTexture=function(t){s.setKTXTranscoderPath(t),s.extensions.add(s.loadKTX2),s.extensions.add(s.resolveCompressedTextureUrl),s.extensions.add(s.detectCompressed),y(e.resource)};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/renderer-adapter"),n=require("lodash-es/isEqual"),r=require("eventemitter3"),s=require("pixi.js");function a(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var o=a(n),i=a(r);function c(e,t,n,r){var s,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var i=e.length-1;i>=0;i--)(s=e[i])&&(o=(a<3?s(o):a>3?s(t,n,o):s(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}function p(e,t,n,r){return new(n||(n=Promise))(function(s,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function i(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,i)}c((r=r.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;var d=class{constructor({game:e,rendererSystem:t}){this.renderers=[],this.game=e,this.rendererSystem=t}register(...e){for(const t of e)t.game=this.game,t.rendererManager=this.rendererSystem.rendererManager,t.containerManager=this.rendererSystem.containerManager,this.renderers.push(t)}componentChanged(t){for(const n of t)for(const t of this.renderers){const r=t.observerInfo[n.componentName];if(r){if([e.OBSERVER_TYPE.ADD,e.OBSERVER_TYPE.REMOVE].indexOf(n.type)>-1){try{t.componentChanged&&t.componentChanged(n)}catch(e){console.error(`gameObject: ${n.gameObject.name}, ${n.componentName} is error.`,n,e)}continue}if(r.findIndex(e=>o(e,n.prop))>-1)try{t.componentChanged&&t.componentChanged(n)}catch(e){console.error(`gameObject: ${n.gameObject&&n.gameObject.name}, ${n.componentName} is componentChanged error.`,n,e)}}}}update(e){for(const t of e.components)for(const n of this.renderers){const r=[];if(n.observerInfo[t.name]&&-1===r.indexOf(e)){r.push(e);try{n.rendererUpdate&&n.rendererUpdate(e)}catch(n){console.info(`gameObject: ${e.name}, ${t.name} is update error`,n)}}}}};class h{constructor(){this.containerMap={}}addContainer({name:e,container:t,gameObject:n}){this.containerMap[e]=t,t.gName=n.name||e}getContainer(e){return this.containerMap[e]}removeContainer(e){const t=this.containerMap[e];t&&t.destroy({children:!0}),delete this.containerMap[e]}updateTransform({name:e,transform:t}){const n=this.containerMap[e];if(!n||!t)return;const{anchor:r,origin:s,position:a,rotation:o,scale:i,size:c,skew:p}=t;n.rotation=o,n.scale=i,n.pivot.x=c.width*s.x,n.pivot.y=c.height*s.y,n.skew=p;let d=a.x,h=a.y;if(t.parent){const e=t.parent;d+=e.size.width*r.x,h+=e.size.height*r.y}n.position={x:d,y:h}}}let m=class extends i{constructor({system:e,containerManager:t}){super(),this.name="Transform",this.waitRemoveIds=[],this.waitChangeScenes=[],this.containerManager=t,this.init(e)}init(e){this.system=e,this.on("changeScene",({scene:e,mode:t,application:n})=>{this.waitChangeScenes.push({scene:e,mode:t,application:n})})}update(){for(const e of this.waitRemoveIds)this.containerManager.removeContainer(e);this.waitRemoveIds=[];for(const e of this.waitChangeScenes){const t=this.containerManager.getContainer(e.scene.id);t&&(e.application.stage.removeChildren(),e.application.stage.addChild(t))}this.waitChangeScenes=[]}componentChanged(t){t.type===e.OBSERVER_TYPE.ADD?this.addContainer(t):t.type===e.OBSERVER_TYPE.CHANGE?this.change(t):t.type===e.OBSERVER_TYPE.REMOVE&&this.waitRemoveIds.push(t.gameObject.id)}addContainer(e){const n=new t.Container;n.label=e.gameObject.name,this.containerManager.addContainer({name:e.gameObject.id,container:n,gameObject:e.gameObject});const r=e.component;Object.defineProperty(r,"worldTransform",{get:()=>n.renderGroup||n.parentRenderGroup?n.worldTransform:void 0})}change(e){const t=e.component;if(t.parent){this.containerManager.getContainer(t.parent.gameObject.id).addChild(this.containerManager.getContainer(e.gameObject.id));const n=e.gameObject.transform.parent&&e.gameObject.transform.parent.gameObject.getComponent("Render");n&&(n.sortDirty=!0)}else{const t=this.containerManager.getContainer(e.gameObject.id);t.parent&&t.parent.removeChild(t)}}destroy(){this.removeAllListeners(),this.waitRemoveIds=null,this.waitChangeScenes=null,this.system=null,this.containerManager=null}};m=c([e.decorators.componentObserver({Transform:["_parent"]})],m);var l,u=m;exports.RENDERER_TYPE=void 0,(l=exports.RENDERER_TYPE||(exports.RENDERER_TYPE={}))[l.UNKNOWN=0]="UNKNOWN",l[l.WEBGL=1]="WEBGL",l[l.CANVAS=2]="CANVAS";let g=class extends e.System{constructor(){super(...arguments),this.multiApps=[]}init(t){return p(this,void 0,void 0,function*(){this.params=t,this.application=yield this.createApplication(t),this.containerManager=new h,this.rendererManager=new d({game:this.game,rendererSystem:this}),this.game.canvas=this.application.canvas,this.transform=new u({system:this,containerManager:this.containerManager}),this.game.on("sceneChanged",({scene:t,mode:n,params:r})=>p(this,void 0,void 0,function*(){let s;switch(n){case e.LOAD_SCENE_MODE.SINGLE:s=this.application;break;case e.LOAD_SCENE_MODE.MULTI_CANVAS:s=yield this.createMultiApplication({params:r})}t.canvas=s.canvas,this.transform.emit("changeScene",{scene:t,mode:n,application:s})})),this.game.on("pauseScene",({scene:e})=>{this.onPauseScene(e)}),this.game.on("startScene",({scene:e})=>{this.onStartScene(e)}),this.game.on("sceneDestroyed",({scene:e})=>p(this,void 0,void 0,function*(){const t=this.multiApps.findIndex(t=>t.canvas===e.canvas);if(t>-1){this.multiApps.splice(t,1)[0].destroy(),e.destroy()}}))})}registerObserver(e){const t=this.constructor.observerInfo;for(const n in e)t[n]||(t[n]=[]),t[n].push(...e[n])}createMultiApplication({params:e}){return p(this,void 0,void 0,function*(){const t=yield this.createApplication(e);return this.multiApps.push(t),t})}createApplication(e){return p(this,void 0,void 0,function*(){const n=new t.Application;var r;return e.debugMode&&(globalThis.__PIXI_APP__=n),yield n.init(Object.assign(Object.assign({sharedTicker:!0},e),{hello:!0})),void 0!==e.enableScroll&&(e.enableScroll?((r=n.renderer).events.autoPreventDefault=!1,r.canvas.style.touchAction="auto"):(e=>{e.events.autoPreventDefault=!0,e.canvas.style.touchAction="none"})(n.renderer)),s.Ticker.shared.stop(),s.Ticker.shared.autoStart=!1,n})}update(){const e=this.componentObserver.clear();for(const t of e)this.transform.componentChanged(t);for(const e of this.game.gameObjects)this.containerManager.updateTransform({name:e.id,transform:e.transform}),this.rendererManager.update(e)}lateUpdate(e){this.transform.update(),this.application.ticker.update(e.time)}onDestroy(){this.application.destroy();for(const e of this.multiApps)e&&e.destroy();this.transform.destroy(),this.transform=null,this.params=null,this.rendererManager=null,this.containerManager=null,this.application=null,this.game=null,this.multiApps=null}resize(e,t){this.params.width=e,this.params.height=t,this.application.renderer.resize(e,t)}getApplicationByScene(e){const t=this.multiApps.findIndex(t=>t.canvas===e.canvas);if(t>-1){return this.multiApps[t]}console.warn("application not found")}onPauseScene(e){const t=this.getApplicationByScene(e);t&&t.stop()}onStartScene(e){const t=this.getApplicationByScene(e);t&&t.start()}resizeByScene(e,t,n){const r=this.getApplicationByScene(e);r&&r.renderer.resize(t,n)}};g.systemName="Renderer",g=c([e.decorators.componentObserver({Transform:["_parent"]})],g);var f=g;let v;function y(e){e.addPreProcessResourceHandler(function(e){var t,n,r;let s=null===(n=null===(t=e.src)||void 0===t?void 0:t.image)||void 0===n?void 0:n.texture;if(!s)return;Array.isArray(s)||(s=[s]);const a=null!==(r=function(){if(v)return v;const e=document.createElement("canvas").getContext("webgl2");if(!e)return console.warn("WebGL not available for compressed textures. Silently failing."),{s3tc:!1,etc:!1,etc1:!1,pvrtc:!1,atc:!1,astc:!1};v={s3tc:!!e.getExtension("WEBGL_compressed_texture_s3tc"),etc:!!e.getExtension("WEBGL_compressed_texture_etc"),etc1:!!e.getExtension("WEBGL_compressed_texture_etc1"),pvrtc:!!e.getExtension("WEBGL_compressed_texture_pvrtc")||!!e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),atc:!!e.getExtension("WEBGL_compressed_texture_atc"),astc:!!e.getExtension("WEBGL_compressed_texture_astc")};try{console.log("Eva.js Supported Compressed Texture Format List: "+Object.keys(v).filter(e=>v[e]).join(", "))}catch(e){}return v}())&&void 0!==r?r:{};let o=s.find(e=>a[e.type]);o&&Object.assign(e.src.image,o)})}class E extends e.System{constructor(e){super(e),this.asyncIdMap={},this.observerInfo=this.constructor.observerInfo}componentChanged(e){}rendererUpdate(e){}update(e){const t=this.componentObserver.clear();for(const e of t)this.componentChanged(e)}increaseAsyncId(e){return this.asyncIdMap[e]=(this.asyncIdMap[e]||0)+1,this.asyncIdMap[e]}validateAsyncId(e,t){return this.asyncIdMap[e]===t}}exports.ContainerManager=h,exports.Renderer=E,exports.RendererManager=d,exports.RendererSystem=f,exports.registerKtx2CompressedTexture=function(t){s.setKTXTranscoderPath(t),s.extensions.add(s.loadKTX2),s.extensions.add(s.resolveCompressedTextureUrl),s.extensions.add(s.detectCompressed),y(e.resource)};
|
|
@@ -37,14 +37,40 @@ declare interface Params {
|
|
|
37
37
|
export declare function registerKtx2CompressedTexture(params: Params): void;
|
|
38
38
|
|
|
39
39
|
export declare class Renderer<T extends {} = {}> extends System<T> {
|
|
40
|
+
/**
|
|
41
|
+
* Renderer name
|
|
42
|
+
*/
|
|
40
43
|
name: string;
|
|
44
|
+
/**
|
|
45
|
+
* currentGame
|
|
46
|
+
*/
|
|
41
47
|
game: Game;
|
|
48
|
+
/**
|
|
49
|
+
* observer component props info
|
|
50
|
+
*/
|
|
42
51
|
static observerInfo: PureObserverInfo;
|
|
52
|
+
/**
|
|
53
|
+
* observer component props info
|
|
54
|
+
*/
|
|
43
55
|
observerInfo: PureObserverInfo;
|
|
56
|
+
/**
|
|
57
|
+
* containerManager
|
|
58
|
+
*/
|
|
44
59
|
containerManager: ContainerManager;
|
|
45
60
|
rendererManager: RendererManager;
|
|
46
61
|
constructor(params?: T);
|
|
62
|
+
/**
|
|
63
|
+
* 当监听的属性变化时候调用
|
|
64
|
+
*
|
|
65
|
+
* called while the observed component props change.
|
|
66
|
+
*/
|
|
47
67
|
componentChanged(_changed: ComponentChanged): void;
|
|
68
|
+
/**
|
|
69
|
+
* 每帧调用
|
|
70
|
+
*
|
|
71
|
+
* called by every loop
|
|
72
|
+
* @param _gameObject gameObject
|
|
73
|
+
*/
|
|
48
74
|
rendererUpdate(_gameObject: GameObject): void;
|
|
49
75
|
update(e?: UpdateParams): void;
|
|
50
76
|
protected asyncIdMap: Record<number, number>;
|
|
@@ -58,14 +84,49 @@ export declare enum RENDERER_TYPE {
|
|
|
58
84
|
CANVAS = 2
|
|
59
85
|
}
|
|
60
86
|
|
|
87
|
+
/**
|
|
88
|
+
* 渲染管理器类
|
|
89
|
+
*
|
|
90
|
+
* RendererManager 负责管理和协调所有渲染器。
|
|
91
|
+
* 它将组件变化事件分发给相应的渲染器,
|
|
92
|
+
* 并在每帧调用渲染器的更新方法。
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const rendererManager = new RendererManager({
|
|
97
|
+
* game,
|
|
98
|
+
* rendererSystem
|
|
99
|
+
* });
|
|
100
|
+
*
|
|
101
|
+
* rendererManager.register(
|
|
102
|
+
* new SpriteRenderer(),
|
|
103
|
+
* new TextRenderer()
|
|
104
|
+
* );
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
61
107
|
export declare class RendererManager {
|
|
108
|
+
/** 游戏实例引用 */
|
|
62
109
|
game: Game;
|
|
110
|
+
/** 渲染系统引用 */
|
|
63
111
|
rendererSystem: RendererSystem;
|
|
112
|
+
/**
|
|
113
|
+
* 构造渲染管理器
|
|
114
|
+
* @param game - 游戏实例
|
|
115
|
+
* @param rendererSystem - 渲染系统实例
|
|
116
|
+
*/
|
|
64
117
|
constructor({ game, rendererSystem }: {
|
|
65
118
|
game: any;
|
|
66
119
|
rendererSystem: any;
|
|
67
120
|
});
|
|
121
|
+
/** 注册的渲染器列表 */
|
|
68
122
|
renderers: Renderer[];
|
|
123
|
+
/**
|
|
124
|
+
* 注册渲染器
|
|
125
|
+
*
|
|
126
|
+
* 将渲染器添加到管理器,并为其设置必要的引用。
|
|
127
|
+
*
|
|
128
|
+
* @param renderers - 要注册的渲染器列表
|
|
129
|
+
*/
|
|
69
130
|
register(...renderers: Renderer[]): void;
|
|
70
131
|
componentChanged(changes: ComponentChanged[]): void;
|
|
71
132
|
update(gameObject: GameObject): void;
|
|
@@ -91,6 +152,9 @@ export declare class RendererSystem extends System<RendererSystemParams> {
|
|
|
91
152
|
lateUpdate(e: any): void;
|
|
92
153
|
onDestroy(): void;
|
|
93
154
|
resize(width: any, height: any): void;
|
|
155
|
+
private getApplicationByScene;
|
|
156
|
+
private onPauseScene;
|
|
157
|
+
private onStartScene;
|
|
94
158
|
resizeByScene(scene: any, width: number, height: number): void;
|
|
95
159
|
}
|
|
96
160
|
|
|
@@ -4,19 +4,19 @@ import isEqual from 'lodash-es/isEqual';
|
|
|
4
4
|
import EventEmitter from 'eventemitter3';
|
|
5
5
|
import { Ticker, setKTXTranscoderPath, extensions, loadKTX2, resolveCompressedTextureUrl, detectCompressed } from 'pixi.js';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
Copyright (c) Microsoft Corporation.
|
|
9
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
10
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
11
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
/******************************************************************************
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
16
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
20
|
***************************************************************************** */
|
|
21
21
|
|
|
22
22
|
function __decorate(decorators, target, key, desc) {
|
|
@@ -27,20 +27,59 @@ function __decorate(decorators, target, key, desc) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
30
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
31
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
32
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
33
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
-
function step(result) { result.done ? resolve(result.value) :
|
|
34
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
35
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
36
|
});
|
|
36
|
-
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
40
|
+
var e = new Error(message);
|
|
41
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
42
|
+
};
|
|
37
43
|
|
|
44
|
+
/**
|
|
45
|
+
* 渲染管理器类
|
|
46
|
+
*
|
|
47
|
+
* RendererManager 负责管理和协调所有渲染器。
|
|
48
|
+
* 它将组件变化事件分发给相应的渲染器,
|
|
49
|
+
* 并在每帧调用渲染器的更新方法。
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const rendererManager = new RendererManager({
|
|
54
|
+
* game,
|
|
55
|
+
* rendererSystem
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* rendererManager.register(
|
|
59
|
+
* new SpriteRenderer(),
|
|
60
|
+
* new TextRenderer()
|
|
61
|
+
* );
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
38
64
|
class RendererManager {
|
|
65
|
+
/**
|
|
66
|
+
* 构造渲染管理器
|
|
67
|
+
* @param game - 游戏实例
|
|
68
|
+
* @param rendererSystem - 渲染系统实例
|
|
69
|
+
*/
|
|
39
70
|
constructor({ game, rendererSystem }) {
|
|
71
|
+
/** 注册的渲染器列表 */
|
|
40
72
|
this.renderers = [];
|
|
41
73
|
this.game = game;
|
|
42
74
|
this.rendererSystem = rendererSystem;
|
|
43
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* 注册渲染器
|
|
78
|
+
*
|
|
79
|
+
* 将渲染器添加到管理器,并为其设置必要的引用。
|
|
80
|
+
*
|
|
81
|
+
* @param renderers - 要注册的渲染器列表
|
|
82
|
+
*/
|
|
44
83
|
register(...renderers) {
|
|
45
84
|
for (const renderer of renderers) {
|
|
46
85
|
renderer.game = this.game;
|
|
@@ -122,9 +161,11 @@ class ContainerManager {
|
|
|
122
161
|
return;
|
|
123
162
|
const { anchor, origin, position, rotation, scale, size, skew } = transform;
|
|
124
163
|
container.rotation = rotation;
|
|
164
|
+
// @ts-ignore
|
|
125
165
|
container.scale = scale;
|
|
126
166
|
container.pivot.x = size.width * origin.x;
|
|
127
167
|
container.pivot.y = size.height * origin.y;
|
|
168
|
+
// @ts-ignore
|
|
128
169
|
container.skew = skew;
|
|
129
170
|
let x = position.x;
|
|
130
171
|
let y = position.y;
|
|
@@ -133,6 +174,7 @@ class ContainerManager {
|
|
|
133
174
|
x = x + parent.size.width * anchor.x;
|
|
134
175
|
y = y + parent.size.height * anchor.y;
|
|
135
176
|
}
|
|
177
|
+
// @ts-ignore
|
|
136
178
|
container.position = { x, y };
|
|
137
179
|
}
|
|
138
180
|
}
|
|
@@ -149,7 +191,12 @@ let Transform = class Transform extends EventEmitter {
|
|
|
149
191
|
init(system) {
|
|
150
192
|
this.system = system;
|
|
151
193
|
this.on('changeScene', ({ scene, mode, application }) => {
|
|
194
|
+
// switch (mode) {
|
|
195
|
+
// case LOAD_SCENE_MODE.SINGLE:
|
|
152
196
|
this.waitChangeScenes.push({ scene, mode, application });
|
|
197
|
+
// break;
|
|
198
|
+
// case LOAD_SCENE_MODE.MULTI_CANVAS:
|
|
199
|
+
// }
|
|
153
200
|
});
|
|
154
201
|
}
|
|
155
202
|
update() {
|
|
@@ -158,6 +205,7 @@ let Transform = class Transform extends EventEmitter {
|
|
|
158
205
|
}
|
|
159
206
|
this.waitRemoveIds = [];
|
|
160
207
|
for (const sceneInfo of this.waitChangeScenes) {
|
|
208
|
+
// set scene
|
|
161
209
|
const container = this.containerManager.getContainer(sceneInfo.scene.id);
|
|
162
210
|
if (container) {
|
|
163
211
|
sceneInfo.application.stage.removeChildren();
|
|
@@ -273,6 +321,12 @@ let Renderer$1 = class Renderer extends System {
|
|
|
273
321
|
application,
|
|
274
322
|
});
|
|
275
323
|
}));
|
|
324
|
+
this.game.on('pauseScene', ({ scene }) => {
|
|
325
|
+
this.onPauseScene(scene);
|
|
326
|
+
});
|
|
327
|
+
this.game.on('startScene', ({ scene }) => {
|
|
328
|
+
this.onStartScene(scene);
|
|
329
|
+
});
|
|
276
330
|
this.game.on('sceneDestroyed', ({ scene }) => __awaiter(this, void 0, void 0, function* () {
|
|
277
331
|
const index = this.multiApps.findIndex(app => app.canvas === scene.canvas);
|
|
278
332
|
if (index > -1) {
|
|
@@ -284,17 +338,20 @@ let Renderer$1 = class Renderer extends System {
|
|
|
284
338
|
});
|
|
285
339
|
}
|
|
286
340
|
registerObserver(observerInfo) {
|
|
341
|
+
// @ts-ignore
|
|
287
342
|
const thisObserverInfo = this.constructor.observerInfo;
|
|
288
343
|
for (const key in observerInfo) {
|
|
289
344
|
if (!thisObserverInfo[key]) {
|
|
290
345
|
thisObserverInfo[key] = [];
|
|
291
346
|
}
|
|
347
|
+
//@ts-ignore
|
|
292
348
|
thisObserverInfo[key].push(...observerInfo[key]);
|
|
293
349
|
}
|
|
294
350
|
}
|
|
295
351
|
createMultiApplication({ params }) {
|
|
296
352
|
return __awaiter(this, void 0, void 0, function* () {
|
|
297
353
|
const app = yield this.createApplication(params);
|
|
354
|
+
// @ts-ignore
|
|
298
355
|
this.multiApps.push(app);
|
|
299
356
|
return app;
|
|
300
357
|
});
|
|
@@ -328,13 +385,6 @@ let Renderer$1 = class Renderer extends System {
|
|
|
328
385
|
}
|
|
329
386
|
}
|
|
330
387
|
lateUpdate(e) {
|
|
331
|
-
for (const gameObject of this.game.gameObjects) {
|
|
332
|
-
this.containerManager.updateTransform({
|
|
333
|
-
name: gameObject.id,
|
|
334
|
-
transform: gameObject.transform,
|
|
335
|
-
});
|
|
336
|
-
this.rendererManager.update(gameObject);
|
|
337
|
-
}
|
|
338
388
|
this.transform.update();
|
|
339
389
|
this.application.ticker.update(e.time);
|
|
340
390
|
}
|
|
@@ -355,18 +405,38 @@ let Renderer$1 = class Renderer extends System {
|
|
|
355
405
|
resize(width, height) {
|
|
356
406
|
this.params.width = width;
|
|
357
407
|
this.params.height = height;
|
|
408
|
+
// @ts-ignore
|
|
358
409
|
this.application.renderer.resize(width, height);
|
|
359
410
|
}
|
|
360
|
-
|
|
411
|
+
getApplicationByScene(scene) {
|
|
361
412
|
const index = this.multiApps.findIndex(app => app.canvas === scene.canvas);
|
|
362
413
|
if (index > -1) {
|
|
363
414
|
const application = this.multiApps[index];
|
|
364
|
-
application
|
|
415
|
+
return application;
|
|
365
416
|
}
|
|
366
417
|
else {
|
|
367
418
|
console.warn('application not found');
|
|
368
419
|
}
|
|
369
420
|
}
|
|
421
|
+
onPauseScene(scene) {
|
|
422
|
+
const app = this.getApplicationByScene(scene);
|
|
423
|
+
if (app) {
|
|
424
|
+
app.stop();
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
onStartScene(scene) {
|
|
428
|
+
const app = this.getApplicationByScene(scene);
|
|
429
|
+
if (app) {
|
|
430
|
+
app.start();
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
resizeByScene(scene, width, height) {
|
|
434
|
+
const app = this.getApplicationByScene(scene);
|
|
435
|
+
if (app) {
|
|
436
|
+
// @ts-ignore
|
|
437
|
+
app.renderer.resize(width, height);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
370
440
|
};
|
|
371
441
|
Renderer$1.systemName = 'Renderer';
|
|
372
442
|
Renderer$1 = __decorate([
|
|
@@ -383,7 +453,9 @@ function getSuportCompressedTextureFormats() {
|
|
|
383
453
|
const canvas = document.createElement('canvas');
|
|
384
454
|
const gl = canvas.getContext('webgl2');
|
|
385
455
|
if (!gl) {
|
|
456
|
+
// #if _DEBUG
|
|
386
457
|
console.warn('WebGL not available for compressed textures. Silently failing.');
|
|
458
|
+
// #endif
|
|
387
459
|
return {
|
|
388
460
|
s3tc: false,
|
|
389
461
|
etc: false,
|
|
@@ -436,14 +508,29 @@ function registerKtx2CompressedTexture(params) {
|
|
|
436
508
|
addPreProcessResourceHandler(resource);
|
|
437
509
|
}
|
|
438
510
|
|
|
511
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
439
512
|
class Renderer extends System {
|
|
440
513
|
constructor(params) {
|
|
441
514
|
super(params);
|
|
442
515
|
this.asyncIdMap = {};
|
|
516
|
+
// @ts-ignore
|
|
443
517
|
this.observerInfo = this.constructor.observerInfo;
|
|
444
518
|
}
|
|
519
|
+
// init(arg?: any): void;
|
|
520
|
+
/**
|
|
521
|
+
* 当监听的属性变化时候调用
|
|
522
|
+
*
|
|
523
|
+
* called while the observed component props change.
|
|
524
|
+
*/
|
|
445
525
|
componentChanged(_changed) { }
|
|
526
|
+
/**
|
|
527
|
+
* 每帧调用
|
|
528
|
+
*
|
|
529
|
+
* called by every loop
|
|
530
|
+
* @param _gameObject gameObject
|
|
531
|
+
*/
|
|
446
532
|
rendererUpdate(_gameObject) { }
|
|
533
|
+
// @ts-ignore
|
|
447
534
|
update(e) {
|
|
448
535
|
const changes = this.componentObserver.clear();
|
|
449
536
|
for (const changed of changes) {
|
|
@@ -459,7 +546,19 @@ class Renderer extends System {
|
|
|
459
546
|
}
|
|
460
547
|
}
|
|
461
548
|
|
|
549
|
+
// import { BaseTexture, utils } from 'pixi.js';
|
|
462
550
|
const mixinPIXI = () => {
|
|
551
|
+
// BaseTexture.prototype.destroy = function () {
|
|
552
|
+
// if (this.imageUrl) {
|
|
553
|
+
// delete utils.TextureCache[this.imageUrl];
|
|
554
|
+
// this.imageUrl = null;
|
|
555
|
+
// }
|
|
556
|
+
// this.source = null;
|
|
557
|
+
// this.dispose();
|
|
558
|
+
// BaseTexture.removeFromCache(this);
|
|
559
|
+
// this.textureCacheIds = null;
|
|
560
|
+
// this._destroyed = true;
|
|
561
|
+
// };
|
|
463
562
|
};
|
|
464
563
|
|
|
465
564
|
mixinPIXI();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2-beta.0",
|
|
4
4
|
"description": "@eva/plugin-renderer",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-renderer.esm.js",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@eva/eva.js": "2.0.
|
|
22
|
-
"@eva/renderer-adapter": "2.0.
|
|
23
|
-
"eventemitter3": "^
|
|
21
|
+
"@eva/eva.js": "2.0.2-beta.0",
|
|
22
|
+
"@eva/renderer-adapter": "2.0.2-beta.0",
|
|
23
|
+
"eventemitter3": "^5.0.4",
|
|
24
24
|
"lodash-es": "^4.17.21",
|
|
25
|
-
"pixi.js": "^8.
|
|
25
|
+
"pixi.js": "^8.17.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"resource-loader": "^4.0.0-rc4"
|