@eva/plugin-renderer-tilemap 2.1.0-beta.2 → 2.1.0-beta.4
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.
|
@@ -41,6 +41,10 @@ var _EVA_IIFE_tilemap = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
41
41
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
45
|
+
var e = new Error(message);
|
|
46
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
47
|
+
};
|
|
44
48
|
function __rest(s, e) {
|
|
45
49
|
var t = {};
|
|
46
50
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var
|
|
1
|
+
function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{},globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||{};var _EVA_IIFE_tilemap=function(e,t,r,n){"use strict";function o(e,t,r,n){var o,i=arguments.length,s=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,n);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(s=(i<3?o(s):i>3?o(t,r,s):o(t,r))||s);return i>3&&s&&Object.defineProperty(t,r,s),s}function i(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function s(e,t,r,n){return new(r||(r=Promise))(function(o,i){function s(e){try{a(n.next(e))}catch(e){i(e)}}function l(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(s,l)}a((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError,"function"==typeof SuppressedError&&SuppressedError;class l extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const a="IDE_PROPERTY_METADATA";function c(e,t,r,n){let o=Reflect.getMetadata("design:type",e,t),i=o===Array;const s=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(o);if("unknown"!==s&&(o=s),n){const e=n();Array.isArray(e)?(i=!0,o=e[0]):o=e}const l=Reflect.getMetadata(a,e.constructor)||{},c=_extends(_extends(_extends({},l[t]||{}),{type:o,isArray:i}),r);l[t]=c,Reflect.defineMetadata(a,l,e.constructor);!function(e,t,r){const n=e.constructor,o=n.IDEProps||{};o[t]=_extends(_extends({key:t},o[t]),r),n.IDEProps=o}(e,t,function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}(c,["isArray"]))}function d(e){return t={type:e},(e,n)=>{if("symbol"==typeof n)throw new l;const{options:o,returnTypeFunc:i}=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(t,r);c(e,n,o,i)};var t,r}var u;!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(u||(u={}));class p extends t.Component{constructor(){super(...arguments),this.tileset="",this.tileWidth=32,this.tileHeight=32,this.tilesetSpacing=0,this.tilesetMargin=0,this.layers=[]}init(e){e&&_extends(this,e)}}p.componentName="Tilemap",o([d("string"),i("design:type",String)],p.prototype,"tileset",void 0),o([d("number"),i("design:type",Number)],p.prototype,"tileWidth",void 0),o([d("number"),i("design:type",Number)],p.prototype,"tileHeight",void 0),o([d("number"),i("design:type",Number)],p.prototype,"tilesetSpacing",void 0),o([d("number"),i("design:type",Number)],p.prototype,"tilesetMargin",void 0);let f=class extends r.Renderer{constructor(){super(...arguments),this.name="Tilemap",this.records={}}init(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){}componentChanged(e){var r,o,i;return s(this,void 0,void 0,function*(){if("Tilemap"!==e.componentName)return;const s=e.component,l=e.gameObject.id;if(e.type===t.OBSERVER_TYPE.ADD){const r=this.increaseAsyncId(l);let o=null;if(s.tileset){const{instance:n}=yield t.resource.getResource(s.tileset);if(!this.validateAsyncId(l,r))return;if(!n)return void console.error(`GameObject:${e.gameObject.name}'s Tilemap tileset load error`);o=n}if(!o)return;const i=new n.Container,a=this.containerManager.getContainer(l);a&&a.addChildAt(i,0);const c={root:i,layerContainers:[],frameTextures:[],baseTexture:o};this.records[l]=c,this.buildLayers(c,s)}else if(e.type===t.OBSERVER_TYPE.CHANGE){const n=this.records[l];if(!n)return;if("tileset"===(null===(o=null===(r=e.prop)||void 0===r?void 0:r.prop)||void 0===o?void 0:o[0])){const e=this.increaseAsyncId(l),{instance:r}=yield t.resource.getResource(s.tileset);if(!this.validateAsyncId(l,e))return;if(!r)return;this.tearDownChildren(n),n.baseTexture=r,this.buildLayers(n,s)}}else if(e.type===t.OBSERVER_TYPE.REMOVE){this.increaseAsyncId(l);const e=this.records[l];if(!e)return;this.tearDownChildren(e);const t=null===(i=this.containerManager)||void 0===i?void 0:i.getContainer(l);t&&t.removeChild(e.root),e.root.destroy({children:!0}),delete this.records[l]}})}tearDownChildren(e){for(const t of e.layerContainers)e.root.removeChild(t),t.destroy({children:!0});e.layerContainers=[];for(const t of e.frameTextures)try{t.destroy(!1)}catch(e){}e.frameTextures=[]}buildLayers(e,t){var r,o,i,s,l,a,c,d,u,p;const f=e.baseTexture;if(!f)return;const h=t.tileWidth||32,y=t.tileHeight||32,g=null!==(r=t.renderTileWidth)&&void 0!==r?r:h,m=null!==(o=t.renderTileHeight)&&void 0!==o?o:y,v=t.tilesetMargin||0,b=t.tilesetSpacing||0,E=null!==(u=null!==(c=null!==(a=null!==(s=null===(i=f.orig)||void 0===i?void 0:i.width)&&void 0!==s?s:null===(l=f.source)||void 0===l?void 0:l.width)&&void 0!==a?a:f.width)&&void 0!==c?c:null===(d=f.frame)||void 0===d?void 0:d.width)&&void 0!==u?u:0,T=E>0?Math.max(1,Math.floor((E-v+b)/(h+b))):1,A=t.tilesetColumns&&t.tilesetColumns>0?t.tilesetColumns:T,w=new Map,x=t=>{var r,o;if(t<=0)return null;const i=t-1,s=w.get(i);if(s)return s;const l=i%A,a=Math.floor(i/A),c=v+l*(h+b),d=v+a*(y+b);try{const t=null!==(o=null!==(r=f.source)&&void 0!==r?r:f.baseTexture)&&void 0!==o?o:f,s=new n.Texture({source:t,frame:new n.Rectangle(c,d,h,y)});return w.set(i,s),e.frameTextures.push(s),s}catch(e){return"undefined"!=typeof console&&console.warn("[Tilemap] Texture slice failed, falling back to base",e),f}};for(const r of t.layers||[]){const t=new n.Container;t.label=null!==(p=r.name)&&void 0!==p?p:"tilemap-layer";const o=r.offsetX||0,i=r.offsetY||0;null!=r.alpha&&(t.alpha=r.alpha),!1===r.visible&&(t.visible=!1);const s=r.data||[],l=r.tint;for(let e=0;e<s.length;e++){const r=s[e];if(r)for(let s=0;s<r.length;s++){const a=r[s];if(!a||a<=0)continue;const c=x(a);if(!c)continue;const d=new n.Sprite(c);d.x=o+s*h,d.y=i+e*y,d.width=g,d.height=m,null!=l&&(d.tint=l),t.addChild(d)}}e.root.addChild(t),e.layerContainers.push(t)}}destroy(){var e;for(const t in this.records){const r=parseInt(t),n=this.records[r];this.tearDownChildren(n);const o=null===(e=this.containerManager)||void 0===e?void 0:e.getContainer(r);o&&o.removeChild(n.root),n.root.destroy({children:!0}),delete this.records[r]}}};f.systemName="Tilemap",f=o([t.decorators.componentObserver({Tilemap:[{prop:["tileset"],deep:!1}]})],f);var h=f;return e.Tilemap=p,e.TilemapSystem=h,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);globalThis.EVA.plugin.renderer.tilemap=globalThis.EVA.plugin.renderer.tilemap||_EVA_IIFE_tilemap;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-tilemap",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.4",
|
|
4
4
|
"description": "@eva/plugin-renderer-tilemap",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-renderer-tilemap.esm.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"homepage": "https://eva.js.org",
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@eva/inspector-decorator": "^2.0.0-beta.0",
|
|
23
|
-
"@eva/eva.js": "2.1.0-beta.
|
|
24
|
-
"@eva/plugin-renderer": "2.1.0-beta.
|
|
23
|
+
"@eva/eva.js": "2.1.0-beta.4",
|
|
24
|
+
"@eva/plugin-renderer": "2.1.0-beta.4",
|
|
25
25
|
"pixi.js": "^8.6.3"
|
|
26
26
|
}
|
|
27
27
|
}
|