@safe-engine/pixi 8.8.7 → 8.8.8

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.
@@ -1,4 +1,4 @@
1
- import { BaseComponentProps } from '..';
1
+ import { BaseComponentProps, Vec2 } from '..';
2
2
  import { ComponentX } from '../components/BaseComponent';
3
3
  import { Spine } from './lib';
4
4
  interface SpineData {
@@ -17,5 +17,12 @@ export declare class SpineSkeleton extends ComponentX<SpineSkeletonProps, Spine>
17
17
  setAnimation(name: string, loop?: boolean): void;
18
18
  setSkeletonData(data: SpineData): void;
19
19
  }
20
+ interface SpineBonesControlComponentProps extends BaseComponentProps<SpineBonesControlComponent> {
21
+ posList: Vec2[];
22
+ bonesName: string[];
23
+ }
24
+ export declare class SpineBonesControlComponent extends ComponentX<SpineBonesControlComponentProps, Spine> {
25
+ start(): void;
26
+ }
20
27
  export {};
21
28
  //# sourceMappingURL=SpineComponent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SpineComponent.d.ts","sourceRoot":"","sources":["../../src/spine/SpineComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,IAAI,CAAA;AACvC,OAAO,EAAE,UAAU,EAAU,MAAM,6BAA6B,CAAA;AAChE,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAE7B,UAAU,SAAS;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,UAAU,kBAAmB,SAAQ,kBAAkB,CAAC,aAAa,CAAC;IACpE,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AACD,qBAAa,aAAc,SAAQ,UAAU,CAAC,kBAAkB,EAAE,KAAK,CAAC;IACtE,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,UAAQ;IAOvC,eAAe,CAAC,IAAI,EAAE,SAAS;CAKhC"}
1
+ {"version":3,"file":"SpineComponent.d.ts","sourceRoot":"","sources":["../../src/spine/SpineComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAkB,IAAI,EAAE,MAAM,IAAI,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAU,MAAM,6BAA6B,CAAA;AAChE,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAE7B,UAAU,SAAS;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,UAAU,kBAAmB,SAAQ,kBAAkB,CAAC,aAAa,CAAC;IACpE,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AACD,qBAAa,aAAc,SAAQ,UAAU,CAAC,kBAAkB,EAAE,KAAK,CAAC;IACtE,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,UAAQ;IAOvC,eAAe,CAAC,IAAI,EAAE,SAAS;CAKhC;AAID,UAAU,+BAAgC,SAAQ,kBAAkB,CAAC,0BAA0B,CAAC;IAC9F,OAAO,EAAE,IAAI,EAAE,CAAA;IACf,SAAS,EAAE,MAAM,EAAE,CAAA;CACpB;AACD,qBAAa,0BAA2B,SAAQ,UAAU,CAAC,+BAA+B,EAAE,KAAK,CAAC;IAChG,KAAK;CAYN"}
@@ -1,3 +1,4 @@
1
+ import { registerSystem } from '..';
1
2
  import { ComponentX, render } from '../components/BaseComponent';
2
3
  export class SpineSkeleton extends ComponentX {
3
4
  setAnimation(name, loop = false) {
@@ -13,3 +14,18 @@ export class SpineSkeleton extends ComponentX {
13
14
  }
14
15
  }
15
16
  Object.defineProperty(SpineSkeleton.prototype, 'render', { value: render });
17
+ export class SpineBonesControlComponent extends ComponentX {
18
+ start() {
19
+ const skel = this.node.getComponent(SpineSkeleton).node.instance;
20
+ const { bonesName = [], posList = [] } = this.props;
21
+ bonesName.forEach((boneName, index) => {
22
+ const bone = skel.skeleton.findBone(boneName);
23
+ if (bone) {
24
+ const pos = posList[index];
25
+ bone.x = pos.x;
26
+ bone.y = pos.y;
27
+ }
28
+ });
29
+ }
30
+ }
31
+ registerSystem(SpineBonesControlComponent);
@@ -6,7 +6,7 @@ interface TiledMapCompProps extends BaseComponentProps<TiledMapComp> {
6
6
  }
7
7
  export declare class TiledMapComp extends ComponentX<TiledMapCompProps, Tilemap> {
8
8
  mapData: any;
9
- getPositionAt(x: number, ty: number): {
9
+ getPositionAt(tx: number, ty: number): {
10
10
  x: number;
11
11
  y: number;
12
12
  equals(other: /*elided*/ any): boolean;
@@ -1 +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,EAAU,kBAAkB,EAAuB,IAAI,EAAE,MAAM,IAAI,CAAA;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAGxD,UAAU,iBAAkB,SAAQ,kBAAkB,CAAC,YAAY,CAAC;IAClE,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,qBAAa,YAAa,SAAQ,UAAU,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACtE,OAAO,EAAE,GAAG,CAAA;IACZ,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;;;;;;;;;;;;;;;;;;;IASnC,MAAM;CASP"}
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,EAAU,kBAAkB,EAAuB,IAAI,EAAE,MAAM,IAAI,CAAA;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAGxD,UAAU,iBAAkB,SAAQ,kBAAkB,CAAC,YAAY,CAAC;IAClE,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,qBAAa,YAAa,SAAQ,UAAU,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACtE,OAAO,EAAE,GAAG,CAAA;IAEZ,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;;;;;;;;;;;;;;;;;;;IAKpC,MAAM;CASP"}
@@ -1,14 +1,10 @@
1
1
  import { Assets, GameWorld, NodeComp, Vec2 } from '..';
2
2
  import { ComponentX } from '../components/BaseComponent';
3
- import { loadIsometricMap } from './tield';
3
+ import { loadIsometricMap, tileToPixel } from './tield';
4
4
  export class TiledMapComp extends ComponentX {
5
- getPositionAt(x, ty) {
6
- const mapData = this.mapData;
7
- const tx = x + 1;
8
- // Chuyển sang toạ độ isometric
9
- const screenX = (tx - ty) * (mapData.tilewidth / 2);
10
- const screenY = (tx + ty) * (mapData.tileheight / 2);
11
- return Vec2(screenX, screenY);
5
+ getPositionAt(tx, ty) {
6
+ const pos = tileToPixel(this.mapData, tx + 1, ty);
7
+ return Vec2(pos);
12
8
  }
13
9
  render() {
14
10
  this.mapData = Assets.get(this.props.mapFile);
@@ -1,3 +1,7 @@
1
1
  import { Tilemap } from '@pixi/tilemap';
2
+ export declare function tileToPixel(map: any, tx: any, ty: any): {
3
+ x: number;
4
+ y: number;
5
+ };
2
6
  export declare function loadIsometricMap(mapUrl: string): Tilemap;
3
7
  //# sourceMappingURL=tield.d.ts.map
@@ -1 +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"}
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,WAAW,CAAC,GAAG,KAAA,EAAE,EAAE,KAAA,EAAE,EAAE,KAAA;;;EA0BtC;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,WAiC9C"}
@@ -1,5 +1,29 @@
1
1
  import { Tilemap } from '@pixi/tilemap';
2
2
  import { Assets, Rectangle, Texture } from 'pixi.js';
3
+ export function tileToPixel(map, tx, ty) {
4
+ const tw = map.tilewidth;
5
+ const th = map.tileheight;
6
+ const { orientation, staggeraxis, staggerindex } = map;
7
+ switch (orientation) {
8
+ case 'orthogonal':
9
+ return { x: tx * tw, y: ty * th };
10
+ case 'isometric':
11
+ return { x: (tx - ty) * (tw / 2), y: (tx + ty) * (th / 2) };
12
+ case 'staggered':
13
+ if (staggeraxis === 'x') {
14
+ const odd = staggerindex === 'odd';
15
+ const offset = tx % 2 === (odd ? 1 : 0) ? th / 2 : 0;
16
+ return { x: tx * (tw / 2), y: ty * th + offset };
17
+ }
18
+ else {
19
+ const odd = staggerindex === 'odd';
20
+ const offset = ty % 2 === (odd ? 1 : 0) ? tw / 2 : 0;
21
+ return { x: tx * tw + offset, y: ty * (th / 2) };
22
+ }
23
+ default:
24
+ throw new Error(`Unknown map type: ${orientation}`);
25
+ }
26
+ }
3
27
  export function loadIsometricMap(mapUrl) {
4
28
  const mapData = Assets.get(mapUrl);
5
29
  const tileset = mapData.tilesets[0];
@@ -25,11 +49,9 @@ export function loadIsometricMap(mapUrl) {
25
49
  const frameY = Math.floor(tileId / cols) * tileH;
26
50
  const tx = i % mapData.width;
27
51
  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);
52
+ const { x, y } = tileToPixel(mapData, tx, ty);
31
53
  const texture = new Texture({ source: baseTexture, frame: new Rectangle(frameX, frameY, tileW, tileH) });
32
- tilemap.tile(texture, screenX, screenY);
54
+ tilemap.tile(texture, x, y);
33
55
  }
34
56
  }
35
57
  return tilemap;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@safe-engine/pixi",
3
- "version": "8.8.7",
3
+ "version": "8.8.8",
4
4
  "description": "safex pixi plugin",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",