@safe-engine/pixi 8.8.4 → 8.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/app.d.ts CHANGED
@@ -3,5 +3,5 @@ export declare function startGame(defaultFont: any, designedResolution: {
3
3
  width: number;
4
4
  height: number;
5
5
  }, assetManager: AssetsClass, id?: string): Promise<Application<Renderer>>;
6
- export declare function loadAll(assets: any, cb?: (progress: number) => void): Promise<void>;
6
+ export declare function loadAll(assets: any, cb?: (progress: number) => void): Promise<any>;
7
7
  //# sourceMappingURL=app.d.ts.map
package/dist/app.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAU,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAMpE,wBAAsB,SAAS,CAC7B,WAAW,KAAA,EACX,kBAAkB;;;CAA+B,EACjD,YAAY,EAAE,WAAW,EACzB,EAAE,SAAe,GAChB,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CA6BhC;AAqBD,wBAAgB,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,iBAuBnE"}
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAU,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAMpE,wBAAsB,SAAS,CAC7B,WAAW,KAAA,EACX,kBAAkB;;;CAA+B,EACjD,YAAY,EAAE,WAAW,EACzB,EAAE,SAAe,GAChB,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CA6BhC;AAqBD,wBAAgB,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,gBAenE"}
package/dist/app.js CHANGED
@@ -63,13 +63,9 @@ function initWorld(defaultFont) {
63
63
  }
64
64
  export function loadAll(assets, cb) {
65
65
  const allAssets = [];
66
- const fontBundle = {};
67
66
  Object.values(assets).forEach((value) => {
68
67
  if (value.skeleton) {
69
- allAssets.push(value.skeleton);
70
- }
71
- else if (value.atlas) {
72
- allAssets.push(value.atlas);
68
+ allAssets.push(value.skeleton, value.atlas);
73
69
  if (value.texture) {
74
70
  allAssets.push(value.texture);
75
71
  }
@@ -77,15 +73,9 @@ export function loadAll(assets, cb) {
77
73
  allAssets.push(value.atlas.replace('.atlas', '.png'));
78
74
  }
79
75
  }
80
- else if (value.endsWith('.ttf')) {
81
- fontBundle[value] = value;
82
- }
83
76
  else {
84
77
  allAssets.push(value);
85
78
  }
86
79
  });
87
- Assets.addBundle('fonts', fontBundle);
88
- return Promise.all([Assets.loadBundle('fonts')]).then(() => __awaiter(this, void 0, void 0, function* () {
89
- yield Assets.load(allAssets, cb);
90
- }));
80
+ return Assets.load(allAssets, cb);
91
81
  }
@@ -0,0 +1,12 @@
1
+ import { Tilemap } from '@pixi/tilemap';
2
+ import { BaseComponentProps } from '..';
3
+ import { ComponentX } from '../components/BaseComponent';
4
+ interface TiledMapCompProps extends BaseComponentProps<TiledMapComp> {
5
+ mapUrl: string;
6
+ }
7
+ export declare class TiledMapComp extends ComponentX<TiledMapCompProps, Tilemap> {
8
+ getPositionAt(x: number, y: number): import("@pixi/tilemap/lib/TileTextureArray").TileTextureArray;
9
+ render(): this;
10
+ }
11
+ export {};
12
+ //# sourceMappingURL=TiledMapComp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TiledMapComp.d.ts","sourceRoot":"","sources":["../../src/tiledmap/TiledMapComp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,kBAAkB,EAAuB,MAAM,IAAI,CAAA;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAGxD,UAAU,iBAAkB,SAAQ,kBAAkB,CAAC,YAAY,CAAC;IAClE,MAAM,EAAE,MAAM,CAAA;CACf;AAED,qBAAa,YAAa,SAAQ,UAAU,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACtE,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAIlC,MAAM;CAQP"}
@@ -0,0 +1,16 @@
1
+ import { GameWorld, NodeComp } from '..';
2
+ import { ComponentX } from '../components/BaseComponent';
3
+ import { loadIsometricMap } from './tield';
4
+ export class TiledMapComp extends ComponentX {
5
+ getPositionAt(x, y) {
6
+ return this.node.instance.getTileset();
7
+ }
8
+ render() {
9
+ const tiledMap = loadIsometricMap(this.props.mapUrl);
10
+ const world = GameWorld.Instance;
11
+ const entity = world.entities.create();
12
+ entity.assign(new NodeComp(tiledMap, entity));
13
+ const comp = entity.assign(this);
14
+ return comp;
15
+ }
16
+ }
@@ -0,0 +1,2 @@
1
+ export declare function setupTiledMap(): void;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tiledmap/index.ts"],"names":[],"mappings":"AAGA,wBAAgB,aAAa,SAE5B"}
@@ -0,0 +1,5 @@
1
+ import { registerSystem } from '../helper/utils';
2
+ import { TiledMapComp } from './TiledMapComp';
3
+ export function setupTiledMap() {
4
+ registerSystem(TiledMapComp);
5
+ }
@@ -0,0 +1,3 @@
1
+ import { Tilemap } from '@pixi/tilemap';
2
+ export declare function loadIsometricMap(mapUrl: string): Tilemap;
3
+ //# sourceMappingURL=tield.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tield.d.ts","sourceRoot":"","sources":["../../src/tiledmap/tield.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAGvC,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,WAoC9C"}
@@ -0,0 +1,36 @@
1
+ import { Tilemap } from '@pixi/tilemap';
2
+ import { Assets, Rectangle, Texture } from 'pixi.js';
3
+ export function loadIsometricMap(mapUrl) {
4
+ const mapData = Assets.get(mapUrl);
5
+ const tileset = mapData.tilesets[0];
6
+ const baseDir = mapUrl.split('/').slice(0, -1).join('/');
7
+ const tilesetImageUrl = `${baseDir}/${tileset.image}`;
8
+ const tilesetTexture = Assets.get(tilesetImageUrl);
9
+ const baseTexture = tilesetTexture.baseTexture;
10
+ const tileW = tileset.tilewidth;
11
+ const tileH = tileset.tileheight;
12
+ const cols = tileset.columns;
13
+ const firstGid = tileset.firstgid;
14
+ const tilemap = new Tilemap(baseTexture);
15
+ for (const layer of mapData.layers) {
16
+ if (layer.type !== 'tilelayer')
17
+ continue;
18
+ const data = layer.data;
19
+ for (let i = 0; i < data.length; i++) {
20
+ const gid = data[i];
21
+ if (gid === 0)
22
+ continue;
23
+ const tileId = gid - firstGid;
24
+ const frameX = (tileId % cols) * tileW;
25
+ const frameY = Math.floor(tileId / cols) * tileH;
26
+ const tx = i % mapData.width;
27
+ const ty = Math.floor(i / mapData.width);
28
+ // Chuyển sang toạ độ isometric
29
+ const screenX = (tx - ty) * (mapData.tilewidth / 2);
30
+ const screenY = (tx + ty) * (mapData.tileheight / 2);
31
+ const texture = new Texture({ source: baseTexture, frame: new Rectangle(frameX, frameY, tileW, tileH) });
32
+ tilemap.tile(texture, screenX, screenY);
33
+ }
34
+ }
35
+ return tilemap;
36
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@safe-engine/pixi",
3
- "version": "8.8.4",
3
+ "version": "8.8.6",
4
4
  "description": "safex pixi plugin",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -18,6 +18,7 @@
18
18
  "license": "ISC",
19
19
  "dependencies": {
20
20
  "@esotericsoftware/spine-core": "^4.2.94",
21
+ "@pixi/tilemap": "^5.0.2",
21
22
  "@pixi/ui": "^2.2.7",
22
23
  "box2d-wasm": "^7.0.0",
23
24
  "entityx-ts": "^2.3.1",