@rpgjs/client 4.2.2 → 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 -42
- 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 -534
- package/src/RpgClient.ts +9 -5
- package/src/RpgClientEngine.ts +135 -815
- 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 -177
- package/LICENSE +0 -19
- package/browser/React-f6f9b1de.js +0 -157
- package/browser/index-e74a289f.js +0 -44225
- package/browser/manifest.json +0 -21
- package/browser/rpg.client.js +0 -40
- package/browser/rpg.client.umd.cjs +0 -44414
- 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 -490
- package/lib/Gui/Gui.js.map +0 -1
- package/lib/Gui/React.d.ts +0 -15
- package/lib/Gui/React.js +0 -113
- 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 -674
- 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 -145
- 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,43 +0,0 @@
|
|
|
1
|
-
import { TileComponentObject } from "@rpgjs/types"
|
|
2
|
-
import { SceneMap } from "../Scene/Map"
|
|
3
|
-
import Tile from "../Tilemap/Tile"
|
|
4
|
-
import TileLayer from "../Tilemap/TileLayer"
|
|
5
|
-
import { AbstractComponent, CellInfo } from "./AbstractComponent"
|
|
6
|
-
import { Container } from "pixi.js"
|
|
7
|
-
|
|
8
|
-
export class TileComponent extends AbstractComponent<TileComponentObject, Container> {
|
|
9
|
-
static readonly id: string = 'tile'
|
|
10
|
-
cacheParams: string[] = []
|
|
11
|
-
gid: number = 0
|
|
12
|
-
|
|
13
|
-
onInit(cell: CellInfo) {
|
|
14
|
-
this.cell = cell
|
|
15
|
-
if (typeof this.value == 'number') {
|
|
16
|
-
this.gid = this.value
|
|
17
|
-
} else {
|
|
18
|
-
this.gid = this.value.gid
|
|
19
|
-
}
|
|
20
|
-
this.updateRender({})
|
|
21
|
-
super.onInit(cell)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
updateRender(object: any) {
|
|
25
|
-
this.removeChildren()
|
|
26
|
-
const height = typeof this.value != 'number' ? this.getValue(object, this.value.height) : null ?? this.cell?.height ?? 0
|
|
27
|
-
const width = typeof this.value != 'number' ? this.getValue(object, this.value.width) : null ?? this.cell?.width ?? 0
|
|
28
|
-
const scene = this.component.getScene<SceneMap>()
|
|
29
|
-
const tilemap = scene.tilemap
|
|
30
|
-
const tileset = TileLayer.findTileSet(
|
|
31
|
-
this.gid,
|
|
32
|
-
tilemap.tilesets
|
|
33
|
-
)
|
|
34
|
-
if (tileset) {
|
|
35
|
-
const tile = new Tile({
|
|
36
|
-
gid: this.gid
|
|
37
|
-
} as any, tileset)
|
|
38
|
-
tile.width = width ?? 0
|
|
39
|
-
tile.height = height ?? 0
|
|
40
|
-
this.addChild(tile)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
package/src/Effects/Animation.ts
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
import { Utils } from '@rpgjs/common'
|
|
2
|
-
import { spritesheets } from '../Sprite/Spritesheets'
|
|
3
|
-
import { SpritesheetOptions, TextureOptions, AnimationFrames, FrameOptions, TransformOptions } from '../Sprite/Spritesheet'
|
|
4
|
-
import { log } from '../Logger'
|
|
5
|
-
import { RpgSound } from '../Sound/RpgSound'
|
|
6
|
-
import { RpgComponent } from '../Components/Component'
|
|
7
|
-
import { Sprite, Container, Texture, Rectangle } from 'pixi.js'
|
|
8
|
-
import { Animation as AnimationEnum } from './AnimationCharacter'
|
|
9
|
-
import { BehaviorSubject, Observable } from 'rxjs'
|
|
10
|
-
|
|
11
|
-
const { isFunction, arrayEquals } = Utils
|
|
12
|
-
|
|
13
|
-
type Image = { image: string }
|
|
14
|
-
|
|
15
|
-
type TextureOptionsMerging = TextureOptions & {
|
|
16
|
-
spriteWidth: number
|
|
17
|
-
spriteHeight: number
|
|
18
|
-
sound?: string
|
|
19
|
-
} & Image & TransformOptions
|
|
20
|
-
|
|
21
|
-
type FrameOptionsMerging = TextureOptionsMerging & FrameOptions
|
|
22
|
-
type SpritesheetOptionsMerging = TextureOptionsMerging & SpritesheetOptions
|
|
23
|
-
type TransformOptionsAsArray = Pick<TransformOptions, 'anchor' | 'scale' | 'skew' | 'pivot'>
|
|
24
|
-
|
|
25
|
-
type AnimationDataFrames = {
|
|
26
|
-
container: Container,
|
|
27
|
-
sprites: FrameOptionsMerging[],
|
|
28
|
-
frames: Texture[][],
|
|
29
|
-
name: string,
|
|
30
|
-
animations: AnimationFrames,
|
|
31
|
-
params: any[],
|
|
32
|
-
data: TextureOptionsMerging
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export class Animation extends Sprite {
|
|
36
|
-
private _attachTo: RpgComponent | undefined
|
|
37
|
-
public hitbox: { w: number, h: number }
|
|
38
|
-
public applyTransform: (
|
|
39
|
-
frame: FrameOptionsMerging,
|
|
40
|
-
data: TextureOptionsMerging,
|
|
41
|
-
spritesheet: SpritesheetOptionsMerging
|
|
42
|
-
) => Partial<FrameOptionsMerging>
|
|
43
|
-
private spritesheet: SpritesheetOptionsMerging
|
|
44
|
-
private currentAnimation: AnimationDataFrames | null = null
|
|
45
|
-
private time: number = 0
|
|
46
|
-
private frameIndex: number = 0
|
|
47
|
-
private animations: Map<string, AnimationDataFrames> = new Map()
|
|
48
|
-
private _animation$: BehaviorSubject<Sprite | null> = new BehaviorSubject(null as any)
|
|
49
|
-
readonly animation$: Observable<Sprite | null> = this._animation$.asObservable()
|
|
50
|
-
|
|
51
|
-
onFinish: () => void
|
|
52
|
-
|
|
53
|
-
get attachTo(): RpgComponent | undefined {
|
|
54
|
-
return this._attachTo
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
set attachTo(component: RpgComponent | undefined) {
|
|
58
|
-
if (!component) return
|
|
59
|
-
component.animationIsPlaying = true
|
|
60
|
-
this._attachTo = component
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
constructor(public id: string) {
|
|
64
|
-
super()
|
|
65
|
-
this.spritesheet = spritesheets.get(this.id)
|
|
66
|
-
if (!this.spritesheet) {
|
|
67
|
-
throw log(`Impossible to find the ${this.id} spritesheet. Did you put the right name or create the spritesheet?`)
|
|
68
|
-
}
|
|
69
|
-
this.createAnimations()
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private createTextures(options: Required<TextureOptionsMerging>): Texture[][] {
|
|
73
|
-
const { width, height, framesHeight, framesWidth, image, offset } = options
|
|
74
|
-
const { baseTexture } = Texture.from(image)
|
|
75
|
-
const spriteWidth = options.spriteWidth
|
|
76
|
-
const spriteHeight = options.spriteHeight
|
|
77
|
-
const frames: Texture[][] = []
|
|
78
|
-
const offsetX = (offset && offset.x) || 0
|
|
79
|
-
const offsetY = (offset && offset.y) || 0
|
|
80
|
-
for (let i = 0; i < framesHeight; i++) {
|
|
81
|
-
frames[i] = []
|
|
82
|
-
for (let j = 0; j < framesWidth; j++) {
|
|
83
|
-
const rectX = j * spriteWidth + offsetX
|
|
84
|
-
const rectY = i * spriteHeight + offsetY
|
|
85
|
-
if (rectY > height) {
|
|
86
|
-
throw log(`Warning, there is a problem with the height of the "${this.id}" spritesheet. When cutting into frames, the frame exceeds the height of the image.`)
|
|
87
|
-
}
|
|
88
|
-
if (rectX > width) {
|
|
89
|
-
throw log(`Warning, there is a problem with the width of the "${this.id}" spritesheet. When cutting into frames, the frame exceeds the width of the image.`)
|
|
90
|
-
}
|
|
91
|
-
frames[i].push(
|
|
92
|
-
new Texture(baseTexture, new Rectangle(rectX, rectY, spriteWidth, spriteHeight))
|
|
93
|
-
)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return frames
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
private createAnimations() {
|
|
100
|
-
const { textures } = this.spritesheet
|
|
101
|
-
if (!textures) {
|
|
102
|
-
return
|
|
103
|
-
}
|
|
104
|
-
for (let animationName in textures) {
|
|
105
|
-
const props: (keyof TextureOptionsMerging)[] = ['width', 'height', 'framesHeight', 'framesWidth', 'rectWidth', 'rectHeight', 'offset', 'image', 'sound']
|
|
106
|
-
const parentObj = props
|
|
107
|
-
.reduce((prev, val) => ({ ...prev, [val]: this.spritesheet[val] }), {})
|
|
108
|
-
const optionsTextures: TextureOptionsMerging = {
|
|
109
|
-
...parentObj,
|
|
110
|
-
...textures[animationName]
|
|
111
|
-
} as any
|
|
112
|
-
const { rectWidth, width = 0, framesWidth = 1, rectHeight, height = 0, framesHeight = 1 } = optionsTextures
|
|
113
|
-
optionsTextures.spriteWidth = rectWidth ? rectWidth : width / framesWidth
|
|
114
|
-
optionsTextures.spriteHeight = rectHeight ? rectHeight : height / framesHeight
|
|
115
|
-
this.animations.set(animationName, {
|
|
116
|
-
container: new Sprite(),
|
|
117
|
-
frames: this.createTextures(optionsTextures as Required<TextureOptionsMerging>),
|
|
118
|
-
name: animationName,
|
|
119
|
-
animations: textures[animationName].animations,
|
|
120
|
-
params: [],
|
|
121
|
-
data: optionsTextures,
|
|
122
|
-
sprites: []
|
|
123
|
-
})
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
private getSpriteSize(name: 'spriteHeight' | 'spriteWidth'): number {
|
|
128
|
-
return this.animations.get(this.currentAnimation?.name || AnimationEnum.Stand)?.data[name] || 0
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
getSpriteHeight(): number {
|
|
132
|
-
return this.getSpriteSize('spriteHeight')
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
getSpriteWidth(): number {
|
|
136
|
-
return this.getSpriteSize('spriteWidth')
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
has(name: string): boolean {
|
|
140
|
-
return this.animations.has(name)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
get(name: string): AnimationDataFrames {
|
|
144
|
-
return this.animations.get(name) as AnimationDataFrames
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
isPlaying(name?: string): boolean {
|
|
148
|
-
if (!name) return !!this.currentAnimation
|
|
149
|
-
if (this.currentAnimation == null) return false
|
|
150
|
-
return this.currentAnimation.name == name
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
stop() {
|
|
154
|
-
this.currentAnimation = null
|
|
155
|
-
this.parent?.removeChild(this)
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
play(name: string, params: any[] = []) {
|
|
159
|
-
const animParams = this.currentAnimation?.params
|
|
160
|
-
|
|
161
|
-
if (this.isPlaying(name) && arrayEquals(params, animParams || [])) return
|
|
162
|
-
|
|
163
|
-
const animation = this.get(name)
|
|
164
|
-
|
|
165
|
-
if (!animation) {
|
|
166
|
-
throw new Error(`Impossible to play the ${name} animation because it doesn't exist on the ${this.id} spritesheet`)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
this.removeChildren()
|
|
170
|
-
animation.sprites = []
|
|
171
|
-
this.currentAnimation = animation
|
|
172
|
-
this.currentAnimation.params = params
|
|
173
|
-
this.time = 0
|
|
174
|
-
this.frameIndex = 0
|
|
175
|
-
|
|
176
|
-
let animations: any = animation.animations;
|
|
177
|
-
animations = isFunction(animations) ? (animations as Function)(...params) : animations
|
|
178
|
-
|
|
179
|
-
this.currentAnimation.container = new Container()
|
|
180
|
-
|
|
181
|
-
for (let container of (animations as FrameOptionsMerging[][])) {
|
|
182
|
-
const sprite = new Sprite()
|
|
183
|
-
for (let frame of container) {
|
|
184
|
-
this.currentAnimation.sprites.push(frame)
|
|
185
|
-
}
|
|
186
|
-
this.currentAnimation.container.addChild(sprite)
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const sound = this.currentAnimation.data.sound
|
|
190
|
-
|
|
191
|
-
if (sound) {
|
|
192
|
-
RpgSound.get(sound).play()
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
this.addChild(this.currentAnimation.container)
|
|
196
|
-
// Updates immediately to avoid flickering
|
|
197
|
-
this.update(1)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
update(deltaRatio: number) {
|
|
201
|
-
if (!this.isPlaying() || !this.currentAnimation) return
|
|
202
|
-
|
|
203
|
-
const { frames, container, sprites, data } = this.currentAnimation
|
|
204
|
-
let frame = sprites[this.frameIndex]
|
|
205
|
-
const nextFrame = sprites[this.frameIndex + 1]
|
|
206
|
-
|
|
207
|
-
if (this.attachTo) {
|
|
208
|
-
const sprite = this.attachTo
|
|
209
|
-
const pos = sprite?.getPositionsOfGraphic('middle')
|
|
210
|
-
if (pos) {
|
|
211
|
-
container.x = pos.x
|
|
212
|
-
container.y = pos.y
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
for (let _sprite of container.children) {
|
|
217
|
-
const sprite = _sprite as Sprite
|
|
218
|
-
|
|
219
|
-
if (!frame || frame.frameY == undefined || frame.frameX == undefined) {
|
|
220
|
-
continue
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
sprite.texture = frames[frame.frameY][frame.frameX]
|
|
224
|
-
|
|
225
|
-
const getVal = <T extends keyof TransformOptions>(prop: T): TransformOptions[T] | undefined =>
|
|
226
|
-
frame[prop] || data[prop] || this.spritesheet[prop]
|
|
227
|
-
|
|
228
|
-
const applyTransform = <T extends keyof TransformOptionsAsArray>(prop: T): void => {
|
|
229
|
-
const val = getVal<T>(prop)
|
|
230
|
-
if (val) {
|
|
231
|
-
sprite[prop as string].set(...val!)
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function applyTransformValue<T extends keyof TransformOptions>(prop: T);
|
|
236
|
-
function applyTransformValue<T extends keyof TransformOptions>(prop: string, alias: T);
|
|
237
|
-
function applyTransformValue<T extends keyof TransformOptions>(prop: T, alias?: T): void {
|
|
238
|
-
const optionProp = alias || prop
|
|
239
|
-
const val = getVal<T>(optionProp)
|
|
240
|
-
if (val !== undefined) {
|
|
241
|
-
sprite[prop as string] = val
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
if (this.applyTransform) {
|
|
246
|
-
frame = {
|
|
247
|
-
...frame,
|
|
248
|
-
...this.applyTransform(frame, data, this.spritesheet)
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const realSize = getVal<'spriteRealSize'>('spriteRealSize')
|
|
254
|
-
const heightOfSprite = typeof realSize == 'number' ? realSize : realSize?.height
|
|
255
|
-
const widthOfSprite = typeof realSize == 'number' ? realSize : realSize?.width
|
|
256
|
-
|
|
257
|
-
const applyAnchorBySize = () => {
|
|
258
|
-
if (heightOfSprite && this.hitbox) {
|
|
259
|
-
const { spriteWidth, spriteHeight } = data
|
|
260
|
-
const w = ((spriteWidth - this.hitbox.w) / 2) / spriteWidth
|
|
261
|
-
const gap = (spriteHeight - heightOfSprite) / 2
|
|
262
|
-
const h = (spriteHeight - this.hitbox.h - gap) / spriteHeight
|
|
263
|
-
sprite.anchor.set(w, h)
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (frame.sound) {
|
|
268
|
-
RpgSound.get(frame.sound).play()
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
applyAnchorBySize()
|
|
272
|
-
|
|
273
|
-
applyTransform('anchor')
|
|
274
|
-
applyTransform('scale')
|
|
275
|
-
applyTransform('skew')
|
|
276
|
-
applyTransform('pivot')
|
|
277
|
-
|
|
278
|
-
applyTransformValue('alpha', 'opacity')
|
|
279
|
-
applyTransformValue('x')
|
|
280
|
-
applyTransformValue('y')
|
|
281
|
-
applyTransformValue('angle')
|
|
282
|
-
applyTransformValue('rotation')
|
|
283
|
-
applyTransformValue('visible')
|
|
284
|
-
|
|
285
|
-
this._animation$.next({
|
|
286
|
-
spriteWidth: widthOfSprite || sprite.width,
|
|
287
|
-
spriteHeight: heightOfSprite || sprite.height,
|
|
288
|
-
anchor: sprite.anchor,
|
|
289
|
-
width: getVal<any>('spriteWidth'),
|
|
290
|
-
height: getVal<any>('spriteHeight')
|
|
291
|
-
} as any)
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
if (!nextFrame) {
|
|
295
|
-
this.time = 0
|
|
296
|
-
this.frameIndex = 0
|
|
297
|
-
if (this.attachTo) {
|
|
298
|
-
this.attachTo.animationIsPlaying = false
|
|
299
|
-
}
|
|
300
|
-
if (this.onFinish) this.onFinish()
|
|
301
|
-
return
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
this.time += deltaRatio
|
|
305
|
-
|
|
306
|
-
if (this.time >= nextFrame.time) {
|
|
307
|
-
this.frameIndex++
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
package/src/Effects/Spinner.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { RpgClientEngine } from "../RpgClientEngine";
|
|
2
|
-
import { Graphics, Renderer } from "pixi.js";
|
|
3
|
-
|
|
4
|
-
export class SpinnerGraphic extends Graphics {
|
|
5
|
-
constructor(private clientEngine: RpgClientEngine) {
|
|
6
|
-
super()
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
render(renderer: Renderer) {
|
|
10
|
-
super.render(renderer)
|
|
11
|
-
this.rotation += 0.12;
|
|
12
|
-
const percent = Math.abs(Math.sin(Date.now() / 1000))
|
|
13
|
-
this
|
|
14
|
-
.clear()
|
|
15
|
-
.lineStyle(4, 0xffffff, 1)
|
|
16
|
-
.moveTo(40, 0)
|
|
17
|
-
.arc(0, 0, 40, 0, Math.PI * 2 * percent, false)
|
|
18
|
-
}
|
|
19
|
-
}
|