canvasengine 2.0.1-beta.1 → 2.0.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.
- package/dist/DebugRenderer-DkjTAc48.js +1384 -0
- package/dist/DebugRenderer-DkjTAc48.js.map +1 -0
- package/dist/components/Button.d.ts +185 -0
- package/dist/components/Button.d.ts.map +1 -0
- package/dist/components/Canvas.d.ts +17 -0
- package/dist/components/Canvas.d.ts.map +1 -0
- package/dist/components/Container.d.ts +25 -0
- package/dist/components/Container.d.ts.map +1 -0
- package/dist/components/DOMContainer.d.ts +28 -0
- package/dist/components/DOMContainer.d.ts.map +1 -0
- package/dist/components/DOMElement.d.ts +54 -0
- package/dist/components/DOMElement.d.ts.map +1 -0
- package/dist/components/DOMSprite.d.ts +127 -0
- package/dist/components/DOMSprite.d.ts.map +1 -0
- package/dist/components/DisplayObject.d.ts +18 -0
- package/dist/components/DisplayObject.d.ts.map +1 -0
- package/dist/components/FocusContainer.d.ts +129 -0
- package/dist/components/FocusContainer.d.ts.map +1 -0
- package/dist/components/Graphic.d.ts +64 -0
- package/dist/components/Graphic.d.ts.map +1 -0
- package/dist/components/Joystick.d.ts +37 -0
- package/dist/components/Joystick.d.ts.map +1 -0
- package/dist/components/Mesh.d.ts +138 -0
- package/dist/components/Mesh.d.ts.map +1 -0
- package/dist/components/NineSliceSprite.d.ts +16 -0
- package/dist/components/NineSliceSprite.d.ts.map +1 -0
- package/dist/components/ParticleEmitter.d.ts +4 -0
- package/dist/components/ParticleEmitter.d.ts.map +1 -0
- package/dist/components/Scene.d.ts +2 -0
- package/dist/components/Scene.d.ts.map +1 -0
- package/dist/components/Sprite.d.ts +182 -0
- package/dist/components/Sprite.d.ts.map +1 -0
- package/dist/components/Text.d.ts +24 -0
- package/dist/components/Text.d.ts.map +1 -0
- package/dist/components/TilingSprite.d.ts +17 -0
- package/dist/components/TilingSprite.d.ts.map +1 -0
- package/dist/components/Video.d.ts +14 -0
- package/dist/components/Video.d.ts.map +1 -0
- package/dist/components/Viewport.d.ts +52 -0
- package/dist/components/Viewport.d.ts.map +1 -0
- package/dist/components/index.d.ts +20 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/types/DisplayObject.d.ts +127 -0
- package/dist/components/types/DisplayObject.d.ts.map +1 -0
- package/dist/components/types/MouseEvent.d.ts +4 -0
- package/dist/components/types/MouseEvent.d.ts.map +1 -0
- package/dist/components/types/Spritesheet.d.ts +248 -0
- package/dist/components/types/Spritesheet.d.ts.map +1 -0
- package/dist/components/types/index.d.ts +4 -0
- package/dist/components/types/index.d.ts.map +1 -0
- package/dist/directives/Controls.d.ts +112 -0
- package/dist/directives/Controls.d.ts.map +1 -0
- package/dist/directives/ControlsBase.d.ts +199 -0
- package/dist/directives/ControlsBase.d.ts.map +1 -0
- package/dist/directives/Drag.d.ts +69 -0
- package/dist/directives/Drag.d.ts.map +1 -0
- package/dist/directives/Flash.d.ts +116 -0
- package/dist/directives/Flash.d.ts.map +1 -0
- package/dist/directives/FocusNavigation.d.ts +52 -0
- package/dist/directives/FocusNavigation.d.ts.map +1 -0
- package/dist/directives/FogVisibility.d.ts +47 -0
- package/dist/directives/FogVisibility.d.ts.map +1 -0
- package/dist/directives/GamepadControls.d.ts +224 -0
- package/dist/directives/GamepadControls.d.ts.map +1 -0
- package/dist/directives/JoystickControls.d.ts +171 -0
- package/dist/directives/JoystickControls.d.ts.map +1 -0
- package/dist/directives/KeyboardControls.d.ts +219 -0
- package/dist/directives/KeyboardControls.d.ts.map +1 -0
- package/dist/directives/Scheduler.d.ts +36 -0
- package/dist/directives/Scheduler.d.ts.map +1 -0
- package/dist/directives/Shake.d.ts +98 -0
- package/dist/directives/Shake.d.ts.map +1 -0
- package/dist/directives/Sound.d.ts +25 -0
- package/dist/directives/Sound.d.ts.map +1 -0
- package/dist/directives/SpriteEffects.d.ts +70 -0
- package/dist/directives/SpriteEffects.d.ts.map +1 -0
- package/dist/directives/Transition.d.ts +10 -0
- package/dist/directives/Transition.d.ts.map +1 -0
- package/dist/directives/ViewportCull.d.ts +11 -0
- package/dist/directives/ViewportCull.d.ts.map +1 -0
- package/dist/directives/ViewportFollow.d.ts +18 -0
- package/dist/directives/ViewportFollow.d.ts.map +1 -0
- package/dist/directives/index.d.ts +15 -0
- package/dist/directives/index.d.ts.map +1 -0
- package/dist/dist-BOOc43Qm.js +778 -0
- package/dist/dist-BOOc43Qm.js.map +1 -0
- package/dist/engine/FocusManager.d.ts +174 -0
- package/dist/engine/FocusManager.d.ts.map +1 -0
- package/dist/engine/animation.d.ts +72 -0
- package/dist/engine/animation.d.ts.map +1 -0
- package/dist/engine/bootstrap.d.ts +52 -0
- package/dist/engine/bootstrap.d.ts.map +1 -0
- package/dist/engine/directive.d.ts +13 -0
- package/dist/engine/directive.d.ts.map +1 -0
- package/dist/engine/reactive.d.ts +139 -0
- package/dist/engine/reactive.d.ts.map +1 -0
- package/dist/engine/signal.d.ts +74 -0
- package/dist/engine/signal.d.ts.map +1 -0
- package/dist/engine/trigger.d.ts +54 -0
- package/dist/engine/trigger.d.ts.map +1 -0
- package/dist/engine/utils.d.ts +89 -0
- package/dist/engine/utils.d.ts.map +1 -0
- package/dist/hooks/addContext.d.ts +2 -0
- package/dist/hooks/addContext.d.ts.map +1 -0
- package/dist/hooks/useFocus.d.ts +60 -0
- package/dist/hooks/useFocus.d.ts.map +1 -0
- package/dist/hooks/useProps.d.ts +53 -0
- package/dist/hooks/useProps.d.ts.map +1 -0
- package/dist/hooks/useRef.d.ts +4 -0
- package/dist/hooks/useRef.d.ts.map +1 -0
- package/dist/index.d.ts +19 -844
- package/dist/index.d.ts.map +1 -0
- package/dist/index.global.js +189 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +15156 -3287
- package/dist/index.js.map +1 -1
- package/dist/utils/Ease.d.ts +17 -0
- package/dist/utils/Ease.d.ts.map +1 -0
- package/dist/utils/GlobalAssetLoader.d.ts +141 -0
- package/dist/utils/GlobalAssetLoader.d.ts.map +1 -0
- package/dist/utils/RadialGradient.d.ts +57 -0
- package/dist/utils/RadialGradient.d.ts.map +1 -0
- package/dist/utils/functions.d.ts +2 -0
- package/dist/utils/functions.d.ts.map +1 -0
- package/dist/utils/tabindex.d.ts +16 -0
- package/dist/utils/tabindex.d.ts.map +1 -0
- package/index.d.ts +1 -3
- package/package.json +19 -52
- package/src/components/Button.ts +406 -0
- package/src/components/Canvas.ts +82 -51
- package/src/components/Container.ts +31 -4
- package/src/components/DOMContainer.ts +387 -0
- package/src/components/DOMElement.ts +556 -0
- package/src/components/DOMSprite.ts +1044 -0
- package/src/components/DisplayObject.ts +423 -202
- package/src/components/FocusContainer.ts +368 -0
- package/src/components/Graphic.ts +255 -68
- package/src/components/Joystick.ts +269 -0
- package/src/components/Mesh.ts +239 -0
- package/src/components/NineSliceSprite.ts +4 -1
- package/src/components/ParticleEmitter.ts +12 -8
- package/src/components/Sprite.ts +441 -54
- package/src/components/Text.ts +270 -26
- package/src/components/Video.ts +110 -0
- package/src/components/Viewport.ts +122 -63
- package/src/components/index.ts +12 -5
- package/src/components/types/DisplayObject.ts +64 -5
- package/src/components/types/Spritesheet.ts +0 -118
- package/src/directives/Controls.ts +254 -0
- package/src/directives/ControlsBase.ts +267 -0
- package/src/directives/Drag.ts +357 -52
- package/src/directives/Flash.ts +419 -0
- package/src/directives/FocusNavigation.ts +113 -0
- package/src/directives/FogVisibility.ts +273 -0
- package/src/directives/GamepadControls.ts +537 -0
- package/src/directives/JoystickControls.ts +396 -0
- package/src/directives/KeyboardControls.ts +86 -431
- package/src/directives/Scheduler.ts +21 -16
- package/src/directives/Shake.ts +298 -0
- package/src/directives/Sound.ts +94 -31
- package/src/directives/SpriteEffects.ts +461 -0
- package/src/directives/ViewportFollow.ts +40 -9
- package/src/directives/index.ts +14 -6
- package/src/engine/FocusManager.ts +510 -0
- package/src/engine/animation.ts +175 -21
- package/src/engine/bootstrap.ts +140 -6
- package/src/engine/directive.ts +4 -4
- package/src/engine/reactive.ts +1266 -167
- package/src/engine/signal.ts +335 -47
- package/src/engine/trigger.ts +95 -12
- package/src/engine/utils.ts +101 -9
- package/src/hooks/useFocus.ts +91 -0
- package/src/hooks/useProps.ts +92 -7
- package/src/index.ts +13 -6
- package/src/types/pixi-cull.d.ts +7 -0
- package/src/utils/GlobalAssetLoader.ts +257 -0
- package/src/utils/RadialGradient.ts +29 -0
- package/src/utils/functions.ts +7 -0
- package/src/utils/tabindex.ts +70 -0
- package/testing/index.ts +42 -0
- package/tsconfig.json +15 -25
- package/vite.config.ts +39 -0
- package/.cursorrules +0 -0
- package/.github/workflows/ci.yml +0 -29
- package/README.md +0 -79
- package/dist/compiler/vite.js +0 -119
- package/dist/compiler/vite.js.map +0 -1
- package/logo.png +0 -0
- package/src/compiler/grammar.pegjs +0 -180
- package/src/compiler/vite.ts +0 -166
- package/src/components/DrawMap/index.ts +0 -65
- package/src/components/Tilemap/Tile.ts +0 -79
- package/src/components/Tilemap/TileGroup.ts +0 -207
- package/src/components/Tilemap/TileLayer.ts +0 -163
- package/src/components/Tilemap/TileSet.ts +0 -41
- package/src/components/Tilemap/index.ts +0 -80
- package/src/presets/Bar.ts +0 -89
- package/src/presets/Button.ts +0 -0
- package/src/presets/Joystick.ts +0 -286
- package/src/presets/NightAmbiant.ts +0 -122
- package/src/presets/Particle.ts +0 -53
- package/starter/assets/logo.png +0 -0
- package/starter/components/app.ce +0 -18
- package/starter/components/hello.ce +0 -35
- package/starter/index.html +0 -21
- package/starter/main.ts +0 -6
- package/starter/package.json +0 -20
- package/starter/tsconfig.json +0 -32
- package/starter/vite.config.ts +0 -12
- package/tsconfig.node.json +0 -10
- package/tsup.config.ts +0 -28
- package/vitest.config.ts +0 -12
|
@@ -1,8 +1,9 @@
|
|
|
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
|
+
import { Graphics, Container, ContainerChild, IRenderLayer } from 'pixi.js';
|
|
6
7
|
|
|
7
8
|
const EVENTS = [
|
|
8
9
|
'bounce-x-end',
|
|
@@ -28,55 +29,103 @@ const EVENTS = [
|
|
|
28
29
|
'zoomed-end'
|
|
29
30
|
]
|
|
30
31
|
|
|
31
|
-
export
|
|
32
|
+
export interface ViewportProps extends Props {
|
|
33
|
+
screenWidth?: number;
|
|
34
|
+
screenHeight?: number;
|
|
35
|
+
worldWidth?: number;
|
|
36
|
+
worldHeight?: number;
|
|
37
|
+
sortableChildren?: boolean;
|
|
38
|
+
clamp?: boolean | {
|
|
39
|
+
left?: number;
|
|
40
|
+
right?: number;
|
|
41
|
+
top?: number;
|
|
42
|
+
bottom?: number;
|
|
43
|
+
};
|
|
44
|
+
context?: any;
|
|
45
|
+
[key: string]: any;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class CanvasViewport extends DisplayObject(Container) {
|
|
32
49
|
private tickSubscription: Subscription
|
|
33
50
|
overrideProps = ['wheel']
|
|
51
|
+
#mask: Graphics
|
|
52
|
+
public viewport: PixiViewport
|
|
34
53
|
|
|
35
54
|
constructor() {
|
|
55
|
+
super()
|
|
36
56
|
const defaultOptions = {
|
|
37
57
|
noTicker: true,
|
|
38
58
|
events: {
|
|
39
59
|
domElement: {
|
|
40
|
-
addEventListener: () => {}
|
|
60
|
+
addEventListener: () => { }
|
|
41
61
|
}
|
|
42
62
|
},
|
|
43
63
|
}
|
|
44
64
|
// @ts-ignore
|
|
45
|
-
|
|
65
|
+
this.viewport = new PixiViewport(defaultOptions)
|
|
66
|
+
super.addChild(this.viewport)
|
|
67
|
+
|
|
68
|
+
this.#mask = new Graphics()
|
|
69
|
+
super.addChild(this.#mask)
|
|
70
|
+
this.mask = this.#mask
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
addChild<U extends any[]>(...children: U): U[0] {
|
|
74
|
+
return this.viewport.addChild(...children)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
addChildAt<T extends ContainerChild | IRenderLayer>(child: T, index: number): T {
|
|
78
|
+
return this.viewport.addChildAt(child, index) as T
|
|
46
79
|
}
|
|
47
80
|
|
|
48
81
|
onInit(props) {
|
|
49
82
|
super.onInit(props)
|
|
50
83
|
for (let event of EVENTS) {
|
|
51
|
-
|
|
52
|
-
if (props[camelCaseEvent]) {
|
|
53
|
-
this.on(event, props[camelCaseEvent])
|
|
54
|
-
}
|
|
84
|
+
if (props[event]) this.viewport.on(event, props[event])
|
|
55
85
|
}
|
|
56
86
|
}
|
|
57
87
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Called when the component is mounted to the scene graph.
|
|
90
|
+
* Initializes viewport settings and subscriptions.
|
|
91
|
+
* @param {Element<CanvasViewport>} element - The element being mounted. Its `props` property (of type ViewportProps) contains component properties and context.
|
|
92
|
+
* @param {number} [index] - The index of the component among its siblings.
|
|
93
|
+
*/
|
|
94
|
+
async onMount(element: Element<any>, index?: number): Promise<void> {
|
|
95
|
+
element.props.context.viewport = this.viewport
|
|
96
|
+
await super.onMount(element, index);
|
|
97
|
+
const { props } = element;
|
|
98
|
+
const { tick, app, canvasSize } = props.context;
|
|
99
|
+
|
|
63
100
|
effect(() => {
|
|
64
|
-
|
|
65
|
-
|
|
101
|
+
if (props.screenWidth === undefined) {
|
|
102
|
+
this.viewport.screenWidth = canvasSize().width
|
|
103
|
+
}
|
|
104
|
+
if (props.screenHeight === undefined) {
|
|
105
|
+
this.viewport.screenHeight = canvasSize().height
|
|
106
|
+
}
|
|
107
|
+
this.updateMask()
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
effect(() => {
|
|
111
|
+
const _app = app()
|
|
112
|
+
if (!_app) return
|
|
113
|
+
|
|
114
|
+
const renderer = _app.renderer
|
|
115
|
+
|
|
116
|
+
renderer.events.domElement.addEventListener(
|
|
117
|
+
'wheel',
|
|
118
|
+
this.viewport.input.wheelFunction
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
this.viewport.options.events = renderer.events
|
|
66
122
|
})
|
|
67
123
|
|
|
68
|
-
renderer.events.domElement.addEventListener(
|
|
69
|
-
'wheel',
|
|
70
|
-
this.input.wheelFunction
|
|
71
|
-
);
|
|
72
|
-
this.options.events = renderer.events
|
|
73
|
-
|
|
74
124
|
this.tickSubscription = tick.observable.subscribe(({ value }) => {
|
|
75
|
-
this.update(value.
|
|
125
|
+
this.viewport.update(value.deltaTime)
|
|
76
126
|
})
|
|
77
127
|
|
|
78
|
-
|
|
79
|
-
this.updateViewportSettings(element.props)
|
|
128
|
+
this.updateViewportSettings(props)
|
|
80
129
|
}
|
|
81
130
|
|
|
82
131
|
onUpdate(props) {
|
|
@@ -86,74 +135,84 @@ export class CanvasViewport extends DisplayObject(PixiViewport) {
|
|
|
86
135
|
|
|
87
136
|
private updateViewportSettings(props) {
|
|
88
137
|
if (props.screenWidth !== undefined) {
|
|
89
|
-
this.screenWidth = props.screenWidth
|
|
138
|
+
this.viewport.screenWidth = props.screenWidth
|
|
90
139
|
}
|
|
91
140
|
if (props.screenHeight !== undefined) {
|
|
92
|
-
this.screenHeight = props.screenHeight
|
|
141
|
+
this.viewport.screenHeight = props.screenHeight
|
|
93
142
|
}
|
|
143
|
+
this.updateMask()
|
|
94
144
|
if (props.worldWidth !== undefined) {
|
|
95
|
-
this.worldWidth = props.worldWidth
|
|
145
|
+
this.viewport.worldWidth = props.worldWidth
|
|
96
146
|
}
|
|
97
147
|
if (props.worldHeight !== undefined) {
|
|
98
|
-
this.worldHeight = props.worldHeight
|
|
148
|
+
this.viewport.worldHeight = props.worldHeight
|
|
149
|
+
}
|
|
150
|
+
if (props.sortableChildren !== undefined) {
|
|
151
|
+
this.viewport.sortableChildren = props.sortableChildren
|
|
152
|
+
}
|
|
153
|
+
if (props.drag) {
|
|
154
|
+
this.viewport.drag(props.drag)
|
|
99
155
|
}
|
|
100
|
-
// if (props.drag) {
|
|
101
|
-
// if (props.drag === true) {
|
|
102
|
-
|
|
103
|
-
// } else {
|
|
104
|
-
// this.drag(props.drag)
|
|
105
|
-
// }
|
|
106
|
-
// }
|
|
107
156
|
if (props.clamp) {
|
|
108
|
-
this.clamp(props.clamp)
|
|
157
|
+
this.viewport.clamp(props.clamp.value ?? props.clamp)
|
|
109
158
|
}
|
|
110
159
|
if (props.wheel) {
|
|
111
160
|
if (props.wheel === true) {
|
|
112
|
-
this.wheel()
|
|
161
|
+
this.viewport.wheel()
|
|
113
162
|
} else {
|
|
114
|
-
this.wheel(props.wheel)
|
|
163
|
+
this.viewport.wheel(props.wheel)
|
|
115
164
|
}
|
|
116
165
|
}
|
|
117
166
|
if (props.decelerate) {
|
|
118
167
|
if (props.decelerate === true) {
|
|
119
|
-
this.decelerate()
|
|
168
|
+
this.viewport.decelerate()
|
|
120
169
|
} else {
|
|
121
|
-
this.decelerate(props.decelerate)
|
|
170
|
+
this.viewport.decelerate(props.decelerate)
|
|
122
171
|
}
|
|
123
172
|
}
|
|
124
173
|
if (props.pinch) {
|
|
125
174
|
if (props.pinch === true) {
|
|
126
|
-
this.pinch()
|
|
175
|
+
this.viewport.pinch()
|
|
127
176
|
} else {
|
|
128
|
-
this.pinch(props.pinch)
|
|
177
|
+
this.viewport.pinch(props.pinch)
|
|
129
178
|
}
|
|
130
179
|
}
|
|
131
180
|
}
|
|
132
181
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
this
|
|
182
|
+
private updateMask() {
|
|
183
|
+
if (!this.#mask) return
|
|
184
|
+
this.#mask
|
|
185
|
+
.clear()
|
|
186
|
+
.rect(0, 0, this.viewport.screenWidth, this.viewport.screenHeight)
|
|
187
|
+
.fill(0xffffff)
|
|
136
188
|
}
|
|
137
|
-
}
|
|
138
189
|
|
|
139
|
-
|
|
190
|
+
/**
|
|
191
|
+
* Called when the component is about to be destroyed.
|
|
192
|
+
* Unsubscribes from the tick observable.
|
|
193
|
+
* @param {Element<any>} parent - The parent element.
|
|
194
|
+
* @param {() => void} [afterDestroy] - An optional callback function to be executed after the component's own destruction logic.
|
|
195
|
+
*/
|
|
196
|
+
async onDestroy(parent: Element<any>, afterDestroy?: () => void): Promise<void> {
|
|
197
|
+
const _afterDestroy = async () => {
|
|
198
|
+
this.tickSubscription.unsubscribe()
|
|
199
|
+
afterDestroy()
|
|
200
|
+
}
|
|
201
|
+
await super.onDestroy(parent, _afterDestroy);
|
|
202
|
+
}
|
|
140
203
|
|
|
141
|
-
|
|
204
|
+
// Proxy methods for viewport plugins
|
|
205
|
+
follow(...args: any[]) {
|
|
206
|
+
return (this.viewport.follow as any)(...args)
|
|
207
|
+
}
|
|
142
208
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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;
|
|
209
|
+
get plugins() {
|
|
210
|
+
return this.viewport.plugins
|
|
211
|
+
}
|
|
155
212
|
}
|
|
156
213
|
|
|
214
|
+
registerComponent('Viewport', CanvasViewport)
|
|
215
|
+
|
|
157
216
|
export function Viewport(props: ViewportProps) {
|
|
158
217
|
return createComponent('Viewport', props);
|
|
159
|
-
}
|
|
218
|
+
}
|
package/src/components/index.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
export { Canvas } from './Canvas'
|
|
2
|
-
export { Container } from './Container'
|
|
3
|
-
export { Graphics, Rect, Circle, Ellipse, Triangle, Svg
|
|
2
|
+
export { Container, type ContainerProps } from './Container'
|
|
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
|
-
export { TiledMap } from './Tilemap'
|
|
9
10
|
export { TilingSprite } from './TilingSprite'
|
|
10
11
|
export { Viewport } from './Viewport'
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
12
|
+
export { NineSliceSprite } from './NineSliceSprite'
|
|
13
|
+
export { type ComponentInstance } from './DisplayObject'
|
|
14
|
+
export { DOMContainer } from './DOMContainer'
|
|
15
|
+
export { DOMElement } from './DOMElement'
|
|
16
|
+
export { DOMSprite } from './DOMSprite'
|
|
17
|
+
export { Button, ButtonState, type ButtonProps, type ButtonStyle } from './Button'
|
|
18
|
+
export { Joystick, type JoystickSettings } from './Joystick'
|
|
19
|
+
export { FocusContainer, Navigation, type FocusContainerProps } from './FocusContainer'
|
|
@@ -1,29 +1,65 @@
|
|
|
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";
|
|
7
|
+
import { FogVisibilityProps } from "../../directives/FogVisibility";
|
|
8
|
+
import type { ClipProps, OcclusionProps, OutlineProps } from "../../directives/SpriteEffects";
|
|
3
9
|
|
|
4
10
|
export type FlexDirection = 'row' | 'column' | 'row-reverse' | 'column-reverse';
|
|
5
11
|
export type JustifyContent = 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around';
|
|
6
12
|
export type AlignContent = 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around';
|
|
7
13
|
export type Size = number | `${number}%`
|
|
8
14
|
export type EdgeSize = SignalOrPrimitive<Size | [Size, Size] | [Size, Size, Size, Size]>
|
|
15
|
+
export type ObjectFit = 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
|
16
|
+
export type ObjectPosition = string;
|
|
17
|
+
export type TransformOrigin = string;
|
|
18
|
+
export type PositionType = 'relative' | 'absolute' | 'static';
|
|
19
|
+
export type Display = 'flex' | 'none';
|
|
20
|
+
|
|
21
|
+
export type ObservablePointSignal = [number, number] | SignalOrPrimitive<[number, number]> | { x: number, y: number } | SignalOrPrimitive<{ x: number, y: number }>;
|
|
9
22
|
|
|
10
23
|
export interface DisplayObjectProps {
|
|
24
|
+
attach?: any;
|
|
11
25
|
ref?: string;
|
|
12
26
|
x?: SignalOrPrimitive<number>;
|
|
13
27
|
y?: SignalOrPrimitive<number>;
|
|
14
28
|
width?: SignalOrPrimitive<Size>;
|
|
15
29
|
height?: SignalOrPrimitive<Size>;
|
|
30
|
+
minWidth?: SignalOrPrimitive<Size>;
|
|
31
|
+
minHeight?: SignalOrPrimitive<Size>;
|
|
32
|
+
maxWidth?: SignalOrPrimitive<Size>;
|
|
33
|
+
maxHeight?: SignalOrPrimitive<Size>;
|
|
34
|
+
display?: Display;
|
|
35
|
+
aspectRatio?: SignalOrPrimitive<number>;
|
|
36
|
+
flexGrow?: SignalOrPrimitive<number>;
|
|
37
|
+
flexShrink?: SignalOrPrimitive<number>;
|
|
38
|
+
flexBasis?: SignalOrPrimitive<Size>;
|
|
39
|
+
rowGap?: SignalOrPrimitive<number>;
|
|
40
|
+
columnGap?: SignalOrPrimitive<number>;
|
|
41
|
+
positionType?: PositionType;
|
|
42
|
+
top?: SignalOrPrimitive<Size>;
|
|
43
|
+
right?: SignalOrPrimitive<Size>;
|
|
44
|
+
bottom?: SignalOrPrimitive<Size>;
|
|
45
|
+
left?: SignalOrPrimitive<Size>;
|
|
46
|
+
objectFit?: ObjectFit;
|
|
47
|
+
objectPosition?: ObjectPosition;
|
|
48
|
+
transformOrigin?: TransformOrigin;
|
|
16
49
|
children?: any[];
|
|
17
50
|
flexDirection?: FlexDirection;
|
|
18
51
|
justifyContent?: JustifyContent;
|
|
52
|
+
alignItems?: AlignContent;
|
|
53
|
+
alignContent?: AlignContent;
|
|
54
|
+
alignSelf?: AlignContent;
|
|
19
55
|
alpha?: SignalOrPrimitive<number>;
|
|
20
56
|
margin?: EdgeSize;
|
|
21
57
|
padding?: EdgeSize;
|
|
22
58
|
border?: EdgeSize;
|
|
23
59
|
absolute?: SignalOrPrimitive<boolean>;
|
|
24
|
-
scale?:
|
|
25
|
-
anchor?:
|
|
26
|
-
skew?:
|
|
60
|
+
scale?: ObservablePointSignal | number;
|
|
61
|
+
anchor?: ObservablePointSignal;
|
|
62
|
+
skew?: ObservablePointSignal;
|
|
27
63
|
tint?: SignalOrPrimitive<number>;
|
|
28
64
|
rotation?: SignalOrPrimitive<number>;
|
|
29
65
|
angle?: SignalOrPrimitive<number>;
|
|
@@ -31,10 +67,32 @@ export interface DisplayObjectProps {
|
|
|
31
67
|
roundPixels?: SignalOrPrimitive<boolean>;
|
|
32
68
|
cursor?: SignalOrPrimitive<string>;
|
|
33
69
|
visible?: SignalOrPrimitive<boolean>;
|
|
34
|
-
pivot?:
|
|
70
|
+
pivot?: ObservablePointSignal;
|
|
35
71
|
filters?: any[];
|
|
36
72
|
blendMode?: SignalOrPrimitive<PIXI.BLEND_MODES>;
|
|
73
|
+
blur?: SignalOrPrimitive<number>;
|
|
74
|
+
/**
|
|
75
|
+
* Optional metadata used by presets (for example `SpriteShadows`)
|
|
76
|
+
* to mark this display object as a shadow caster.
|
|
77
|
+
*/
|
|
78
|
+
shadowCaster?: any;
|
|
79
|
+
/**
|
|
80
|
+
* Optional metadata used by presets (for example `Footprints`)
|
|
81
|
+
* to mark this display object as a footprint caster.
|
|
82
|
+
*/
|
|
83
|
+
footprintCaster?: any;
|
|
84
|
+
|
|
85
|
+
// Directives
|
|
86
|
+
drag?: DragProps;
|
|
87
|
+
viewportFollow?: ViewportFollowProps;
|
|
88
|
+
shake?: ShakeProps;
|
|
89
|
+
flash?: FlashProps;
|
|
90
|
+
fogVisibility?: FogVisibilityProps;
|
|
91
|
+
outline?: OutlineProps;
|
|
92
|
+
clip?: ClipProps;
|
|
93
|
+
occlusion?: OcclusionProps;
|
|
37
94
|
|
|
95
|
+
// Events
|
|
38
96
|
click?: PIXI.FederatedEventHandler;
|
|
39
97
|
mousedown?: PIXI.FederatedEventHandler;
|
|
40
98
|
mouseenter?: PIXI.FederatedEventHandler;
|
|
@@ -65,4 +123,5 @@ export interface DisplayObjectProps {
|
|
|
65
123
|
touchmove?: PIXI.FederatedEventHandler;
|
|
66
124
|
touchstart?: PIXI.FederatedEventHandler;
|
|
67
125
|
wheel?: PIXI.FederatedEventHandler<PIXI.FederatedWheelEvent>;
|
|
68
|
-
|
|
126
|
+
tabindex?: SignalOrPrimitive<number>;
|
|
127
|
+
}
|
|
@@ -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
|
}
|