@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
package/src/GameEngine.ts
DELETED
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import { RpgCommonGame, RpgCommonPlayer, GameSide, RpgShape } from "@rpgjs/common";
|
|
2
|
-
import { BehaviorSubject, combineLatest, Observable, Subject, map } from "rxjs";
|
|
3
|
-
import { RpgRenderer } from "./Renderer";
|
|
4
|
-
import { RpgClientEngine } from "./RpgClientEngine";
|
|
5
|
-
import { LayoutObject, ObjectFixture, ObjectFixtureList } from "@rpgjs/types";
|
|
6
|
-
|
|
7
|
-
export class GameEngineClient extends RpgCommonGame {
|
|
8
|
-
playerId: string
|
|
9
|
-
standalone: boolean
|
|
10
|
-
clientEngine: RpgClientEngine
|
|
11
|
-
renderer: RpgRenderer
|
|
12
|
-
|
|
13
|
-
private _objects: BehaviorSubject<ObjectFixtureList> = new BehaviorSubject({})
|
|
14
|
-
private _obsObjects: {
|
|
15
|
-
[id: string]: BehaviorSubject<ObjectFixture>
|
|
16
|
-
} = {}
|
|
17
|
-
private _obsObjectsDeleteNotifier$: {
|
|
18
|
-
[id: string]: Subject<void>
|
|
19
|
-
} = {}
|
|
20
|
-
private _shapes: BehaviorSubject<ObjectFixtureList> = new BehaviorSubject({})
|
|
21
|
-
private _objectsChanged: BehaviorSubject<ObjectFixtureList> = new BehaviorSubject({})
|
|
22
|
-
|
|
23
|
-
world = {
|
|
24
|
-
getObjects: this.getObjects.bind(this),
|
|
25
|
-
getObject: (id: string): RpgCommonPlayer | null => {
|
|
26
|
-
const obj = this.getObject(id)
|
|
27
|
-
if (!obj) return null
|
|
28
|
-
return obj.object
|
|
29
|
-
},
|
|
30
|
-
getShape: (id: string): RpgShape | null => {
|
|
31
|
-
const obj = this.getShape(id)
|
|
32
|
-
if (!obj) return null
|
|
33
|
-
return obj.object
|
|
34
|
-
},
|
|
35
|
-
getAll: (id: string): RpgCommonPlayer | RpgShape | null => {
|
|
36
|
-
const obj = this.getObjectAndShape(id)
|
|
37
|
-
if (!obj) return null
|
|
38
|
-
return obj.object
|
|
39
|
-
},
|
|
40
|
-
removeObject: this.removeObject.bind(this),
|
|
41
|
-
getObjectsOfGroup: () => {
|
|
42
|
-
return {
|
|
43
|
-
...this.getObjects(),
|
|
44
|
-
...this.events
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
getShapesOfGroup: () => {
|
|
48
|
-
return this.getShapes()
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
initialize() {
|
|
53
|
-
super.initialize(GameSide.Client)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
private _get(prop: '_objects' | '_shapes', id: string): ObjectFixture | null {
|
|
57
|
-
const objects = this[prop].value
|
|
58
|
-
const val = objects[id]
|
|
59
|
-
if (!val) return null
|
|
60
|
-
return val
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
get objectsChanged(): Observable<{ [id: string]: ObjectFixture }> {
|
|
64
|
-
return this._objectsChanged.asObservable()
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
setObjectsChanged(val: {
|
|
68
|
-
[playerId: string]: ObjectFixture
|
|
69
|
-
}) {
|
|
70
|
-
this._objectsChanged.next(val)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
listenObject(id: string): Observable<ObjectFixture> {
|
|
74
|
-
return this._obsObjects[id].asObservable()
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
get objects(): Observable<{ [id: string]: ObjectFixture }> {
|
|
78
|
-
return this._objects.asObservable()
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
get shapes(): Observable<{ [id: string]: ObjectFixture }> {
|
|
82
|
-
return this._shapes.asObservable()
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
get all(): Observable<{ [id: string]: ObjectFixture }> {
|
|
86
|
-
return combineLatest([
|
|
87
|
-
this.objects,
|
|
88
|
-
this.shapes
|
|
89
|
-
]).pipe(
|
|
90
|
-
map(([objects, shapes]) => {
|
|
91
|
-
return {
|
|
92
|
-
...objects,
|
|
93
|
-
...shapes
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
getShapes(): { [id: string]: ObjectFixture } {
|
|
100
|
-
return this._shapes.value
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
getObjects(): { [id: string]: ObjectFixture } {
|
|
104
|
-
return this._objects.value
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
getObject(id: string): ObjectFixture | null {
|
|
108
|
-
return this._get('_objects', id)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
getShape(id: string): ObjectFixture | null {
|
|
112
|
-
return this._get('_shapes', id)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
getObjectAndShape(id: string): ObjectFixture | null {
|
|
116
|
-
let obj = this.getObject(id)
|
|
117
|
-
if (!obj) obj = this.getShape(id)
|
|
118
|
-
return obj
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
resetObjects() {
|
|
122
|
-
for (let id in this._obsObjectsDeleteNotifier$) {
|
|
123
|
-
this._obsObjectsDeleteNotifier$[id].next()
|
|
124
|
-
this._obsObjectsDeleteNotifier$[id].complete()
|
|
125
|
-
this._obsObjects[id].complete()
|
|
126
|
-
}
|
|
127
|
-
this._obsObjectsDeleteNotifier$ = {}
|
|
128
|
-
this._obsObjects = {}
|
|
129
|
-
this._objects.next({})
|
|
130
|
-
this._shapes.next({})
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
getDeleteNotifier(id: string): Observable<void> {
|
|
134
|
-
return this._obsObjectsDeleteNotifier$[id].asObservable()
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
private _remove(prop: '_objects' | '_shapes', id: string) {
|
|
138
|
-
const logic = prop == '_objects' ? this.getObject(id) : this.getShape(id)
|
|
139
|
-
if (logic) {
|
|
140
|
-
const objects = { ...this[prop].value } // clone
|
|
141
|
-
delete objects[id]
|
|
142
|
-
this._obsObjectsDeleteNotifier$[id].next()
|
|
143
|
-
this._obsObjectsDeleteNotifier$[id].complete()
|
|
144
|
-
this._obsObjects[id].complete()
|
|
145
|
-
delete this._obsObjects[id]
|
|
146
|
-
delete this._obsObjectsDeleteNotifier$[id]
|
|
147
|
-
this[prop].next(objects)
|
|
148
|
-
return true
|
|
149
|
-
}
|
|
150
|
-
return false
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
removeObject(id: string): boolean {
|
|
154
|
-
if (this.events[id]) {
|
|
155
|
-
delete this.events[id]
|
|
156
|
-
}
|
|
157
|
-
return this._remove('_objects', id)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
removeShape(id: string): boolean {
|
|
161
|
-
return this._remove('_shapes', id)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
removeObjectAndShape(id: string): boolean {
|
|
165
|
-
let bool = this.removeObject(id)
|
|
166
|
-
if (!bool) bool = this.removeShape(id)
|
|
167
|
-
return bool
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
static toArray(obj: any, prop: string) {
|
|
171
|
-
if (obj[prop]) obj[prop] = Object.values(obj[prop])
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
updateObject(obj) {
|
|
175
|
-
const {
|
|
176
|
-
playerId: id,
|
|
177
|
-
params,
|
|
178
|
-
localEvent,
|
|
179
|
-
paramsChanged,
|
|
180
|
-
isShape
|
|
181
|
-
} = obj
|
|
182
|
-
if (paramsChanged.components) {
|
|
183
|
-
paramsChanged.layout = {
|
|
184
|
-
center: {
|
|
185
|
-
lines: [
|
|
186
|
-
{
|
|
187
|
-
col: paramsChanged.components
|
|
188
|
-
}
|
|
189
|
-
]
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
const layoutToArray = (params) => {
|
|
194
|
-
const layout = params.layout as LayoutObject<any> | undefined
|
|
195
|
-
if (layout) {
|
|
196
|
-
['center', 'top', 'right', 'bottom', 'left'].forEach((key) => {
|
|
197
|
-
if (!layout[key]) return
|
|
198
|
-
GameEngineClient.toArray(layout[key], 'lines')
|
|
199
|
-
if (!layout[key].lines) return
|
|
200
|
-
layout[key].lines.map(layout => {
|
|
201
|
-
GameEngineClient.toArray(layout, 'col')
|
|
202
|
-
})
|
|
203
|
-
})
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
layoutToArray(params)
|
|
207
|
-
GameEngineClient.toArray(params, 'polygon')
|
|
208
|
-
const isMe = () => id == this.playerId
|
|
209
|
-
let logic
|
|
210
|
-
let teleported = false
|
|
211
|
-
let propName = '_objects'
|
|
212
|
-
|
|
213
|
-
const createObsForObject = (data) => {
|
|
214
|
-
this._obsObjectsDeleteNotifier$[id] = new Subject()
|
|
215
|
-
this._obsObjects[id] = new BehaviorSubject(data)
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (isShape) {
|
|
219
|
-
propName = '_shapes'
|
|
220
|
-
logic = this.world.getShape(id)
|
|
221
|
-
if (!logic) {
|
|
222
|
-
logic = this.addShape(params)
|
|
223
|
-
createObsForObject({ logic })
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
if (localEvent) {
|
|
228
|
-
logic = this.events[id]
|
|
229
|
-
if (!logic) {
|
|
230
|
-
logic = this.addEvent(RpgCommonPlayer, id)
|
|
231
|
-
createObsForObject({ logic })
|
|
232
|
-
this.events[id] = {
|
|
233
|
-
object: logic
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
logic = logic.object
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
logic = this.world.getObject(id)
|
|
242
|
-
}
|
|
243
|
-
if (!logic) {
|
|
244
|
-
logic = this.addPlayer(RpgCommonPlayer, id)
|
|
245
|
-
createObsForObject({ logic })
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
logic.prevParamsChanged = Object.assign({}, logic)
|
|
249
|
-
for (let key in params) {
|
|
250
|
-
if (!localEvent &&
|
|
251
|
-
(key == 'position' ||
|
|
252
|
-
(key == 'direction' && paramsChanged && paramsChanged.position))) {
|
|
253
|
-
if (isMe() && logic.canMove) continue
|
|
254
|
-
}
|
|
255
|
-
logic[key] = params[key]
|
|
256
|
-
}
|
|
257
|
-
if (paramsChanged) {
|
|
258
|
-
layoutToArray(paramsChanged)
|
|
259
|
-
if (paramsChanged.layout) logic.componentChanged = paramsChanged.layout
|
|
260
|
-
if (paramsChanged.teleported) {
|
|
261
|
-
teleported = true
|
|
262
|
-
logic.position = { ...params.position } // clone
|
|
263
|
-
logic.direction = params.direction
|
|
264
|
-
}
|
|
265
|
-
if (!logic.paramsChanged) logic.paramsChanged = {}
|
|
266
|
-
logic.paramsChanged = paramsChanged
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
const newObject = {
|
|
270
|
-
object: logic,
|
|
271
|
-
paramsChanged
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
this.setObject(id, newObject)
|
|
275
|
-
|
|
276
|
-
return newObject
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
setObject(id: string, newObject) {
|
|
280
|
-
const propName = newObject.object instanceof RpgShape ? '_shapes' : '_objects'
|
|
281
|
-
this[propName].next({
|
|
282
|
-
...this[propName].value,
|
|
283
|
-
...{
|
|
284
|
-
[id]: newObject
|
|
285
|
-
}
|
|
286
|
-
})
|
|
287
|
-
this._obsObjects[id].next(newObject)
|
|
288
|
-
}
|
|
289
|
-
}
|
package/src/Gui/React.ts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { createRoot } from 'react-dom/client';
|
|
2
|
-
import { createElement, Fragment, useState, createContext, useEffect, useContext, useCallback, useSyncExternalStore, useRef } from 'react'
|
|
3
|
-
import { RpgClientEngine } from '../RpgClientEngine';
|
|
4
|
-
import { EVENTS_MAP, RpgRenderer } from '../Renderer';
|
|
5
|
-
import { BehaviorSubject, map, tap, combineLatest, Subject } from 'rxjs';
|
|
6
|
-
import type { Gui } from './Gui';
|
|
7
|
-
import { inject } from '../inject';
|
|
8
|
-
|
|
9
|
-
export { useStore } from '@nanostores/react'
|
|
10
|
-
export const RpgReactContext = createContext({} as any)
|
|
11
|
-
|
|
12
|
-
// TODO
|
|
13
|
-
export const useObjects = () => {
|
|
14
|
-
const [objects, setObjects] = useState([] as any[])
|
|
15
|
-
const { rpgObjects } = useContext(RpgReactContext)
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
rpgObjects
|
|
18
|
-
.pipe(
|
|
19
|
-
map((objects: any) => Object.values(objects).map((obj: any) => obj.object))
|
|
20
|
-
)
|
|
21
|
-
.subscribe(setObjects)
|
|
22
|
-
}, [])
|
|
23
|
-
return objects
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// TODO
|
|
27
|
-
export const useCurrentPlayer = () => {
|
|
28
|
-
const { rpgCurrentPlayer } = useContext(RpgReactContext);
|
|
29
|
-
|
|
30
|
-
const currentPlayerRef = useRef({});
|
|
31
|
-
let _onChanges
|
|
32
|
-
|
|
33
|
-
const subscribe = (onChanges) => {
|
|
34
|
-
_onChanges = onChanges
|
|
35
|
-
return () => {
|
|
36
|
-
_onChanges = null
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
const ob$ = rpgCurrentPlayer
|
|
42
|
-
.pipe(
|
|
43
|
-
map((player: any) => player.object),
|
|
44
|
-
tap((player: any) => currentPlayerRef.current = player)
|
|
45
|
-
);
|
|
46
|
-
const subscription = ob$.subscribe(() => {
|
|
47
|
-
_onChanges?.()
|
|
48
|
-
});
|
|
49
|
-
return () => subscription.unsubscribe();
|
|
50
|
-
}, []);
|
|
51
|
-
|
|
52
|
-
return useSyncExternalStore(subscribe, () => currentPlayerRef.current);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const useEventPropagator = () => {
|
|
56
|
-
const ref = useRef(null);
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
if (ref.current) {
|
|
59
|
-
const element = ref.current as HTMLElement;
|
|
60
|
-
const eventListeners = {};
|
|
61
|
-
const renderer = inject(RpgRenderer)
|
|
62
|
-
|
|
63
|
-
EVENTS_MAP.MouseEvent.forEach(eventType => {
|
|
64
|
-
const listener = event => renderer.propagateEvent(event)
|
|
65
|
-
element.addEventListener(eventType, listener);
|
|
66
|
-
eventListeners[eventType] = listener;
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
return () => {
|
|
70
|
-
EVENTS_MAP.MouseEvent.forEach(eventType => {
|
|
71
|
-
element.removeEventListener(eventType, eventListeners[eventType]);
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
}, [ref]);
|
|
76
|
-
return ref
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export class ReactGui {
|
|
80
|
-
private app: any
|
|
81
|
-
private clientEngine: RpgClientEngine
|
|
82
|
-
private renderer: RpgRenderer
|
|
83
|
-
private _gui: BehaviorSubject<any[]> = new BehaviorSubject([] as any)
|
|
84
|
-
//private _tooltips: BehaviorSubject<any[]> = new BehaviorSubject([] as any)
|
|
85
|
-
|
|
86
|
-
constructor(rootEl: HTMLDivElement, parentGui: Gui) {
|
|
87
|
-
this.app = createRoot(rootEl)
|
|
88
|
-
this.clientEngine = parentGui.clientEngine
|
|
89
|
-
this.renderer = this.clientEngine.renderer
|
|
90
|
-
|
|
91
|
-
const GuiTooltip = (ui): any => {
|
|
92
|
-
return () => {
|
|
93
|
-
const [_tooltip, setTooltip] = useState<any[]>([])
|
|
94
|
-
useEffect(() => {
|
|
95
|
-
parentGui.listenTooltipObjects.subscribe(setTooltip)
|
|
96
|
-
// force combineLatest to emit first value
|
|
97
|
-
parentGui.currentScene?.objectsMoving.next({})
|
|
98
|
-
}, [parentGui.currentScene])
|
|
99
|
-
return parentGui.tooltipFilter(_tooltip).map(sprite => createElement('div', {
|
|
100
|
-
style: parentGui.tooltipPosition({ x: sprite.position.x, y: sprite.position.y }),
|
|
101
|
-
key: sprite.id,
|
|
102
|
-
}, createElement(ui.gui, {
|
|
103
|
-
spriteData: sprite,
|
|
104
|
-
...(ui.data || {}),
|
|
105
|
-
})))
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const GuiWrapper = () => {
|
|
110
|
-
const [_gui, setGui] = useState<any[]>([])
|
|
111
|
-
useEffect(() => {
|
|
112
|
-
this._gui.subscribe(gui => setGui(gui))
|
|
113
|
-
}, [])
|
|
114
|
-
|
|
115
|
-
return createElement(RpgReactContext.Provider, {
|
|
116
|
-
value: parentGui.getInjectObject()
|
|
117
|
-
},
|
|
118
|
-
..._gui.filter(ui => ui.display && !ui.attachToSprite).map(ui => createElement('div', {
|
|
119
|
-
key: ui.name,
|
|
120
|
-
style: { 'pointerEvents': 'auto' },
|
|
121
|
-
},
|
|
122
|
-
createElement(ui.gui, ui.data || {})
|
|
123
|
-
)),
|
|
124
|
-
..._gui.filter(ui => ui.display && ui.attachToSprite).map(ui => createElement('div', {
|
|
125
|
-
key: ui.name,
|
|
126
|
-
style: { 'pointerEvents': 'auto' },
|
|
127
|
-
}, createElement(GuiTooltip(ui)))),
|
|
128
|
-
)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
this.app.render(
|
|
132
|
-
createElement(GuiWrapper)
|
|
133
|
-
)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
set gui(val) {
|
|
137
|
-
let array: any = []
|
|
138
|
-
for (let key in val) {
|
|
139
|
-
// ignore vuejs component
|
|
140
|
-
if (!val[key].isFunction) continue
|
|
141
|
-
array.push(val[key])
|
|
142
|
-
}
|
|
143
|
-
this._gui.next(array)
|
|
144
|
-
}
|
|
145
|
-
}
|
package/src/Gui/Vue.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { renderList as _renderList, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, resolveDynamicComponent as _resolveDynamicComponent, normalizeProps as _normalizeProps, guardReactiveProps as _guardReactiveProps, createBlock as _createBlock, mergeProps as _mergeProps, createCommentVNode as _createCommentVNode, normalizeStyle as _normalizeStyle, createElementVNode as _createElementVNode } from "vue"
|
|
2
|
-
import { App, ComponentPublicInstance, createApp } from 'vue'
|
|
3
|
-
import { RpgCommonPlayer, Utils } from '@rpgjs/common'
|
|
4
|
-
import { EVENTS_MAP, RpgRenderer } from '../Renderer'
|
|
5
|
-
import { GameEngineClient } from '../GameEngine'
|
|
6
|
-
import { RpgClientEngine } from '../RpgClientEngine'
|
|
7
|
-
import type { Gui } from './Gui'
|
|
8
|
-
import { Scene } from '../Scene/Scene'
|
|
9
|
-
|
|
10
|
-
interface VueInstance extends ComponentPublicInstance {
|
|
11
|
-
gui: GuiList,
|
|
12
|
-
tooltips: RpgCommonPlayer[]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface GuiOptions {
|
|
16
|
-
data: any,
|
|
17
|
-
attachToSprite: boolean
|
|
18
|
-
display: boolean,
|
|
19
|
-
name: string
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface GuiList {
|
|
23
|
-
[guiName: string]: GuiOptions
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface VueInstance extends ComponentPublicInstance {
|
|
27
|
-
gui: GuiList,
|
|
28
|
-
tooltips: RpgCommonPlayer[]
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const _hoisted_1 = {
|
|
32
|
-
id: "tooltips",
|
|
33
|
-
style: { "position": "absolute", "top": "0", "left": "0" }
|
|
34
|
-
}
|
|
35
|
-
function render(_ctx, _cache) {
|
|
36
|
-
return (_openBlock(), _createElementBlock("div", {}, [
|
|
37
|
-
(_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.fixedGui, (ui) => {
|
|
38
|
-
return (_openBlock(), _createElementBlock(_Fragment, null, [
|
|
39
|
-
(ui.display)
|
|
40
|
-
? (_openBlock(), _createBlock(_resolveDynamicComponent(ui.name), _normalizeProps(_mergeProps({ key: 0, style: { pointerEvents: 'auto' } }, ui.data)), null, 16 /* FULL_PROPS */))
|
|
41
|
-
: _createCommentVNode("v-if", true)
|
|
42
|
-
], 64 /* STABLE_FRAGMENT */))
|
|
43
|
-
}), 256 /* UNKEYED_FRAGMENT */)),
|
|
44
|
-
_createElementVNode("div", _hoisted_1, [
|
|
45
|
-
(_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.attachedGui, (ui) => {
|
|
46
|
-
return (_openBlock(), _createElementBlock(_Fragment, null, [
|
|
47
|
-
(ui.display)
|
|
48
|
-
? (_openBlock(true), _createElementBlock(_Fragment, { key: 0 }, _renderList(_ctx.tooltipFilter(_ctx.tooltips, ui), (tooltip) => {
|
|
49
|
-
return (_openBlock(), _createElementBlock("div", {
|
|
50
|
-
style: _normalizeStyle(_ctx.tooltipPosition(tooltip.position))
|
|
51
|
-
}, [
|
|
52
|
-
(_openBlock(), _createBlock(_resolveDynamicComponent(ui.name), _mergeProps({ ...ui.data, spriteData: tooltip, style: { pointerEvents: 'auto' } }, {
|
|
53
|
-
ref_for: true,
|
|
54
|
-
ref: ui.name
|
|
55
|
-
}), null, 16 /* FULL_PROPS */))
|
|
56
|
-
], 4 /* STYLE */))
|
|
57
|
-
}), 256 /* UNKEYED_FRAGMENT */))
|
|
58
|
-
: _createCommentVNode("v-if", true)
|
|
59
|
-
], 64 /* STABLE_FRAGMENT */))
|
|
60
|
-
}), 256 /* UNKEYED_FRAGMENT */))
|
|
61
|
-
])
|
|
62
|
-
], 32 /* HYDRATE_EVENTS */))
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
export class VueGui {
|
|
67
|
-
private renderer: RpgRenderer
|
|
68
|
-
private gameEngine: GameEngineClient
|
|
69
|
-
private clientEngine: RpgClientEngine
|
|
70
|
-
private app: App
|
|
71
|
-
private vm: VueInstance
|
|
72
|
-
private socket
|
|
73
|
-
|
|
74
|
-
constructor(rootEl: HTMLDivElement, private parentGui: Gui) {
|
|
75
|
-
this.clientEngine = parentGui.clientEngine
|
|
76
|
-
this.renderer = this.clientEngine.renderer
|
|
77
|
-
this.gameEngine = this.clientEngine.gameEngine
|
|
78
|
-
const { gui } = parentGui
|
|
79
|
-
|
|
80
|
-
const obj = {
|
|
81
|
-
render,
|
|
82
|
-
data() {
|
|
83
|
-
return {
|
|
84
|
-
gui: {},
|
|
85
|
-
tooltips: []
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
provide: () => {
|
|
89
|
-
return parentGui.getInjectObject()
|
|
90
|
-
},
|
|
91
|
-
computed: {
|
|
92
|
-
fixedGui() {
|
|
93
|
-
return Object.values(this.gui).filter((gui: any) => !gui.attachToSprite)
|
|
94
|
-
},
|
|
95
|
-
attachedGui() {
|
|
96
|
-
return Object.values(this.gui).filter((gui: any) => gui.attachToSprite)
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
methods: {
|
|
100
|
-
tooltipPosition: parentGui.tooltipPosition.bind(parentGui),
|
|
101
|
-
tooltipFilter: parentGui.tooltipFilter.bind(parentGui)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
this.app = createApp(obj)
|
|
106
|
-
|
|
107
|
-
const guiVue = Object.values(gui).filter(ui => !Utils.isFunction(ui))
|
|
108
|
-
|
|
109
|
-
for (let ui of guiVue) {
|
|
110
|
-
this.app.component(ui.name, ui.gui)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
this.app.directive('propagate', {
|
|
114
|
-
mounted: (el, binding) => {
|
|
115
|
-
el.eventListeners = {};
|
|
116
|
-
EVENTS_MAP.MouseEvent.forEach(eventType => {
|
|
117
|
-
const callback = (ev) => {
|
|
118
|
-
this.renderer.propagateEvent(ev);
|
|
119
|
-
};
|
|
120
|
-
el.eventListeners[eventType] = callback;
|
|
121
|
-
el.addEventListener(eventType, callback);
|
|
122
|
-
});
|
|
123
|
-
},
|
|
124
|
-
unmounted(el, binding) {
|
|
125
|
-
EVENTS_MAP.MouseEvent.forEach(eventType => {
|
|
126
|
-
const callback = el.eventListeners[eventType];
|
|
127
|
-
if (callback) {
|
|
128
|
-
el.removeEventListener(eventType, callback);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
this.vm = this.app.mount(rootEl) as VueInstance
|
|
135
|
-
this.renderer.app = this.app
|
|
136
|
-
this.renderer.vm = this.vm
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
_setSceneReady() {
|
|
140
|
-
this.parentGui.listenTooltipObjects.subscribe((tooltips) => {
|
|
141
|
-
this.vm.tooltips = [...tooltips]
|
|
142
|
-
})
|
|
143
|
-
this.parentGui.currentScene?.objectsMoving.next({})
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
set gui(val) {
|
|
147
|
-
for (let key in val) {
|
|
148
|
-
// ignore react component
|
|
149
|
-
if (val[key].isFunction) continue
|
|
150
|
-
this.vm.gui[key] = val[key]
|
|
151
|
-
}
|
|
152
|
-
this.vm.gui = Object.assign({}, this.vm.gui)
|
|
153
|
-
}
|
|
154
|
-
}
|
package/src/Interfaces/Scene.ts
DELETED