canvasengine 2.0.0-beta.4 → 2.0.0-beta.41

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 (142) hide show
  1. package/dist/DebugRenderer-BxfW34YG.js +172 -0
  2. package/dist/DebugRenderer-BxfW34YG.js.map +1 -0
  3. package/dist/components/Button.d.ts +183 -0
  4. package/dist/components/Button.d.ts.map +1 -0
  5. package/dist/components/Canvas.d.ts +18 -0
  6. package/dist/components/Canvas.d.ts.map +1 -0
  7. package/dist/components/DOMElement.d.ts +44 -0
  8. package/dist/components/DOMElement.d.ts.map +1 -0
  9. package/dist/components/Graphic.d.ts +65 -0
  10. package/dist/components/Graphic.d.ts.map +1 -0
  11. package/dist/components/Joystick.d.ts +36 -0
  12. package/dist/components/Joystick.d.ts.map +1 -0
  13. package/dist/components/NineSliceSprite.d.ts +17 -0
  14. package/dist/components/NineSliceSprite.d.ts.map +1 -0
  15. package/dist/components/ParticleEmitter.d.ts +5 -0
  16. package/dist/components/ParticleEmitter.d.ts.map +1 -0
  17. package/dist/components/Scene.d.ts +2 -0
  18. package/dist/components/Scene.d.ts.map +1 -0
  19. package/dist/components/Text.d.ts +26 -0
  20. package/dist/components/Text.d.ts.map +1 -0
  21. package/dist/components/TilingSprite.d.ts +18 -0
  22. package/dist/components/TilingSprite.d.ts.map +1 -0
  23. package/dist/components/Video.d.ts +15 -0
  24. package/dist/components/Video.d.ts.map +1 -0
  25. package/dist/components/index.d.ts +18 -0
  26. package/dist/components/index.d.ts.map +1 -0
  27. package/dist/components/types/DisplayObject.d.ts +110 -0
  28. package/dist/components/types/DisplayObject.d.ts.map +1 -0
  29. package/dist/components/types/MouseEvent.d.ts +4 -0
  30. package/dist/components/types/MouseEvent.d.ts.map +1 -0
  31. package/dist/components/types/Spritesheet.d.ts +248 -0
  32. package/dist/components/types/Spritesheet.d.ts.map +1 -0
  33. package/dist/components/types/index.d.ts +5 -0
  34. package/dist/components/types/index.d.ts.map +1 -0
  35. package/dist/directives/Controls.d.ts +113 -0
  36. package/dist/directives/Controls.d.ts.map +1 -0
  37. package/dist/directives/ControlsBase.d.ts +198 -0
  38. package/dist/directives/ControlsBase.d.ts.map +1 -0
  39. package/dist/directives/Drag.d.ts +70 -0
  40. package/dist/directives/Drag.d.ts.map +1 -0
  41. package/dist/directives/Flash.d.ts +117 -0
  42. package/dist/directives/Flash.d.ts.map +1 -0
  43. package/dist/directives/GamepadControls.d.ts +225 -0
  44. package/dist/directives/GamepadControls.d.ts.map +1 -0
  45. package/dist/directives/JoystickControls.d.ts +172 -0
  46. package/dist/directives/JoystickControls.d.ts.map +1 -0
  47. package/dist/directives/KeyboardControls.d.ts +219 -0
  48. package/dist/directives/KeyboardControls.d.ts.map +1 -0
  49. package/dist/directives/Scheduler.d.ts +36 -0
  50. package/dist/directives/Scheduler.d.ts.map +1 -0
  51. package/dist/directives/Shake.d.ts +98 -0
  52. package/dist/directives/Shake.d.ts.map +1 -0
  53. package/dist/directives/Sound.d.ts +26 -0
  54. package/dist/directives/Sound.d.ts.map +1 -0
  55. package/dist/directives/Transition.d.ts +11 -0
  56. package/dist/directives/Transition.d.ts.map +1 -0
  57. package/dist/directives/ViewportCull.d.ts +12 -0
  58. package/dist/directives/ViewportCull.d.ts.map +1 -0
  59. package/dist/directives/ViewportFollow.d.ts +19 -0
  60. package/dist/directives/ViewportFollow.d.ts.map +1 -0
  61. package/dist/directives/index.d.ts +13 -0
  62. package/dist/directives/index.d.ts.map +1 -0
  63. package/dist/engine/animation.d.ts +73 -0
  64. package/dist/engine/animation.d.ts.map +1 -0
  65. package/dist/engine/bootstrap.d.ts +16 -0
  66. package/dist/engine/bootstrap.d.ts.map +1 -0
  67. package/dist/engine/directive.d.ts +14 -0
  68. package/dist/engine/directive.d.ts.map +1 -0
  69. package/dist/engine/reactive.d.ts +105 -0
  70. package/dist/engine/reactive.d.ts.map +1 -0
  71. package/dist/engine/signal.d.ts +72 -0
  72. package/dist/engine/signal.d.ts.map +1 -0
  73. package/dist/engine/trigger.d.ts +54 -0
  74. package/dist/engine/trigger.d.ts.map +1 -0
  75. package/dist/engine/utils.d.ts +90 -0
  76. package/dist/engine/utils.d.ts.map +1 -0
  77. package/dist/hooks/addContext.d.ts +2 -0
  78. package/dist/hooks/addContext.d.ts.map +1 -0
  79. package/dist/hooks/useProps.d.ts +42 -0
  80. package/dist/hooks/useProps.d.ts.map +1 -0
  81. package/dist/hooks/useRef.d.ts +5 -0
  82. package/dist/hooks/useRef.d.ts.map +1 -0
  83. package/dist/index-BnuKipxl.js +12568 -0
  84. package/dist/index-BnuKipxl.js.map +1 -0
  85. package/dist/index.d.ts +15 -1083
  86. package/dist/index.d.ts.map +1 -0
  87. package/dist/index.global.js +29 -0
  88. package/dist/index.global.js.map +1 -0
  89. package/dist/index.js +81 -3041
  90. package/dist/index.js.map +1 -1
  91. package/dist/utils/Ease.d.ts +17 -0
  92. package/dist/utils/Ease.d.ts.map +1 -0
  93. package/dist/utils/GlobalAssetLoader.d.ts +141 -0
  94. package/dist/utils/GlobalAssetLoader.d.ts.map +1 -0
  95. package/dist/utils/RadialGradient.d.ts +58 -0
  96. package/dist/utils/RadialGradient.d.ts.map +1 -0
  97. package/dist/utils/functions.d.ts +2 -0
  98. package/dist/utils/functions.d.ts.map +1 -0
  99. package/package.json +13 -7
  100. package/src/components/Button.ts +396 -0
  101. package/src/components/Canvas.ts +61 -45
  102. package/src/components/Container.ts +21 -2
  103. package/src/components/DOMContainer.ts +123 -0
  104. package/src/components/DOMElement.ts +421 -0
  105. package/src/components/DisplayObject.ts +350 -197
  106. package/src/components/Graphic.ts +200 -34
  107. package/src/components/Joystick.ts +363 -0
  108. package/src/components/Mesh.ts +222 -0
  109. package/src/components/NineSliceSprite.ts +4 -1
  110. package/src/components/ParticleEmitter.ts +12 -8
  111. package/src/components/Sprite.ts +306 -30
  112. package/src/components/Text.ts +125 -18
  113. package/src/components/Video.ts +110 -0
  114. package/src/components/Viewport.ts +59 -43
  115. package/src/components/index.ts +8 -2
  116. package/src/components/types/DisplayObject.ts +34 -0
  117. package/src/components/types/Spritesheet.ts +0 -118
  118. package/src/directives/Controls.ts +254 -0
  119. package/src/directives/ControlsBase.ts +266 -0
  120. package/src/directives/Drag.ts +357 -52
  121. package/src/directives/Flash.ts +419 -0
  122. package/src/directives/GamepadControls.ts +537 -0
  123. package/src/directives/JoystickControls.ts +396 -0
  124. package/src/directives/KeyboardControls.ts +66 -424
  125. package/src/directives/Shake.ts +295 -0
  126. package/src/directives/Sound.ts +94 -31
  127. package/src/directives/ViewportFollow.ts +35 -7
  128. package/src/directives/index.ts +12 -6
  129. package/src/engine/animation.ts +175 -21
  130. package/src/engine/bootstrap.ts +23 -3
  131. package/src/engine/directive.ts +2 -2
  132. package/src/engine/reactive.ts +780 -177
  133. package/src/engine/signal.ts +35 -4
  134. package/src/engine/trigger.ts +34 -7
  135. package/src/engine/utils.ts +19 -3
  136. package/src/hooks/useProps.ts +1 -1
  137. package/src/index.ts +4 -2
  138. package/src/utils/GlobalAssetLoader.ts +257 -0
  139. package/src/utils/functions.ts +7 -0
  140. package/testing/index.ts +12 -0
  141. package/tsconfig.json +17 -0
  142. package/vite.config.ts +39 -0
@@ -0,0 +1,110 @@
1
+ import { Texture } from "pixi.js";
2
+ import { h, mount } from "../engine/signal";
3
+ import { useDefineProps } from "../hooks/useProps";
4
+ import { Sprite } from "./Sprite";
5
+ import { effect, Signal, signal } from "@signe/reactive";
6
+
7
+ interface VideoProps {
8
+ src: string;
9
+ paused?: boolean;
10
+ loop?: boolean;
11
+ muted?: boolean;
12
+ loader?: {
13
+ onComplete?: (texture: Texture) => void;
14
+ onProgress?: (progress: number) => void;
15
+ };
16
+ }
17
+
18
+ export function Video(props: VideoProps) {
19
+ const eventsMap = {
20
+ audioprocess: null,
21
+ canplay: null,
22
+ canplaythrough: null,
23
+ complete: null,
24
+ durationchange: null,
25
+ emptied: null,
26
+ ended: null,
27
+ loadeddata: null,
28
+ loadedmetadata: null,
29
+ pause: null,
30
+ play: null,
31
+ playing: null,
32
+ progress: null,
33
+ ratechange: null,
34
+ seeked: null,
35
+ seeking: null,
36
+ stalled: null,
37
+ suspend: null,
38
+ timeupdate: null,
39
+ volumechange: null,
40
+ waiting: null
41
+ }
42
+
43
+ const video: Signal<HTMLVideoElement | null> = signal(null)
44
+ const defineProps = useDefineProps(props)
45
+ const { play, loop, muted } = defineProps({
46
+ play: {
47
+ type: Boolean,
48
+ default: true
49
+ },
50
+ loop: {
51
+ type: Boolean,
52
+ default: false
53
+ },
54
+ muted: {
55
+ type: Boolean,
56
+ default: false
57
+ }
58
+ })
59
+
60
+ effect(() => {
61
+ const _video = video()
62
+ const state = play()
63
+ if (_video && state !== undefined) {
64
+ if (state) {
65
+ _video.play()
66
+ } else {
67
+ _video.pause()
68
+ }
69
+ }
70
+ if (_video && loop()) {
71
+ _video.loop = loop()
72
+ }
73
+ if (_video && muted()) {
74
+ _video.muted = muted()
75
+ }
76
+ })
77
+
78
+ mount(() => {
79
+ return () => {
80
+ for (let event in eventsMap) {
81
+ if (eventsMap[event]) {
82
+ video().removeEventListener(event, eventsMap[event])
83
+ }
84
+ }
85
+ }
86
+ })
87
+
88
+ return h(Sprite, {
89
+ ...props,
90
+ image: props.src,
91
+ loader: {
92
+ onComplete: (texture) => {
93
+ const source = texture.source.resource
94
+ video.set(source)
95
+ if (props?.loader?.onComplete) {
96
+ props.loader.onComplete(texture)
97
+ }
98
+ for (let event in eventsMap) {
99
+ if (props[event]) {
100
+ const cb = (ev) => {
101
+ props[event](ev)
102
+ }
103
+ eventsMap[event] = cb
104
+ source.addEventListener(event, cb)
105
+ }
106
+ }
107
+ }
108
+ }
109
+ })
110
+ }
@@ -1,8 +1,8 @@
1
1
  import { Viewport as PixiViewport } from 'pixi-viewport';
2
2
  import { Subscription } from 'rxjs';
3
- import { createComponent, registerComponent } from '../engine/reactive';
4
- import { DisplayObject } from './DisplayObject';
5
- import { effect } from '@signe/reactive';
3
+ import { createComponent, registerComponent, Element, Props } from '../engine/reactive';
4
+ import { DisplayObject, ComponentInstance } from './DisplayObject';
5
+ import { effect, Signal } from '@signe/reactive';
6
6
 
7
7
  const EVENTS = [
8
8
  'bounce-x-end',
@@ -28,6 +28,21 @@ const EVENTS = [
28
28
  'zoomed-end'
29
29
  ]
30
30
 
31
+ export interface ViewportProps extends Props {
32
+ screenWidth?: number;
33
+ screenHeight?: number;
34
+ worldWidth?: number;
35
+ worldHeight?: number;
36
+ clamp?: boolean | {
37
+ left?: number;
38
+ right?: number;
39
+ top?: number;
40
+ bottom?: number;
41
+ };
42
+ context?: any;
43
+ [key: string]: any;
44
+ }
45
+
31
46
  export class CanvasViewport extends DisplayObject(PixiViewport) {
32
47
  private tickSubscription: Subscription
33
48
  overrideProps = ['wheel']
@@ -48,16 +63,20 @@ export class CanvasViewport extends DisplayObject(PixiViewport) {
48
63
  onInit(props) {
49
64
  super.onInit(props)
50
65
  for (let event of EVENTS) {
51
- const camelCaseEvent = event.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
52
- if (props[camelCaseEvent]) {
53
- this.on(event, props[camelCaseEvent])
54
- }
66
+ if (props[event]) this.on(event, props[event])
55
67
  }
56
68
  }
57
69
 
58
- onMount(element) {
59
- super.onMount(element)
60
- const { tick, renderer, canvasSize } = element.props.context
70
+ /**
71
+ * Called when the component is mounted to the scene graph.
72
+ * Initializes viewport settings and subscriptions.
73
+ * @param {Element<CanvasViewport>} element - The element being mounted. Its `props` property (of type ViewportProps) contains component properties and context.
74
+ * @param {number} [index] - The index of the component among its siblings.
75
+ */
76
+ async onMount(element: Element<CanvasViewport>, index?: number): Promise<void> {
77
+ await super.onMount(element, index);
78
+ const { props } = element;
79
+ const { tick, app, canvasSize } = props.context;
61
80
  let isDragging = false
62
81
 
63
82
  effect(() => {
@@ -65,18 +84,26 @@ export class CanvasViewport extends DisplayObject(PixiViewport) {
65
84
  this.screenHeight = canvasSize().height
66
85
  })
67
86
 
68
- renderer.events.domElement.addEventListener(
69
- 'wheel',
70
- this.input.wheelFunction
71
- );
72
- this.options.events = renderer.events
87
+ effect(() => {
88
+ const _app = app()
89
+ if (!_app) return
90
+
91
+ const renderer = _app.renderer
92
+
93
+ renderer.events.domElement.addEventListener(
94
+ 'wheel',
95
+ this.input.wheelFunction
96
+ );
97
+
98
+ this.options.events = renderer.events
99
+ })
73
100
 
74
101
  this.tickSubscription = tick.observable.subscribe(({ value }) => {
75
102
  this.update(value.timestamp)
76
103
  })
77
104
 
78
105
  element.props.context.viewport = this
79
- this.updateViewportSettings(element.props)
106
+ this.updateViewportSettings(props)
80
107
  }
81
108
 
82
109
  onUpdate(props) {
@@ -97,15 +124,11 @@ export class CanvasViewport extends DisplayObject(PixiViewport) {
97
124
  if (props.worldHeight !== undefined) {
98
125
  this.worldHeight = props.worldHeight
99
126
  }
100
- // if (props.drag) {
101
- // if (props.drag === true) {
102
-
103
- // } else {
104
- // this.drag(props.drag)
105
- // }
106
- // }
127
+ if (props.drag) {
128
+ this.drag(props.drag)
129
+ }
107
130
  if (props.clamp) {
108
- this.clamp(props.clamp)
131
+ this.clamp(props.clamp.value ?? props.clamp)
109
132
  }
110
133
  if (props.wheel) {
111
134
  if (props.wheel === true) {
@@ -130,30 +153,23 @@ export class CanvasViewport extends DisplayObject(PixiViewport) {
130
153
  }
131
154
  }
132
155
 
133
- onDestroy(): void {
134
- super.onDestroy()
135
- this.tickSubscription.unsubscribe()
156
+ /**
157
+ * Called when the component is about to be destroyed.
158
+ * Unsubscribes from the tick observable.
159
+ * @param {Element<any>} parent - The parent element.
160
+ * @param {() => void} [afterDestroy] - An optional callback function to be executed after the component's own destruction logic.
161
+ */
162
+ async onDestroy(parent: Element<any>, afterDestroy?: () => void): Promise<void> {
163
+ const _afterDestroy = async () => {
164
+ this.tickSubscription.unsubscribe()
165
+ afterDestroy()
166
+ }
167
+ await super.onDestroy(parent, _afterDestroy);
136
168
  }
137
169
  }
138
170
 
139
- export interface CanvasViewport extends PixiViewport { }
140
-
141
171
  registerComponent('Viewport', CanvasViewport)
142
172
 
143
- export interface ViewportProps {
144
- screenWidth?: number;
145
- screenHeight?: number;
146
- worldWidth?: number;
147
- worldHeight?: number;
148
- clamp?: boolean | {
149
- left?: number;
150
- right?: number;
151
- top?: number;
152
- bottom?: number;
153
- };
154
- [key: string]: any;
155
- }
156
-
157
173
  export function Viewport(props: ViewportProps) {
158
174
  return createComponent('Viewport', props);
159
175
  }
@@ -1,11 +1,17 @@
1
1
  export { Canvas } from './Canvas'
2
2
  export { Container } from './Container'
3
- export { Graphics, Rect, Circle, Ellipse, Triangle, Svg as svg } from './Graphic'
3
+ export { Graphics, Rect, Circle, Ellipse, Triangle, Svg } from './Graphic'
4
+ export { Mesh } from './Mesh'
4
5
  export { Scene } from './Scene'
5
6
  export { ParticlesEmitter } from './ParticleEmitter'
6
7
  export { Sprite } from './Sprite'
8
+ export { Video } from './Video'
7
9
  export { Text } from './Text'
8
10
  export { TilingSprite } from './TilingSprite'
9
11
  export { Viewport } from './Viewport'
10
12
  export { NineSliceSprite } from './NineSliceSprite'
11
- export { type ComponentInstance } from './DisplayObject'
13
+ export { type ComponentInstance } from './DisplayObject'
14
+ export { DOMContainer } from './DOMContainer'
15
+ export { DOMElement } from './DOMElement'
16
+ export { Button, ButtonState, type ButtonProps, type ButtonStyle } from './Button'
17
+ export { Joystick, type JoystickSettings, type JoystickChangeEvent } from './Joystick'
@@ -1,18 +1,45 @@
1
1
  import * as PIXI from "pixi.js";
2
2
  import { SignalOrPrimitive } from ".";
3
+ import { DragProps } from "../../directives/Drag";
4
+ import { ViewportFollowProps } from "../../directives/ViewportFollow";
5
+ import { ShakeProps } from "../../directives/Shake";
6
+ import { FlashProps } from "../../directives/Flash";
3
7
 
4
8
  export type FlexDirection = 'row' | 'column' | 'row-reverse' | 'column-reverse';
5
9
  export type JustifyContent = 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around';
6
10
  export type AlignContent = 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around';
7
11
  export type Size = number | `${number}%`
8
12
  export type EdgeSize = SignalOrPrimitive<Size | [Size, Size] | [Size, Size, Size, Size]>
13
+ export type ObjectFit = 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
14
+ export type ObjectPosition = string;
15
+ export type TransformOrigin = string;
16
+ export type PositionType = 'relative' | 'absolute' | 'static';
9
17
 
10
18
  export interface DisplayObjectProps {
19
+ attach?: any;
11
20
  ref?: string;
12
21
  x?: SignalOrPrimitive<number>;
13
22
  y?: SignalOrPrimitive<number>;
14
23
  width?: SignalOrPrimitive<Size>;
15
24
  height?: SignalOrPrimitive<Size>;
25
+ minWidth?: SignalOrPrimitive<Size>;
26
+ minHeight?: SignalOrPrimitive<Size>;
27
+ maxWidth?: SignalOrPrimitive<Size>;
28
+ maxHeight?: SignalOrPrimitive<Size>;
29
+ aspectRatio?: SignalOrPrimitive<number>;
30
+ flexGrow?: SignalOrPrimitive<number>;
31
+ flexShrink?: SignalOrPrimitive<number>;
32
+ flexBasis?: SignalOrPrimitive<Size>;
33
+ rowGap?: SignalOrPrimitive<number>;
34
+ columnGap?: SignalOrPrimitive<number>;
35
+ positionType?: PositionType;
36
+ top?: SignalOrPrimitive<Size>;
37
+ right?: SignalOrPrimitive<Size>;
38
+ bottom?: SignalOrPrimitive<Size>;
39
+ left?: SignalOrPrimitive<Size>;
40
+ objectFit?: ObjectFit;
41
+ objectPosition?: ObjectPosition;
42
+ transformOrigin?: TransformOrigin;
16
43
  children?: any[];
17
44
  flexDirection?: FlexDirection;
18
45
  justifyContent?: JustifyContent;
@@ -36,6 +63,13 @@ export interface DisplayObjectProps {
36
63
  blendMode?: SignalOrPrimitive<PIXI.BLEND_MODES>;
37
64
  blur?: SignalOrPrimitive<number>;
38
65
 
66
+ // Directives
67
+ drag?: DragProps;
68
+ viewportFollow?: ViewportFollowProps;
69
+ shake?: ShakeProps;
70
+ flash?: FlashProps;
71
+
72
+ // Events
39
73
  click?: PIXI.FederatedEventHandler;
40
74
  mousedown?: PIXI.FederatedEventHandler;
41
75
  mouseenter?: PIXI.FederatedEventHandler;
@@ -208,124 +208,6 @@ export interface TexturesOptions extends TextureOptions, TransformOptions {
208
208
  }
209
209
 
210
210
  export interface SpritesheetOptions extends TransformOptions, TextureOptions {
211
- /**
212
- * Object containing all animations.
213
- * The key to the object is the name of the animation. The value is a two-dimensional array
214
- *
215
- * ```ts
216
- * textures: {
217
- * myanim: {
218
- * animations: [
219
- * [ { time: 0, frameX: 0, frameY: 0 } ]
220
- * ]
221
- * }
222
- * }
223
- * ```
224
- *
225
- * The first array represents an animation group. You can put several of them together to create an animation cluster. For example, several explosions with the same spritesheet
226
- * The second array represents the animation itself which will animate over time. The object indicates, over a period of time (in frame), which part of the spritesheet will be taken (`frameX`, `frameY`)
227
- *
228
- * Here are the properties:
229
- *
230
- * * `time`: Time in frame
231
- * * `frameX`: Retrieve a frame from the spritesheet on the X-axis
232
- * * `frameY`: Retrieve a frame from the spritesheet on the Y-axis
233
- * * `opacity`
234
- * * `pivot`
235
- * * `anchor`
236
- * * `rotation`
237
- * * `angle`
238
- * * `scale`
239
- * * `skew`
240
- * * `x`
241
- * * `y`
242
- * * `visible`
243
- * * `sound`: The sound that will be played during the frame
244
- *
245
- * ---
246
- * **Extract Animation of Spritesheet**
247
- *
248
- * Sometimes the animation is part of the image
249
- *
250
- * ```ts
251
- * textures: {
252
- * myanim: {
253
- * rectWidth: 64,
254
- * rectHeight: 64,
255
- * framesWidth: 10,
256
- * framesHeight: 2,
257
- * offset: {x: 0, y: 230},
258
- * sound: 'my-sound-id', // You can put a sound just for the animation
259
- * animations: [
260
- * [ { time: 0, frameX: 0, frameY: 0 } ]
261
- * ]
262
- * }
263
- * }
264
- * ```
265
- *
266
- * Above, we can specify which part we want to recover
267
- *
268
- * 1. We go to the position {0, 230} of the image (`offset`)
269
- * 2. We recover cells of 64px (`rectWidth` and `rectHeight`)
270
- * 3. And we get 20 cells (10 on the width, 2 on the height) (`frameX` and `frameY`)
271
- *
272
- * ---
273
- *
274
- * **Advanced**
275
- *
276
- * You can create an animation that will be linked to a data. For example, different animation according to a direction of the character.
277
- *
278
- * Full example:
279
- *
280
- * ```ts
281
- * import { Spritesheet, Animation, Direction } from '@rpgjs/client'
282
- *
283
- * @Spritesheet({
284
- * id: 'chest',
285
- * image: require('./assets/chest.png'),
286
- * width: 124,
287
- * height: 61,
288
- * framesHeight: 2,
289
- * framesWidth: 4,
290
- * textures: {
291
- * [Animation.Stand]: {
292
- * animations: direction => [[ {time: 0, frameX: 3, frameY: direction == Direction.Up ? 0 : 1 } ]]
293
- * }
294
- * })
295
- * })
296
- * export class Chest { }
297
- * ```
298
- *
299
- * > It is important to know that `Animation.Stand` animation is called if it exists. it only works in the case of an event that doesn't move. The direction is then sent
300
- *
301
- * As you can see, the property contains a function that returns the array for the animation. Here, it is the direction but the parameters depend on the call of the animation. Example:
302
- *
303
- * ```ts
304
- * import { Spritesheet, Animation, Direction, RpgSprite, ISpriteCharacter } from '@rpgjs/client'
305
- *
306
- * @Spritesheet({
307
- * id: 'chest',
308
- * image: require('./assets/chest.png'),
309
- * width: 124,
310
- * height: 61,
311
- * framesHeight: 2,
312
- * framesWidth: 4,
313
- * textures: {
314
- * [Animation.Stand]: {
315
- * animations: str => [[ {time: 0, frameX: 3, frameY: str == 'hello' ? 0 : 1 } ]]
316
- * }
317
- * }
318
- * })
319
- * export class Chest implements ISpriteCharacter {
320
- * onCharacterStand(sprite: RpgSprite) {
321
- * sprite.animation.play(Animation.Stand, ['hello'])
322
- * }
323
- * }
324
- * ```
325
- *
326
- * @prop { { [animName: string]: { animations: Array<Array<FrameOptions>> | Function, ...other } } } [textures]
327
- * @memberof Spritesheet
328
- * */
329
211
  textures?: {
330
212
  [animationName: string]: Partial<TexturesOptions> & Pick<TexturesOptions, 'animations'>
331
213
  }