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,163 +0,0 @@
|
|
|
1
|
-
import { CompositeTilemap, POINT_STRUCT_SIZE, Tilemap, settings } from '@pixi/tilemap';
|
|
2
|
-
import { Layer, Tile as TileClass } from '@rpgjs/tiled';
|
|
3
|
-
import { createComponent, registerComponent } from '../../engine/reactive';
|
|
4
|
-
import { DisplayObject } from '../DisplayObject';
|
|
5
|
-
import { Tile } from './Tile';
|
|
6
|
-
import { TileSet } from './TileSet';
|
|
7
|
-
|
|
8
|
-
settings.use32bitIndex = true
|
|
9
|
-
|
|
10
|
-
export class CanvasTileLayer extends DisplayObject(CompositeTilemap) {
|
|
11
|
-
private _tiles: any = {}
|
|
12
|
-
tiles: (TileClass | null)[]
|
|
13
|
-
private _layer: Layer
|
|
14
|
-
|
|
15
|
-
static findTileSet(gid: number, tileSets: TileSet[]) {
|
|
16
|
-
let tileset: TileSet | undefined
|
|
17
|
-
for (let i = tileSets.length - 1; i >= 0; i--) {
|
|
18
|
-
tileset = tileSets[i]
|
|
19
|
-
if (tileset.firstgid && tileset.firstgid <= gid) {
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return tileset;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** @internal */
|
|
27
|
-
createTile(x: number, y: number, options: any = {}): Tile | undefined {
|
|
28
|
-
const { real, filter } = options
|
|
29
|
-
const { tilewidth, tileheight, width } = this._layer
|
|
30
|
-
if (real) {
|
|
31
|
-
x = Math.floor(x / tilewidth)
|
|
32
|
-
y = Math.floor(y / tileheight)
|
|
33
|
-
}
|
|
34
|
-
const i = x + y * width;
|
|
35
|
-
const tiledTile = this._layer.getTileByIndex(i)
|
|
36
|
-
|
|
37
|
-
if (!tiledTile || (tiledTile && tiledTile.gid == 0)) return
|
|
38
|
-
|
|
39
|
-
const tileset = CanvasTileLayer.findTileSet(
|
|
40
|
-
tiledTile.gid,
|
|
41
|
-
this.tileSets
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
if (!tileset) return
|
|
45
|
-
|
|
46
|
-
const tile = new Tile(
|
|
47
|
-
tiledTile,
|
|
48
|
-
tileset
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
tile.x = x * tilewidth;
|
|
52
|
-
tile.y =
|
|
53
|
-
y * tileheight +
|
|
54
|
-
(tileheight -
|
|
55
|
-
tile.texture.height);
|
|
56
|
-
|
|
57
|
-
tile._x = x;
|
|
58
|
-
tile._y = y;
|
|
59
|
-
|
|
60
|
-
if (tileset.tileoffset) {
|
|
61
|
-
tile.x += tileset.tileoffset.x ?? 0;
|
|
62
|
-
tile.y += tileset.tileoffset.y ?? 0;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (filter) {
|
|
66
|
-
const ret = filter(tile)
|
|
67
|
-
if (!ret) return
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return tile
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** @internal */
|
|
74
|
-
changeTile(x: number, y: number) {
|
|
75
|
-
const { tilewidth, tileheight } = this._layer
|
|
76
|
-
x = Math.floor(x / tilewidth)
|
|
77
|
-
y = Math.floor(y / tileheight)
|
|
78
|
-
const oldTile: Tile = this._tiles[x + ';' + y]
|
|
79
|
-
const newTile = this.createTile(x, y)
|
|
80
|
-
if (!oldTile && newTile) {
|
|
81
|
-
this._addFrame(newTile, x, y)
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
if (newTile) {
|
|
85
|
-
const bufComposite: CompositeTilemap = new CompositeTilemap()
|
|
86
|
-
const frame = bufComposite.tile(newTile.texture, newTile.x, newTile.y)
|
|
87
|
-
newTile.setAnimation(frame)
|
|
88
|
-
this._tiles[x + ';' + y] = newTile
|
|
89
|
-
// @ts-ignore
|
|
90
|
-
const pointsBufComposite = (bufComposite.children[0] as Tilemap).pointsBuf
|
|
91
|
-
// Change Texture (=0, 1 and 7, rotate (=4), animX (=5), animY (=6))
|
|
92
|
-
;[0, 1, 4, 6, 7, 8].forEach((i) => {
|
|
93
|
-
if (this.pointsBuf) this.pointsBuf[oldTile.pointsBufIndex + i] = pointsBufComposite[i]
|
|
94
|
-
})
|
|
95
|
-
// @ts-ignore
|
|
96
|
-
this.children[0].modificationMarker = 0
|
|
97
|
-
this._addFrame(newTile, x, y)
|
|
98
|
-
this['modificationMarker'] = 0
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
delete this._tiles[x + ';' + y]
|
|
102
|
-
if (this.pointsBuf) this.pointsBuf.splice(oldTile.pointsBufIndex, POINT_STRUCT_SIZE)
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/** @internal */
|
|
108
|
-
get pointsBuf(): number[] | null {
|
|
109
|
-
const child = this.children[0] as Tilemap
|
|
110
|
-
if (!child) return null
|
|
111
|
-
return child['pointsBuf']
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
private _addFrame(tile: Tile, x: number, y: number) {
|
|
115
|
-
const frame = this.tile(tile.texture, tile.x, tile.y, {
|
|
116
|
-
rotate: tile.texture.rotate
|
|
117
|
-
})
|
|
118
|
-
const pb = this.pointsBuf
|
|
119
|
-
if (!pb) return null
|
|
120
|
-
tile.pointsBufIndex = pb.length - POINT_STRUCT_SIZE
|
|
121
|
-
tile.setAnimation(frame)
|
|
122
|
-
this._tiles[x + ';' + y] = tile
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
onMount(args) {
|
|
126
|
-
const { props } = args
|
|
127
|
-
this.tileSets = props.tilesets
|
|
128
|
-
this._layer = new Layer({
|
|
129
|
-
...props
|
|
130
|
-
}, this.tileSets)
|
|
131
|
-
super.onMount(args)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
onUpdate(props) {
|
|
135
|
-
super.onUpdate(props)
|
|
136
|
-
if (!this.isMounted) return
|
|
137
|
-
if (props.tileheight) this._layer.tileheight = props.tileheight
|
|
138
|
-
if (props.tilewidth) this._layer.tilewidth = props.tilewidth
|
|
139
|
-
if (props.width) this._layer.width = props.width
|
|
140
|
-
if (props.height) this._layer.height = props.height
|
|
141
|
-
if (props.parallaxX) this._layer.parallaxX = props.parallaxx
|
|
142
|
-
if (props.parallaxY) this._layer.parallaxY = props.parallaxy
|
|
143
|
-
|
|
144
|
-
this.removeChildren()
|
|
145
|
-
|
|
146
|
-
for (let y = 0; y < this._layer.height; y++) {
|
|
147
|
-
for (let x = 0; x < this._layer.width; x++) {
|
|
148
|
-
const tile = this.createTile(x, y)
|
|
149
|
-
if (tile) {
|
|
150
|
-
this._addFrame(tile, x, y)
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export interface CanvasTileLayer extends CompositeTilemap { }
|
|
158
|
-
|
|
159
|
-
registerComponent('CompositeTileLayer', CanvasTileLayer)
|
|
160
|
-
|
|
161
|
-
export function CompositeTileLayer(props) {
|
|
162
|
-
return createComponent('CompositeTileLayer', props)
|
|
163
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { TiledTileset, Tileset as TiledTilesetClass } from "@rpgjs/tiled";
|
|
2
|
-
import { Assets, Rectangle, Texture } from "pixi.js";
|
|
3
|
-
|
|
4
|
-
export class TileSet extends TiledTilesetClass {
|
|
5
|
-
public textures: Texture[] = [];
|
|
6
|
-
private tileGroups = {};
|
|
7
|
-
|
|
8
|
-
constructor(tileSet: TiledTileset) {
|
|
9
|
-
super(tileSet);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
loadGroup() {
|
|
13
|
-
// for (let tile of this.tileset.tiles) {
|
|
14
|
-
// }
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** @internal */
|
|
18
|
-
async load(image: string) {
|
|
19
|
-
const texture = await Assets.load(image);
|
|
20
|
-
for (
|
|
21
|
-
let y = this.margin;
|
|
22
|
-
y < this.image.height;
|
|
23
|
-
y += this.tileheight + this.spacing
|
|
24
|
-
) {
|
|
25
|
-
for (
|
|
26
|
-
let x = this.margin;
|
|
27
|
-
x < this.image.width;
|
|
28
|
-
x += this.tilewidth + this.spacing
|
|
29
|
-
) {
|
|
30
|
-
this.textures.push(
|
|
31
|
-
new Texture({
|
|
32
|
-
source: texture.source,
|
|
33
|
-
frame: new Rectangle(+x, +y, +this.tilewidth, +this.tileheight),
|
|
34
|
-
})
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
this.loadGroup();
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { TiledLayer, TiledLayerType, TiledMap, TiledParserFile, TiledTileset } from "@rpgjs/tiled"
|
|
2
|
-
import { effect, signal } from '@signe/reactive'
|
|
3
|
-
import { loop } from "../../engine/reactive"
|
|
4
|
-
import { h } from "../../engine/signal"
|
|
5
|
-
import { useProps } from "../../hooks/useProps"
|
|
6
|
-
import { Container } from "../Container"
|
|
7
|
-
import { TilingSprite } from "../TilingSprite"
|
|
8
|
-
import { CompositeTileLayer } from "./TileLayer"
|
|
9
|
-
import { TileSet } from "./TileSet"
|
|
10
|
-
|
|
11
|
-
export function TiledMap(props) {
|
|
12
|
-
const { map } = useProps(props)
|
|
13
|
-
const layers = signal<TiledLayer[]>([])
|
|
14
|
-
const objectLayer = props.objectLayer
|
|
15
|
-
let tilesets: TiledTileset[] = []
|
|
16
|
-
let mapData: TiledMap = {} as TiledMap
|
|
17
|
-
|
|
18
|
-
const parseTmx = async (file: string, relativePath: string = '') => {
|
|
19
|
-
if (typeof file !== 'string') {
|
|
20
|
-
return file
|
|
21
|
-
}
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
const parser = new TiledParserFile(
|
|
24
|
-
file,
|
|
25
|
-
{
|
|
26
|
-
basePath: '',
|
|
27
|
-
staticDir: '',
|
|
28
|
-
relativePath
|
|
29
|
-
}
|
|
30
|
-
)
|
|
31
|
-
const data = await parser.parseFilePromise({
|
|
32
|
-
getOnlyBasename: false
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
return data
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
effect(async () => {
|
|
39
|
-
mapData = await parseTmx(map())
|
|
40
|
-
for (let tileSet of mapData.tilesets) {
|
|
41
|
-
tilesets.push(await new TileSet(tileSet).load(tileSet.image.source))
|
|
42
|
-
}
|
|
43
|
-
layers.set(mapData.layers)
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
const createLayer = (layers, props = {}) => {
|
|
47
|
-
return h(Container, props, loop(layers, (layer) => {
|
|
48
|
-
switch (layer.type) {
|
|
49
|
-
case TiledLayerType.Tile:
|
|
50
|
-
return h(CompositeTileLayer, {
|
|
51
|
-
tilewidth: mapData.tilewidth,
|
|
52
|
-
tileheight: mapData.tileheight,
|
|
53
|
-
// @ts-ignore
|
|
54
|
-
width: mapData.width,
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
height: mapData.height,
|
|
57
|
-
...layer,
|
|
58
|
-
tilesets
|
|
59
|
-
})
|
|
60
|
-
case TiledLayerType.Image:
|
|
61
|
-
const { width, height, source } = layer.image
|
|
62
|
-
return h(TilingSprite, {
|
|
63
|
-
image: source,
|
|
64
|
-
...layer,
|
|
65
|
-
width: layer.repeatx ? layer.width * layer.tilewidth : width,
|
|
66
|
-
height: layer.repeaty ? layer.height * layer.tileheight : height
|
|
67
|
-
})
|
|
68
|
-
case TiledLayerType.Group:
|
|
69
|
-
return createLayer(signal(layer.layers), layer)
|
|
70
|
-
case TiledLayerType.ObjectGroup:
|
|
71
|
-
const child = objectLayer?.(layer)
|
|
72
|
-
return h(Container, layer, child)
|
|
73
|
-
default:
|
|
74
|
-
return h(Container)
|
|
75
|
-
}
|
|
76
|
-
}))
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return createLayer(layers)
|
|
80
|
-
}
|
package/src/presets/Bar.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Graphics } from "../components";
|
|
2
|
-
import { h } from "../engine/signal";
|
|
3
|
-
import * as PIXI from "pixi.js";
|
|
4
|
-
import { useProps } from "../hooks/useProps";
|
|
5
|
-
|
|
6
|
-
interface BarProps {
|
|
7
|
-
backgroundColor?: string;
|
|
8
|
-
foregroundColor?: string;
|
|
9
|
-
value: number;
|
|
10
|
-
maxValue: number;
|
|
11
|
-
width: number;
|
|
12
|
-
height: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function componentToHex(c) {
|
|
16
|
-
var hex = c.toString(16);
|
|
17
|
-
return hex.length == 1 ? "0" + hex : hex;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function rgbToHex(r, g, b) {
|
|
21
|
-
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function Bar(opts: BarProps) {
|
|
25
|
-
const {
|
|
26
|
-
width,
|
|
27
|
-
height,
|
|
28
|
-
value,
|
|
29
|
-
maxValue,
|
|
30
|
-
backgroundColor,
|
|
31
|
-
foregroundColor,
|
|
32
|
-
border,
|
|
33
|
-
innerMargin,
|
|
34
|
-
borderRadius,
|
|
35
|
-
} = useProps(opts, {
|
|
36
|
-
backgroundColor: "#000000",
|
|
37
|
-
foregroundColor: "#FFFFFF",
|
|
38
|
-
innerMargin: 0,
|
|
39
|
-
borderRadius: 0,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
return h(
|
|
43
|
-
Graphics,
|
|
44
|
-
{
|
|
45
|
-
...opts,
|
|
46
|
-
width,
|
|
47
|
-
height,
|
|
48
|
-
draw(g: PIXI.Graphics) {
|
|
49
|
-
if (borderRadius()) {
|
|
50
|
-
g.roundRect(0, 0, width(), height(), borderRadius());
|
|
51
|
-
} else {
|
|
52
|
-
g.rect(0, 0, width(), height());
|
|
53
|
-
}
|
|
54
|
-
if (border) {
|
|
55
|
-
g.stroke(border);
|
|
56
|
-
}
|
|
57
|
-
g.fill(backgroundColor());
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
h(Graphics, {
|
|
61
|
-
width,
|
|
62
|
-
height,
|
|
63
|
-
draw(g: PIXI.Graphics) {
|
|
64
|
-
const margin = innerMargin();
|
|
65
|
-
const _borderRadius = borderRadius();
|
|
66
|
-
const w = Math.max(
|
|
67
|
-
0,
|
|
68
|
-
Math.min(
|
|
69
|
-
width() - 2 * margin,
|
|
70
|
-
(value() / maxValue()) * (width() - 2 * margin)
|
|
71
|
-
)
|
|
72
|
-
);
|
|
73
|
-
const h = height() - 2 * margin;
|
|
74
|
-
if (borderRadius) {
|
|
75
|
-
g.roundRect(margin, margin, w, h, _borderRadius);
|
|
76
|
-
} else {
|
|
77
|
-
g.rect(margin, margin, w, h);
|
|
78
|
-
}
|
|
79
|
-
const color = foregroundColor();
|
|
80
|
-
if (color.startsWith("rgba")) {
|
|
81
|
-
const [r, g, b, a] = color.match(/\d+(\.\d+)?/g).map(Number);
|
|
82
|
-
g.fill({ color: rgbToHex(r, g, b), alpha: a });
|
|
83
|
-
} else {
|
|
84
|
-
g.fill(color);
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
})
|
|
88
|
-
);
|
|
89
|
-
}
|
package/src/presets/Button.ts
DELETED
|
File without changes
|
package/src/presets/Joystick.ts
DELETED
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Joystick
|
|
3
|
-
*
|
|
4
|
-
* Inspired by https://github.com/endel/pixi-virtual-joystick
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as PIXI from "pixi.js";
|
|
8
|
-
import { Container, Graphics, Sprite } from "../components";
|
|
9
|
-
import { h } from "../engine/signal";
|
|
10
|
-
import { signal } from "@signe/reactive";
|
|
11
|
-
|
|
12
|
-
export interface JoystickChangeEvent {
|
|
13
|
-
angle: number;
|
|
14
|
-
direction: Direction;
|
|
15
|
-
power: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export enum Direction {
|
|
19
|
-
LEFT = "left",
|
|
20
|
-
TOP = "top",
|
|
21
|
-
BOTTOM = "bottom",
|
|
22
|
-
RIGHT = "right",
|
|
23
|
-
TOP_LEFT = "top_left",
|
|
24
|
-
TOP_RIGHT = "top_right",
|
|
25
|
-
BOTTOM_LEFT = "bottom_left",
|
|
26
|
-
BOTTOM_RIGHT = "bottom_right",
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface JoystickSettings {
|
|
30
|
-
outer?: string;
|
|
31
|
-
inner?: string;
|
|
32
|
-
outerScale?: { x: number; y: number };
|
|
33
|
-
innerScale?: { x: number; y: number };
|
|
34
|
-
onChange?: (data: JoystickChangeEvent) => void;
|
|
35
|
-
onStart?: () => void;
|
|
36
|
-
onEnd?: () => void;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function Joystick(opts: JoystickSettings = {}) {
|
|
40
|
-
const settings = Object.assign(
|
|
41
|
-
{
|
|
42
|
-
outerScale: { x: 1, y: 1 },
|
|
43
|
-
innerScale: { x: 1, y: 1 },
|
|
44
|
-
},
|
|
45
|
-
opts
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
let outerRadius = 70;
|
|
49
|
-
let innerRadius = 10;
|
|
50
|
-
const innerAlphaStandby = 0.5;
|
|
51
|
-
|
|
52
|
-
let dragging = false;
|
|
53
|
-
let startPosition: PIXI.PointData | null = null;
|
|
54
|
-
let power = 0;
|
|
55
|
-
|
|
56
|
-
const innerPositionX = signal(0);
|
|
57
|
-
const innerPositionY = signal(0);
|
|
58
|
-
const innerAlpha = signal(innerAlphaStandby);
|
|
59
|
-
|
|
60
|
-
function getPower(centerPoint: PIXI.Point) {
|
|
61
|
-
const a = centerPoint.x - 0;
|
|
62
|
-
const b = centerPoint.y - 0;
|
|
63
|
-
return Math.min(1, Math.sqrt(a * a + b * b) / outerRadius);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function getDirection(center: PIXI.Point) {
|
|
67
|
-
let rad = Math.atan2(center.y, center.x); // [-PI, PI]
|
|
68
|
-
if ((rad >= -Math.PI / 8 && rad < 0) || (rad >= 0 && rad < Math.PI / 8)) {
|
|
69
|
-
return Direction.RIGHT;
|
|
70
|
-
} else if (rad >= Math.PI / 8 && rad < (3 * Math.PI) / 8) {
|
|
71
|
-
return Direction.BOTTOM_RIGHT;
|
|
72
|
-
} else if (rad >= (3 * Math.PI) / 8 && rad < (5 * Math.PI) / 8) {
|
|
73
|
-
return Direction.BOTTOM;
|
|
74
|
-
} else if (rad >= (5 * Math.PI) / 8 && rad < (7 * Math.PI) / 8) {
|
|
75
|
-
return Direction.BOTTOM_LEFT;
|
|
76
|
-
} else if (
|
|
77
|
-
(rad >= (7 * Math.PI) / 8 && rad < Math.PI) ||
|
|
78
|
-
(rad >= -Math.PI && rad < (-7 * Math.PI) / 8)
|
|
79
|
-
) {
|
|
80
|
-
return Direction.LEFT;
|
|
81
|
-
} else if (rad >= (-7 * Math.PI) / 8 && rad < (-5 * Math.PI) / 8) {
|
|
82
|
-
return Direction.TOP_LEFT;
|
|
83
|
-
} else if (rad >= (-5 * Math.PI) / 8 && rad < (-3 * Math.PI) / 8) {
|
|
84
|
-
return Direction.TOP;
|
|
85
|
-
} else {
|
|
86
|
-
return Direction.TOP_RIGHT;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function handleDragStart(event: PIXI.FederatedPointerEvent) {
|
|
91
|
-
startPosition = event.getLocalPosition(this);
|
|
92
|
-
dragging = true;
|
|
93
|
-
innerAlpha.set(1);
|
|
94
|
-
settings.onStart?.();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function handleDragEnd() {
|
|
98
|
-
if (!dragging) return;
|
|
99
|
-
innerPositionX.set(0);
|
|
100
|
-
innerPositionY.set(0);
|
|
101
|
-
dragging = false;
|
|
102
|
-
innerAlpha.set(innerAlphaStandby);
|
|
103
|
-
settings.onEnd?.();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function handleDragMove(event: PIXI.FederatedPointerEvent) {
|
|
107
|
-
if (dragging == false) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
let newPosition = event.getLocalPosition(this);
|
|
112
|
-
|
|
113
|
-
let sideX = newPosition.x - (startPosition?.x ?? 0);
|
|
114
|
-
let sideY = newPosition.y - (startPosition?.y ?? 0);
|
|
115
|
-
|
|
116
|
-
let centerPoint = new PIXI.Point(0, 0);
|
|
117
|
-
let angle = 0;
|
|
118
|
-
|
|
119
|
-
if (sideX == 0 && sideY == 0) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
let calRadius = 0;
|
|
124
|
-
|
|
125
|
-
if (sideX * sideX + sideY * sideY >= outerRadius * outerRadius) {
|
|
126
|
-
calRadius = outerRadius;
|
|
127
|
-
} else {
|
|
128
|
-
calRadius = outerRadius - innerRadius;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* x: -1 <-> 1
|
|
133
|
-
* y: -1 <-> 1
|
|
134
|
-
* Y
|
|
135
|
-
* ^
|
|
136
|
-
* |
|
|
137
|
-
* 180 | 90
|
|
138
|
-
* ------------> X
|
|
139
|
-
* 270 | 360
|
|
140
|
-
* |
|
|
141
|
-
* |
|
|
142
|
-
*/
|
|
143
|
-
|
|
144
|
-
let direction = Direction.LEFT;
|
|
145
|
-
|
|
146
|
-
if (sideX == 0) {
|
|
147
|
-
if (sideY > 0) {
|
|
148
|
-
centerPoint.set(0, sideY > outerRadius ? outerRadius : sideY);
|
|
149
|
-
angle = 270;
|
|
150
|
-
direction = Direction.BOTTOM;
|
|
151
|
-
} else {
|
|
152
|
-
centerPoint.set(
|
|
153
|
-
0,
|
|
154
|
-
-(Math.abs(sideY) > outerRadius ? outerRadius : Math.abs(sideY))
|
|
155
|
-
);
|
|
156
|
-
angle = 90;
|
|
157
|
-
direction = Direction.TOP;
|
|
158
|
-
}
|
|
159
|
-
innerPositionX.set(centerPoint.x);
|
|
160
|
-
innerPositionY.set(centerPoint.y);
|
|
161
|
-
power = getPower(centerPoint);
|
|
162
|
-
settings.onChange?.({ angle, direction, power });
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (sideY == 0) {
|
|
167
|
-
if (sideX > 0) {
|
|
168
|
-
centerPoint.set(
|
|
169
|
-
Math.abs(sideX) > outerRadius ? outerRadius : Math.abs(sideX),
|
|
170
|
-
0
|
|
171
|
-
);
|
|
172
|
-
angle = 0;
|
|
173
|
-
direction = Direction.LEFT;
|
|
174
|
-
} else {
|
|
175
|
-
centerPoint.set(
|
|
176
|
-
-(Math.abs(sideX) > outerRadius ? outerRadius : Math.abs(sideX)),
|
|
177
|
-
0
|
|
178
|
-
);
|
|
179
|
-
angle = 180;
|
|
180
|
-
direction = Direction.RIGHT;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
innerPositionX.set(centerPoint.x);
|
|
184
|
-
innerPositionY.set(centerPoint.y);
|
|
185
|
-
power = getPower(centerPoint);
|
|
186
|
-
settings.onChange?.({ angle, direction, power });
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
let tanVal = Math.abs(sideY / sideX);
|
|
191
|
-
let radian = Math.atan(tanVal);
|
|
192
|
-
angle = (radian * 180) / Math.PI;
|
|
193
|
-
|
|
194
|
-
let centerX = 0;
|
|
195
|
-
let centerY = 0;
|
|
196
|
-
|
|
197
|
-
if (sideX * sideX + sideY * sideY >= outerRadius * outerRadius) {
|
|
198
|
-
centerX = outerRadius * Math.cos(radian);
|
|
199
|
-
centerY = outerRadius * Math.sin(radian);
|
|
200
|
-
} else {
|
|
201
|
-
centerX = Math.abs(sideX) > outerRadius ? outerRadius : Math.abs(sideX);
|
|
202
|
-
centerY = Math.abs(sideY) > outerRadius ? outerRadius : Math.abs(sideY);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (sideY < 0) {
|
|
206
|
-
centerY = -Math.abs(centerY);
|
|
207
|
-
}
|
|
208
|
-
if (sideX < 0) {
|
|
209
|
-
centerX = -Math.abs(centerX);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (sideX > 0 && sideY < 0) {
|
|
213
|
-
// < 90
|
|
214
|
-
} else if (sideX < 0 && sideY < 0) {
|
|
215
|
-
// 90 ~ 180
|
|
216
|
-
angle = 180 - angle;
|
|
217
|
-
} else if (sideX < 0 && sideY > 0) {
|
|
218
|
-
// 180 ~ 270
|
|
219
|
-
angle = angle + 180;
|
|
220
|
-
} else if (sideX > 0 && sideY > 0) {
|
|
221
|
-
// 270 ~ 369
|
|
222
|
-
angle = 360 - angle;
|
|
223
|
-
}
|
|
224
|
-
centerPoint.set(centerX, centerY);
|
|
225
|
-
power = getPower(centerPoint);
|
|
226
|
-
|
|
227
|
-
direction = getDirection(centerPoint);
|
|
228
|
-
innerPositionX.set(centerPoint.x);
|
|
229
|
-
innerPositionY.set(centerPoint.y);
|
|
230
|
-
|
|
231
|
-
settings.onChange?.({ angle, direction, power });
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
let innerElement;
|
|
235
|
-
let outerElement;
|
|
236
|
-
|
|
237
|
-
if (!settings.outer) {
|
|
238
|
-
outerElement = h(Graphics, {
|
|
239
|
-
draw: (g) => {
|
|
240
|
-
g.circle(0, 0, outerRadius).fill(0x000000);
|
|
241
|
-
},
|
|
242
|
-
alpha: 0.5,
|
|
243
|
-
});
|
|
244
|
-
} else {
|
|
245
|
-
outerElement = h(Sprite, {
|
|
246
|
-
image: settings.outer,
|
|
247
|
-
anchor: { x: 0.5, y: 0.5 },
|
|
248
|
-
scale: settings.outerScale,
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const innerOptions: any = {
|
|
253
|
-
scale: settings.innerScale,
|
|
254
|
-
x: innerPositionX,
|
|
255
|
-
y: innerPositionY,
|
|
256
|
-
alpha: innerAlpha,
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
if (!settings.inner) {
|
|
260
|
-
innerElement = h(Graphics, {
|
|
261
|
-
draw: (g) => {
|
|
262
|
-
g.circle(0, 0, innerRadius * 2.5).fill(0x000000);
|
|
263
|
-
},
|
|
264
|
-
...innerOptions,
|
|
265
|
-
});
|
|
266
|
-
} else {
|
|
267
|
-
innerElement = h(Sprite, {
|
|
268
|
-
image: settings.inner,
|
|
269
|
-
anchor: { x: 0.5, y: 0.5 },
|
|
270
|
-
...innerOptions,
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return h(
|
|
275
|
-
Container,
|
|
276
|
-
{
|
|
277
|
-
...opts,
|
|
278
|
-
pointerdown: handleDragStart,
|
|
279
|
-
pointerup: handleDragEnd,
|
|
280
|
-
pointerupoutside: handleDragEnd,
|
|
281
|
-
pointermove: handleDragMove,
|
|
282
|
-
},
|
|
283
|
-
outerElement,
|
|
284
|
-
innerElement
|
|
285
|
-
);
|
|
286
|
-
}
|