@rpgjs/client 4.3.0 → 5.0.0-alpha.0
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/Game/EffectManager.d.ts +5 -0
- package/dist/Game/Event.d.ts +4 -0
- package/dist/Game/Map.d.ts +7 -0
- package/dist/Game/Player.d.ts +4 -0
- package/dist/Gui/Gui.d.ts +23 -0
- package/{lib → dist}/RpgClient.d.ts +9 -6
- package/dist/RpgClientEngine.d.ts +43 -0
- package/dist/components/effects/index.d.ts +4 -0
- package/dist/components/gui/index.d.ts +3 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/core/inject.d.ts +5 -0
- package/dist/core/setup.d.ts +6 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/index10.js +8 -0
- package/dist/index10.js.map +1 -0
- package/dist/index11.js +10 -0
- package/dist/index11.js.map +1 -0
- package/dist/index12.js +8 -0
- package/dist/index12.js.map +1 -0
- package/dist/index13.js +17 -0
- package/dist/index13.js.map +1 -0
- package/dist/index14.js +50 -0
- package/dist/index14.js.map +1 -0
- package/dist/index15.js +191 -0
- package/dist/index15.js.map +1 -0
- package/dist/index16.js +9 -0
- package/dist/index16.js.map +1 -0
- package/dist/index17.js +387 -0
- package/dist/index17.js.map +1 -0
- package/dist/index18.js +31 -0
- package/dist/index18.js.map +1 -0
- package/dist/index19.js +24 -0
- package/dist/index19.js.map +1 -0
- package/dist/index2.js +112 -0
- package/dist/index2.js.map +1 -0
- package/dist/index20.js +2421 -0
- package/dist/index20.js.map +1 -0
- package/dist/index21.js +114 -0
- package/dist/index21.js.map +1 -0
- package/dist/index22.js +109 -0
- package/dist/index22.js.map +1 -0
- package/dist/index23.js +71 -0
- package/dist/index23.js.map +1 -0
- package/dist/index24.js +21 -0
- package/dist/index24.js.map +1 -0
- package/dist/index25.js +41 -0
- package/dist/index25.js.map +1 -0
- package/dist/index26.js +5 -0
- package/dist/index26.js.map +1 -0
- package/dist/index27.js +322 -0
- package/dist/index27.js.map +1 -0
- package/dist/index28.js +25 -0
- package/dist/index28.js.map +1 -0
- package/dist/index29.js +11 -0
- package/dist/index29.js.map +1 -0
- package/dist/index3.js +87 -0
- package/dist/index3.js.map +1 -0
- package/dist/index30.js +11 -0
- package/dist/index30.js.map +1 -0
- package/dist/index31.js +174 -0
- package/dist/index31.js.map +1 -0
- package/dist/index32.js +501 -0
- package/dist/index32.js.map +1 -0
- package/dist/index33.js +12 -0
- package/dist/index33.js.map +1 -0
- package/dist/index34.js +4403 -0
- package/dist/index34.js.map +1 -0
- package/dist/index35.js +91 -0
- package/dist/index35.js.map +1 -0
- package/dist/index36.js +61 -0
- package/dist/index36.js.map +1 -0
- package/dist/index37.js +20 -0
- package/dist/index37.js.map +1 -0
- package/dist/index38.js +20 -0
- package/dist/index38.js.map +1 -0
- package/dist/index4.js +54 -0
- package/dist/index4.js.map +1 -0
- package/dist/index5.js +15 -0
- package/dist/index5.js.map +1 -0
- package/dist/index6.js +17 -0
- package/dist/index6.js.map +1 -0
- package/dist/index7.js +31 -0
- package/dist/index7.js.map +1 -0
- package/dist/index8.js +90 -0
- package/dist/index8.js.map +1 -0
- package/dist/index9.js +76 -0
- package/dist/index9.js.map +1 -0
- package/dist/module.d.ts +14 -0
- package/dist/presets/index.d.ts +22 -0
- package/{lib/Presets/AnimationSpritesheet.d.ts → dist/presets/rmspritesheet.d.ts} +6 -2
- package/dist/services/AbstractSocket.d.ts +15 -0
- package/dist/services/loadMap.d.ts +14 -0
- package/dist/services/mmorpg.d.ts +32 -0
- package/dist/services/standalone.d.ts +34 -0
- package/package.json +25 -41
- package/src/Game/EffectManager.ts +20 -0
- package/src/Game/Event.ts +5 -0
- package/src/Game/Map.ts +10 -0
- package/src/Game/Object.ts +16 -0
- package/src/Game/Player.ts +5 -0
- package/src/Gui/Gui.ts +80 -533
- package/src/RpgClient.ts +9 -5
- package/src/RpgClientEngine.ts +135 -818
- package/src/components/character.ce +104 -0
- package/src/components/effects/animation.ce +19 -0
- package/src/components/effects/hit.ce +87 -0
- package/src/components/effects/index.ts +7 -0
- package/src/components/gui/dialogbox/index.ce +194 -0
- package/src/components/gui/dialogbox/itemMenu.ce +23 -0
- package/src/components/gui/dialogbox/selection.ce +67 -0
- package/src/components/gui/index.ts +5 -0
- package/src/components/index.ts +3 -0
- package/src/components/scenes/canvas.ce +51 -0
- package/src/components/scenes/draw-map.ce +56 -0
- package/src/components/scenes/element-map.ce +23 -0
- package/src/components/scenes/event-layer.ce +20 -0
- package/src/core/inject.ts +17 -0
- package/src/core/setup.ts +18 -0
- package/src/index.ts +13 -29
- package/src/module.ts +93 -0
- package/src/presets/index.ts +5 -0
- package/src/{Presets/AnimationSpritesheet.ts → presets/rmspritesheet.ts} +4 -5
- package/src/services/AbstractSocket.ts +14 -0
- package/src/services/loadMap.ts +33 -0
- package/src/services/mmorpg.ts +64 -0
- package/src/services/standalone.ts +101 -0
- package/src/types/canvas-engine.d.ts +26 -0
- package/tsconfig.json +8 -3
- package/vite.config.ts +34 -0
- package/CHANGELOG.md +0 -189
- package/LICENSE +0 -19
- package/browser/React-ece4b906.js +0 -195
- package/browser/index-ba657126.js +0 -44229
- package/browser/manifest.json +0 -21
- package/browser/rpg.client.js +0 -40
- package/browser/rpg.client.umd.cjs +0 -44456
- package/lib/Components/AbstractComponent.d.ts +0 -32
- package/lib/Components/AbstractComponent.js +0 -93
- package/lib/Components/AbstractComponent.js.map +0 -1
- package/lib/Components/BarComponent.d.ts +0 -21
- package/lib/Components/BarComponent.js +0 -169
- package/lib/Components/BarComponent.js.map +0 -1
- package/lib/Components/Component.d.ts +0 -124
- package/lib/Components/Component.js +0 -425
- package/lib/Components/Component.js.map +0 -1
- package/lib/Components/DebugComponent.d.ts +0 -11
- package/lib/Components/DebugComponent.js +0 -32
- package/lib/Components/DebugComponent.js.map +0 -1
- package/lib/Components/ImageComponent.d.ts +0 -11
- package/lib/Components/ImageComponent.js +0 -30
- package/lib/Components/ImageComponent.js.map +0 -1
- package/lib/Components/ShapeComponent.d.ts +0 -11
- package/lib/Components/ShapeComponent.js +0 -57
- package/lib/Components/ShapeComponent.js.map +0 -1
- package/lib/Components/TextComponent.d.ts +0 -11
- package/lib/Components/TextComponent.js +0 -35
- package/lib/Components/TextComponent.js.map +0 -1
- package/lib/Components/TileComponent.d.ts +0 -10
- package/lib/Components/TileComponent.js +0 -40
- package/lib/Components/TileComponent.js.map +0 -1
- package/lib/Effects/Animation.d.ts +0 -55
- package/lib/Effects/Animation.js +0 -233
- package/lib/Effects/Animation.js.map +0 -1
- package/lib/Effects/AnimationCharacter.d.ts +0 -7
- package/lib/Effects/AnimationCharacter.js +0 -9
- package/lib/Effects/AnimationCharacter.js.map +0 -1
- package/lib/Effects/Spinner.d.ts +0 -7
- package/lib/Effects/Spinner.js +0 -18
- package/lib/Effects/Spinner.js.map +0 -1
- package/lib/Effects/Timeline.d.ts +0 -151
- package/lib/Effects/Timeline.js +0 -369
- package/lib/Effects/Timeline.js.map +0 -1
- package/lib/Effects/TransitionScene.d.ts +0 -18
- package/lib/Effects/TransitionScene.js +0 -50
- package/lib/Effects/TransitionScene.js.map +0 -1
- package/lib/GameEngine.d.ts +0 -68
- package/lib/GameEngine.js +0 -254
- package/lib/GameEngine.js.map +0 -1
- package/lib/Gui/Gui.d.ts +0 -110
- package/lib/Gui/Gui.js +0 -489
- package/lib/Gui/Gui.js.map +0 -1
- package/lib/Gui/React.d.ts +0 -28
- package/lib/Gui/React.js +0 -147
- package/lib/Gui/React.js.map +0 -1
- package/lib/Gui/Vue.d.ts +0 -13
- package/lib/Gui/Vue.js +0 -114
- package/lib/Gui/Vue.js.map +0 -1
- package/lib/Interfaces/Character.d.ts +0 -6
- package/lib/Interfaces/Character.js +0 -2
- package/lib/Interfaces/Character.js.map +0 -1
- package/lib/Interfaces/Scene.d.ts +0 -10
- package/lib/Interfaces/Scene.js +0 -2
- package/lib/Interfaces/Scene.js.map +0 -1
- package/lib/KeyboardControls.d.ts +0 -367
- package/lib/KeyboardControls.js +0 -714
- package/lib/KeyboardControls.js.map +0 -1
- package/lib/Logger.d.ts +0 -1
- package/lib/Logger.js +0 -4
- package/lib/Logger.js.map +0 -1
- package/lib/Presets/AnimationSpritesheet.js +0 -39
- package/lib/Presets/AnimationSpritesheet.js.map +0 -1
- package/lib/Presets/Scene.d.ts +0 -3
- package/lib/Presets/Scene.js +0 -5
- package/lib/Presets/Scene.js.map +0 -1
- package/lib/Renderer.d.ts +0 -62
- package/lib/Renderer.js +0 -300
- package/lib/Renderer.js.map +0 -1
- package/lib/Resources.d.ts +0 -22
- package/lib/Resources.js +0 -38
- package/lib/Resources.js.map +0 -1
- package/lib/RpgClient.js +0 -2
- package/lib/RpgClient.js.map +0 -1
- package/lib/RpgClientEngine.d.ts +0 -257
- package/lib/RpgClientEngine.js +0 -677
- package/lib/RpgClientEngine.js.map +0 -1
- package/lib/Scene/EventLayer.d.ts +0 -4
- package/lib/Scene/EventLayer.js +0 -8
- package/lib/Scene/EventLayer.js.map +0 -1
- package/lib/Scene/Map.d.ts +0 -109
- package/lib/Scene/Map.js +0 -319
- package/lib/Scene/Map.js.map +0 -1
- package/lib/Scene/Scene.d.ts +0 -184
- package/lib/Scene/Scene.js +0 -250
- package/lib/Scene/Scene.js.map +0 -1
- package/lib/Scene/SceneData.d.ts +0 -4
- package/lib/Scene/SceneData.js +0 -8
- package/lib/Scene/SceneData.js.map +0 -1
- package/lib/Sound/RpgSound.d.ts +0 -11
- package/lib/Sound/RpgSound.js +0 -46
- package/lib/Sound/RpgSound.js.map +0 -1
- package/lib/Sound/Sound.d.ts +0 -78
- package/lib/Sound/Sound.js +0 -12
- package/lib/Sound/Sound.js.map +0 -1
- package/lib/Sound/Sounds.d.ts +0 -2
- package/lib/Sound/Sounds.js +0 -6
- package/lib/Sound/Sounds.js.map +0 -1
- package/lib/Sprite/Character.d.ts +0 -18
- package/lib/Sprite/Character.js +0 -131
- package/lib/Sprite/Character.js.map +0 -1
- package/lib/Sprite/Player.d.ts +0 -3
- package/lib/Sprite/Player.js +0 -4
- package/lib/Sprite/Player.js.map +0 -1
- package/lib/Sprite/Spritesheet.d.ts +0 -365
- package/lib/Sprite/Spritesheet.js +0 -13
- package/lib/Sprite/Spritesheet.js.map +0 -1
- package/lib/Sprite/Spritesheets.d.ts +0 -3
- package/lib/Sprite/Spritesheets.js +0 -6
- package/lib/Sprite/Spritesheets.js.map +0 -1
- package/lib/Tilemap/CommonLayer.d.ts +0 -10
- package/lib/Tilemap/CommonLayer.js +0 -17
- package/lib/Tilemap/CommonLayer.js.map +0 -1
- package/lib/Tilemap/ImageLayer.d.ts +0 -4
- package/lib/Tilemap/ImageLayer.js +0 -16
- package/lib/Tilemap/ImageLayer.js.map +0 -1
- package/lib/Tilemap/Tile.d.ts +0 -21
- package/lib/Tilemap/Tile.js +0 -67
- package/lib/Tilemap/Tile.js.map +0 -1
- package/lib/Tilemap/TileLayer.d.ts +0 -13
- package/lib/Tilemap/TileLayer.js +0 -122
- package/lib/Tilemap/TileLayer.js.map +0 -1
- package/lib/Tilemap/TileSet.d.ts +0 -7
- package/lib/Tilemap/TileSet.js +0 -24
- package/lib/Tilemap/TileSet.js.map +0 -1
- package/lib/Tilemap/index.d.ts +0 -28
- package/lib/Tilemap/index.js +0 -151
- package/lib/Tilemap/index.js.map +0 -1
- package/lib/clientEntryPoint.d.ts +0 -89
- package/lib/clientEntryPoint.js +0 -48
- package/lib/clientEntryPoint.js.map +0 -1
- package/lib/index.d.ts +0 -26
- package/lib/index.js +0 -27
- package/lib/index.js.map +0 -1
- package/lib/inject.d.ts +0 -23
- package/lib/inject.js +0 -30
- package/lib/inject.js.map +0 -1
- package/rpg.toml +0 -14
- package/src/Components/AbstractComponent.ts +0 -120
- package/src/Components/BarComponent.ts +0 -181
- package/src/Components/Component.ts +0 -515
- package/src/Components/DebugComponent.ts +0 -36
- package/src/Components/ImageComponent.ts +0 -30
- package/src/Components/ShapeComponent.ts +0 -64
- package/src/Components/TextComponent.ts +0 -33
- package/src/Components/TileComponent.ts +0 -43
- package/src/Effects/Animation.ts +0 -310
- package/src/Effects/AnimationCharacter.ts +0 -7
- package/src/Effects/Spinner.ts +0 -19
- package/src/Effects/Timeline.ts +0 -378
- package/src/Effects/TransitionScene.ts +0 -59
- package/src/GameEngine.ts +0 -289
- package/src/Gui/React.ts +0 -193
- package/src/Gui/Vue.ts +0 -154
- package/src/Interfaces/Character.ts +0 -7
- package/src/Interfaces/Scene.ts +0 -9
- package/src/KeyboardControls.ts +0 -748
- package/src/Logger.ts +0 -3
- package/src/Presets/Scene.ts +0 -3
- package/src/Renderer.ts +0 -334
- package/src/Resources.ts +0 -39
- package/src/Scene/EventLayer.ts +0 -9
- package/src/Scene/Map.ts +0 -402
- package/src/Scene/Scene.ts +0 -305
- package/src/Scene/SceneData.ts +0 -13
- package/src/Sound/RpgSound.ts +0 -50
- package/src/Sound/Sound.ts +0 -91
- package/src/Sound/Sounds.ts +0 -7
- package/src/Sprite/Character.ts +0 -157
- package/src/Sprite/Player.ts +0 -3
- package/src/Sprite/Spritesheet.ts +0 -392
- package/src/Sprite/Spritesheets.ts +0 -8
- package/src/Tilemap/CommonLayer.ts +0 -20
- package/src/Tilemap/ImageLayer.ts +0 -20
- package/src/Tilemap/Tile.ts +0 -80
- package/src/Tilemap/TileLayer.ts +0 -142
- package/src/Tilemap/TileSet.ts +0 -40
- package/src/Tilemap/index.ts +0 -175
- package/src/clientEntryPoint.ts +0 -150
- package/src/inject.ts +0 -34
- package/src/types/howler.d.ts +0 -73
|
@@ -1,392 +0,0 @@
|
|
|
1
|
-
import { constructor } from "@rpgjs/types"
|
|
2
|
-
import { ClassDeclaration } from "typescript"
|
|
3
|
-
|
|
4
|
-
export interface TransformOptions {
|
|
5
|
-
/**
|
|
6
|
-
* The global value of opacity (between 0 and 1)
|
|
7
|
-
*
|
|
8
|
-
* @prop {number} [opacity]
|
|
9
|
-
* @memberof Spritesheet
|
|
10
|
-
* */
|
|
11
|
-
opacity?: number
|
|
12
|
-
/**
|
|
13
|
-
* The global value of pivot.
|
|
14
|
-
*
|
|
15
|
-
* 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.
|
|
16
|
-
*
|
|
17
|
-
* The array has two elements: [x, y]. If y is omitted, both x and y will be set to x.
|
|
18
|
-
*
|
|
19
|
-
* ```ts
|
|
20
|
-
* pivot: [0.5, 0.8]
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @prop {Array<number>} [pivot]
|
|
24
|
-
* @memberof Spritesheet
|
|
25
|
-
* */
|
|
26
|
-
pivot?: number[]
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* The global value of anchor.
|
|
30
|
-
*
|
|
31
|
-
* Position of the origin point
|
|
32
|
-
*
|
|
33
|
-
* The array has two elements: [x, y]. If y is omitted, both x and y will be set to x.
|
|
34
|
-
*
|
|
35
|
-
* ```ts
|
|
36
|
-
* anchor: [0.5, 0.8]
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* @prop {Array<number>} [anchor]
|
|
40
|
-
* @memberof Spritesheet
|
|
41
|
-
* */
|
|
42
|
-
anchor?: number[]
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Defines the actual size of the sprite that is inside a larger rectangle.
|
|
46
|
-
* 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
|
|
47
|
-
*
|
|
48
|
-
* > 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
|
|
49
|
-
*
|
|
50
|
-
* @prop {{ width: number, height: number } | number} [spriteRealSize]
|
|
51
|
-
* @since 3.2.0
|
|
52
|
-
* @memberof Spritesheet
|
|
53
|
-
* */
|
|
54
|
-
spriteRealSize?: { width: number, height: number } | number
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* The global value of rotation
|
|
58
|
-
*
|
|
59
|
-
* Rotation. This will rotate the display object's projection by this angle (in radians).
|
|
60
|
-
*
|
|
61
|
-
* @prop {number} [angle]
|
|
62
|
-
* @memberof Spritesheet
|
|
63
|
-
* */
|
|
64
|
-
angle?: number
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* The global value of rotation
|
|
68
|
-
*
|
|
69
|
-
* Rotation. This is an alias for rotation, but in degrees.
|
|
70
|
-
*
|
|
71
|
-
* @prop {number} [rotation]
|
|
72
|
-
* @memberof Spritesheet
|
|
73
|
-
* */
|
|
74
|
-
rotation?: number
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* The global value of scale.
|
|
78
|
-
*
|
|
79
|
-
* 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.
|
|
80
|
-
*
|
|
81
|
-
* The array has two elements: [x, y]. If y is omitted, both x and y will be set to x.
|
|
82
|
-
*
|
|
83
|
-
* ```ts
|
|
84
|
-
* scale: [0.5, 0.8]
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
* @prop {Array<number>} [scale]
|
|
88
|
-
* @memberof Spritesheet
|
|
89
|
-
* */
|
|
90
|
-
scale?: number[]
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* The global value of skew.
|
|
94
|
-
*
|
|
95
|
-
* Skewing. This can be used to deform a rectangular display object into a parallelogram.
|
|
96
|
-
*
|
|
97
|
-
* 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 β.
|
|
98
|
-
*
|
|
99
|
-
* 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" = ϴ.
|
|
100
|
-
*
|
|
101
|
-
* 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.
|
|
102
|
-
*
|
|
103
|
-
* The array has two elements: [x, y]. If y is omitted, both x and y will be set to x.
|
|
104
|
-
*
|
|
105
|
-
* @prop {Array<number>} [skew]
|
|
106
|
-
* @memberof Spritesheet
|
|
107
|
-
* */
|
|
108
|
-
skew?: number[]
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* The global value of X translation
|
|
112
|
-
*
|
|
113
|
-
* @prop {number} [x]
|
|
114
|
-
* @memberof Spritesheet
|
|
115
|
-
* */
|
|
116
|
-
x?: number
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* The global value of Y translation
|
|
120
|
-
*
|
|
121
|
-
* @prop {number} [y]
|
|
122
|
-
* @memberof Spritesheet
|
|
123
|
-
* */
|
|
124
|
-
y?: number
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* The global value of visible
|
|
128
|
-
*
|
|
129
|
-
* @prop {boolean} [visible]
|
|
130
|
-
* @memberof Spritesheet
|
|
131
|
-
* */
|
|
132
|
-
visible?: boolean
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Define the sound that will be played for all animations in the spritesheet. Remember to create the sound before with the @Sound decorator
|
|
136
|
-
*
|
|
137
|
-
* @prop {string} [sound]
|
|
138
|
-
* @memberof Spritesheet
|
|
139
|
-
* */
|
|
140
|
-
sound?: string
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export interface FrameOptions extends TransformOptions {
|
|
144
|
-
time: number
|
|
145
|
-
frameX?: number
|
|
146
|
-
frameY?: number
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export interface TextureOptions {
|
|
150
|
-
/**
|
|
151
|
-
* The number of frames on the width
|
|
152
|
-
*
|
|
153
|
-
* @prop {number} framesWidth
|
|
154
|
-
* @memberof Spritesheet
|
|
155
|
-
* */
|
|
156
|
-
framesWidth?: number,
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* The number of frames on the height
|
|
160
|
-
*
|
|
161
|
-
* @prop {number} framesHeight
|
|
162
|
-
* @memberof Spritesheet
|
|
163
|
-
* */
|
|
164
|
-
framesHeight?: number,
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* The width of the image (in pixels)
|
|
168
|
-
*
|
|
169
|
-
* @prop {number} width
|
|
170
|
-
* @memberof Spritesheet
|
|
171
|
-
* */
|
|
172
|
-
width?: number,
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* The height of the image (in pixels)
|
|
176
|
-
*
|
|
177
|
-
* @prop {number} height
|
|
178
|
-
* @memberof Spritesheet
|
|
179
|
-
* */
|
|
180
|
-
height?: number
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Takes a width of a rectangle in the image. Equivalent to `width / framesWidth`
|
|
184
|
-
*
|
|
185
|
-
* @prop {number} [rectWidth]
|
|
186
|
-
* @memberof Spritesheet
|
|
187
|
-
* */
|
|
188
|
-
rectWidth?: number,
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Takes a height of a rectangle in the image. Equivalent to `height / framesHeight`
|
|
192
|
-
*
|
|
193
|
-
* @prop {number} [rectHeight]
|
|
194
|
-
* @memberof Spritesheet
|
|
195
|
-
* */
|
|
196
|
-
rectHeight?: number,
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* To take the texture, start at a well defined X and Y position. Otherwise, it starts at 0,0
|
|
200
|
-
*
|
|
201
|
-
* @prop {number} [offset]
|
|
202
|
-
* @memberof Spritesheet
|
|
203
|
-
* */
|
|
204
|
-
offset?: { x: number, y: number }
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export type AnimationFrames = FrameOptions[][] | ((...args: any) => FrameOptions[][])
|
|
208
|
-
|
|
209
|
-
export interface TexturesOptions extends TextureOptions, TransformOptions {
|
|
210
|
-
animations: AnimationFrames
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
export interface SpritesheetOptions extends TransformOptions, TextureOptions {
|
|
214
|
-
/**
|
|
215
|
-
* Object containing all animations.
|
|
216
|
-
* The key to the object is the name of the animation. The value is a two-dimensional array
|
|
217
|
-
*
|
|
218
|
-
* ```ts
|
|
219
|
-
* textures: {
|
|
220
|
-
* myanim: {
|
|
221
|
-
* animations: [
|
|
222
|
-
* [ { time: 0, frameX: 0, frameY: 0 } ]
|
|
223
|
-
* ]
|
|
224
|
-
* }
|
|
225
|
-
* }
|
|
226
|
-
* ```
|
|
227
|
-
*
|
|
228
|
-
* 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
|
|
229
|
-
* 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`)
|
|
230
|
-
*
|
|
231
|
-
* Here are the properties:
|
|
232
|
-
*
|
|
233
|
-
* * `time`: Time in frame
|
|
234
|
-
* * `frameX`: Retrieve a frame from the spritesheet on the X-axis
|
|
235
|
-
* * `frameY`: Retrieve a frame from the spritesheet on the Y-axis
|
|
236
|
-
* * `opacity`
|
|
237
|
-
* * `pivot`
|
|
238
|
-
* * `anchor`
|
|
239
|
-
* * `rotation`
|
|
240
|
-
* * `angle`
|
|
241
|
-
* * `scale`
|
|
242
|
-
* * `skew`
|
|
243
|
-
* * `x`
|
|
244
|
-
* * `y`
|
|
245
|
-
* * `visible`
|
|
246
|
-
* * `sound`: The sound that will be played during the frame
|
|
247
|
-
*
|
|
248
|
-
* ---
|
|
249
|
-
* **Extract Animation of Spritesheet**
|
|
250
|
-
*
|
|
251
|
-
* Sometimes the animation is part of the image
|
|
252
|
-
*
|
|
253
|
-
* ```ts
|
|
254
|
-
* textures: {
|
|
255
|
-
* myanim: {
|
|
256
|
-
* rectWidth: 64,
|
|
257
|
-
* rectHeight: 64,
|
|
258
|
-
* framesWidth: 10,
|
|
259
|
-
* framesHeight: 2,
|
|
260
|
-
* offset: {x: 0, y: 230},
|
|
261
|
-
* sound: 'my-sound-id', // You can put a sound just for the animation
|
|
262
|
-
* animations: [
|
|
263
|
-
* [ { time: 0, frameX: 0, frameY: 0 } ]
|
|
264
|
-
* ]
|
|
265
|
-
* }
|
|
266
|
-
* }
|
|
267
|
-
* ```
|
|
268
|
-
*
|
|
269
|
-
* Above, we can specify which part we want to recover
|
|
270
|
-
*
|
|
271
|
-
* 1. We go to the position {0, 230} of the image (`offset`)
|
|
272
|
-
* 2. We recover cells of 64px (`rectWidth` and `rectHeight`)
|
|
273
|
-
* 3. And we get 20 cells (10 on the width, 2 on the height) (`frameX` and `frameY`)
|
|
274
|
-
*
|
|
275
|
-
* ---
|
|
276
|
-
*
|
|
277
|
-
* **Advanced**
|
|
278
|
-
*
|
|
279
|
-
* You can create an animation that will be linked to a data. For example, different animation according to a direction of the character.
|
|
280
|
-
*
|
|
281
|
-
* Full example:
|
|
282
|
-
*
|
|
283
|
-
* ```ts
|
|
284
|
-
* import { Spritesheet, Animation, Direction } from '@rpgjs/client'
|
|
285
|
-
*
|
|
286
|
-
* @Spritesheet({
|
|
287
|
-
* id: 'chest',
|
|
288
|
-
* image: require('./assets/chest.png'),
|
|
289
|
-
* width: 124,
|
|
290
|
-
* height: 61,
|
|
291
|
-
* framesHeight: 2,
|
|
292
|
-
* framesWidth: 4,
|
|
293
|
-
* textures: {
|
|
294
|
-
* [Animation.Stand]: {
|
|
295
|
-
* animations: direction => [[ {time: 0, frameX: 3, frameY: direction == Direction.Up ? 0 : 1 } ]]
|
|
296
|
-
* }
|
|
297
|
-
* })
|
|
298
|
-
* })
|
|
299
|
-
* export class Chest { }
|
|
300
|
-
* ```
|
|
301
|
-
*
|
|
302
|
-
* > 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
|
|
303
|
-
*
|
|
304
|
-
* 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:
|
|
305
|
-
*
|
|
306
|
-
* ```ts
|
|
307
|
-
* import { Spritesheet, Animation, Direction, RpgSprite, ISpriteCharacter } from '@rpgjs/client'
|
|
308
|
-
*
|
|
309
|
-
* @Spritesheet({
|
|
310
|
-
* id: 'chest',
|
|
311
|
-
* image: require('./assets/chest.png'),
|
|
312
|
-
* width: 124,
|
|
313
|
-
* height: 61,
|
|
314
|
-
* framesHeight: 2,
|
|
315
|
-
* framesWidth: 4,
|
|
316
|
-
* textures: {
|
|
317
|
-
* [Animation.Stand]: {
|
|
318
|
-
* animations: str => [[ {time: 0, frameX: 3, frameY: str == 'hello' ? 0 : 1 } ]]
|
|
319
|
-
* }
|
|
320
|
-
* }
|
|
321
|
-
* })
|
|
322
|
-
* export class Chest implements ISpriteCharacter {
|
|
323
|
-
* onCharacterStand(sprite: RpgSprite) {
|
|
324
|
-
* sprite.animation.play(Animation.Stand, ['hello'])
|
|
325
|
-
* }
|
|
326
|
-
* }
|
|
327
|
-
* ```
|
|
328
|
-
*
|
|
329
|
-
* @prop { { [animName: string]: { animations: Array<Array<FrameOptions>> | Function, ...other } } } [textures]
|
|
330
|
-
* @memberof Spritesheet
|
|
331
|
-
* */
|
|
332
|
-
textures?: {
|
|
333
|
-
[animationName: string]: Partial<TexturesOptions> & Pick<TexturesOptions, 'animations'>
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
type SpritesheetImageOptions = SpritesheetOptions & {
|
|
338
|
-
/**
|
|
339
|
-
* The link to the image
|
|
340
|
-
*
|
|
341
|
-
* > Do not use the `images` property
|
|
342
|
-
* > Remember to wrap the link to the image with the `require` function.
|
|
343
|
-
*
|
|
344
|
-
* ```ts
|
|
345
|
-
* image: require('./assets/hero.png')
|
|
346
|
-
* ```
|
|
347
|
-
*
|
|
348
|
-
* @prop {string} [image]
|
|
349
|
-
* @memberof Spritesheet
|
|
350
|
-
* */
|
|
351
|
-
image?: string,
|
|
352
|
-
/**
|
|
353
|
-
* Spritesheet identifier.
|
|
354
|
-
*
|
|
355
|
-
* > Do not use the `images` property
|
|
356
|
-
*
|
|
357
|
-
* @prop {string} [id]
|
|
358
|
-
* @memberof Spritesheet
|
|
359
|
-
* */
|
|
360
|
-
id: string
|
|
361
|
-
}
|
|
362
|
-
type SpritesheetImagesOptions = SpritesheetOptions & {
|
|
363
|
-
/**
|
|
364
|
-
* Put the different images that are concerned by the properties below.
|
|
365
|
-
* The key of the object is the identifier of the spritesheet and the value and the link to the image.
|
|
366
|
-
*
|
|
367
|
-
* > Remember to wrap the link to the image with the `require` function.
|
|
368
|
-
*
|
|
369
|
-
* ```ts
|
|
370
|
-
* images: {
|
|
371
|
-
* hero: require('./assets/hero.png')
|
|
372
|
-
* }
|
|
373
|
-
* ```
|
|
374
|
-
*
|
|
375
|
-
* @prop { { [id: string]: string } } [images]
|
|
376
|
-
* @memberof Spritesheet
|
|
377
|
-
* */
|
|
378
|
-
images?: { [id: string]: string }
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
export function Spritesheet(options: SpritesheetImageOptions)
|
|
382
|
-
export function Spritesheet(options: SpritesheetImagesOptions)
|
|
383
|
-
export function Spritesheet(options: SpritesheetImageOptions | SpritesheetImagesOptions) {
|
|
384
|
-
return (target: Function) => {
|
|
385
|
-
if ('images' in options) target['images'] = options.images
|
|
386
|
-
if ('id' in options) target['id'] = options.id
|
|
387
|
-
for (let key in options) {
|
|
388
|
-
target.prototype[key] = options[key]
|
|
389
|
-
}
|
|
390
|
-
return
|
|
391
|
-
}
|
|
392
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { RpgClientEngine } from '..'
|
|
2
|
-
import { _initResource } from '../Resources'
|
|
3
|
-
|
|
4
|
-
export const spritesheets: Map<string, any> = new Map()
|
|
5
|
-
|
|
6
|
-
export function _initSpritesheet(_spritesheets, engine: RpgClientEngine) {
|
|
7
|
-
return _initResource(spritesheets, _spritesheets, 'image', engine)
|
|
8
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Layer } from "@rpgjs/tiled"
|
|
2
|
-
import TileMap from './index'
|
|
3
|
-
import { Container } from "pixi.js"
|
|
4
|
-
|
|
5
|
-
export class CommonLayer extends Container {
|
|
6
|
-
z: number
|
|
7
|
-
|
|
8
|
-
constructor(protected layer: Layer, protected map: TileMap) {
|
|
9
|
-
super()
|
|
10
|
-
this.applyProperties()
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
applyProperties() {
|
|
14
|
-
this.alpha = this.layer.opacity ?? 1
|
|
15
|
-
this.visible = this.layer.visible ?? true
|
|
16
|
-
this.x = this.layer.offsetx ?? 0
|
|
17
|
-
this.y = this.layer.offsety ?? 0
|
|
18
|
-
this.z = this.layer.properties.z ?? 0
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { CommonLayer } from './CommonLayer';
|
|
2
|
-
import { Texture, TilingSprite } from 'pixi.js';
|
|
3
|
-
|
|
4
|
-
export default class ImageLayer extends CommonLayer {
|
|
5
|
-
applyProperties() {
|
|
6
|
-
super.applyProperties()
|
|
7
|
-
const engine = this.map['renderer']['clientEngine']
|
|
8
|
-
if (this.layer.image && this.layer.image.source && engine) {
|
|
9
|
-
const { width, height, source } = this.layer.image
|
|
10
|
-
const data = this.map.getData()
|
|
11
|
-
const texture = Texture.from(engine.getResourceUrl(source))
|
|
12
|
-
const tilingSprite = new TilingSprite(
|
|
13
|
-
texture,
|
|
14
|
-
this.layer.repeatx ? data.width * data.tilewidth : width,
|
|
15
|
-
this.layer.repeaty ? data.height * data.tileheight : height
|
|
16
|
-
)
|
|
17
|
-
this.addChild(tilingSprite)
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
package/src/Tilemap/Tile.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { Texture, AnimatedSprite, groupD8 } from "pixi.js";
|
|
2
|
-
import TileSet from "./TileSet";
|
|
3
|
-
import { Tile as TiledTileClass } from '@rpgjs/tiled'
|
|
4
|
-
import { CompositeTilemap } from "@pixi/tilemap";
|
|
5
|
-
|
|
6
|
-
export default class Tile extends AnimatedSprite {
|
|
7
|
-
static getTextures(tile: TiledTileClass, tileSet: TileSet) {
|
|
8
|
-
const textures: Texture[] = [];
|
|
9
|
-
|
|
10
|
-
if (tile.animations && tile.animations.length) {
|
|
11
|
-
tile.animations.forEach(frame => {
|
|
12
|
-
textures.push(tileSet.textures[frame.tileid].clone())
|
|
13
|
-
});
|
|
14
|
-
} else {
|
|
15
|
-
textures.push(tileSet.textures[tile.gid - tileSet.firstgid].clone())
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return textures;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
animations: { tileid: number, duration: number }[] = []
|
|
22
|
-
_x: number = 0
|
|
23
|
-
_y: number = 0
|
|
24
|
-
pointsBufIndex: number
|
|
25
|
-
properties: any = {}
|
|
26
|
-
|
|
27
|
-
constructor(
|
|
28
|
-
private tile: TiledTileClass,
|
|
29
|
-
private tileSet: TileSet
|
|
30
|
-
) {
|
|
31
|
-
super(Tile.getTextures(tile, tileSet));
|
|
32
|
-
this.animations = tile.animations || []
|
|
33
|
-
this.properties = tile.properties
|
|
34
|
-
this.textures = Tile.getTextures(tile, tileSet)
|
|
35
|
-
this.texture = this.textures[0] as Texture
|
|
36
|
-
this.flip()
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
get gid() {
|
|
40
|
-
return this.tile.gid
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
setAnimation(frame: CompositeTilemap) {
|
|
44
|
-
const size = this.animations.length
|
|
45
|
-
if (size > 1) {
|
|
46
|
-
const offset = (this.animations[1].tileid - this.animations[0].tileid) * this.width
|
|
47
|
-
frame.tileAnimX(offset, size)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
flip() {
|
|
52
|
-
let symmetry
|
|
53
|
-
let i=0
|
|
54
|
-
const add = (symmetrySecond) => {
|
|
55
|
-
i++
|
|
56
|
-
if (symmetry) symmetry = groupD8.add(symmetry, symmetrySecond)
|
|
57
|
-
else symmetry = symmetrySecond
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (this.tile.horizontalFlip) {
|
|
61
|
-
add(groupD8.MIRROR_HORIZONTAL)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (this.tile.verticalFlip) {
|
|
65
|
-
add(groupD8.MIRROR_VERTICAL)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (this.tile.diagonalFlip) {
|
|
69
|
-
if (i % 2 == 0) {
|
|
70
|
-
add(groupD8.MAIN_DIAGONAL)
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
add(groupD8.REVERSE_DIAGONAL)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (symmetry) this.texture.rotate = symmetry
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
}
|
package/src/Tilemap/TileLayer.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import Tile from './Tile';
|
|
2
|
-
import { CompositeTilemap, settings, POINT_STRUCT_SIZE, Tilemap } from '@pixi/tilemap'
|
|
3
|
-
import { Layer, Tile as TileClass } from '@rpgjs/tiled';
|
|
4
|
-
import TileSet from './TileSet';
|
|
5
|
-
import TileMap from '.';
|
|
6
|
-
import { CommonLayer } from './CommonLayer';
|
|
7
|
-
|
|
8
|
-
settings.use32bitIndex = true
|
|
9
|
-
|
|
10
|
-
export default class TileLayer extends CommonLayer {
|
|
11
|
-
private tilemap: CompositeTilemap
|
|
12
|
-
private _tiles: any = {}
|
|
13
|
-
tiles: (TileClass | null)[]
|
|
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
|
-
constructor(layer: Layer, private tileSets: TileSet[], map: TileMap) {
|
|
27
|
-
super(layer, map)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** @internal */
|
|
31
|
-
createTile(x: number, y: number, options: any = {}): Tile | undefined {
|
|
32
|
-
const { real, filter } = options
|
|
33
|
-
const { width, tilewidth, tileheight } = this.map.getData()
|
|
34
|
-
if (real) {
|
|
35
|
-
x = Math.floor(x / tilewidth)
|
|
36
|
-
y = Math.floor(y / tileheight)
|
|
37
|
-
}
|
|
38
|
-
const i = x + y * width;
|
|
39
|
-
const tiledTile = this.layer.getTileByIndex(i)
|
|
40
|
-
|
|
41
|
-
if (!tiledTile || (tiledTile && tiledTile.gid == 0)) return
|
|
42
|
-
|
|
43
|
-
const tileset = TileLayer.findTileSet(
|
|
44
|
-
tiledTile.gid,
|
|
45
|
-
this.tileSets
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
if (!tileset) return
|
|
49
|
-
|
|
50
|
-
const tile = new Tile(
|
|
51
|
-
tiledTile,
|
|
52
|
-
tileset
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
tile.x = x * tilewidth;
|
|
56
|
-
tile.y =
|
|
57
|
-
y * tileheight +
|
|
58
|
-
(tileheight -
|
|
59
|
-
tile.texture.height);
|
|
60
|
-
|
|
61
|
-
tile._x = x;
|
|
62
|
-
tile._y = y;
|
|
63
|
-
|
|
64
|
-
if (tileset.tileoffset) {
|
|
65
|
-
tile.x += tileset.tileoffset.x ?? 0;
|
|
66
|
-
tile.y += tileset.tileoffset.y ?? 0;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (filter) {
|
|
70
|
-
const ret = filter(tile)
|
|
71
|
-
if (!ret) return
|
|
72
|
-
}
|
|
73
|
-
return tile
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** @internal */
|
|
77
|
-
changeTile(x: number, y: number) {
|
|
78
|
-
const { tilewidth, tileheight } = this.map.getData()
|
|
79
|
-
x = Math.floor(x / tilewidth)
|
|
80
|
-
y = Math.floor(y / tileheight)
|
|
81
|
-
const oldTile: Tile = this._tiles[x + ';' + y]
|
|
82
|
-
const newTile = this.createTile(x, y)
|
|
83
|
-
if (!oldTile && newTile) {
|
|
84
|
-
this.addFrame(newTile, x, y)
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
if (newTile) {
|
|
88
|
-
const bufComposite: CompositeTilemap = new CompositeTilemap()
|
|
89
|
-
const frame = bufComposite.tile(newTile.texture, newTile.x, newTile.y)
|
|
90
|
-
newTile.setAnimation(frame)
|
|
91
|
-
this._tiles[x + ';' + y] = newTile
|
|
92
|
-
// @ts-ignore
|
|
93
|
-
const pointsBufComposite = (bufComposite.children[0] as Tilemap).pointsBuf
|
|
94
|
-
// Change Texture (=0, 1 and 7, rotate (=4), animX (=5), animY (=6))
|
|
95
|
-
;[0, 1, 4, 6, 7, 8].forEach((i) => {
|
|
96
|
-
if (this.pointsBuf) this.pointsBuf[oldTile.pointsBufIndex + i] = pointsBufComposite[i]
|
|
97
|
-
})
|
|
98
|
-
// @ts-ignore
|
|
99
|
-
this.tilemap.children[0].modificationMarker = 0
|
|
100
|
-
this.addFrame(newTile, x, y)
|
|
101
|
-
this['modificationMarker'] = 0
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
delete this._tiles[x + ';' + y]
|
|
105
|
-
if (this.pointsBuf) this.pointsBuf.splice(oldTile.pointsBufIndex, POINT_STRUCT_SIZE)
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** @internal */
|
|
111
|
-
get pointsBuf(): number[] | null {
|
|
112
|
-
const child = this.tilemap.children[0] as Tilemap
|
|
113
|
-
if (!child) return null
|
|
114
|
-
return child['pointsBuf']
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
private addFrame(tile: Tile, x: number, y: number) {
|
|
118
|
-
const frame = this.tilemap.tile(tile.texture, tile.x, tile.y, {
|
|
119
|
-
rotate: tile.texture.rotate
|
|
120
|
-
})
|
|
121
|
-
const pb = this.pointsBuf
|
|
122
|
-
if (!pb) return null
|
|
123
|
-
tile.pointsBufIndex = pb.length - POINT_STRUCT_SIZE
|
|
124
|
-
tile.setAnimation(frame)
|
|
125
|
-
this._tiles[x + ';' + y] = tile
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** @internal */
|
|
129
|
-
create() {
|
|
130
|
-
this.tilemap = new CompositeTilemap()
|
|
131
|
-
const { width, height } = this.map.getData()
|
|
132
|
-
for (let y = 0; y < height; y++) {
|
|
133
|
-
for (let x = 0; x < width; x++) {
|
|
134
|
-
const tile = this.createTile(x, y)
|
|
135
|
-
if (tile) {
|
|
136
|
-
this.addFrame(tile, x, y)
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
this.addChild(this.tilemap as any)
|
|
141
|
-
}
|
|
142
|
-
}
|
package/src/Tilemap/TileSet.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { spritesheets } from '../Sprite/Spritesheets'
|
|
2
|
-
import { TiledTileset, Tileset as TiledTilesetClass } from '@rpgjs/tiled'
|
|
3
|
-
import { log } from '../Logger'
|
|
4
|
-
import { Texture, BaseTexture, Rectangle } from 'pixi.js'
|
|
5
|
-
|
|
6
|
-
export default class TileSet extends TiledTilesetClass {
|
|
7
|
-
private baseTexture: BaseTexture
|
|
8
|
-
public textures: Texture[] = []
|
|
9
|
-
|
|
10
|
-
constructor(tileSet: TiledTileset) {
|
|
11
|
-
super(tileSet)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** @internal */
|
|
15
|
-
load() {
|
|
16
|
-
const spritesheet = spritesheets.get(this.name)
|
|
17
|
-
if (!spritesheet) {
|
|
18
|
-
throw log(`Impossible to find ${this.name} tileset`)
|
|
19
|
-
}
|
|
20
|
-
this.baseTexture = spritesheet.resource
|
|
21
|
-
for (
|
|
22
|
-
let y = this.margin;
|
|
23
|
-
y < this.image.height;
|
|
24
|
-
y += this.tileheight + this.spacing
|
|
25
|
-
) {
|
|
26
|
-
for (
|
|
27
|
-
let x = this.margin;
|
|
28
|
-
x < this.image.width;
|
|
29
|
-
x += this.tilewidth + this.spacing
|
|
30
|
-
) {
|
|
31
|
-
this.textures.push(
|
|
32
|
-
new Texture(
|
|
33
|
-
this.baseTexture,
|
|
34
|
-
new Rectangle(+x, +y, +this.tilewidth, +this.tileheight)
|
|
35
|
-
)
|
|
36
|
-
)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|