@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
package/src/Scene/Map.ts
DELETED
|
@@ -1,402 +0,0 @@
|
|
|
1
|
-
import { RpgCommonMap, RpgPlugin, HookClient, RpgShape, Utils, RpgCommonPlayer, InjectContext } from '@rpgjs/common'
|
|
2
|
-
import TileMap from '../Tilemap'
|
|
3
|
-
import * as _PixiViewport from 'pixi-viewport'
|
|
4
|
-
import { type Viewport } from 'pixi-viewport'
|
|
5
|
-
import { Scene, SceneObservableData, SceneSpriteLogic } from './Scene'
|
|
6
|
-
import { spritesheets } from '../Sprite/Spritesheets'
|
|
7
|
-
import { RpgSound } from '../Sound/RpgSound'
|
|
8
|
-
import { TiledLayerType, TiledMap } from '@rpgjs/tiled'
|
|
9
|
-
import { RpgComponent } from '../Components/Component'
|
|
10
|
-
import { type CameraOptions } from '@rpgjs/types'
|
|
11
|
-
import { Assets, Container, Point, IRenderer, DisplayObjectEvents, utils, FederatedPointerEvent } from 'pixi.js'
|
|
12
|
-
import { EventLayer } from './EventLayer'
|
|
13
|
-
|
|
14
|
-
interface MapObject extends TiledMap {
|
|
15
|
-
id: number
|
|
16
|
-
sounds: string | string[] | undefined
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// The export was made in this way to ensure compatibility with unit tests (https://github.com/RSamaium/RPG-JS/issues/240)
|
|
20
|
-
const { Viewport: PixiViewport } = _PixiViewport;
|
|
21
|
-
|
|
22
|
-
export class SceneMap extends Scene {
|
|
23
|
-
static readonly EVENTS_LAYER_DEFAULT: string = 'events-layer-default'
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Get the tilemap
|
|
27
|
-
*
|
|
28
|
-
* @prop {PIXI.Container} [tilemap]
|
|
29
|
-
* @memberof RpgSceneMap
|
|
30
|
-
* */
|
|
31
|
-
public tilemap: TileMap
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The viewport of the map
|
|
35
|
-
*
|
|
36
|
-
* It automatically follows the sprite representing the player but you can attach it to something else
|
|
37
|
-
*
|
|
38
|
-
* > Do not change the size of the viewport
|
|
39
|
-
*
|
|
40
|
-
* @prop {PIXI.Viewport} viewport
|
|
41
|
-
* @memberof RpgSceneMap
|
|
42
|
-
* */
|
|
43
|
-
public viewport: Viewport | undefined
|
|
44
|
-
private players: object = {}
|
|
45
|
-
private isLoaded: boolean = false
|
|
46
|
-
private gameMap: RpgCommonMap | undefined
|
|
47
|
-
private eventsLayers: {
|
|
48
|
-
[eventLayerName: string]: Container
|
|
49
|
-
} = {}
|
|
50
|
-
private defaultLayer: Container | undefined
|
|
51
|
-
|
|
52
|
-
shapes = {}
|
|
53
|
-
|
|
54
|
-
constructor(
|
|
55
|
-
protected context: InjectContext,
|
|
56
|
-
private renderer: IRenderer,
|
|
57
|
-
private options: { screenWidth?: number, screenHeight?: number, drawMap?: boolean } = {}
|
|
58
|
-
) {
|
|
59
|
-
super(context)
|
|
60
|
-
if (options.drawMap === undefined) this.options.drawMap = true
|
|
61
|
-
this.onInit()
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
private constructMethods() {
|
|
65
|
-
[
|
|
66
|
-
'getTileIndex',
|
|
67
|
-
'getTileByIndex',
|
|
68
|
-
'getTileOriginPosition',
|
|
69
|
-
'getTileByPosition',
|
|
70
|
-
'getLayerByName'
|
|
71
|
-
].forEach(method => this[method] = (this.gameMap as any)[method].bind(this.gameMap));
|
|
72
|
-
[
|
|
73
|
-
'heightPx',
|
|
74
|
-
'widthPx',
|
|
75
|
-
'zTileHeight',
|
|
76
|
-
'tileHeight',
|
|
77
|
-
'tileWidth',
|
|
78
|
-
'data',
|
|
79
|
-
'layers'
|
|
80
|
-
].forEach(prop => this[prop] = (this.gameMap as any)[prop])
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/** @internal */
|
|
85
|
-
async load(obj: MapObject, prevObj: MapObject, isUpdate = false): Promise<Viewport> {
|
|
86
|
-
let { sounds } = obj
|
|
87
|
-
const { clientEngine } = this.game
|
|
88
|
-
|
|
89
|
-
if (sounds) {
|
|
90
|
-
if (!Utils.isArray(sounds)) sounds = obj.sounds = <string[]>[sounds]
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
this.gameMap = new RpgCommonMap()
|
|
94
|
-
this.gameMap.load(obj)
|
|
95
|
-
this.gameMap.clearCacheTilesets()
|
|
96
|
-
this.constructMethods()
|
|
97
|
-
|
|
98
|
-
RpgCommonMap.bufferClient.set(obj.id, this.gameMap)
|
|
99
|
-
|
|
100
|
-
this.tilemap = new TileMap(this.context, this.gameMap.getData())
|
|
101
|
-
|
|
102
|
-
// TODO: Remove this
|
|
103
|
-
Assets.reset()
|
|
104
|
-
|
|
105
|
-
let nbLoad = 0
|
|
106
|
-
|
|
107
|
-
const objects = this.game.world.getObjectsOfGroup()
|
|
108
|
-
|
|
109
|
-
for (let { object } of Object.values(objects) as any[]) {
|
|
110
|
-
if (Utils.isInstanceOf(object, RpgCommonPlayer) && object) {
|
|
111
|
-
(object as RpgCommonPlayer).updateInVirtualGrid()
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const assets: string[] = []
|
|
116
|
-
for (let tileset of this.tilemap.tilesets) {
|
|
117
|
-
let spritesheet = spritesheets.get(tileset.name)
|
|
118
|
-
if (!spritesheet) {
|
|
119
|
-
clientEngine.addSpriteSheet(tileset.image.source, tileset.name)
|
|
120
|
-
spritesheet = spritesheets.get(tileset.name)
|
|
121
|
-
}
|
|
122
|
-
if (spritesheet?.resource) {
|
|
123
|
-
continue
|
|
124
|
-
}
|
|
125
|
-
Assets.add(tileset.name, spritesheet.image)
|
|
126
|
-
assets.push(tileset.name)
|
|
127
|
-
nbLoad++
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (nbLoad > 0) {
|
|
131
|
-
const assetsLoaded = await Assets.load(assets)
|
|
132
|
-
for (let assetName in assetsLoaded) {
|
|
133
|
-
const spritesheet = spritesheets.get(assetName)
|
|
134
|
-
if (spritesheet) spritesheet.resource = assetsLoaded[assetName]
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
RpgPlugin.emit(HookClient.SceneMapLoading, Assets)
|
|
139
|
-
|
|
140
|
-
this.tilemap.load({
|
|
141
|
-
drawTiles: this.options.drawMap,
|
|
142
|
-
isUpdate
|
|
143
|
-
})
|
|
144
|
-
this.viewport = new PixiViewport({
|
|
145
|
-
screenWidth: this.options.screenWidth,
|
|
146
|
-
screenHeight: this.options.screenHeight,
|
|
147
|
-
worldWidth: obj.width * obj.tilewidth,
|
|
148
|
-
worldHeight: obj.height * obj.tileheight,
|
|
149
|
-
noTicker: true,
|
|
150
|
-
events: this.renderer.events
|
|
151
|
-
})
|
|
152
|
-
this.tilemap.addChild(this.animationLayer)
|
|
153
|
-
this.viewport.clamp({ direction: 'all' })
|
|
154
|
-
this.viewport.addChild(this.tilemap, ...this.createEventLayers(obj))
|
|
155
|
-
this.isLoaded = true
|
|
156
|
-
if (prevObj.sounds && prevObj.sounds instanceof Array) {
|
|
157
|
-
prevObj.sounds.forEach(soundId => {
|
|
158
|
-
const continueSound = (<string[]>obj.sounds || []).find(id => id == soundId)
|
|
159
|
-
if (!continueSound) RpgSound.stop(soundId)
|
|
160
|
-
})
|
|
161
|
-
}
|
|
162
|
-
if (sounds) (<string[]>sounds).forEach(soundId => RpgSound.play(soundId))
|
|
163
|
-
if (this.onLoad) this.onLoad()
|
|
164
|
-
|
|
165
|
-
return this.viewport
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
createEventLayers(map: MapObject): Container[] {
|
|
169
|
-
const containers: Container[] = []
|
|
170
|
-
map.layers.forEach((layerData) => {
|
|
171
|
-
if (layerData.type !== TiledLayerType.ObjectGroup) return
|
|
172
|
-
if (this.eventsLayers[layerData.name]) {
|
|
173
|
-
containers.push(this.eventsLayers[layerData.name])
|
|
174
|
-
return
|
|
175
|
-
}
|
|
176
|
-
const layer = new EventLayer()
|
|
177
|
-
this.defaultLayer = this.eventsLayers[layerData.name] = layer
|
|
178
|
-
containers.push(layer)
|
|
179
|
-
})
|
|
180
|
-
if (containers.length == 0) {
|
|
181
|
-
if (!this.defaultLayer) {
|
|
182
|
-
this.defaultLayer = new EventLayer()
|
|
183
|
-
}
|
|
184
|
-
containers.push(this.defaultLayer)
|
|
185
|
-
}
|
|
186
|
-
this.cameraFollowSprite(this.game.playerId)
|
|
187
|
-
return containers
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
getEventLayer(objectName?: string): Container | undefined {
|
|
191
|
-
for (let layerData of this.data.layers) {
|
|
192
|
-
if (layerData.type != TiledLayerType.ObjectGroup) {
|
|
193
|
-
continue
|
|
194
|
-
}
|
|
195
|
-
if (!layerData.objects) {
|
|
196
|
-
continue
|
|
197
|
-
}
|
|
198
|
-
for (let object of layerData.objects) {
|
|
199
|
-
if (object.name == objectName) {
|
|
200
|
-
return this.eventsLayers[layerData.name]
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return this.defaultLayer
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/** @internal */
|
|
208
|
-
changeTile(x: number, y: number, layers: {
|
|
209
|
-
[layerName: string]: object
|
|
210
|
-
}) {
|
|
211
|
-
for (let layerName in layers) {
|
|
212
|
-
const layerInfo = layers[layerName]
|
|
213
|
-
this.gameMap?.setTile(x, y, layerName, layerInfo)
|
|
214
|
-
this.tilemap.changeTile(x, y, layerName)
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/** @internal */
|
|
219
|
-
draw(t: number, deltaTime: number, deltaRatio: number, frame: number) {
|
|
220
|
-
if (!this.isLoaded) {
|
|
221
|
-
return
|
|
222
|
-
}
|
|
223
|
-
super.draw(t, deltaTime, deltaRatio, frame)
|
|
224
|
-
this.tilemap.drawAnimateTile(frame)
|
|
225
|
-
this.viewport?.update(deltaTime)
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// @internal
|
|
229
|
-
updateTilesOverlayAllSprites() {
|
|
230
|
-
const objects = this.objects
|
|
231
|
-
for (let [id, sprite] of objects) {
|
|
232
|
-
this.updateTilesOverlay(sprite)
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
private updateTilesOverlay(sprite: RpgComponent) {
|
|
237
|
-
if (!this.gameMap) return sprite
|
|
238
|
-
const { tileWidth, tileHeight } = this.gameMap
|
|
239
|
-
const { tilesOverlay }: any = sprite
|
|
240
|
-
const bounds = sprite.parent.getLocalBounds()
|
|
241
|
-
const width = Math.ceil(bounds.width / tileWidth) * tileWidth
|
|
242
|
-
const height = Math.ceil(bounds.height / tileHeight) * tileHeight
|
|
243
|
-
const _x = bounds.x
|
|
244
|
-
const _y = bounds.y
|
|
245
|
-
|
|
246
|
-
const addTile = (x, y) => {
|
|
247
|
-
const tiles = this.tilemap.createOverlayTiles(x, y, sprite)
|
|
248
|
-
if (tiles.length) tilesOverlay.addChild(...tiles)
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
tilesOverlay.removeChildren()
|
|
252
|
-
|
|
253
|
-
for (let i = _x; i <= _x + width; i += tileWidth) {
|
|
254
|
-
for (let j = _y; j <= _y + height; j += tileHeight) {
|
|
255
|
-
addTile(i, j)
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
return sprite
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
onUpdateObject(logic: SceneSpriteLogic, sprite: RpgComponent, moving: boolean): RpgComponent {
|
|
262
|
-
const { paramsChanged } = logic
|
|
263
|
-
if (!this.gameMap) return sprite
|
|
264
|
-
if (moving || (paramsChanged && (paramsChanged.width || paramsChanged.height))) {
|
|
265
|
-
this.updateTilesOverlay(sprite)
|
|
266
|
-
}
|
|
267
|
-
return sprite
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/** @internal */
|
|
271
|
-
setPlayerPosition(id: string, { x, y }: { x: number, y: number }) {
|
|
272
|
-
this.players[id].x = x
|
|
273
|
-
this.players[id].y = y
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/** @internal */
|
|
277
|
-
updateScene(obj: SceneObservableData) { }
|
|
278
|
-
|
|
279
|
-
addObject(obj: RpgCommonPlayer | RpgShape, id: string): RpgComponent {
|
|
280
|
-
const wrapper = new Container()
|
|
281
|
-
const inner = new Container()
|
|
282
|
-
const tilesOverlay = new Container()
|
|
283
|
-
const component = new RpgComponent(obj, this)
|
|
284
|
-
|
|
285
|
-
component.tilesOverlay = tilesOverlay
|
|
286
|
-
inner.addChild(component)
|
|
287
|
-
wrapper.addChild(inner, tilesOverlay)
|
|
288
|
-
|
|
289
|
-
this.objects.set(id, component)
|
|
290
|
-
this.getEventLayer(obj.id)?.addChild(wrapper)
|
|
291
|
-
if (component.isCurrentPlayer) this.cameraFollowSprite(id)
|
|
292
|
-
component.onInit()
|
|
293
|
-
return component
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
removeObject(id: string) {
|
|
297
|
-
let sprite = this.objects.get(id)
|
|
298
|
-
if (sprite) {
|
|
299
|
-
if (!sprite.animationIsPlaying) {
|
|
300
|
-
this.objects.delete(id)
|
|
301
|
-
RpgPlugin.emit(HookClient.SceneRemoveSprite, [this, sprite], true)
|
|
302
|
-
RpgPlugin.emit(HookClient.RemoveSprite, sprite)
|
|
303
|
-
sprite.destroy()
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
sprite.visible = false
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
getShape(name: string): RpgShape | undefined {
|
|
312
|
-
return this.game.getShape(name)?.object
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
getShapes(): RpgShape[] {
|
|
316
|
-
const shapes = Object.values(this.game.getShapes())
|
|
317
|
-
return shapes.map(shape => shape.object)
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
cameraFollowSprite(id: string, options: CameraOptions = {}) {
|
|
321
|
-
const sprite = this.getSprite(id)
|
|
322
|
-
const follow = () => {
|
|
323
|
-
if (sprite) this.viewport?.follow(sprite)
|
|
324
|
-
}
|
|
325
|
-
if (options.smoothMove) {
|
|
326
|
-
this.viewport?.plugins.remove('follow')
|
|
327
|
-
let moreOptions = {}
|
|
328
|
-
if (typeof options.smoothMove != 'boolean') {
|
|
329
|
-
moreOptions = options.smoothMove
|
|
330
|
-
}
|
|
331
|
-
this.viewport?.animate({
|
|
332
|
-
position: new Point(sprite?.x, sprite?.y),
|
|
333
|
-
...moreOptions,
|
|
334
|
-
callbackOnComplete: follow
|
|
335
|
-
})
|
|
336
|
-
}
|
|
337
|
-
else {
|
|
338
|
-
follow()
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* Listen to the events of the smile on the stage
|
|
344
|
-
*
|
|
345
|
-
* @title Listen mouse event
|
|
346
|
-
* @method on(eventName,callback)
|
|
347
|
-
* @since 3.0.0-beta.4
|
|
348
|
-
* @param {string} eventName Name of the event (see PIXI documentation). Name often used in the codes
|
|
349
|
-
* - click
|
|
350
|
-
* - mousedown
|
|
351
|
-
* - mouseup
|
|
352
|
-
* - mousemove
|
|
353
|
-
* - pointerdown
|
|
354
|
-
* - pointermove
|
|
355
|
-
* - pointerup
|
|
356
|
-
* - (etc...)
|
|
357
|
-
* @param {(position: { x: number, y: number }, ev?: PIXI.InteractionEvent ) => any} callback
|
|
358
|
-
* @example
|
|
359
|
-
* ```ts
|
|
360
|
-
* sceneMap.on('pointerdown', (position) => {
|
|
361
|
-
* console.log(position)
|
|
362
|
-
* })
|
|
363
|
-
* ```
|
|
364
|
-
* @returns {void}
|
|
365
|
-
* @memberof RpgSceneMap
|
|
366
|
-
*/
|
|
367
|
-
on(eventName: keyof DisplayObjectEvents, cb: (position: { x: number, y: number }, ev?: any) => any) {
|
|
368
|
-
if (!this.viewport) return
|
|
369
|
-
this.viewport.eventMode = 'static'
|
|
370
|
-
this.viewport.on(eventName, (...args) => {
|
|
371
|
-
const ev: FederatedPointerEvent = args[0] as any
|
|
372
|
-
const pos = ev.getLocalPosition(this.viewport as Viewport)
|
|
373
|
-
if (ev.defaultPrevented) return
|
|
374
|
-
cb(pos, ev)
|
|
375
|
-
})
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
export interface SceneMap {
|
|
380
|
-
data: any;
|
|
381
|
-
tileWidth: number;
|
|
382
|
-
tileHeight: number;
|
|
383
|
-
layers: any[];
|
|
384
|
-
widthPx: number;
|
|
385
|
-
heightPx: number;
|
|
386
|
-
zTileHeight: number
|
|
387
|
-
getShapes(): RpgShape[];
|
|
388
|
-
getShape(name: string): RpgShape | undefined;
|
|
389
|
-
getPositionByShape(filter: (shape: RpgShape) => {}): {
|
|
390
|
-
x: number;
|
|
391
|
-
y: number;
|
|
392
|
-
z: number;
|
|
393
|
-
} | null;
|
|
394
|
-
getTileIndex(x: number, y: number, [z]?: [number]): number;
|
|
395
|
-
getTileByIndex(tileIndex: number, zPlayer?: [number, number]): any;
|
|
396
|
-
getTileOriginPosition(x: number, y: number): {
|
|
397
|
-
x: number;
|
|
398
|
-
y: number;
|
|
399
|
-
};
|
|
400
|
-
getTileByPosition(x: number, y: number, z?: [number, number]): any;
|
|
401
|
-
getLayerByName(name: string): any
|
|
402
|
-
}
|
package/src/Scene/Scene.ts
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
import { RpgPlugin, HookClient, DefaultInput, InjectContext } from '@rpgjs/common'
|
|
2
|
-
import { KeyboardControls } from '../KeyboardControls'
|
|
3
|
-
import RpgSprite from '../Sprite/Character'
|
|
4
|
-
import { Animation } from '../Effects/Animation'
|
|
5
|
-
import { BehaviorSubject, Observable, Subject } from 'rxjs'
|
|
6
|
-
import { GameEngineClient } from '../GameEngine'
|
|
7
|
-
import { RpgComponent } from '../Components/Component'
|
|
8
|
-
import { Controls } from '@rpgjs/types'
|
|
9
|
-
import { Container } from 'pixi.js'
|
|
10
|
-
import { RpgGui } from '../Gui/Gui'
|
|
11
|
-
|
|
12
|
-
export type SceneObservableData = {
|
|
13
|
-
data: {
|
|
14
|
-
[key: string]: any
|
|
15
|
-
},
|
|
16
|
-
partial: {
|
|
17
|
-
[key: string]: any
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface SceneSpriteLogic {
|
|
22
|
-
paramsChanged: {
|
|
23
|
-
[key: string]: any
|
|
24
|
-
} | null,
|
|
25
|
-
prevParamsChanged: object
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export abstract class Scene {
|
|
29
|
-
protected objects: Map<string, RpgComponent> = new Map()
|
|
30
|
-
protected animationLayer: Container = new Container()
|
|
31
|
-
|
|
32
|
-
private controls: KeyboardControls = this.context.inject(KeyboardControls)
|
|
33
|
-
private animations: Animation[] = []
|
|
34
|
-
|
|
35
|
-
private _data: BehaviorSubject<SceneObservableData> = new BehaviorSubject({
|
|
36
|
-
data: {},
|
|
37
|
-
partial: {}
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @deprecated Use `inject(GameEngineClient)` instead. Will be removed in v5
|
|
42
|
-
*/
|
|
43
|
-
public game: GameEngineClient = this.context.inject(GameEngineClient)
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Listen to the movement of objects on stage
|
|
47
|
-
*
|
|
48
|
-
* @prop {Observable<{ [key: string]: object }>} [objectsMoving]
|
|
49
|
-
* @readonly
|
|
50
|
-
* @memberof RpgScene
|
|
51
|
-
* @since v4.1.0
|
|
52
|
-
*
|
|
53
|
-
* In <module>/scene-map.ts
|
|
54
|
-
*
|
|
55
|
-
* ```ts
|
|
56
|
-
* import { RpgSceneMap } from '@rpgjs/client'
|
|
57
|
-
*
|
|
58
|
-
* export default {
|
|
59
|
-
* onAfterLoading(scene: RpgSceneMap) {
|
|
60
|
-
* scene.objectsMoving.subscribe((objects) => {
|
|
61
|
-
* console.log(objects)
|
|
62
|
-
* })
|
|
63
|
-
* }
|
|
64
|
-
* }
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
public readonly objectsMoving: Subject<{
|
|
68
|
-
[key: string]: any
|
|
69
|
-
}> = new Subject()
|
|
70
|
-
|
|
71
|
-
constructor(protected context: InjectContext) {
|
|
72
|
-
const { globalConfig } = this.game.clientEngine
|
|
73
|
-
const mergeInputs = {
|
|
74
|
-
...DefaultInput,
|
|
75
|
-
...(globalConfig.inputs || {})
|
|
76
|
-
}
|
|
77
|
-
this.controls.setInputs(this.inputs || mergeInputs)
|
|
78
|
-
RpgGui._setSceneReady(this)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Listen to all the synchronized values of the scene with the server
|
|
83
|
-
*
|
|
84
|
-
* ```ts
|
|
85
|
-
* import { RpgClient, RpgModule, RpgSceneMap } from '@rpgjs/client'
|
|
86
|
-
*
|
|
87
|
-
* @RpgModule<RpgClient>({
|
|
88
|
-
scenes: {
|
|
89
|
-
map: {
|
|
90
|
-
onAfterLoading(scene: RpgSceneMap) {
|
|
91
|
-
scene.valuesChange.subscribe((obj) => {
|
|
92
|
-
console.log(obj.data, obj.partial)
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
})
|
|
98
|
-
export default class RpgClientModuleEngine {}
|
|
99
|
-
* ```
|
|
100
|
-
*
|
|
101
|
-
* - `data` represents all the current data of the scene (`users`, `events` and others)
|
|
102
|
-
* - `partial` represents only the data that has changed on the scene
|
|
103
|
-
*
|
|
104
|
-
* > In the class, you can also use the onChanges hook
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* @prop {Observable<{ data: object, partial: object }>} [valuesChange]
|
|
108
|
-
* @readonly
|
|
109
|
-
* @memberof RpgScene
|
|
110
|
-
*/
|
|
111
|
-
get valuesChange(): Observable<SceneObservableData> {
|
|
112
|
-
return this._data.asObservable()
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
private triggerSpriteChanges(logic: SceneSpriteLogic, sprite: RpgComponent, moving: boolean) {
|
|
116
|
-
if (this.onUpdateObject) this.onUpdateObject(logic, sprite, moving)
|
|
117
|
-
RpgPlugin.emit(HookClient.UpdateSprite, [sprite, logic], true)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** @internal */
|
|
121
|
-
update(obj?: SceneObservableData) {
|
|
122
|
-
if (!obj) {
|
|
123
|
-
this.updateScene(this._data.value)
|
|
124
|
-
return
|
|
125
|
-
}
|
|
126
|
-
this.updateScene(obj)
|
|
127
|
-
RpgPlugin.emit(HookClient.SceneOnChanges, [this, obj], true)
|
|
128
|
-
this._data.next(obj)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/** @internal */
|
|
132
|
-
draw(time: number, deltaTime: number, deltaRatio: number, frame: number) {
|
|
133
|
-
const logicObjects = {
|
|
134
|
-
...this.game.world.getObjects(),
|
|
135
|
-
...this.game.events,
|
|
136
|
-
...this.game.getShapes()
|
|
137
|
-
}
|
|
138
|
-
const renderObjects = this.objects
|
|
139
|
-
const sizeLogic = Object.values(logicObjects).length
|
|
140
|
-
const objectMoving = {}
|
|
141
|
-
for (let key in logicObjects) {
|
|
142
|
-
const val: any = logicObjects[key].object
|
|
143
|
-
const valueChanged = logicObjects[key].paramsChanged
|
|
144
|
-
if (!renderObjects.has(key)) {
|
|
145
|
-
const sprite = this.addObject(val, key)
|
|
146
|
-
this.triggerSpriteChanges(val, sprite, true)
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
const object = renderObjects.get(key)
|
|
150
|
-
if (!object?.update) return
|
|
151
|
-
const ret = object.update(val, valueChanged, time, deltaRatio)
|
|
152
|
-
this.triggerSpriteChanges(val, object, ret.moving)
|
|
153
|
-
if (ret.moving) objectMoving[val.id] = val
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
if (sizeLogic < renderObjects.size) {
|
|
157
|
-
renderObjects.forEach((val, key) => {
|
|
158
|
-
if (!logicObjects[key]) {
|
|
159
|
-
this.removeObject(key)
|
|
160
|
-
}
|
|
161
|
-
})
|
|
162
|
-
}
|
|
163
|
-
for (let animation of this.animations) {
|
|
164
|
-
animation.update(deltaRatio)
|
|
165
|
-
}
|
|
166
|
-
this.onDraw(time)
|
|
167
|
-
if (Object.values(objectMoving).length) {
|
|
168
|
-
this.objectsMoving.next(objectMoving)
|
|
169
|
-
}
|
|
170
|
-
RpgPlugin.emit(HookClient.SceneDraw, this)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
abstract onUpdateObject(logic: SceneSpriteLogic, sprite: RpgComponent, moving: boolean): void
|
|
174
|
-
abstract addObject(obj, id: string): RpgComponent
|
|
175
|
-
abstract removeObject(id: string)
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Display an animation on the scene
|
|
179
|
-
*
|
|
180
|
-
* The object is the following:
|
|
181
|
-
* * `graphic`: Spritesheet id
|
|
182
|
-
* * `animationName`: The name of the animation
|
|
183
|
-
* * `attachTo`: Define a sprite. The animation will follow this sprite (optional)
|
|
184
|
-
* * `x`: Position X (0 by default)
|
|
185
|
-
* * `y`: Position Y (0 by default)
|
|
186
|
-
* * `loop`: Display the animation in a loop (false by default)
|
|
187
|
-
*
|
|
188
|
-
* ```ts
|
|
189
|
-
* import { RpgClient, RpgModule, RpgSceneMap } from '@rpgjs/client'
|
|
190
|
-
*
|
|
191
|
-
|
|
192
|
-
* @RpgModule<RpgClient>({
|
|
193
|
-
scenes: {
|
|
194
|
-
map: {
|
|
195
|
-
onAfterLoading(scene: RpgSceneMap) {
|
|
196
|
-
const animation = scene.showAnimation({
|
|
197
|
-
graphic: 'my-spritesheet',
|
|
198
|
-
animationName: 'my-anim'
|
|
199
|
-
})
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
})
|
|
204
|
-
export default class RpgClientModuleEngine {}
|
|
205
|
-
* ```
|
|
206
|
-
*
|
|
207
|
-
* The return is an animation containing two methods:
|
|
208
|
-
* * `play()`: Play the animation (Already the case when calling the method)
|
|
209
|
-
* * `stop()`: Stop the animation
|
|
210
|
-
*
|
|
211
|
-
* They have a hook:
|
|
212
|
-
*
|
|
213
|
-
* `onFinish`: Triggered when the animation is finished
|
|
214
|
-
*
|
|
215
|
-
* ```ts
|
|
216
|
-
* animation.onFinish = () => {
|
|
217
|
-
* console.log('finish !')
|
|
218
|
-
* }
|
|
219
|
-
* ```
|
|
220
|
-
*
|
|
221
|
-
* @title Show Animation
|
|
222
|
-
* @method scene.showAnimation(object)
|
|
223
|
-
* @param {object} object
|
|
224
|
-
* @returns {Animation}
|
|
225
|
-
* @memberof RpgScene
|
|
226
|
-
*/
|
|
227
|
-
showAnimation({
|
|
228
|
-
graphic,
|
|
229
|
-
animationName,
|
|
230
|
-
attachTo,
|
|
231
|
-
x = 0,
|
|
232
|
-
y = 0,
|
|
233
|
-
loop = false,
|
|
234
|
-
replaceGraphic = false
|
|
235
|
-
}: {
|
|
236
|
-
graphic: string,
|
|
237
|
-
animationName: string,
|
|
238
|
-
attachTo?: RpgComponent,
|
|
239
|
-
x?: number,
|
|
240
|
-
y?: number,
|
|
241
|
-
loop?: boolean,
|
|
242
|
-
replaceGraphic?: boolean
|
|
243
|
-
}): Animation | undefined {
|
|
244
|
-
if (replaceGraphic && attachTo) {
|
|
245
|
-
attachTo.showAnimation(graphic, animationName)
|
|
246
|
-
return
|
|
247
|
-
}
|
|
248
|
-
const animation = new Animation(graphic)
|
|
249
|
-
this.animationLayer.addChild(animation)
|
|
250
|
-
if (!loop) {
|
|
251
|
-
animation.onFinish = () => {
|
|
252
|
-
animation.stop()
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
if (attachTo) {
|
|
256
|
-
animation.attachTo = attachTo
|
|
257
|
-
}
|
|
258
|
-
else {
|
|
259
|
-
animation.x = x
|
|
260
|
-
animation.y = y
|
|
261
|
-
}
|
|
262
|
-
animation.play(animationName)
|
|
263
|
-
this.animations.push(animation)
|
|
264
|
-
return animation
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Retrieve a sprite according to its identifier
|
|
269
|
-
*
|
|
270
|
-
* @title Get Sprite
|
|
271
|
-
* @method scene.getSprite(id)
|
|
272
|
-
* @param {string} id
|
|
273
|
-
* @returns {RpgSprite | undefined}
|
|
274
|
-
* @memberof RpgScene
|
|
275
|
-
*/
|
|
276
|
-
getSprite(id: string) { return this.getPlayer(id) }
|
|
277
|
-
getPlayer(id: string): RpgComponent | undefined {
|
|
278
|
-
return this.objects.get(id)
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Retrieve a sprite that the player controls
|
|
283
|
-
*
|
|
284
|
-
* @title Get Current Player
|
|
285
|
-
* @method scene.getCurrentPlayer()
|
|
286
|
-
* @returns {RpgSprite | undefined}
|
|
287
|
-
* @memberof RpgScene
|
|
288
|
-
*/
|
|
289
|
-
getCurrentPlayer(): RpgSprite | RpgComponent | undefined {
|
|
290
|
-
return this.objects.get(this.game.playerId)
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
// Hooks
|
|
294
|
-
onInit() {}
|
|
295
|
-
onLoad() {}
|
|
296
|
-
onChanges(obj) {}
|
|
297
|
-
onDraw(t: number) {}
|
|
298
|
-
onAddSprite(sprite: RpgSprite) {}
|
|
299
|
-
onRemoveSprite(sprite: RpgSprite) {}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
export interface Scene {
|
|
303
|
-
inputs: Controls,
|
|
304
|
-
updateScene(obj: SceneObservableData)
|
|
305
|
-
}
|