@safe-engine/pixi 8.8.5 → 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.
@@ -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.5",
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",