dacha 0.18.0-alpha.9 → 0.18.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.
Files changed (66) hide show
  1. package/build/contrib/components/bitmap-text/index.d.ts +11 -11
  2. package/build/contrib/components/bitmap-text/index.js +13 -10
  3. package/build/contrib/components/index.d.ts +1 -0
  4. package/build/contrib/components/index.js +1 -0
  5. package/build/contrib/components/interpolation/index.d.ts +85 -0
  6. package/build/contrib/components/interpolation/index.js +101 -0
  7. package/build/contrib/components/mesh/index.d.ts +13 -13
  8. package/build/contrib/components/mesh/index.js +12 -9
  9. package/build/contrib/components/pixi-view/index.d.ts +5 -5
  10. package/build/contrib/components/pixi-view/index.js +5 -2
  11. package/build/contrib/components/rigid-body/index.d.ts +8 -0
  12. package/build/contrib/components/rigid-body/index.js +8 -0
  13. package/build/contrib/components/shape/index.d.ts +20 -36
  14. package/build/contrib/components/shape/index.js +27 -23
  15. package/build/contrib/components/sprite/index.d.ts +22 -14
  16. package/build/contrib/components/sprite/index.js +23 -10
  17. package/build/contrib/systems/index.d.ts +2 -0
  18. package/build/contrib/systems/index.js +1 -0
  19. package/build/contrib/systems/interpolator/api.d.ts +40 -0
  20. package/build/contrib/systems/interpolator/api.js +70 -0
  21. package/build/contrib/systems/interpolator/index.d.ts +3 -0
  22. package/build/contrib/systems/interpolator/index.js +2 -0
  23. package/build/contrib/systems/interpolator/system.d.ts +31 -0
  24. package/build/contrib/systems/interpolator/system.js +96 -0
  25. package/build/contrib/systems/interpolator/tests/helpers.d.ts +13 -0
  26. package/build/contrib/systems/interpolator/tests/helpers.js +45 -0
  27. package/build/contrib/systems/interpolator/utils.d.ts +5 -0
  28. package/build/contrib/systems/interpolator/utils.js +41 -0
  29. package/build/contrib/systems/physics-system/api.d.ts +45 -1
  30. package/build/contrib/systems/physics-system/api.js +49 -0
  31. package/build/contrib/systems/physics-system/consts.d.ts +3 -1
  32. package/build/contrib/systems/physics-system/consts.js +4 -1
  33. package/build/contrib/systems/physics-system/physics-system.js +7 -1
  34. package/build/contrib/systems/physics-system/subsystems/collision-detection/dynamic-aabb-tree/index.d.ts +1 -1
  35. package/build/contrib/systems/physics-system/subsystems/collision-detection/dynamic-aabb-tree/index.js +21 -15
  36. package/build/contrib/systems/physics-system/subsystems/collision-detection/index.d.ts +11 -11
  37. package/build/contrib/systems/physics-system/subsystems/collision-detection/index.js +130 -124
  38. package/build/contrib/systems/physics-system/subsystems/collision-detection/query-utils.d.ts +5 -0
  39. package/build/contrib/systems/physics-system/subsystems/collision-detection/query-utils.js +97 -81
  40. package/build/contrib/systems/physics-system/subsystems/collision-detection/types.d.ts +0 -15
  41. package/build/contrib/systems/physics-system/subsystems/collision-detection/utils.d.ts +3 -0
  42. package/build/contrib/systems/physics-system/subsystems/collision-detection/utils.js +9 -0
  43. package/build/contrib/systems/physics-system/subsystems/physics/mass-properties.js +1 -1
  44. package/build/contrib/systems/physics-system/types.d.ts +12 -2
  45. package/build/contrib/systems/renderer/actor-render-tree.js +15 -6
  46. package/build/contrib/systems/renderer/builders/mesh-builder/index.d.ts +0 -1
  47. package/build/contrib/systems/renderer/builders/mesh-builder/index.js +0 -21
  48. package/build/contrib/systems/renderer/builders/pixi-view-builder/index.js +2 -1
  49. package/build/contrib/systems/renderer/builders/sprite-builder/index.js +8 -0
  50. package/build/contrib/systems/renderer/material/consts.d.ts +1 -1
  51. package/build/contrib/systems/renderer/material/consts.js +3 -1
  52. package/build/contrib/systems/renderer/material/index.js +11 -5
  53. package/build/engine/data-lib/index.d.ts +1 -1
  54. package/build/engine/data-lib/index.js +1 -1
  55. package/build/engine/data-lib/pool.d.ts +9 -0
  56. package/build/engine/data-lib/pool.js +19 -0
  57. package/build/engine/game-loop.js +3 -3
  58. package/build/engine/math-lib/math/ops.d.ts +16 -0
  59. package/build/engine/math-lib/math/ops.js +25 -0
  60. package/package.json +1 -1
  61. package/build/contrib/systems/physics-system/subsystems/collision-detection/dispersion-calculator/index.d.ts +0 -11
  62. package/build/contrib/systems/physics-system/subsystems/collision-detection/dispersion-calculator/index.js +0 -41
  63. package/build/engine/data-lib/sort/index.d.ts +0 -1
  64. package/build/engine/data-lib/sort/index.js +0 -1
  65. package/build/engine/data-lib/sort/insertion-sort.d.ts +0 -1
  66. package/build/engine/data-lib/sort/insertion-sort.js +0 -14
@@ -8,17 +8,17 @@ interface RenderData {
8
8
  }
9
9
  type TextAlign = 'left' | 'center' | 'right';
10
10
  export interface BitmapTextConfig {
11
- text: string;
12
- font: string;
13
- fontSize: number;
14
- align: TextAlign;
15
- color: string;
16
- opacity: number;
17
- blending: BlendingMode;
18
- disabled: boolean;
19
- sortingLayer: string;
20
- sortOffsetX: number;
21
- sortOffsetY: number;
11
+ text?: string;
12
+ font?: string;
13
+ fontSize?: number;
14
+ align?: TextAlign;
15
+ color?: string;
16
+ opacity?: number;
17
+ blending?: BlendingMode;
18
+ disabled?: boolean;
19
+ sortingLayer?: string;
20
+ sortOffsetX?: number;
21
+ sortOffsetY?: number;
22
22
  }
23
23
  /**
24
24
  * BitmapText component for rendering text using a bitmap font.
@@ -60,16 +60,19 @@ export class BitmapText extends Component {
60
60
  renderData;
61
61
  constructor(config) {
62
62
  super();
63
- this.text = config.text;
64
- this.font = config.font;
65
- this.fontSize = config.fontSize;
66
- this.align = config.align;
67
- this.color = config.color;
68
- this.opacity = config.opacity;
69
- this.blending = config.blending;
70
- this.disabled = config.disabled;
71
- this.sortingLayer = config.sortingLayer;
72
- this.sortOffset = { x: config.sortOffsetX, y: config.sortOffsetY };
63
+ this.text = config.text ?? 'Text';
64
+ this.font = config.font ?? '';
65
+ this.fontSize = config.fontSize ?? 10;
66
+ this.align = config.align ?? 'center';
67
+ this.color = config.color ?? '#000000';
68
+ this.opacity = config.opacity ?? 1;
69
+ this.blending = config.blending ?? 'normal';
70
+ this.disabled = config.disabled ?? false;
71
+ this.sortingLayer = config.sortingLayer ?? 'default';
72
+ this.sortOffset = {
73
+ x: config.sortOffsetX ?? 0,
74
+ y: config.sortOffsetY ?? 0,
75
+ };
73
76
  }
74
77
  }
75
78
  BitmapText.componentName = 'BitmapText';
@@ -3,6 +3,7 @@ export { KeyboardControl, type KeyboardControlConfig, } from './keyboard-control
3
3
  export { Collider, type ColliderConfig, type ColliderShape, type ColliderType, type BoxColliderShape, type CircleColliderShape, type SegmentColliderShape, type CapsuleColliderShape, } from './collider';
4
4
  export { RigidBody, type RigidBodyConfig } from './rigid-body';
5
5
  export { CharacterBody, type CharacterBodyConfig } from './character-body';
6
+ export { Interpolation, type InterpolationConfig, type InterpolationMode, } from './interpolation';
6
7
  export { Animatable, type AnimatableConfig } from './animatable';
7
8
  export { Sprite, type SpriteConfig } from './sprite';
8
9
  export { Transform, type TransformConfig } from './transform';
@@ -3,6 +3,7 @@ export { KeyboardControl, } from './keyboard-control';
3
3
  export { Collider, } from './collider';
4
4
  export { RigidBody } from './rigid-body';
5
5
  export { CharacterBody } from './character-body';
6
+ export { Interpolation, } from './interpolation';
6
7
  export { Animatable } from './animatable';
7
8
  export { Sprite } from './sprite';
8
9
  export { Transform } from './transform';
@@ -0,0 +1,85 @@
1
+ import { Component } from '../../../engine/component';
2
+ export type InterpolationMode = 'interpolate' | 'extrapolate';
3
+ export interface InterpolationConfig {
4
+ mode?: InterpolationMode;
5
+ snapThreshold?: number;
6
+ disabled?: boolean;
7
+ }
8
+ /**
9
+ * Component that smooths rendering of actors moved during fixed updates.
10
+ *
11
+ * Interpolator keeps local-space snapshots of the actor's Transform around
12
+ * each fixed step and blends them into the render-facing
13
+ * `renderX`/`renderY`/`renderRotation` values every render frame using
14
+ * `Time.alpha`. The renderer prefers these values over the Transform.
15
+ *
16
+ * The Transform component always holds the authoritative simulation state.
17
+ * Interpolated values are only visible to the renderer and to consumers of
18
+ * InterpolatorAPI, so simulation code can never accidentally read a
19
+ * visually smoothed but physically incorrect position.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * actor.setComponent(new Interpolation({ mode: 'interpolate' }));
24
+ *
25
+ * // After teleporting the actor, skip smoothing for the jump:
26
+ * actor.getComponent(Transform).world.position.x = 500;
27
+ * actor.getComponent(Interpolation).snap();
28
+ * ```
29
+ *
30
+ * @category Components
31
+ */
32
+ export declare class Interpolation extends Component {
33
+ /**
34
+ * How render values are produced. `interpolate` blends between the last
35
+ * two fixed steps (smooth, adds up to one fixed step of visual latency).
36
+ * `extrapolate` projects the latest step forward using the rigid body
37
+ * velocity (no added latency, may briefly overshoot on impacts).
38
+ *
39
+ * `extrapolate` uses the world-space rigid body velocity against
40
+ * local-space snapshots, so it is intended for root-level actors.
41
+ */
42
+ mode: InterpolationMode;
43
+ /**
44
+ * Maximum distance in world units treated as continuous movement between
45
+ * two fixed steps. Larger jumps snap instead of gliding. `0` disables
46
+ * the automatic snap detection.
47
+ */
48
+ snapThreshold: number;
49
+ /** Whether smoothing is turned off. The renderer falls back to Transform. */
50
+ disabled: boolean;
51
+ /** @internal Local-space position X from the previous fixed step */
52
+ _prevX: number;
53
+ /** @internal Local-space position Y from the previous fixed step */
54
+ _prevY: number;
55
+ /** @internal Local-space rotation from the previous fixed step */
56
+ _prevRotation: number;
57
+ /** @internal Local-space position X from the latest fixed step */
58
+ _currX: number;
59
+ /** @internal Local-space position Y from the latest fixed step */
60
+ _currY: number;
61
+ /** @internal Local-space rotation from the latest fixed step */
62
+ _currRotation: number;
63
+ /** @internal Whether snapshots have been initialized since (re)enabling */
64
+ _initialized: boolean;
65
+ /** @internal Whether smoothing should be skipped at the next opportunity */
66
+ _snapRequested: boolean;
67
+ /** Render-facing local-space position X, written by Interpolator */
68
+ renderX: number;
69
+ /** Render-facing local-space position Y, written by Interpolator */
70
+ renderY: number;
71
+ /** Render-facing local-space rotation, written by Interpolator */
72
+ renderRotation: number;
73
+ constructor(config?: InterpolationConfig);
74
+ /**
75
+ * Whether the render-facing values hold a valid snapshot yet. `false`
76
+ * until the Interpolator takes its first snapshot after the component is
77
+ * (re)enabled.
78
+ */
79
+ get initialized(): boolean;
80
+ /**
81
+ * Requests an immediate jump to the Transform instead of
82
+ * smoothing towards it. Call right after teleporting the actor.
83
+ */
84
+ snap(): void;
85
+ }
@@ -0,0 +1,101 @@
1
+ import { Component } from '../../../engine/component';
2
+ /**
3
+ * Component that smooths rendering of actors moved during fixed updates.
4
+ *
5
+ * Interpolator keeps local-space snapshots of the actor's Transform around
6
+ * each fixed step and blends them into the render-facing
7
+ * `renderX`/`renderY`/`renderRotation` values every render frame using
8
+ * `Time.alpha`. The renderer prefers these values over the Transform.
9
+ *
10
+ * The Transform component always holds the authoritative simulation state.
11
+ * Interpolated values are only visible to the renderer and to consumers of
12
+ * InterpolatorAPI, so simulation code can never accidentally read a
13
+ * visually smoothed but physically incorrect position.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * actor.setComponent(new Interpolation({ mode: 'interpolate' }));
18
+ *
19
+ * // After teleporting the actor, skip smoothing for the jump:
20
+ * actor.getComponent(Transform).world.position.x = 500;
21
+ * actor.getComponent(Interpolation).snap();
22
+ * ```
23
+ *
24
+ * @category Components
25
+ */
26
+ export class Interpolation extends Component {
27
+ /**
28
+ * How render values are produced. `interpolate` blends between the last
29
+ * two fixed steps (smooth, adds up to one fixed step of visual latency).
30
+ * `extrapolate` projects the latest step forward using the rigid body
31
+ * velocity (no added latency, may briefly overshoot on impacts).
32
+ *
33
+ * `extrapolate` uses the world-space rigid body velocity against
34
+ * local-space snapshots, so it is intended for root-level actors.
35
+ */
36
+ mode;
37
+ /**
38
+ * Maximum distance in world units treated as continuous movement between
39
+ * two fixed steps. Larger jumps snap instead of gliding. `0` disables
40
+ * the automatic snap detection.
41
+ */
42
+ snapThreshold;
43
+ /** Whether smoothing is turned off. The renderer falls back to Transform. */
44
+ disabled;
45
+ /** @internal Local-space position X from the previous fixed step */
46
+ _prevX;
47
+ /** @internal Local-space position Y from the previous fixed step */
48
+ _prevY;
49
+ /** @internal Local-space rotation from the previous fixed step */
50
+ _prevRotation;
51
+ /** @internal Local-space position X from the latest fixed step */
52
+ _currX;
53
+ /** @internal Local-space position Y from the latest fixed step */
54
+ _currY;
55
+ /** @internal Local-space rotation from the latest fixed step */
56
+ _currRotation;
57
+ /** @internal Whether snapshots have been initialized since (re)enabling */
58
+ _initialized;
59
+ /** @internal Whether smoothing should be skipped at the next opportunity */
60
+ _snapRequested;
61
+ /** Render-facing local-space position X, written by Interpolator */
62
+ renderX;
63
+ /** Render-facing local-space position Y, written by Interpolator */
64
+ renderY;
65
+ /** Render-facing local-space rotation, written by Interpolator */
66
+ renderRotation;
67
+ constructor(config = {}) {
68
+ super();
69
+ const { mode = 'interpolate', snapThreshold = 0, disabled = false, } = config;
70
+ this.mode = mode;
71
+ this.snapThreshold = snapThreshold;
72
+ this.disabled = disabled;
73
+ this._prevX = 0;
74
+ this._prevY = 0;
75
+ this._prevRotation = 0;
76
+ this._currX = 0;
77
+ this._currY = 0;
78
+ this._currRotation = 0;
79
+ this._initialized = false;
80
+ this._snapRequested = false;
81
+ this.renderX = 0;
82
+ this.renderY = 0;
83
+ this.renderRotation = 0;
84
+ }
85
+ /**
86
+ * Whether the render-facing values hold a valid snapshot yet. `false`
87
+ * until the Interpolator takes its first snapshot after the component is
88
+ * (re)enabled.
89
+ */
90
+ get initialized() {
91
+ return this._initialized;
92
+ }
93
+ /**
94
+ * Requests an immediate jump to the Transform instead of
95
+ * smoothing towards it. Call right after teleporting the actor.
96
+ */
97
+ snap() {
98
+ this._snapRequested = true;
99
+ }
100
+ }
101
+ Interpolation.componentName = 'Interpolation';
@@ -13,20 +13,20 @@ export interface MaterialConfig {
13
13
  options: Record<string, unknown>;
14
14
  }
15
15
  export interface MeshConfig {
16
- src: string;
17
- width: number;
18
- height: number;
19
- slice: number;
20
- flipX: boolean;
21
- flipY: boolean;
22
- sortingLayer: string;
23
- sortOffsetX: number;
24
- sortOffsetY: number;
25
- color: string;
26
- blending: BlendingMode;
27
- opacity: number;
16
+ src?: string;
17
+ width?: number;
18
+ height?: number;
19
+ slice?: number;
20
+ flipX?: boolean;
21
+ flipY?: boolean;
22
+ sortingLayer?: string;
23
+ sortOffsetX?: number;
24
+ sortOffsetY?: number;
25
+ color?: string;
26
+ blending?: BlendingMode;
27
+ opacity?: number;
28
28
  material?: MaterialConfig;
29
- disabled: boolean;
29
+ disabled?: boolean;
30
30
  }
31
31
  /**
32
32
  * Mesh component for rendering 2D textures with a custom shader.
@@ -78,16 +78,19 @@ export class Mesh extends Component {
78
78
  */
79
79
  constructor(config) {
80
80
  super();
81
- this.src = config.src;
82
- this.width = config.width;
83
- this.height = config.height;
84
- this.slice = config.slice;
81
+ this.src = config.src ?? '';
82
+ this.width = config.width ?? 10;
83
+ this.height = config.height ?? 10;
84
+ this.slice = config.slice ?? 1;
85
85
  this.currentFrame = 0;
86
- this.flipX = config.flipX;
87
- this.flipY = config.flipY;
88
- this.disabled = config.disabled;
89
- this.sortingLayer = config.sortingLayer;
90
- this.sortOffset = { x: config.sortOffsetX, y: config.sortOffsetY };
86
+ this.flipX = config.flipX ?? false;
87
+ this.flipY = config.flipY ?? false;
88
+ this.disabled = config.disabled ?? false;
89
+ this.sortingLayer = config.sortingLayer ?? 'default';
90
+ this.sortOffset = {
91
+ x: config.sortOffsetX ?? 0,
92
+ y: config.sortOffsetY ?? 0,
93
+ };
91
94
  this.color = config.color ?? '#ffffff';
92
95
  this.blending = config.blending ?? 'normal';
93
96
  this.opacity = config.opacity ?? 1;
@@ -5,10 +5,10 @@ interface RenderData {
5
5
  view: ViewContainer;
6
6
  }
7
7
  export interface PixiViewConfig {
8
- createView: () => ViewContainer;
9
- sortingLayer: string;
10
- sortOffsetX: number;
11
- sortOffsetY: number;
8
+ createView?: () => ViewContainer;
9
+ sortingLayer?: string;
10
+ sortOffsetX?: number;
11
+ sortOffsetY?: number;
12
12
  }
13
13
  /**
14
14
  * PixiView component for rendering a view.
@@ -41,7 +41,7 @@ export interface PixiViewConfig {
41
41
  */
42
42
  export declare class PixiView extends Component {
43
43
  /** Function to create a custom pixi.js view */
44
- createView: () => ViewContainer;
44
+ createView?: () => ViewContainer;
45
45
  /** Sorting layer of the pixi view */
46
46
  sortingLayer: string;
47
47
  /** Center point of the pixi view */
@@ -45,8 +45,11 @@ export class PixiView extends Component {
45
45
  constructor(config) {
46
46
  super();
47
47
  this.createView = config.createView;
48
- this.sortingLayer = config.sortingLayer;
49
- this.sortOffset = { x: config.sortOffsetX, y: config.sortOffsetY };
48
+ this.sortingLayer = config.sortingLayer ?? 'default';
49
+ this.sortOffset = {
50
+ x: config.sortOffsetX ?? 0,
51
+ y: config.sortOffsetY ?? 0,
52
+ };
50
53
  }
51
54
  /** Get the pixi.js view. It's only available after the actor with this component is added to a scene */
52
55
  get view() {
@@ -31,6 +31,13 @@ interface PointImpulse {
31
31
  * impulses, gravity, collisions, and rotation. Static and kinematic bodies can
32
32
  * participate in collisions but are not moved by solver impulses.
33
33
  *
34
+ * Physics is simulated in world space.
35
+ *
36
+ * Rigid bodies may be parented only to actors with static transforms. A moving
37
+ * parent (for example, a dynamic or kinematic rigid body) and the physics
38
+ * simulation would both control the child's transform, so the result is
39
+ * undefined.
40
+ *
34
41
  * @example
35
42
  * ```typescript
36
43
  * // Create a dynamic rigid body
@@ -115,6 +122,7 @@ export declare class RigidBody extends Component {
115
122
  /**
116
123
  * Sets the mass used by dynamic bodies.
117
124
  *
125
+ * Mass is an authored, kilogram-like scalar.
118
126
  * Non-positive values make the body immovable by forces and impulses.
119
127
  */
120
128
  set mass(value: number);
@@ -7,6 +7,13 @@ import { Vector2 } from '../../../engine/math-lib';
7
7
  * impulses, gravity, collisions, and rotation. Static and kinematic bodies can
8
8
  * participate in collisions but are not moved by solver impulses.
9
9
  *
10
+ * Physics is simulated in world space.
11
+ *
12
+ * Rigid bodies may be parented only to actors with static transforms. A moving
13
+ * parent (for example, a dynamic or kinematic rigid body) and the physics
14
+ * simulation would both control the child's transform, so the result is
15
+ * undefined.
16
+ *
10
17
  * @example
11
18
  * ```typescript
12
19
  * // Create a dynamic rigid body
@@ -134,6 +141,7 @@ export class RigidBody extends Component {
134
141
  /**
135
142
  * Sets the mass used by dynamic bodies.
136
143
  *
144
+ * Mass is an authored, kilogram-like scalar.
137
145
  * Non-positive values make the body immovable by forces and impulses.
138
146
  */
139
147
  set mass(value) {
@@ -9,45 +9,29 @@ interface RenderData {
9
9
  export type ShapeType = 'rectangle' | 'roundRectangle' | 'circle' | 'ellipse' | 'line';
10
10
  export interface BaseShapeConfig {
11
11
  strokeColor?: string;
12
- strokeWidth: number;
13
- strokeAlignment: number;
14
- pixelLine: boolean;
12
+ strokeWidth?: number;
13
+ strokeAlignment?: number;
14
+ pixelLine?: boolean;
15
15
  fill?: string;
16
- opacity: number;
17
- blending: BlendingMode;
18
- disabled: boolean;
19
- sortingLayer: string;
20
- sortOffsetX: number;
21
- sortOffsetY: number;
22
- }
23
- export interface RectangleShapeConfig extends BaseShapeConfig {
24
- type: 'rectangle';
25
- sizeX: number;
26
- sizeY: number;
16
+ opacity?: number;
17
+ blending?: BlendingMode;
18
+ disabled?: boolean;
19
+ sortingLayer?: string;
20
+ sortOffsetX?: number;
21
+ sortOffsetY?: number;
27
22
  }
28
- export interface RoundRectangleShapeConfig extends BaseShapeConfig {
29
- type: 'roundRectangle';
30
- sizeX: number;
31
- sizeY: number;
32
- radius: number;
33
- }
34
- export interface CircleShapeConfig extends BaseShapeConfig {
35
- type: 'circle';
36
- radius: number;
37
- }
38
- export interface EllipseShapeConfig extends BaseShapeConfig {
39
- type: 'ellipse';
40
- radiusX: number;
41
- radiusY: number;
42
- }
43
- export interface LineShapeConfig extends BaseShapeConfig {
44
- type: 'line';
45
- point1X: number;
46
- point1Y: number;
47
- point2X: number;
48
- point2Y: number;
23
+ export interface ShapeConfig extends BaseShapeConfig {
24
+ type?: ShapeType;
25
+ sizeX?: number;
26
+ sizeY?: number;
27
+ radius?: number;
28
+ radiusX?: number;
29
+ radiusY?: number;
30
+ point1X?: number;
31
+ point1Y?: number;
32
+ point2X?: number;
33
+ point2Y?: number;
49
34
  }
50
- export type ShapeConfig = RectangleShapeConfig | RoundRectangleShapeConfig | CircleShapeConfig | EllipseShapeConfig | LineShapeConfig;
51
35
  export interface RectangleShapeGeometry {
52
36
  type: 'rectangle';
53
37
  size: Point;
@@ -71,47 +71,51 @@ export class Shape extends Component {
71
71
  */
72
72
  constructor(config) {
73
73
  super();
74
- this.strokeColor = config.strokeColor;
75
- this.strokeWidth = config.strokeWidth;
76
- this.strokeAlignment = config.strokeAlignment;
77
- this.pixelLine = config.pixelLine;
78
- this.fill = config.fill;
79
- this.opacity = config.opacity;
80
- this.blending = config.blending;
81
- this.disabled = config.disabled;
82
- this.sortingLayer = config.sortingLayer;
83
- this.sortOffset = { x: config.sortOffsetX, y: config.sortOffsetY };
84
- switch (config.type) {
74
+ this.strokeColor = config.strokeColor ?? '#ffffff';
75
+ this.strokeWidth = config.strokeWidth ?? 0;
76
+ this.strokeAlignment = config.strokeAlignment ?? 0.5;
77
+ this.pixelLine = config.pixelLine ?? false;
78
+ this.fill = config.fill ?? '#ffffff';
79
+ this.opacity = config.opacity ?? 1;
80
+ this.blending = config.blending ?? 'normal';
81
+ this.disabled = config.disabled ?? false;
82
+ this.sortingLayer = config.sortingLayer ?? 'default';
83
+ this.sortOffset = {
84
+ x: config.sortOffsetX ?? 0,
85
+ y: config.sortOffsetY ?? 0,
86
+ };
87
+ const type = config.type ?? 'rectangle';
88
+ switch (type) {
85
89
  case 'rectangle':
86
90
  this.geometry = {
87
- type: config.type,
88
- size: { x: config.sizeX, y: config.sizeY },
91
+ type,
92
+ size: { x: config.sizeX ?? 10, y: config.sizeY ?? 10 },
89
93
  };
90
94
  break;
91
95
  case 'roundRectangle':
92
96
  this.geometry = {
93
- type: config.type,
94
- size: { x: config.sizeX, y: config.sizeY },
95
- radius: config.radius,
97
+ type,
98
+ size: { x: config.sizeX ?? 10, y: config.sizeY ?? 10 },
99
+ radius: config.radius ?? 2,
96
100
  };
97
101
  break;
98
102
  case 'circle':
99
103
  this.geometry = {
100
- type: config.type,
101
- radius: config.radius,
104
+ type,
105
+ radius: config.radius ?? 5,
102
106
  };
103
107
  break;
104
108
  case 'ellipse':
105
109
  this.geometry = {
106
- type: config.type,
107
- radius: { x: config.radiusX, y: config.radiusY },
110
+ type,
111
+ radius: { x: config.radiusX ?? 5, y: config.radiusY ?? 5 },
108
112
  };
109
113
  break;
110
114
  case 'line':
111
115
  this.geometry = {
112
- type: config.type,
113
- point1: { x: config.point1X, y: config.point1Y },
114
- point2: { x: config.point2X, y: config.point2Y },
116
+ type,
117
+ point1: { x: config.point1X ?? -5, y: config.point1Y ?? 0 },
118
+ point2: { x: config.point2X ?? 5, y: config.point2Y ?? 0 },
115
119
  };
116
120
  }
117
121
  }
@@ -10,20 +10,22 @@ interface RenderData {
10
10
  type FitType = 'stretch' | 'repeat';
11
11
  export { type BlendingMode } from '../../types/view';
12
12
  export interface SpriteConfig {
13
- src: string;
14
- width: number;
15
- height: number;
16
- slice: number;
17
- flipX: boolean;
18
- flipY: boolean;
19
- sortingLayer: string;
20
- sortOffsetX: number;
21
- sortOffsetY: number;
22
- fit: FitType;
23
- color: string;
24
- blending: BlendingMode;
25
- opacity: number;
26
- disabled: boolean;
13
+ src?: string;
14
+ width?: number;
15
+ height?: number;
16
+ slice?: number;
17
+ flipX?: boolean;
18
+ flipY?: boolean;
19
+ sortingLayer?: string;
20
+ sortOffsetX?: number;
21
+ sortOffsetY?: number;
22
+ textureOffsetX?: number;
23
+ textureOffsetY?: number;
24
+ fit?: FitType;
25
+ color?: string;
26
+ blending?: BlendingMode;
27
+ opacity?: number;
28
+ disabled?: boolean;
27
29
  }
28
30
  /**
29
31
  * Sprite component for rendering 2D textures.
@@ -80,6 +82,12 @@ export declare class Sprite extends Component {
80
82
  sortingLayer: string;
81
83
  /** Center point for sorting calculations */
82
84
  sortOffset: Point;
85
+ /**
86
+ * Texture sampling offset in pixels. Only applies to `fit: 'repeat'`
87
+ * With flipX/flipY the tile is mirrored, so a positive offset scrolls in
88
+ * the mirrored direction.
89
+ */
90
+ textureOffset: Point;
83
91
  /** Current frame to render */
84
92
  currentFrame?: number;
85
93
  /** How the texture should fit within the sprite bounds */
@@ -54,6 +54,12 @@ export class Sprite extends Component {
54
54
  sortingLayer;
55
55
  /** Center point for sorting calculations */
56
56
  sortOffset;
57
+ /**
58
+ * Texture sampling offset in pixels. Only applies to `fit: 'repeat'`
59
+ * With flipX/flipY the tile is mirrored, so a positive offset scrolls in
60
+ * the mirrored direction.
61
+ */
62
+ textureOffset;
57
63
  /** Current frame to render */
58
64
  currentFrame;
59
65
  /** How the texture should fit within the sprite bounds */
@@ -73,17 +79,24 @@ export class Sprite extends Component {
73
79
  */
74
80
  constructor(config) {
75
81
  super();
76
- this.src = config.src;
77
- this.width = config.width;
78
- this.height = config.height;
79
- this.slice = config.slice;
82
+ this.src = config.src ?? '';
83
+ this.width = config.width ?? 10;
84
+ this.height = config.height ?? 10;
85
+ this.slice = config.slice ?? 1;
80
86
  this.currentFrame = 0;
81
- this.flipX = config.flipX;
82
- this.flipY = config.flipY;
83
- this.disabled = config.disabled;
84
- this.sortingLayer = config.sortingLayer;
85
- this.sortOffset = { x: config.sortOffsetX, y: config.sortOffsetY };
86
- this.fit = config.fit;
87
+ this.flipX = config.flipX ?? false;
88
+ this.flipY = config.flipY ?? false;
89
+ this.disabled = config.disabled ?? false;
90
+ this.sortingLayer = config.sortingLayer ?? 'default';
91
+ this.sortOffset = {
92
+ x: config.sortOffsetX ?? 0,
93
+ y: config.sortOffsetY ?? 0,
94
+ };
95
+ this.textureOffset = {
96
+ x: config.textureOffsetX ?? 0,
97
+ y: config.textureOffsetY ?? 0,
98
+ };
99
+ this.fit = config.fit ?? 'stretch';
87
100
  this.color = config.color ?? '#ffffff';
88
101
  this.blending = config.blending ?? 'normal';
89
102
  this.opacity = config.opacity ?? 1;
@@ -4,6 +4,8 @@ export { GameStatsMeter } from './game-stats-meter';
4
4
  export { KeyboardInputSystem } from './keyboard-input-system';
5
5
  export { KeyboardControlSystem } from './keyboard-control-system';
6
6
  export { CharacterController } from './character-controller';
7
+ export { Interpolator, InterpolatorAPI } from './interpolator';
8
+ export type { RenderTransform } from './interpolator';
7
9
  export { MouseControlSystem } from './mouse-control-system';
8
10
  export { MouseInputSystem } from './mouse-input-system';
9
11
  export { PhysicsSystem, PhysicsAPI } from './physics-system';