@safe-engine/pixi 8.8.7 → 8.9.1

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,9 +1,11 @@
1
1
  import { Constructor } from 'entityx-ts';
2
- import { BaseComponentProps } from '..';
2
+ import { BaseComponentProps, Container } from '..';
3
3
  import { NodeComp } from '../components/NodeComp';
4
- export declare class EnhancedComponent<Props = object, N extends NodeComp<any> = NodeComp<any>> {
4
+ export declare class EnhancedComponent<Props = object, N extends NodeComp<Container> = NodeComp<Container>> {
5
5
  props: Props;
6
6
  enabled: boolean;
7
+ private _ticker;
8
+ private _timers;
7
9
  constructor(data?: BaseComponentProps<EnhancedComponent> & Props);
8
10
  init(data?: Props): void;
9
11
  node: N;
@@ -11,6 +13,10 @@ export declare class EnhancedComponent<Props = object, N extends NodeComp<any> =
11
13
  getComponent<T extends ComponentType>(component: Constructor<T>): T;
12
14
  getComponentsInChildren<T extends ComponentType>(component: Constructor<T>): T[];
13
15
  getComponentInChildren<T extends ComponentType>(component: Constructor<T>): T;
16
+ schedule(callback: any, interval: any, repeat?: number, delay?: number): void;
17
+ scheduleOnce(callback: any, delay: any, key?: any): void;
18
+ unschedule(callback: any): void;
19
+ unscheduleAllCallbacks(): void;
14
20
  isEqual(other: EnhancedComponent): boolean;
15
21
  }
16
22
  export type ComponentType = EnhancedComponent | NodeComp;
@@ -1 +1 @@
1
- {"version":3,"file":"EnhancedComponent.d.ts","sourceRoot":"","sources":["../../src/base/EnhancedComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,IAAI,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AAEjD,qBAAa,iBAAiB,CAAC,KAAK,GAAG,MAAM,EAAE,CAAC,SAAS,QAAQ,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAA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,EAAE,KAAK;IAQjB,IAAI,EAAE,CAAC,CAAA;IAEP,YAAY,CAAC,CAAC,SAAS,iBAAiB,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC;IAGzD,YAAY,CAAC,CAAC,SAAS,aAAa,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC;IAGnE,uBAAuB,CAAC,CAAC,SAAS,aAAa,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE;IAGhF,sBAAsB,CAAC,CAAC,SAAS,aAAa,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC;IAG7E,QAAQ,CAAC,QAAQ,KAAA,EAAE,QAAQ,KAAA,EAAE,MAAM,SAAiB,EAAE,KAAK,SAAI;IAwB/D,YAAY,CAAC,QAAQ,KAAA,EAAE,KAAK,KAAA,EAAE,GAAG,MAAY;IAsB7C,UAAU,CAAC,QAAQ,KAAA;IAQnB,sBAAsB;IAMtB,OAAO,CAAC,KAAK,EAAE,iBAAiB;CAGjC;AAED,MAAM,MAAM,aAAa,GAAG,iBAAiB,GAAG,QAAQ,CAAA"}
@@ -1,8 +1,12 @@
1
+ import { REPEAT_FOREVER } from 'pixi-action-ease';
2
+ import { Ticker } from '..';
1
3
  export class EnhancedComponent {
2
4
  constructor(data) {
3
5
  this.props = {};
4
6
  this.enabled = true;
5
7
  this.init(data);
8
+ this._ticker = Ticker.shared;
9
+ this._timers = new Map(); // Map<Function, TimerInfo>
6
10
  }
7
11
  init(data) {
8
12
  if (data) {
@@ -24,6 +28,57 @@ export class EnhancedComponent {
24
28
  getComponentInChildren(component) {
25
29
  return this.node.getComponentInChildren(component);
26
30
  }
31
+ schedule(callback, interval, repeat = REPEAT_FOREVER, delay = 0) {
32
+ if (this._timers.has(callback)) {
33
+ this.unschedule(callback);
34
+ }
35
+ let elapsed = -delay;
36
+ let count = 0;
37
+ const fn = () => {
38
+ elapsed += this._ticker.deltaMS / 1000;
39
+ if (elapsed >= interval) {
40
+ elapsed -= interval;
41
+ callback(count);
42
+ count++;
43
+ if (count > repeat) {
44
+ this.unschedule(callback);
45
+ }
46
+ }
47
+ };
48
+ this._timers.set(callback, { fn });
49
+ this._ticker.add(fn);
50
+ }
51
+ scheduleOnce(callback, delay, key = undefined) {
52
+ if (key) {
53
+ // Cho phép hủy bằng key thay vì callback
54
+ if (this._timers.has(key)) {
55
+ this.unschedule(key);
56
+ }
57
+ }
58
+ let elapsed = 0;
59
+ const fn = () => {
60
+ elapsed += this._ticker.deltaMS / 1000;
61
+ if (elapsed >= delay) {
62
+ callback();
63
+ this.unschedule(key || callback);
64
+ }
65
+ };
66
+ this._timers.set(key || callback, { fn });
67
+ this._ticker.add(fn);
68
+ }
69
+ unschedule(callback) {
70
+ const timer = this._timers.get(callback);
71
+ if (timer) {
72
+ this._ticker.remove(timer.fn);
73
+ this._timers.delete(callback);
74
+ }
75
+ }
76
+ unscheduleAllCallbacks() {
77
+ for (const { fn } of this._timers.values()) {
78
+ this._ticker.remove(fn);
79
+ }
80
+ this._timers.clear();
81
+ }
27
82
  isEqual(other) {
28
83
  return this.node.entity.id === other.node.entity.id;
29
84
  }
@@ -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.9.1",
4
4
  "description": "safex pixi plugin",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -17,12 +17,12 @@
17
17
  "author": "",
18
18
  "license": "ISC",
19
19
  "dependencies": {
20
- "@esotericsoftware/spine-core": "^4.2.94",
20
+ "@esotericsoftware/spine-core": "^4.2.95",
21
21
  "@pixi/tilemap": "^5.0.2",
22
22
  "@pixi/ui": "^2.2.7",
23
23
  "box2d-wasm": "^7.0.0",
24
24
  "entityx-ts": "^2.3.1",
25
- "pixi-action-ease": "^3.2.5",
25
+ "pixi-action-ease": "^3.3.1",
26
26
  "pixi-tagged-text-plus": "0.0.1-next.2",
27
27
  "pixi.js": "8.12.0",
28
28
  "planck": "^1.4.2"