canvasengine 1.3.0 → 2.0.1-beta.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 (125) hide show
  1. package/.cursorrules +0 -0
  2. package/.github/workflows/ci.yml +29 -0
  3. package/README.md +79 -0
  4. package/dist/compiler/vite.js +119 -0
  5. package/dist/compiler/vite.js.map +1 -0
  6. package/dist/index.d.ts +846 -0
  7. package/dist/index.js +3340 -0
  8. package/dist/index.js.map +1 -0
  9. package/index.d.ts +6 -0
  10. package/logo.png +0 -0
  11. package/package.json +84 -18
  12. package/src/compiler/grammar.pegjs +180 -0
  13. package/src/compiler/vite.ts +166 -0
  14. package/src/components/Canvas.ts +134 -0
  15. package/src/components/Container.ts +46 -0
  16. package/src/components/DisplayObject.ts +458 -0
  17. package/src/components/DrawMap/index.ts +65 -0
  18. package/src/components/Graphic.ts +147 -0
  19. package/src/components/NineSliceSprite.ts +46 -0
  20. package/src/components/ParticleEmitter.ts +39 -0
  21. package/src/components/Scene.ts +6 -0
  22. package/src/components/Sprite.ts +493 -0
  23. package/src/components/Text.ts +145 -0
  24. package/src/components/Tilemap/Tile.ts +79 -0
  25. package/src/components/Tilemap/TileGroup.ts +207 -0
  26. package/src/components/Tilemap/TileLayer.ts +163 -0
  27. package/src/components/Tilemap/TileSet.ts +41 -0
  28. package/src/components/Tilemap/index.ts +80 -0
  29. package/src/components/TilingSprite.ts +39 -0
  30. package/src/components/Viewport.ts +159 -0
  31. package/src/components/index.ts +12 -0
  32. package/src/components/types/DisplayObject.ts +68 -0
  33. package/src/components/types/MouseEvent.ts +3 -0
  34. package/src/components/types/Spritesheet.ts +389 -0
  35. package/src/components/types/index.ts +4 -0
  36. package/src/directives/Drag.ts +84 -0
  37. package/src/directives/KeyboardControls.ts +922 -0
  38. package/src/directives/Scheduler.ts +112 -0
  39. package/src/directives/Sound.ts +91 -0
  40. package/src/directives/Transition.ts +45 -0
  41. package/src/directives/ViewportCull.ts +40 -0
  42. package/src/directives/ViewportFollow.ts +26 -0
  43. package/src/directives/index.ts +7 -0
  44. package/src/engine/animation.ts +113 -0
  45. package/src/engine/bootstrap.ts +19 -0
  46. package/src/engine/directive.ts +23 -0
  47. package/src/engine/reactive.ts +379 -0
  48. package/src/engine/signal.ts +138 -0
  49. package/src/engine/trigger.ts +40 -0
  50. package/src/engine/utils.ts +135 -0
  51. package/src/hooks/addContext.ts +6 -0
  52. package/src/hooks/useProps.ts +155 -0
  53. package/src/hooks/useRef.ts +21 -0
  54. package/src/index.ts +14 -0
  55. package/src/presets/Bar.ts +89 -0
  56. package/src/presets/Button.ts +0 -0
  57. package/src/presets/Joystick.ts +286 -0
  58. package/src/presets/NightAmbiant.ts +122 -0
  59. package/src/presets/Particle.ts +53 -0
  60. package/src/utils/Ease.ts +33 -0
  61. package/src/utils/RadialGradient.ts +86 -0
  62. package/starter/assets/logo.png +0 -0
  63. package/starter/components/app.ce +18 -0
  64. package/starter/components/hello.ce +35 -0
  65. package/starter/index.html +21 -0
  66. package/starter/main.ts +6 -0
  67. package/starter/package.json +20 -0
  68. package/starter/tsconfig.json +32 -0
  69. package/starter/vite.config.ts +12 -0
  70. package/tsconfig.json +32 -0
  71. package/tsconfig.node.json +10 -0
  72. package/tsup.config.ts +28 -0
  73. package/vitest.config.ts +12 -0
  74. package/.gitattributes +0 -22
  75. package/.npmignore +0 -163
  76. package/canvasengine-1.3.0.all.min.js +0 -21
  77. package/canvasengine.js +0 -5802
  78. package/core/DB.js +0 -24
  79. package/core/ModelServer.js +0 -348
  80. package/core/Users.js +0 -190
  81. package/core/engine-common.js +0 -952
  82. package/doc/cocoonjs.md +0 -36
  83. package/doc/doc-lang.yml +0 -43
  84. package/doc/doc-router.yml +0 -14
  85. package/doc/doc-tuto.yml +0 -9
  86. package/doc/doc.yml +0 -39
  87. package/doc/element.md +0 -37
  88. package/doc/entity.md +0 -90
  89. package/doc/extend.md +0 -47
  90. package/doc/get_started.md +0 -19
  91. package/doc/images/entity.png +0 -0
  92. package/doc/multitouch.md +0 -58
  93. package/doc/nodejs.md +0 -142
  94. package/doc/scene.md +0 -44
  95. package/doc/text.md +0 -156
  96. package/examples/server/client.html +0 -31
  97. package/examples/server/server.js +0 -16
  98. package/examples/tiled_server/client.html +0 -52
  99. package/examples/tiled_server/images/tiles_spritesheet.png +0 -0
  100. package/examples/tiled_server/server/map.json +0 -50
  101. package/examples/tiled_server/server/map.tmx +0 -16
  102. package/examples/tiled_server/server/server.js +0 -16
  103. package/extends/Animation.js +0 -910
  104. package/extends/Effect.js +0 -252
  105. package/extends/Gleed2d.js +0 -252
  106. package/extends/Hit.js +0 -1509
  107. package/extends/Input.js +0 -699
  108. package/extends/Marshal.js +0 -716
  109. package/extends/Scrolling.js +0 -388
  110. package/extends/Soundmanager2.js +0 -5466
  111. package/extends/Spritesheet.js +0 -196
  112. package/extends/Text.js +0 -366
  113. package/extends/Tiled.js +0 -403
  114. package/extends/Window.js +0 -575
  115. package/extends/gamepad.js +0 -397
  116. package/extends/socket.io.min.js +0 -2
  117. package/extends/swf/soundmanager2.swf +0 -0
  118. package/extends/swf/soundmanager2_debug.swf +0 -0
  119. package/extends/swf/soundmanager2_flash9.swf +0 -0
  120. package/extends/swf/soundmanager2_flash9_debug.swf +0 -0
  121. package/extends/swf/soundmanager2_flash_xdomain.zip +0 -0
  122. package/extends/workers/transition.js +0 -43
  123. package/index.js +0 -46
  124. package/license.txt +0 -19
  125. package/readme.md +0 -483
@@ -0,0 +1,159 @@
1
+ import { Viewport as PixiViewport } from 'pixi-viewport';
2
+ import { Subscription } from 'rxjs';
3
+ import { createComponent, registerComponent } from '../engine/reactive';
4
+ import { DisplayObject } from './DisplayObject';
5
+ import { effect } from '@signe/reactive';
6
+
7
+ const EVENTS = [
8
+ 'bounce-x-end',
9
+ 'bounce-x-start',
10
+ 'bounce-y-end',
11
+ 'bounce-y-start',
12
+ 'clicked',
13
+ 'drag-end',
14
+ 'drag-start',
15
+ 'frame-end',
16
+ 'mouse-edge-end',
17
+ 'mouse-edge-start',
18
+ 'moved',
19
+ 'moved-end',
20
+ 'pinch-end',
21
+ 'pinch-start',
22
+ 'snap-end',
23
+ 'snap-start',
24
+ 'snap-zoom-end',
25
+ 'snap-zoom-start',
26
+ 'wheel-scroll',
27
+ 'zoomed',
28
+ 'zoomed-end'
29
+ ]
30
+
31
+ export class CanvasViewport extends DisplayObject(PixiViewport) {
32
+ private tickSubscription: Subscription
33
+ overrideProps = ['wheel']
34
+
35
+ constructor() {
36
+ const defaultOptions = {
37
+ noTicker: true,
38
+ events: {
39
+ domElement: {
40
+ addEventListener: () => {}
41
+ }
42
+ },
43
+ }
44
+ // @ts-ignore
45
+ super(defaultOptions)
46
+ }
47
+
48
+ onInit(props) {
49
+ super.onInit(props)
50
+ 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
+ }
55
+ }
56
+ }
57
+
58
+ onMount(element) {
59
+ super.onMount(element)
60
+ const { tick, renderer, canvasSize } = element.props.context
61
+ let isDragging = false
62
+
63
+ effect(() => {
64
+ this.screenWidth = canvasSize().width
65
+ this.screenHeight = canvasSize().height
66
+ })
67
+
68
+ renderer.events.domElement.addEventListener(
69
+ 'wheel',
70
+ this.input.wheelFunction
71
+ );
72
+ this.options.events = renderer.events
73
+
74
+ this.tickSubscription = tick.observable.subscribe(({ value }) => {
75
+ this.update(value.timestamp)
76
+ })
77
+
78
+ element.props.context.viewport = this
79
+ this.updateViewportSettings(element.props)
80
+ }
81
+
82
+ onUpdate(props) {
83
+ super.onUpdate(props)
84
+ this.updateViewportSettings(props)
85
+ }
86
+
87
+ private updateViewportSettings(props) {
88
+ if (props.screenWidth !== undefined) {
89
+ this.screenWidth = props.screenWidth
90
+ }
91
+ if (props.screenHeight !== undefined) {
92
+ this.screenHeight = props.screenHeight
93
+ }
94
+ if (props.worldWidth !== undefined) {
95
+ this.worldWidth = props.worldWidth
96
+ }
97
+ if (props.worldHeight !== undefined) {
98
+ this.worldHeight = props.worldHeight
99
+ }
100
+ // if (props.drag) {
101
+ // if (props.drag === true) {
102
+
103
+ // } else {
104
+ // this.drag(props.drag)
105
+ // }
106
+ // }
107
+ if (props.clamp) {
108
+ this.clamp(props.clamp)
109
+ }
110
+ if (props.wheel) {
111
+ if (props.wheel === true) {
112
+ this.wheel()
113
+ } else {
114
+ this.wheel(props.wheel)
115
+ }
116
+ }
117
+ if (props.decelerate) {
118
+ if (props.decelerate === true) {
119
+ this.decelerate()
120
+ } else {
121
+ this.decelerate(props.decelerate)
122
+ }
123
+ }
124
+ if (props.pinch) {
125
+ if (props.pinch === true) {
126
+ this.pinch()
127
+ } else {
128
+ this.pinch(props.pinch)
129
+ }
130
+ }
131
+ }
132
+
133
+ onDestroy(): void {
134
+ super.onDestroy()
135
+ this.tickSubscription.unsubscribe()
136
+ }
137
+ }
138
+
139
+ export interface CanvasViewport extends PixiViewport { }
140
+
141
+ registerComponent('Viewport', CanvasViewport)
142
+
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
+ export function Viewport(props: ViewportProps) {
158
+ return createComponent('Viewport', props);
159
+ }
@@ -0,0 +1,12 @@
1
+ export { Canvas } from './Canvas'
2
+ export { Container } from './Container'
3
+ export { Graphics, Rect, Circle, Ellipse, Triangle, Svg as svg } from './Graphic'
4
+ export { Scene } from './Scene'
5
+ export { ParticlesEmitter } from './ParticleEmitter'
6
+ export { Sprite } from './Sprite'
7
+ export { Text } from './Text'
8
+ export { TiledMap } from './Tilemap'
9
+ export { TilingSprite } from './TilingSprite'
10
+ export { Viewport } from './Viewport'
11
+ export { ImageMap } from './DrawMap'
12
+ export { NineSliceSprite } from './NineSliceSprite'
@@ -0,0 +1,68 @@
1
+ import * as PIXI from "pixi.js";
2
+ import { SignalOrPrimitive } from ".";
3
+
4
+ export type FlexDirection = 'row' | 'column' | 'row-reverse' | 'column-reverse';
5
+ export type JustifyContent = 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around';
6
+ export type AlignContent = 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around';
7
+ export type Size = number | `${number}%`
8
+ export type EdgeSize = SignalOrPrimitive<Size | [Size, Size] | [Size, Size, Size, Size]>
9
+
10
+ export interface DisplayObjectProps {
11
+ ref?: string;
12
+ x?: SignalOrPrimitive<number>;
13
+ y?: SignalOrPrimitive<number>;
14
+ width?: SignalOrPrimitive<Size>;
15
+ height?: SignalOrPrimitive<Size>;
16
+ children?: any[];
17
+ flexDirection?: FlexDirection;
18
+ justifyContent?: JustifyContent;
19
+ alpha?: SignalOrPrimitive<number>;
20
+ margin?: EdgeSize;
21
+ padding?: EdgeSize;
22
+ border?: EdgeSize;
23
+ absolute?: SignalOrPrimitive<boolean>;
24
+ scale?: SignalOrPrimitive<{ x: number, y: number } | number>;
25
+ anchor?: SignalOrPrimitive<{ x: number, y: number }>;
26
+ skew?: SignalOrPrimitive<{ x: number, y: number }>;
27
+ tint?: SignalOrPrimitive<number>;
28
+ rotation?: SignalOrPrimitive<number>;
29
+ angle?: SignalOrPrimitive<number>;
30
+ zIndex?: SignalOrPrimitive<number>;
31
+ roundPixels?: SignalOrPrimitive<boolean>;
32
+ cursor?: SignalOrPrimitive<string>;
33
+ visible?: SignalOrPrimitive<boolean>;
34
+ pivot?: SignalOrPrimitive<{ x: number, y: number }>;
35
+ filters?: any[];
36
+ blendMode?: SignalOrPrimitive<PIXI.BLEND_MODES>;
37
+
38
+ click?: PIXI.FederatedEventHandler;
39
+ mousedown?: PIXI.FederatedEventHandler;
40
+ mouseenter?: PIXI.FederatedEventHandler;
41
+ mouseleave?: PIXI.FederatedEventHandler;
42
+ mousemove?: PIXI.FederatedEventHandler;
43
+ mouseout?: PIXI.FederatedEventHandler;
44
+ mouseover?: PIXI.FederatedEventHandler;
45
+ mouseup?: PIXI.FederatedEventHandler;
46
+ mouseupoutside?: PIXI.FederatedEventHandler;
47
+ pointercancel?: PIXI.FederatedEventHandler;
48
+ pointerdown?: PIXI.FederatedEventHandler;
49
+ pointerenter?: PIXI.FederatedEventHandler;
50
+ pointerleave?: PIXI.FederatedEventHandler;
51
+ pointermove?: PIXI.FederatedEventHandler;
52
+ pointerout?: PIXI.FederatedEventHandler;
53
+ pointerover?: PIXI.FederatedEventHandler;
54
+ pointertap?: PIXI.FederatedEventHandler;
55
+ pointerup?: PIXI.FederatedEventHandler;
56
+ pointerupoutside?: PIXI.FederatedEventHandler;
57
+ rightclick?: PIXI.FederatedEventHandler;
58
+ rightdown?: PIXI.FederatedEventHandler;
59
+ rightup?: PIXI.FederatedEventHandler;
60
+ rightupoutside?: PIXI.FederatedEventHandler;
61
+ tap?: PIXI.FederatedEventHandler;
62
+ touchcancel?: PIXI.FederatedEventHandler;
63
+ touchend?: PIXI.FederatedEventHandler;
64
+ touchendoutside?: PIXI.FederatedEventHandler;
65
+ touchmove?: PIXI.FederatedEventHandler;
66
+ touchstart?: PIXI.FederatedEventHandler;
67
+ wheel?: PIXI.FederatedEventHandler<PIXI.FederatedWheelEvent>;
68
+ }
@@ -0,0 +1,3 @@
1
+ export interface MouseEvent {
2
+ click?: (e: any) => void
3
+ }
@@ -0,0 +1,389 @@
1
+ export interface TransformOptions {
2
+ /**
3
+ * The global value of opacity (between 0 and 1)
4
+ *
5
+ * @prop {number} [opacity]
6
+ * @memberof Spritesheet
7
+ * */
8
+ opacity?: number
9
+ /**
10
+ * The global value of pivot.
11
+ *
12
+ * Invariant under rotation, scaling, and skewing. The projection of into the parent's space of the pivot is equal to position, regardless of the other three transformations. In other words, It is the center of rotation, scaling, and skewing.
13
+ *
14
+ * The array has two elements: [x, y]. If y is omitted, both x and y will be set to x.
15
+ *
16
+ * ```ts
17
+ * pivot: [0.5, 0.8]
18
+ * ```
19
+ *
20
+ * @prop {Array<number>} [pivot]
21
+ * @memberof Spritesheet
22
+ * */
23
+ pivot?: number[]
24
+
25
+ /**
26
+ * The global value of anchor.
27
+ *
28
+ * Position of the origin point
29
+ *
30
+ * The array has two elements: [x, y]. If y is omitted, both x and y will be set to x.
31
+ *
32
+ * ```ts
33
+ * anchor: [0.5, 0.8]
34
+ * ```
35
+ *
36
+ * @prop {Array<number>} [anchor]
37
+ * @memberof Spritesheet
38
+ * */
39
+ anchor?: number[]
40
+
41
+ /**
42
+ * Defines the actual size of the sprite that is inside a larger rectangle.
43
+ * For example, if the texture rectangle is 192x192 while the character, which is in the center, is only 64x64 then set `spriteRealSize: 64`. This way the character will be well positioned in relation to the animations that have a different rectangle
44
+ *
45
+ * > You can also put `spriteRealSize: { width: 64, height: 64 }` but be aware that the width is not concerned because it will always be centered while the height depends on the hitbox
46
+ *
47
+ * @prop {{ width: number, height: number } | number} [spriteRealSize]
48
+ * @since 3.2.0
49
+ * @memberof Spritesheet
50
+ * */
51
+ spriteRealSize?: { width: number, height: number } | number
52
+
53
+ /**
54
+ * The global value of rotation
55
+ *
56
+ * Rotation. This will rotate the display object's projection by this angle (in radians).
57
+ *
58
+ * @prop {number} [angle]
59
+ * @memberof Spritesheet
60
+ * */
61
+ angle?: number
62
+
63
+ /**
64
+ * The global value of rotation
65
+ *
66
+ * Rotation. This is an alias for rotation, but in degrees.
67
+ *
68
+ * @prop {number} [rotation]
69
+ * @memberof Spritesheet
70
+ * */
71
+ rotation?: number
72
+
73
+ /**
74
+ * The global value of scale.
75
+ *
76
+ * Scaling. This will stretch (or compress) the display object's projection. The scale factors are along the local coordinate axes. In other words, the display object is scaled before rotated or skewed. The center of scaling is the pivot.
77
+ *
78
+ * The array has two elements: [x, y]. If y is omitted, both x and y will be set to x.
79
+ *
80
+ * ```ts
81
+ * scale: [0.5, 0.8]
82
+ * ```
83
+ *
84
+ * @prop {Array<number>} [scale]
85
+ * @memberof Spritesheet
86
+ * */
87
+ scale?: number[]
88
+
89
+ /**
90
+ * The global value of skew.
91
+ *
92
+ * Skewing. This can be used to deform a rectangular display object into a parallelogram.
93
+ *
94
+ * In PixiJS, skew has a slightly different behaviour than the conventional meaning. It can be thought of the net rotation applied to the coordinate axes (separately). For example, if "skew.x" is ⍺ and "skew.y" is β, then the line x = 0 will be rotated by ⍺ (y = -x*cot⍺) and the line y = 0 will be rotated by β (y = x*tanβ). A line y = x*tanϴ (i.e. a line at angle ϴ to the x-axis in local-space) will be rotated by an angle between ⍺ and β.
95
+ *
96
+ * It can be observed that if skew is applied equally to both axes, then it will be equivalent to applying a rotation. Indeed, if "skew.x" = -ϴ and "skew.y" = ϴ, it will produce an equivalent of "rotation" = ϴ.
97
+ *
98
+ * Another quite interesting observation is that "skew.x", "skew.y", rotation are communtative operations. Indeed, because rotation is essentially a careful combination of the two.
99
+ *
100
+ * The array has two elements: [x, y]. If y is omitted, both x and y will be set to x.
101
+ *
102
+ * @prop {Array<number>} [skew]
103
+ * @memberof Spritesheet
104
+ * */
105
+ skew?: number[]
106
+
107
+ /**
108
+ * The global value of X translation
109
+ *
110
+ * @prop {number} [x]
111
+ * @memberof Spritesheet
112
+ * */
113
+ x?: number
114
+
115
+ /**
116
+ * The global value of Y translation
117
+ *
118
+ * @prop {number} [y]
119
+ * @memberof Spritesheet
120
+ * */
121
+ y?: number
122
+
123
+ /**
124
+ * The global value of visible
125
+ *
126
+ * @prop {boolean} [visible]
127
+ * @memberof Spritesheet
128
+ * */
129
+ visible?: boolean
130
+
131
+ /**
132
+ * Define the sound that will be played for all animations in the spritesheet. Remember to create the sound before with the @Sound decorator
133
+ *
134
+ * @prop {string} [sound]
135
+ * @memberof Spritesheet
136
+ * */
137
+ sound?: string
138
+ }
139
+
140
+ export interface FrameOptions extends TransformOptions {
141
+ time: number
142
+ frameX?: number
143
+ frameY?: number
144
+ }
145
+
146
+ export interface TextureOptions {
147
+ /**
148
+ * The number of frames on the width
149
+ *
150
+ * @prop {number} framesWidth
151
+ * @memberof Spritesheet
152
+ * */
153
+ framesWidth?: number,
154
+
155
+ /**
156
+ * The number of frames on the height
157
+ *
158
+ * @prop {number} framesHeight
159
+ * @memberof Spritesheet
160
+ * */
161
+ framesHeight?: number,
162
+
163
+ /**
164
+ * The width of the image (in pixels)
165
+ *
166
+ * @prop {number} width
167
+ * @memberof Spritesheet
168
+ * */
169
+ width?: number,
170
+
171
+ /**
172
+ * The height of the image (in pixels)
173
+ *
174
+ * @prop {number} height
175
+ * @memberof Spritesheet
176
+ * */
177
+ height?: number
178
+
179
+ /**
180
+ * Takes a width of a rectangle in the image. Equivalent to `width / framesWidth`
181
+ *
182
+ * @prop {number} [rectWidth]
183
+ * @memberof Spritesheet
184
+ * */
185
+ rectWidth?: number,
186
+
187
+ /**
188
+ * Takes a height of a rectangle in the image. Equivalent to `height / framesHeight`
189
+ *
190
+ * @prop {number} [rectHeight]
191
+ * @memberof Spritesheet
192
+ * */
193
+ rectHeight?: number,
194
+
195
+ /**
196
+ * To take the texture, start at a well defined X and Y position. Otherwise, it starts at 0,0
197
+ *
198
+ * @prop {number} [offset]
199
+ * @memberof Spritesheet
200
+ * */
201
+ offset?: { x: number, y: number }
202
+ }
203
+
204
+ export type AnimationFrames = FrameOptions[][] | ((...args: any) => FrameOptions[][])
205
+
206
+ export interface TexturesOptions extends TextureOptions, TransformOptions {
207
+ animations: AnimationFrames
208
+ }
209
+
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
+ textures?: {
330
+ [animationName: string]: Partial<TexturesOptions> & Pick<TexturesOptions, 'animations'>
331
+ }
332
+ }
333
+
334
+ type SpritesheetImageOptions = SpritesheetOptions & {
335
+ /**
336
+ * The link to the image
337
+ *
338
+ * > Do not use the `images` property
339
+ * > Remember to wrap the link to the image with the `require` function.
340
+ *
341
+ * ```ts
342
+ * image: require('./assets/hero.png')
343
+ * ```
344
+ *
345
+ * @prop {string} [image]
346
+ * @memberof Spritesheet
347
+ * */
348
+ image?: string,
349
+ /**
350
+ * Spritesheet identifier.
351
+ *
352
+ * > Do not use the `images` property
353
+ *
354
+ * @prop {string} [id]
355
+ * @memberof Spritesheet
356
+ * */
357
+ id: string
358
+ }
359
+ type SpritesheetImagesOptions = SpritesheetOptions & {
360
+ /**
361
+ * Put the different images that are concerned by the properties below.
362
+ * The key of the object is the identifier of the spritesheet and the value and the link to the image.
363
+ *
364
+ * > Remember to wrap the link to the image with the `require` function.
365
+ *
366
+ * ```ts
367
+ * images: {
368
+ * hero: require('./assets/hero.png')
369
+ * }
370
+ * ```
371
+ *
372
+ * @prop { { [id: string]: string } } [images]
373
+ * @memberof Spritesheet
374
+ * */
375
+ images?: { [id: string]: string }
376
+ }
377
+
378
+ export function Spritesheet(options: SpritesheetImageOptions)
379
+ export function Spritesheet(options: SpritesheetImagesOptions)
380
+ export function Spritesheet(options: SpritesheetImageOptions | SpritesheetImagesOptions) {
381
+ return (target: Function) => {
382
+ if ('images' in options) target['images'] = options.images
383
+ if ('id' in options) target['id'] = options.id
384
+ for (let key in options) {
385
+ target.prototype[key] = options[key]
386
+ }
387
+ return
388
+ }
389
+ }
@@ -0,0 +1,4 @@
1
+ import { Signal } from "@signe/reactive";
2
+ import { AnimatedSignal } from "../../engine/animation";
3
+
4
+ export type SignalOrPrimitive<T> = T | Signal<T> | AnimatedSignal<T>;