@rpgjs/client 4.1.2 → 4.2.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/CHANGELOG.md +20 -0
- package/browser/{React-da18564b.js → React-c40e162b.js} +25 -0
- package/browser/index-9602bbc0.js +44217 -0
- package/browser/manifest.json +10 -1
- package/browser/rpg.client.js +33 -44122
- package/browser/rpg.client.umd.cjs +458 -337
- package/lib/Effects/TransitionScene.d.ts +4 -3
- package/lib/Effects/TransitionScene.js +4 -2
- package/lib/Effects/TransitionScene.js.map +1 -1
- package/lib/GameEngine.d.ts +1 -1
- package/lib/GameEngine.js +4 -1
- package/lib/GameEngine.js.map +1 -1
- package/lib/Gui/Gui.d.ts +2 -1
- package/lib/Gui/Gui.js +7 -5
- package/lib/Gui/Gui.js.map +1 -1
- package/lib/Gui/React.d.ts +1 -0
- package/lib/Gui/React.js +23 -0
- package/lib/Gui/React.js.map +1 -1
- package/lib/Gui/Vue.js +21 -2
- package/lib/Gui/Vue.js.map +1 -1
- package/lib/KeyboardControls.d.ts +40 -14
- package/lib/KeyboardControls.js +42 -15
- package/lib/KeyboardControls.js.map +1 -1
- package/lib/Renderer.d.ts +13 -5
- package/lib/Renderer.js +40 -16
- package/lib/Renderer.js.map +1 -1
- package/lib/Resources.js.map +1 -1
- package/lib/RpgClientEngine.d.ts +10 -4
- package/lib/RpgClientEngine.js +26 -17
- package/lib/RpgClientEngine.js.map +1 -1
- package/lib/Scene/Map.d.ts +4 -5
- package/lib/Scene/Map.js +6 -4
- package/lib/Scene/Map.js.map +1 -1
- package/lib/Scene/Scene.d.ts +7 -2
- package/lib/Scene/Scene.js +9 -3
- package/lib/Scene/Scene.js.map +1 -1
- package/lib/Tilemap/index.d.ts +4 -3
- package/lib/Tilemap/index.js +4 -2
- package/lib/Tilemap/index.js.map +1 -1
- package/lib/clientEntryPoint.js +5 -5
- package/lib/clientEntryPoint.js.map +1 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -1
- package/lib/inject.d.ts +23 -0
- package/lib/inject.js +30 -0
- package/lib/inject.js.map +1 -0
- package/package.json +5 -5
- package/src/Effects/TransitionScene.ts +3 -1
- package/src/GameEngine.ts +2 -2
- package/src/Gui/Gui.ts +5 -5
- package/src/Gui/React.ts +26 -1
- package/src/Gui/Vue.ts +24 -6
- package/src/KeyboardControls.ts +43 -15
- package/src/Renderer.ts +44 -19
- package/src/Resources.ts +0 -1
- package/src/RpgClientEngine.ts +29 -18
- package/src/Scene/Map.ts +8 -7
- package/src/Scene/Scene.ts +8 -4
- package/src/Tilemap/index.ts +3 -3
- package/src/clientEntryPoint.ts +6 -4
- package/src/index.ts +4 -1
- package/src/inject.ts +34 -0
|
@@ -1,257 +1,7 @@
|
|
|
1
1
|
(function(global2, factory) {
|
|
2
|
-
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("
|
|
3
|
-
})(this, function(exports2,
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react-dom"), require("react"), require("@rpgjs/common"), require("rxjs"), require("vue")) : typeof define === "function" && define.amd ? define(["exports", "react-dom", "react", "@rpgjs/common", "rxjs", "vue"], factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, factory(global2.RpgClient = {}, global2.require$$0$1, global2.react, global2.common, global2.rxjs, global2.Vue));
|
|
3
|
+
})(this, function(exports2, require$$0$1, react, common, rxjs, vue) {
|
|
4
4
|
"use strict";
|
|
5
|
-
class GameEngineClient extends common.RpgCommonGame {
|
|
6
|
-
constructor() {
|
|
7
|
-
super(common.GameSide.Client);
|
|
8
|
-
this._objects = new rxjs.BehaviorSubject({});
|
|
9
|
-
this._obsObjects = {};
|
|
10
|
-
this._obsObjectsDeleteNotifier$ = {};
|
|
11
|
-
this._shapes = new rxjs.BehaviorSubject({});
|
|
12
|
-
this._objectsChanged = new rxjs.BehaviorSubject({});
|
|
13
|
-
this.world = {
|
|
14
|
-
getObjects: this.getObjects.bind(this),
|
|
15
|
-
getObject: (id) => {
|
|
16
|
-
const obj = this.getObject(id);
|
|
17
|
-
if (!obj)
|
|
18
|
-
return null;
|
|
19
|
-
return obj.object;
|
|
20
|
-
},
|
|
21
|
-
getShape: (id) => {
|
|
22
|
-
const obj = this.getShape(id);
|
|
23
|
-
if (!obj)
|
|
24
|
-
return null;
|
|
25
|
-
return obj.object;
|
|
26
|
-
},
|
|
27
|
-
getAll: (id) => {
|
|
28
|
-
const obj = this.getObjectAndShape(id);
|
|
29
|
-
if (!obj)
|
|
30
|
-
return null;
|
|
31
|
-
return obj.object;
|
|
32
|
-
},
|
|
33
|
-
removeObject: this.removeObject.bind(this),
|
|
34
|
-
getObjectsOfGroup: () => {
|
|
35
|
-
return {
|
|
36
|
-
...this.getObjects(),
|
|
37
|
-
...this.events
|
|
38
|
-
};
|
|
39
|
-
},
|
|
40
|
-
getShapesOfGroup: () => {
|
|
41
|
-
return this.getShapes();
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
_get(prop, id) {
|
|
46
|
-
const objects = this[prop].value;
|
|
47
|
-
const val = objects[id];
|
|
48
|
-
if (!val)
|
|
49
|
-
return null;
|
|
50
|
-
return val;
|
|
51
|
-
}
|
|
52
|
-
get objectsChanged() {
|
|
53
|
-
return this._objectsChanged.asObservable();
|
|
54
|
-
}
|
|
55
|
-
setObjectsChanged(val) {
|
|
56
|
-
this._objectsChanged.next(val);
|
|
57
|
-
}
|
|
58
|
-
listenObject(id) {
|
|
59
|
-
return this._obsObjects[id].asObservable();
|
|
60
|
-
}
|
|
61
|
-
get objects() {
|
|
62
|
-
return this._objects.asObservable();
|
|
63
|
-
}
|
|
64
|
-
get shapes() {
|
|
65
|
-
return this._shapes.asObservable();
|
|
66
|
-
}
|
|
67
|
-
get all() {
|
|
68
|
-
return rxjs.combineLatest([this.objects, this.shapes]).pipe(rxjs.map(([objects, shapes]) => {
|
|
69
|
-
return {
|
|
70
|
-
...objects,
|
|
71
|
-
...shapes
|
|
72
|
-
};
|
|
73
|
-
}));
|
|
74
|
-
}
|
|
75
|
-
getShapes() {
|
|
76
|
-
return this._shapes.value;
|
|
77
|
-
}
|
|
78
|
-
getObjects() {
|
|
79
|
-
return this._objects.value;
|
|
80
|
-
}
|
|
81
|
-
getObject(id) {
|
|
82
|
-
return this._get("_objects", id);
|
|
83
|
-
}
|
|
84
|
-
getShape(id) {
|
|
85
|
-
return this._get("_shapes", id);
|
|
86
|
-
}
|
|
87
|
-
getObjectAndShape(id) {
|
|
88
|
-
let obj = this.getObject(id);
|
|
89
|
-
if (!obj)
|
|
90
|
-
obj = this.getShape(id);
|
|
91
|
-
return obj;
|
|
92
|
-
}
|
|
93
|
-
resetObjects() {
|
|
94
|
-
for (let id in this._obsObjectsDeleteNotifier$) {
|
|
95
|
-
this._obsObjectsDeleteNotifier$[id].next();
|
|
96
|
-
this._obsObjectsDeleteNotifier$[id].complete();
|
|
97
|
-
this._obsObjects[id].complete();
|
|
98
|
-
}
|
|
99
|
-
this._obsObjectsDeleteNotifier$ = {};
|
|
100
|
-
this._obsObjects = {};
|
|
101
|
-
this._objects.next({});
|
|
102
|
-
this._shapes.next({});
|
|
103
|
-
}
|
|
104
|
-
getDeleteNotifier(id) {
|
|
105
|
-
return this._obsObjectsDeleteNotifier$[id].asObservable();
|
|
106
|
-
}
|
|
107
|
-
_remove(prop, id) {
|
|
108
|
-
const logic = prop == "_objects" ? this.getObject(id) : this.getShape(id);
|
|
109
|
-
if (logic) {
|
|
110
|
-
const objects = {
|
|
111
|
-
...this[prop].value
|
|
112
|
-
};
|
|
113
|
-
delete objects[id];
|
|
114
|
-
this._obsObjectsDeleteNotifier$[id].next();
|
|
115
|
-
this._obsObjectsDeleteNotifier$[id].complete();
|
|
116
|
-
this._obsObjects[id].complete();
|
|
117
|
-
delete this._obsObjects[id];
|
|
118
|
-
delete this._obsObjectsDeleteNotifier$[id];
|
|
119
|
-
this[prop].next(objects);
|
|
120
|
-
return true;
|
|
121
|
-
}
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
removeObject(id) {
|
|
125
|
-
if (this.events[id]) {
|
|
126
|
-
delete this.events[id];
|
|
127
|
-
}
|
|
128
|
-
return this._remove("_objects", id);
|
|
129
|
-
}
|
|
130
|
-
removeShape(id) {
|
|
131
|
-
return this._remove("_shapes", id);
|
|
132
|
-
}
|
|
133
|
-
removeObjectAndShape(id) {
|
|
134
|
-
let bool = this.removeObject(id);
|
|
135
|
-
if (!bool)
|
|
136
|
-
bool = this.removeShape(id);
|
|
137
|
-
return bool;
|
|
138
|
-
}
|
|
139
|
-
static toArray(obj, prop) {
|
|
140
|
-
if (obj[prop])
|
|
141
|
-
obj[prop] = Object.values(obj[prop]);
|
|
142
|
-
}
|
|
143
|
-
updateObject(obj) {
|
|
144
|
-
const {
|
|
145
|
-
playerId: id,
|
|
146
|
-
params,
|
|
147
|
-
localEvent,
|
|
148
|
-
paramsChanged,
|
|
149
|
-
isShape
|
|
150
|
-
} = obj;
|
|
151
|
-
if (paramsChanged.components) {
|
|
152
|
-
paramsChanged.layout = {
|
|
153
|
-
center: {
|
|
154
|
-
lines: [{
|
|
155
|
-
col: paramsChanged.components
|
|
156
|
-
}]
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
const layoutToArray = (params2) => {
|
|
161
|
-
const layout = params2.layout;
|
|
162
|
-
if (layout) {
|
|
163
|
-
["center", "top", "right", "bottom", "left"].forEach((key) => {
|
|
164
|
-
if (!layout[key])
|
|
165
|
-
return;
|
|
166
|
-
GameEngineClient.toArray(layout[key], "lines");
|
|
167
|
-
if (!layout[key].lines)
|
|
168
|
-
return;
|
|
169
|
-
layout[key].lines.map((layout2) => {
|
|
170
|
-
GameEngineClient.toArray(layout2, "col");
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
layoutToArray(params);
|
|
176
|
-
GameEngineClient.toArray(params, "polygon");
|
|
177
|
-
const isMe = () => id == this.playerId;
|
|
178
|
-
let logic;
|
|
179
|
-
const createObsForObject = (data) => {
|
|
180
|
-
this._obsObjectsDeleteNotifier$[id] = new rxjs.Subject();
|
|
181
|
-
this._obsObjects[id] = new rxjs.BehaviorSubject(data);
|
|
182
|
-
};
|
|
183
|
-
if (isShape) {
|
|
184
|
-
logic = this.world.getShape(id);
|
|
185
|
-
if (!logic) {
|
|
186
|
-
logic = this.addShape(params);
|
|
187
|
-
createObsForObject({
|
|
188
|
-
logic
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
} else {
|
|
192
|
-
if (localEvent) {
|
|
193
|
-
logic = this.events[id];
|
|
194
|
-
if (!logic) {
|
|
195
|
-
logic = this.addEvent(common.RpgCommonPlayer, id);
|
|
196
|
-
createObsForObject({
|
|
197
|
-
logic
|
|
198
|
-
});
|
|
199
|
-
this.events[id] = {
|
|
200
|
-
object: logic
|
|
201
|
-
};
|
|
202
|
-
} else {
|
|
203
|
-
logic = logic.object;
|
|
204
|
-
}
|
|
205
|
-
} else {
|
|
206
|
-
logic = this.world.getObject(id);
|
|
207
|
-
}
|
|
208
|
-
if (!logic) {
|
|
209
|
-
logic = this.addPlayer(common.RpgCommonPlayer, id);
|
|
210
|
-
createObsForObject({
|
|
211
|
-
logic
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
logic.prevParamsChanged = Object.assign({}, logic);
|
|
216
|
-
for (let key in params) {
|
|
217
|
-
if (!localEvent && (key == "position" || key == "direction" && paramsChanged && paramsChanged.position)) {
|
|
218
|
-
if (isMe() && logic.canMove)
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
|
-
logic[key] = params[key];
|
|
222
|
-
}
|
|
223
|
-
if (paramsChanged) {
|
|
224
|
-
layoutToArray(paramsChanged);
|
|
225
|
-
if (paramsChanged.layout)
|
|
226
|
-
logic.componentChanged = paramsChanged.layout;
|
|
227
|
-
if (paramsChanged.teleported) {
|
|
228
|
-
logic.position = {
|
|
229
|
-
...params.position
|
|
230
|
-
};
|
|
231
|
-
logic.direction = params.direction;
|
|
232
|
-
}
|
|
233
|
-
if (!logic.paramsChanged)
|
|
234
|
-
logic.paramsChanged = {};
|
|
235
|
-
logic.paramsChanged = paramsChanged;
|
|
236
|
-
}
|
|
237
|
-
const newObject = {
|
|
238
|
-
object: logic,
|
|
239
|
-
paramsChanged
|
|
240
|
-
};
|
|
241
|
-
this.setObject(id, newObject);
|
|
242
|
-
return newObject;
|
|
243
|
-
}
|
|
244
|
-
setObject(id, newObject) {
|
|
245
|
-
const propName = newObject.object instanceof common.RpgShape ? "_shapes" : "_objects";
|
|
246
|
-
this[propName].next({
|
|
247
|
-
...this[propName].value,
|
|
248
|
-
...{
|
|
249
|
-
[id]: newObject
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
this._obsObjects[id].next(newObject);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
5
|
const keyCodeTable = {
|
|
256
6
|
3: "break",
|
|
257
7
|
8: "backspace",
|
|
@@ -436,8 +186,9 @@
|
|
|
436
186
|
};
|
|
437
187
|
const inverseKeyCodeTable = inverse(keyCodeTable);
|
|
438
188
|
class KeyboardControls {
|
|
439
|
-
constructor(
|
|
440
|
-
this.
|
|
189
|
+
constructor(context2) {
|
|
190
|
+
this.context = context2;
|
|
191
|
+
this.clientEngine = this.context.inject(RpgClientEngine);
|
|
441
192
|
this.keyState = {};
|
|
442
193
|
this.boundKeys = {};
|
|
443
194
|
this.stop = false;
|
|
@@ -445,7 +196,7 @@
|
|
|
445
196
|
this._controlsOptions = {};
|
|
446
197
|
const {
|
|
447
198
|
globalConfig
|
|
448
|
-
} = clientEngine;
|
|
199
|
+
} = this.clientEngine;
|
|
449
200
|
this.setupListeners();
|
|
450
201
|
this.setInputs({
|
|
451
202
|
...common.DefaultInput,
|
|
@@ -576,43 +327,56 @@
|
|
|
576
327
|
this.clientEngine.keyChange.next(keyName);
|
|
577
328
|
}
|
|
578
329
|
/**
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
330
|
+
* From the name of the entry, we retrieve the control information
|
|
331
|
+
*
|
|
332
|
+
* ```ts
|
|
333
|
+
* import { Input, inject, KeyboardControls } from '@rpgjs/client'
|
|
334
|
+
*
|
|
335
|
+
* const controls = inject(KeyboardControls)
|
|
336
|
+
* controls.getControl(Input.Enter)
|
|
337
|
+
|
|
338
|
+
* if (control) {
|
|
339
|
+
* console.log(control.actionName) // action
|
|
340
|
+
* }
|
|
341
|
+
* ```
|
|
342
|
+
* @title Get Control
|
|
343
|
+
* @method getControl(inputName)
|
|
344
|
+
* @param {string} inputName
|
|
345
|
+
* @returns { { actionName: string, options: any } | undefined }
|
|
346
|
+
* @memberof KeyboardControls
|
|
347
|
+
*/
|
|
348
|
+
getControl(inputName) {
|
|
349
|
+
return this.boundKeys[inputName];
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Returns all controls
|
|
583
353
|
*
|
|
584
|
-
*
|
|
585
|
-
*
|
|
586
|
-
*
|
|
587
|
-
* console.log(control.actionName) // action
|
|
588
|
-
* }
|
|
589
|
-
* ```
|
|
590
|
-
* @title Get Control
|
|
591
|
-
* @method getControl(inputName)
|
|
592
|
-
* @param {string} inputName
|
|
593
|
-
* @returns { { actionName: string, options: any } | undefined }
|
|
354
|
+
* @method getControls()
|
|
355
|
+
* @since 4.2.0
|
|
356
|
+
* @returns { { [key: string]: BoundKey } }
|
|
594
357
|
* @memberof KeyboardControls
|
|
595
358
|
*/
|
|
596
|
-
|
|
597
|
-
return this.boundKeys
|
|
359
|
+
getControls() {
|
|
360
|
+
return this.boundKeys;
|
|
598
361
|
}
|
|
599
362
|
/**
|
|
600
363
|
* Triggers an input according to the name of the control
|
|
601
364
|
*
|
|
602
365
|
* ```ts
|
|
603
|
-
* import { Control } from '@rpgjs/client'
|
|
366
|
+
* import { Control, inject, KeyboardControls } from '@rpgjs/client'
|
|
604
367
|
*
|
|
605
|
-
*
|
|
606
|
-
*
|
|
368
|
+
* const controls = inject(KeyboardControls)
|
|
369
|
+
* controls.applyControl(Control.Action)
|
|
607
370
|
* ```
|
|
608
371
|
*
|
|
609
372
|
* You can put a second parameter or indicate on whether the key is pressed or released
|
|
610
373
|
*
|
|
611
374
|
* ```ts
|
|
612
|
-
* import { Control } from '@rpgjs/client'
|
|
375
|
+
* import { Control, inject, KeyboardControls } from '@rpgjs/client'
|
|
613
376
|
*
|
|
614
|
-
*
|
|
615
|
-
*
|
|
377
|
+
* const controls = inject(KeyboardControls)
|
|
378
|
+
* controls.applyControl(Control.Up, true) // keydown
|
|
379
|
+
* controls.applyControl(Control.Up, false) // keyup
|
|
616
380
|
* ```
|
|
617
381
|
* @title Apply Control
|
|
618
382
|
* @method applyControl(controlName,isDown)
|
|
@@ -672,10 +436,10 @@
|
|
|
672
436
|
* * delay.otherControls {string | string[]} Indicates the other controls that will also have the delay at the same time
|
|
673
437
|
*
|
|
674
438
|
* ```ts
|
|
675
|
-
* import { Control, Input } from '@rpgjs/client'
|
|
439
|
+
* import { Control, Input, inject, KeyboardControls } from '@rpgjs/client'
|
|
676
440
|
*
|
|
677
|
-
*
|
|
678
|
-
*
|
|
441
|
+
* const controls = inject(KeyboardControls)
|
|
442
|
+
* controls.setInputs({
|
|
679
443
|
[Control.Up]: {
|
|
680
444
|
repeat: true,
|
|
681
445
|
bind: Input.Up
|
|
@@ -738,6 +502,18 @@
|
|
|
738
502
|
* Control.Action | action
|
|
739
503
|
* Control.Back | back
|
|
740
504
|
*
|
|
505
|
+
* @enum {string} Mouse Event
|
|
506
|
+
*
|
|
507
|
+
* click | Click
|
|
508
|
+
* dblclick | Double Click
|
|
509
|
+
* mousedown | Mouse Down
|
|
510
|
+
* mouseup | Mouse Up
|
|
511
|
+
* mouseover | Mouse Over
|
|
512
|
+
* mousemove | Mouse Move
|
|
513
|
+
* mouseout | Mouse Out
|
|
514
|
+
* contextmenu | Context Menu
|
|
515
|
+
*
|
|
516
|
+
*
|
|
741
517
|
* @enum {string} Input
|
|
742
518
|
*
|
|
743
519
|
* break | Pause
|
|
@@ -31888,10 +31664,10 @@ void main(void)
|
|
|
31888
31664
|
intersection
|
|
31889
31665
|
} = common.Utils;
|
|
31890
31666
|
class TileMap extends Container {
|
|
31891
|
-
constructor(
|
|
31667
|
+
constructor(context2, data) {
|
|
31892
31668
|
super();
|
|
31669
|
+
this.context = context2;
|
|
31893
31670
|
this.data = data;
|
|
31894
|
-
this.renderer = renderer;
|
|
31895
31671
|
this.background = new Graphics();
|
|
31896
31672
|
this.tilewidth = 0;
|
|
31897
31673
|
this.tileheight = 0;
|
|
@@ -31900,6 +31676,7 @@ void main(void)
|
|
|
31900
31676
|
this.layers = {};
|
|
31901
31677
|
this.tilesLayer = new Container();
|
|
31902
31678
|
this.frameTile = 0;
|
|
31679
|
+
this.renderer = this.context.inject(RpgRenderer);
|
|
31903
31680
|
this.x = 0;
|
|
31904
31681
|
this.y = 0;
|
|
31905
31682
|
this.create(data);
|
|
@@ -36149,6 +35926,259 @@ void main(void)
|
|
|
36149
35926
|
}
|
|
36150
35927
|
}
|
|
36151
35928
|
}
|
|
35929
|
+
class GameEngineClient extends common.RpgCommonGame {
|
|
35930
|
+
constructor() {
|
|
35931
|
+
super(...arguments);
|
|
35932
|
+
this._objects = new rxjs.BehaviorSubject({});
|
|
35933
|
+
this._obsObjects = {};
|
|
35934
|
+
this._obsObjectsDeleteNotifier$ = {};
|
|
35935
|
+
this._shapes = new rxjs.BehaviorSubject({});
|
|
35936
|
+
this._objectsChanged = new rxjs.BehaviorSubject({});
|
|
35937
|
+
this.world = {
|
|
35938
|
+
getObjects: this.getObjects.bind(this),
|
|
35939
|
+
getObject: (id) => {
|
|
35940
|
+
const obj = this.getObject(id);
|
|
35941
|
+
if (!obj)
|
|
35942
|
+
return null;
|
|
35943
|
+
return obj.object;
|
|
35944
|
+
},
|
|
35945
|
+
getShape: (id) => {
|
|
35946
|
+
const obj = this.getShape(id);
|
|
35947
|
+
if (!obj)
|
|
35948
|
+
return null;
|
|
35949
|
+
return obj.object;
|
|
35950
|
+
},
|
|
35951
|
+
getAll: (id) => {
|
|
35952
|
+
const obj = this.getObjectAndShape(id);
|
|
35953
|
+
if (!obj)
|
|
35954
|
+
return null;
|
|
35955
|
+
return obj.object;
|
|
35956
|
+
},
|
|
35957
|
+
removeObject: this.removeObject.bind(this),
|
|
35958
|
+
getObjectsOfGroup: () => {
|
|
35959
|
+
return {
|
|
35960
|
+
...this.getObjects(),
|
|
35961
|
+
...this.events
|
|
35962
|
+
};
|
|
35963
|
+
},
|
|
35964
|
+
getShapesOfGroup: () => {
|
|
35965
|
+
return this.getShapes();
|
|
35966
|
+
}
|
|
35967
|
+
};
|
|
35968
|
+
}
|
|
35969
|
+
initialize() {
|
|
35970
|
+
super.initialize(common.GameSide.Client);
|
|
35971
|
+
}
|
|
35972
|
+
_get(prop, id) {
|
|
35973
|
+
const objects = this[prop].value;
|
|
35974
|
+
const val = objects[id];
|
|
35975
|
+
if (!val)
|
|
35976
|
+
return null;
|
|
35977
|
+
return val;
|
|
35978
|
+
}
|
|
35979
|
+
get objectsChanged() {
|
|
35980
|
+
return this._objectsChanged.asObservable();
|
|
35981
|
+
}
|
|
35982
|
+
setObjectsChanged(val) {
|
|
35983
|
+
this._objectsChanged.next(val);
|
|
35984
|
+
}
|
|
35985
|
+
listenObject(id) {
|
|
35986
|
+
return this._obsObjects[id].asObservable();
|
|
35987
|
+
}
|
|
35988
|
+
get objects() {
|
|
35989
|
+
return this._objects.asObservable();
|
|
35990
|
+
}
|
|
35991
|
+
get shapes() {
|
|
35992
|
+
return this._shapes.asObservable();
|
|
35993
|
+
}
|
|
35994
|
+
get all() {
|
|
35995
|
+
return rxjs.combineLatest([this.objects, this.shapes]).pipe(rxjs.map(([objects, shapes]) => {
|
|
35996
|
+
return {
|
|
35997
|
+
...objects,
|
|
35998
|
+
...shapes
|
|
35999
|
+
};
|
|
36000
|
+
}));
|
|
36001
|
+
}
|
|
36002
|
+
getShapes() {
|
|
36003
|
+
return this._shapes.value;
|
|
36004
|
+
}
|
|
36005
|
+
getObjects() {
|
|
36006
|
+
return this._objects.value;
|
|
36007
|
+
}
|
|
36008
|
+
getObject(id) {
|
|
36009
|
+
return this._get("_objects", id);
|
|
36010
|
+
}
|
|
36011
|
+
getShape(id) {
|
|
36012
|
+
return this._get("_shapes", id);
|
|
36013
|
+
}
|
|
36014
|
+
getObjectAndShape(id) {
|
|
36015
|
+
let obj = this.getObject(id);
|
|
36016
|
+
if (!obj)
|
|
36017
|
+
obj = this.getShape(id);
|
|
36018
|
+
return obj;
|
|
36019
|
+
}
|
|
36020
|
+
resetObjects() {
|
|
36021
|
+
for (let id in this._obsObjectsDeleteNotifier$) {
|
|
36022
|
+
this._obsObjectsDeleteNotifier$[id].next();
|
|
36023
|
+
this._obsObjectsDeleteNotifier$[id].complete();
|
|
36024
|
+
this._obsObjects[id].complete();
|
|
36025
|
+
}
|
|
36026
|
+
this._obsObjectsDeleteNotifier$ = {};
|
|
36027
|
+
this._obsObjects = {};
|
|
36028
|
+
this._objects.next({});
|
|
36029
|
+
this._shapes.next({});
|
|
36030
|
+
}
|
|
36031
|
+
getDeleteNotifier(id) {
|
|
36032
|
+
return this._obsObjectsDeleteNotifier$[id].asObservable();
|
|
36033
|
+
}
|
|
36034
|
+
_remove(prop, id) {
|
|
36035
|
+
const logic = prop == "_objects" ? this.getObject(id) : this.getShape(id);
|
|
36036
|
+
if (logic) {
|
|
36037
|
+
const objects = {
|
|
36038
|
+
...this[prop].value
|
|
36039
|
+
};
|
|
36040
|
+
delete objects[id];
|
|
36041
|
+
this._obsObjectsDeleteNotifier$[id].next();
|
|
36042
|
+
this._obsObjectsDeleteNotifier$[id].complete();
|
|
36043
|
+
this._obsObjects[id].complete();
|
|
36044
|
+
delete this._obsObjects[id];
|
|
36045
|
+
delete this._obsObjectsDeleteNotifier$[id];
|
|
36046
|
+
this[prop].next(objects);
|
|
36047
|
+
return true;
|
|
36048
|
+
}
|
|
36049
|
+
return false;
|
|
36050
|
+
}
|
|
36051
|
+
removeObject(id) {
|
|
36052
|
+
if (this.events[id]) {
|
|
36053
|
+
delete this.events[id];
|
|
36054
|
+
}
|
|
36055
|
+
return this._remove("_objects", id);
|
|
36056
|
+
}
|
|
36057
|
+
removeShape(id) {
|
|
36058
|
+
return this._remove("_shapes", id);
|
|
36059
|
+
}
|
|
36060
|
+
removeObjectAndShape(id) {
|
|
36061
|
+
let bool = this.removeObject(id);
|
|
36062
|
+
if (!bool)
|
|
36063
|
+
bool = this.removeShape(id);
|
|
36064
|
+
return bool;
|
|
36065
|
+
}
|
|
36066
|
+
static toArray(obj, prop) {
|
|
36067
|
+
if (obj[prop])
|
|
36068
|
+
obj[prop] = Object.values(obj[prop]);
|
|
36069
|
+
}
|
|
36070
|
+
updateObject(obj) {
|
|
36071
|
+
const {
|
|
36072
|
+
playerId: id,
|
|
36073
|
+
params,
|
|
36074
|
+
localEvent,
|
|
36075
|
+
paramsChanged,
|
|
36076
|
+
isShape
|
|
36077
|
+
} = obj;
|
|
36078
|
+
if (paramsChanged.components) {
|
|
36079
|
+
paramsChanged.layout = {
|
|
36080
|
+
center: {
|
|
36081
|
+
lines: [{
|
|
36082
|
+
col: paramsChanged.components
|
|
36083
|
+
}]
|
|
36084
|
+
}
|
|
36085
|
+
};
|
|
36086
|
+
}
|
|
36087
|
+
const layoutToArray = (params2) => {
|
|
36088
|
+
const layout = params2.layout;
|
|
36089
|
+
if (layout) {
|
|
36090
|
+
["center", "top", "right", "bottom", "left"].forEach((key) => {
|
|
36091
|
+
if (!layout[key])
|
|
36092
|
+
return;
|
|
36093
|
+
GameEngineClient.toArray(layout[key], "lines");
|
|
36094
|
+
if (!layout[key].lines)
|
|
36095
|
+
return;
|
|
36096
|
+
layout[key].lines.map((layout2) => {
|
|
36097
|
+
GameEngineClient.toArray(layout2, "col");
|
|
36098
|
+
});
|
|
36099
|
+
});
|
|
36100
|
+
}
|
|
36101
|
+
};
|
|
36102
|
+
layoutToArray(params);
|
|
36103
|
+
GameEngineClient.toArray(params, "polygon");
|
|
36104
|
+
const isMe = () => id == this.playerId;
|
|
36105
|
+
let logic;
|
|
36106
|
+
const createObsForObject = (data) => {
|
|
36107
|
+
this._obsObjectsDeleteNotifier$[id] = new rxjs.Subject();
|
|
36108
|
+
this._obsObjects[id] = new rxjs.BehaviorSubject(data);
|
|
36109
|
+
};
|
|
36110
|
+
if (isShape) {
|
|
36111
|
+
logic = this.world.getShape(id);
|
|
36112
|
+
if (!logic) {
|
|
36113
|
+
logic = this.addShape(params);
|
|
36114
|
+
createObsForObject({
|
|
36115
|
+
logic
|
|
36116
|
+
});
|
|
36117
|
+
}
|
|
36118
|
+
} else {
|
|
36119
|
+
if (localEvent) {
|
|
36120
|
+
logic = this.events[id];
|
|
36121
|
+
if (!logic) {
|
|
36122
|
+
logic = this.addEvent(common.RpgCommonPlayer, id);
|
|
36123
|
+
createObsForObject({
|
|
36124
|
+
logic
|
|
36125
|
+
});
|
|
36126
|
+
this.events[id] = {
|
|
36127
|
+
object: logic
|
|
36128
|
+
};
|
|
36129
|
+
} else {
|
|
36130
|
+
logic = logic.object;
|
|
36131
|
+
}
|
|
36132
|
+
} else {
|
|
36133
|
+
logic = this.world.getObject(id);
|
|
36134
|
+
}
|
|
36135
|
+
if (!logic) {
|
|
36136
|
+
logic = this.addPlayer(common.RpgCommonPlayer, id);
|
|
36137
|
+
createObsForObject({
|
|
36138
|
+
logic
|
|
36139
|
+
});
|
|
36140
|
+
}
|
|
36141
|
+
}
|
|
36142
|
+
logic.prevParamsChanged = Object.assign({}, logic);
|
|
36143
|
+
for (let key in params) {
|
|
36144
|
+
if (!localEvent && (key == "position" || key == "direction" && paramsChanged && paramsChanged.position)) {
|
|
36145
|
+
if (isMe() && logic.canMove)
|
|
36146
|
+
continue;
|
|
36147
|
+
}
|
|
36148
|
+
logic[key] = params[key];
|
|
36149
|
+
}
|
|
36150
|
+
if (paramsChanged) {
|
|
36151
|
+
layoutToArray(paramsChanged);
|
|
36152
|
+
if (paramsChanged.layout)
|
|
36153
|
+
logic.componentChanged = paramsChanged.layout;
|
|
36154
|
+
if (paramsChanged.teleported) {
|
|
36155
|
+
logic.position = {
|
|
36156
|
+
...params.position
|
|
36157
|
+
};
|
|
36158
|
+
logic.direction = params.direction;
|
|
36159
|
+
}
|
|
36160
|
+
if (!logic.paramsChanged)
|
|
36161
|
+
logic.paramsChanged = {};
|
|
36162
|
+
logic.paramsChanged = paramsChanged;
|
|
36163
|
+
}
|
|
36164
|
+
const newObject = {
|
|
36165
|
+
object: logic,
|
|
36166
|
+
paramsChanged
|
|
36167
|
+
};
|
|
36168
|
+
this.setObject(id, newObject);
|
|
36169
|
+
return newObject;
|
|
36170
|
+
}
|
|
36171
|
+
setObject(id, newObject) {
|
|
36172
|
+
const propName = newObject.object instanceof common.RpgShape ? "_shapes" : "_objects";
|
|
36173
|
+
this[propName].next({
|
|
36174
|
+
...this[propName].value,
|
|
36175
|
+
...{
|
|
36176
|
+
[id]: newObject
|
|
36177
|
+
}
|
|
36178
|
+
});
|
|
36179
|
+
this._obsObjects[id].next(newObject);
|
|
36180
|
+
}
|
|
36181
|
+
}
|
|
36152
36182
|
const _hoisted_1 = {
|
|
36153
36183
|
id: "tooltips",
|
|
36154
36184
|
style: {
|
|
@@ -36269,8 +36299,6 @@ void main(void)
|
|
|
36269
36299
|
methods: {
|
|
36270
36300
|
tooltipPosition: parentGui.tooltipPosition.bind(parentGui),
|
|
36271
36301
|
tooltipFilter: parentGui.tooltipFilter.bind(parentGui)
|
|
36272
|
-
},
|
|
36273
|
-
mounted() {
|
|
36274
36302
|
}
|
|
36275
36303
|
};
|
|
36276
36304
|
this.app = vue.createApp(obj);
|
|
@@ -36278,6 +36306,26 @@ void main(void)
|
|
|
36278
36306
|
for (let ui of guiVue) {
|
|
36279
36307
|
this.app.component(ui.name, ui.gui);
|
|
36280
36308
|
}
|
|
36309
|
+
this.app.directive("propagate", {
|
|
36310
|
+
mounted: (el, binding2) => {
|
|
36311
|
+
el.eventListeners = {};
|
|
36312
|
+
EVENTS_MAP.MouseEvent.forEach((eventType) => {
|
|
36313
|
+
const callback = (ev) => {
|
|
36314
|
+
this.renderer.propagateEvent(ev);
|
|
36315
|
+
};
|
|
36316
|
+
el.eventListeners[eventType] = callback;
|
|
36317
|
+
el.addEventListener(eventType, callback);
|
|
36318
|
+
});
|
|
36319
|
+
},
|
|
36320
|
+
unmounted(el, binding2) {
|
|
36321
|
+
EVENTS_MAP.MouseEvent.forEach((eventType) => {
|
|
36322
|
+
const callback = el.eventListeners[eventType];
|
|
36323
|
+
if (callback) {
|
|
36324
|
+
el.removeEventListener(eventType, callback);
|
|
36325
|
+
}
|
|
36326
|
+
});
|
|
36327
|
+
}
|
|
36328
|
+
});
|
|
36281
36329
|
this.vm = this.app.mount(rootEl);
|
|
36282
36330
|
this.renderer.app = this.app;
|
|
36283
36331
|
this.renderer.vm = this.vm;
|
|
@@ -36308,11 +36356,11 @@ void main(void)
|
|
|
36308
36356
|
this.currentScene = null;
|
|
36309
36357
|
this.librariesInstances = [];
|
|
36310
36358
|
}
|
|
36311
|
-
async _initialize(
|
|
36359
|
+
async _initialize(context2, guiEl) {
|
|
36312
36360
|
var _a;
|
|
36313
|
-
this.clientEngine =
|
|
36314
|
-
this.renderer =
|
|
36315
|
-
this.gameEngine =
|
|
36361
|
+
this.clientEngine = context2.inject(RpgClientEngine);
|
|
36362
|
+
this.renderer = context2.inject(RpgRenderer);
|
|
36363
|
+
this.gameEngine = context2.inject(GameEngineClient);
|
|
36316
36364
|
const {
|
|
36317
36365
|
gui
|
|
36318
36366
|
} = this.renderer.options;
|
|
@@ -36788,20 +36836,21 @@ void main(void)
|
|
|
36788
36836
|
}
|
|
36789
36837
|
const RpgGui = new Gui();
|
|
36790
36838
|
let Scene$1 = class Scene {
|
|
36791
|
-
constructor(
|
|
36792
|
-
this.
|
|
36839
|
+
constructor(context2) {
|
|
36840
|
+
this.context = context2;
|
|
36793
36841
|
this.objects = /* @__PURE__ */ new Map();
|
|
36794
36842
|
this.animationLayer = new Container();
|
|
36843
|
+
this.controls = this.context.inject(KeyboardControls);
|
|
36795
36844
|
this.animations = [];
|
|
36796
36845
|
this._data = new rxjs.BehaviorSubject({
|
|
36797
36846
|
data: {},
|
|
36798
36847
|
partial: {}
|
|
36799
36848
|
});
|
|
36849
|
+
this.game = this.context.inject(GameEngineClient);
|
|
36800
36850
|
this.objectsMoving = new rxjs.Subject();
|
|
36801
36851
|
const {
|
|
36802
36852
|
globalConfig
|
|
36803
36853
|
} = this.game.clientEngine;
|
|
36804
|
-
this.controls = this.game.clientEngine.controls;
|
|
36805
36854
|
const mergeInputs = {
|
|
36806
36855
|
...common.DefaultInput,
|
|
36807
36856
|
...globalConfig.inputs || {}
|
|
@@ -38518,9 +38567,9 @@ void main(void)
|
|
|
38518
38567
|
Viewport: PixiViewport
|
|
38519
38568
|
} = _PixiViewport;
|
|
38520
38569
|
class SceneMap extends Scene$1 {
|
|
38521
|
-
constructor(
|
|
38522
|
-
super(
|
|
38523
|
-
this.
|
|
38570
|
+
constructor(context2, renderer, options = {}) {
|
|
38571
|
+
super(context2);
|
|
38572
|
+
this.context = context2;
|
|
38524
38573
|
this.renderer = renderer;
|
|
38525
38574
|
this.options = options;
|
|
38526
38575
|
this.players = {};
|
|
@@ -38552,7 +38601,7 @@ void main(void)
|
|
|
38552
38601
|
this.gameMap.clearCacheTilesets();
|
|
38553
38602
|
this.constructMethods();
|
|
38554
38603
|
common.RpgCommonMap.bufferClient.set(obj.id, this.gameMap);
|
|
38555
|
-
this.tilemap = new TileMap(this.
|
|
38604
|
+
this.tilemap = new TileMap(this.context, this.gameMap.getData());
|
|
38556
38605
|
Assets.reset();
|
|
38557
38606
|
let nbLoad = 0;
|
|
38558
38607
|
const objects = this.game.world.getObjectsOfGroup();
|
|
@@ -38823,6 +38872,8 @@ void main(void)
|
|
|
38823
38872
|
this.viewport.on(eventName, (...args) => {
|
|
38824
38873
|
const ev = args[0];
|
|
38825
38874
|
const pos = ev.getLocalPosition(this.viewport);
|
|
38875
|
+
if (ev.defaultPrevented)
|
|
38876
|
+
return;
|
|
38826
38877
|
cb(pos, ev);
|
|
38827
38878
|
});
|
|
38828
38879
|
}
|
|
@@ -39195,13 +39246,14 @@ void main(void)
|
|
|
39195
39246
|
}
|
|
39196
39247
|
}
|
|
39197
39248
|
class TransitionScene {
|
|
39198
|
-
constructor(
|
|
39199
|
-
this.
|
|
39249
|
+
constructor(context2, container) {
|
|
39250
|
+
this.context = context2;
|
|
39200
39251
|
this.container = container;
|
|
39201
39252
|
this.frameIndex = 0;
|
|
39202
39253
|
this.animations = [];
|
|
39203
39254
|
this.complete = () => {
|
|
39204
39255
|
};
|
|
39256
|
+
this.clientEngine = this.context.inject(RpgClientEngine);
|
|
39205
39257
|
}
|
|
39206
39258
|
addFadeIn() {
|
|
39207
39259
|
return this.addFading(1, 0);
|
|
@@ -39256,9 +39308,17 @@ void main(void)
|
|
|
39256
39308
|
const {
|
|
39257
39309
|
elementToPositionAbsolute
|
|
39258
39310
|
} = common.Utils;
|
|
39311
|
+
const EVENTS_MAP = {
|
|
39312
|
+
MouseEvent: ["click", "dblclick", "mousedown", "mouseup", "mousemove", "mouseenter", "mouseleave", "mouseover", "mouseout", "contextmenu", "wheel"],
|
|
39313
|
+
KeyboardEvent: ["keydown", "keyup", "keypress", "keydownoutside", "keyupoutside", "keypressoutside"],
|
|
39314
|
+
PointerEvent: ["pointerdown", "pointerup", "pointermove", "pointerover", "pointerout", "pointerenter", "pointerleave", "pointercancel"],
|
|
39315
|
+
TouchEvent: ["touchstart", "touchend", "touchmove", "touchcancel"]
|
|
39316
|
+
};
|
|
39259
39317
|
class RpgRenderer {
|
|
39260
|
-
constructor(
|
|
39261
|
-
this.
|
|
39318
|
+
constructor(context2) {
|
|
39319
|
+
this.context = context2;
|
|
39320
|
+
this.gameEngine = this.context.inject(GameEngineClient);
|
|
39321
|
+
this.clientEngine = this.context.inject(RpgClientEngine);
|
|
39262
39322
|
this.stage = new Container();
|
|
39263
39323
|
this.sceneContainer = new Container();
|
|
39264
39324
|
this.fadeContainer = new Graphics();
|
|
@@ -39267,7 +39327,6 @@ void main(void)
|
|
|
39267
39327
|
this.scene = null;
|
|
39268
39328
|
this._width = 800;
|
|
39269
39329
|
this._height = 400;
|
|
39270
|
-
this.gameEngine = this.clientEngine.gameEngine;
|
|
39271
39330
|
this.loadingScene = {
|
|
39272
39331
|
transitionIn: new rxjs.Subject(),
|
|
39273
39332
|
transitionOut: new rxjs.Subject()
|
|
@@ -39354,8 +39413,23 @@ void main(void)
|
|
|
39354
39413
|
this.fadeContainer.addChild(this.spinner);
|
|
39355
39414
|
this.fadeContainer.visible = false;
|
|
39356
39415
|
this.fadeContainer.alpha = 0;
|
|
39357
|
-
await RpgGui._initialize(this.
|
|
39416
|
+
await RpgGui._initialize(this.context, this.guiEl);
|
|
39358
39417
|
this.resize();
|
|
39418
|
+
this.bindMouseControls();
|
|
39419
|
+
}
|
|
39420
|
+
bindMouseControls() {
|
|
39421
|
+
const controlInstance = this.context.inject(KeyboardControls);
|
|
39422
|
+
const controls = controlInstance.getControls();
|
|
39423
|
+
for (let key in controls) {
|
|
39424
|
+
const {
|
|
39425
|
+
actionName
|
|
39426
|
+
} = controls[key];
|
|
39427
|
+
if (EVENTS_MAP.MouseEvent.includes(key)) {
|
|
39428
|
+
this.canvas.addEventListener(key, (e2) => {
|
|
39429
|
+
controlInstance.applyControl(actionName);
|
|
39430
|
+
});
|
|
39431
|
+
}
|
|
39432
|
+
}
|
|
39359
39433
|
}
|
|
39360
39434
|
/** @internal */
|
|
39361
39435
|
resize() {
|
|
@@ -39430,7 +39504,7 @@ void main(void)
|
|
|
39430
39504
|
this.loadingScene.transitionOut.complete();
|
|
39431
39505
|
};
|
|
39432
39506
|
if (this.transitionMode == 1) {
|
|
39433
|
-
new TransitionScene(this.
|
|
39507
|
+
new TransitionScene(this.context, this.fadeContainer).addFadeOut().onComplete(finish).start();
|
|
39434
39508
|
} else {
|
|
39435
39509
|
finish();
|
|
39436
39510
|
}
|
|
@@ -39457,7 +39531,7 @@ void main(void)
|
|
|
39457
39531
|
switch (name) {
|
|
39458
39532
|
case Scene.Map:
|
|
39459
39533
|
const sceneClass = scenes[Scene.Map] || SceneMap;
|
|
39460
|
-
this.scene = new sceneClass(this.
|
|
39534
|
+
this.scene = new sceneClass(this.context, this.renderer, {
|
|
39461
39535
|
screenWidth: this.renderer.screen.width,
|
|
39462
39536
|
screenHeight: this.renderer.screen.height,
|
|
39463
39537
|
drawMap: this.options.drawMap
|
|
@@ -39473,7 +39547,7 @@ void main(void)
|
|
|
39473
39547
|
common.RpgPlugin.emit(common.HookClient.AfterSceneLoading, this.scene);
|
|
39474
39548
|
};
|
|
39475
39549
|
if (this.transitionMode == 1) {
|
|
39476
|
-
new TransitionScene(this.
|
|
39550
|
+
new TransitionScene(this.context, this.fadeContainer).addFadeIn().onComplete(finish).start();
|
|
39477
39551
|
} else {
|
|
39478
39552
|
finish();
|
|
39479
39553
|
}
|
|
@@ -39492,12 +39566,18 @@ void main(void)
|
|
|
39492
39566
|
* @returns {void}
|
|
39493
39567
|
*/
|
|
39494
39568
|
propagateEvent(ev) {
|
|
39495
|
-
|
|
39569
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
39570
|
+
const canvasX = rect.left + window.scrollX;
|
|
39571
|
+
const canvasY = rect.top + window.scrollY;
|
|
39572
|
+
const realX = ev.clientX - canvasX;
|
|
39573
|
+
const realY = ev.clientY - canvasY;
|
|
39496
39574
|
const boundary = new EventBoundary(this.stage);
|
|
39497
39575
|
const event = new FederatedPointerEvent(boundary);
|
|
39498
|
-
event.global.set(
|
|
39576
|
+
event.global.set(realX, realY);
|
|
39499
39577
|
event.type = ev.type;
|
|
39500
|
-
|
|
39578
|
+
const hitTestTarget = boundary.hitTest(realX, realY);
|
|
39579
|
+
hitTestTarget == null ? void 0 : hitTestTarget.dispatchEvent(event);
|
|
39580
|
+
this.canvas.dispatchEvent(new MouseEvent(ev.type, ev));
|
|
39501
39581
|
}
|
|
39502
39582
|
/***
|
|
39503
39583
|
* Propagate events from an HTMLElement to the canvas
|
|
@@ -39509,13 +39589,7 @@ void main(void)
|
|
|
39509
39589
|
* @returns {void}
|
|
39510
39590
|
*/
|
|
39511
39591
|
addPropagateEventsFrom(el) {
|
|
39512
|
-
|
|
39513
|
-
MouseEvent: ["click", "mousedown", "mouseup", "mousemove", "mouseenter", "mouseleave", "mouseover", "mouseout", "contextmenu", "wheel"],
|
|
39514
|
-
KeyboardEvent: ["keydown", "keyup", "keypress", "keydownoutside", "keyupoutside", "keypressoutside"],
|
|
39515
|
-
PointerEvent: ["pointerdown", "pointerup", "pointermove", "pointerover", "pointerout", "pointerenter", "pointerleave", "pointercancel"],
|
|
39516
|
-
TouchEvent: ["touchstart", "touchend", "touchmove", "touchcancel"]
|
|
39517
|
-
};
|
|
39518
|
-
for (let [_Constructor, events] of Object.entries(eventMap)) {
|
|
39592
|
+
for (let [_Constructor, events] of Object.entries(EVENTS_MAP)) {
|
|
39519
39593
|
for (let type of events) {
|
|
39520
39594
|
el.addEventListener(type, (e2) => {
|
|
39521
39595
|
const _class = window[_Constructor] ?? MouseEvent;
|
|
@@ -42346,15 +42420,22 @@ void main(void)
|
|
|
42346
42420
|
* @param {string} socket
|
|
42347
42421
|
* @return {World}
|
|
42348
42422
|
*/
|
|
42349
|
-
listen(socket,
|
|
42423
|
+
listen(socket, options = {}) {
|
|
42424
|
+
if (options.encoded === void 0)
|
|
42425
|
+
options.encoded = true;
|
|
42350
42426
|
this.socket = socket;
|
|
42351
42427
|
this.socket.on("uid", (response) => {
|
|
42352
42428
|
WorldClass.userId = response;
|
|
42353
42429
|
});
|
|
42430
|
+
this.socket.on("connect", () => {
|
|
42431
|
+
this.obs$.next({});
|
|
42432
|
+
});
|
|
42354
42433
|
this.socket.on("w", (response) => {
|
|
42355
|
-
|
|
42356
|
-
|
|
42357
|
-
|
|
42434
|
+
if (options.encoded) {
|
|
42435
|
+
const bufView = new Uint8Array(response);
|
|
42436
|
+
response = browser.decode(bufView);
|
|
42437
|
+
}
|
|
42438
|
+
const [roomId, time, data] = response;
|
|
42358
42439
|
const lastRoomId = this.obs$.value.roomId;
|
|
42359
42440
|
let mergeData = {};
|
|
42360
42441
|
let resetProps = [];
|
|
@@ -43361,8 +43442,8 @@ void main(void)
|
|
|
43361
43442
|
isString
|
|
43362
43443
|
} = common.Utils;
|
|
43363
43444
|
class RpgClientEngine {
|
|
43364
|
-
constructor(
|
|
43365
|
-
this.
|
|
43445
|
+
constructor(context2, options) {
|
|
43446
|
+
this.context = context2;
|
|
43366
43447
|
this.options = options;
|
|
43367
43448
|
this.globalConfig = {};
|
|
43368
43449
|
this._tick = new rxjs.BehaviorSubject({
|
|
@@ -43386,6 +43467,7 @@ void main(void)
|
|
|
43386
43467
|
this.serverFps = 60;
|
|
43387
43468
|
this.scheduler = new common.Scheduler();
|
|
43388
43469
|
this._serverUrl = "";
|
|
43470
|
+
this.gameEngine = this.context.inject(GameEngineClient);
|
|
43389
43471
|
this.objects = this.gameEngine.objects;
|
|
43390
43472
|
this.envs = {};
|
|
43391
43473
|
this.envs = options.envs || {};
|
|
@@ -43398,14 +43480,14 @@ void main(void)
|
|
|
43398
43480
|
});
|
|
43399
43481
|
}
|
|
43400
43482
|
async _init() {
|
|
43401
|
-
this.renderer =
|
|
43402
|
-
const
|
|
43483
|
+
this.renderer = this.context.inject(RpgRenderer);
|
|
43484
|
+
const pluginLoadResource = async (hookName, type) => {
|
|
43403
43485
|
const resource = this.options[type] || [];
|
|
43404
43486
|
this.options[type] = [...common.Utils.arrayFlat(await common.RpgPlugin.emit(hookName, resource)) || [], ...resource];
|
|
43405
43487
|
};
|
|
43406
|
-
await
|
|
43407
|
-
await
|
|
43408
|
-
await
|
|
43488
|
+
await pluginLoadResource(common.HookClient.AddSpriteSheet, "spritesheets");
|
|
43489
|
+
await pluginLoadResource(common.HookClient.AddGui, "gui");
|
|
43490
|
+
await pluginLoadResource(common.HookClient.AddSound, "sounds");
|
|
43409
43491
|
this.renderer.options = {
|
|
43410
43492
|
selector: "#rpg",
|
|
43411
43493
|
selectorCanvas: "#canvas",
|
|
@@ -43435,7 +43517,7 @@ void main(void)
|
|
|
43435
43517
|
});
|
|
43436
43518
|
}
|
|
43437
43519
|
}
|
|
43438
|
-
this.controls =
|
|
43520
|
+
this.controls = this.context.inject(KeyboardControls);
|
|
43439
43521
|
}
|
|
43440
43522
|
addResource(resourceClass, cb) {
|
|
43441
43523
|
let array2 = resourceClass;
|
|
@@ -43544,7 +43626,7 @@ void main(void)
|
|
|
43544
43626
|
}
|
|
43545
43627
|
}
|
|
43546
43628
|
const envUrl = this.envs.VITE_SERVER_URL;
|
|
43547
|
-
this.connection(serverUri.url ? serverUri.url + ":" + serverUri.port : envUrl ? envUrl : void 0);
|
|
43629
|
+
await this.connection(serverUri.url ? serverUri.url + ":" + serverUri.port : envUrl ? envUrl : void 0);
|
|
43548
43630
|
}
|
|
43549
43631
|
}
|
|
43550
43632
|
/**
|
|
@@ -43634,7 +43716,7 @@ void main(void)
|
|
|
43634
43716
|
* @returns {void}
|
|
43635
43717
|
* @memberof RpgClientEngine
|
|
43636
43718
|
*/
|
|
43637
|
-
connection(uri) {
|
|
43719
|
+
async connection(uri) {
|
|
43638
43720
|
const {
|
|
43639
43721
|
standalone
|
|
43640
43722
|
} = this.gameEngine;
|
|
@@ -43661,12 +43743,19 @@ void main(void)
|
|
|
43661
43743
|
this.socket.on("connect_error", (err) => {
|
|
43662
43744
|
common.RpgPlugin.emit(common.HookClient.ConnectedError, [this, err, this.socket], true);
|
|
43663
43745
|
});
|
|
43664
|
-
this.socket.on("preLoadScene", (
|
|
43665
|
-
|
|
43746
|
+
this.socket.on("preLoadScene", ({
|
|
43747
|
+
id,
|
|
43748
|
+
reconnect
|
|
43749
|
+
}) => {
|
|
43750
|
+
if (this.lastScene == id) {
|
|
43666
43751
|
return;
|
|
43667
43752
|
}
|
|
43668
|
-
this.lastScene =
|
|
43669
|
-
this.renderer.transitionScene(
|
|
43753
|
+
this.lastScene = id;
|
|
43754
|
+
this.renderer.transitionScene(id);
|
|
43755
|
+
if (reconnect) {
|
|
43756
|
+
this.roomJoin.next("");
|
|
43757
|
+
this.roomJoin.complete();
|
|
43758
|
+
}
|
|
43670
43759
|
});
|
|
43671
43760
|
this.socket.on(SocketEvents.GameReload, () => {
|
|
43672
43761
|
window.location.reload();
|
|
@@ -43677,7 +43766,7 @@ void main(void)
|
|
|
43677
43766
|
}) => {
|
|
43678
43767
|
this.renderer.loadScene(name, data);
|
|
43679
43768
|
});
|
|
43680
|
-
this.socket.on(SocketEvents.ChangeServer, ({
|
|
43769
|
+
this.socket.on(SocketEvents.ChangeServer, async ({
|
|
43681
43770
|
url: url2,
|
|
43682
43771
|
port
|
|
43683
43772
|
}) => {
|
|
@@ -43849,7 +43938,7 @@ void main(void)
|
|
|
43849
43938
|
});
|
|
43850
43939
|
RpgGui._setSocket(this.socket);
|
|
43851
43940
|
if (standalone) {
|
|
43852
|
-
this.socket.connection({
|
|
43941
|
+
await this.socket.connection({
|
|
43853
43942
|
auth: {
|
|
43854
43943
|
token: this.session
|
|
43855
43944
|
}
|
|
@@ -43994,6 +44083,13 @@ void main(void)
|
|
|
43994
44083
|
RpgSound.clear();
|
|
43995
44084
|
}
|
|
43996
44085
|
}
|
|
44086
|
+
let instanceContext = null;
|
|
44087
|
+
function inject(service, args = []) {
|
|
44088
|
+
return instanceContext.inject(service, args);
|
|
44089
|
+
}
|
|
44090
|
+
function setInject(context2) {
|
|
44091
|
+
instanceContext = context2;
|
|
44092
|
+
}
|
|
43997
44093
|
const clientEntryPoint = (modules, options) => {
|
|
43998
44094
|
if (!options.globalConfig)
|
|
43999
44095
|
options.globalConfig = {};
|
|
@@ -44034,9 +44130,9 @@ void main(void)
|
|
|
44034
44130
|
engine: relationsEngine
|
|
44035
44131
|
}
|
|
44036
44132
|
});
|
|
44037
|
-
const
|
|
44038
|
-
|
|
44039
|
-
return
|
|
44133
|
+
const context2 = new common.InjectContext();
|
|
44134
|
+
setInject(context2);
|
|
44135
|
+
return context2.inject(RpgClientEngine, [options]);
|
|
44040
44136
|
};
|
|
44041
44137
|
const RMSpritesheet = (framesWidth, framesHeight, frameStand = 1) => {
|
|
44042
44138
|
const frameY = (direction) => {
|
|
@@ -44159,6 +44255,27 @@ void main(void)
|
|
|
44159
44255
|
}, []);
|
|
44160
44256
|
return react.useSyncExternalStore(subscribe, () => currentPlayerRef.current);
|
|
44161
44257
|
};
|
|
44258
|
+
const useEventPropagator = () => {
|
|
44259
|
+
const ref = react.useRef(null);
|
|
44260
|
+
react.useEffect(() => {
|
|
44261
|
+
if (ref.current) {
|
|
44262
|
+
const element = ref.current;
|
|
44263
|
+
const eventListeners = {};
|
|
44264
|
+
const renderer = inject(RpgRenderer);
|
|
44265
|
+
EVENTS_MAP.MouseEvent.forEach((eventType) => {
|
|
44266
|
+
const listener = (event) => renderer.propagateEvent(event);
|
|
44267
|
+
element.addEventListener(eventType, listener);
|
|
44268
|
+
eventListeners[eventType] = listener;
|
|
44269
|
+
});
|
|
44270
|
+
return () => {
|
|
44271
|
+
EVENTS_MAP.MouseEvent.forEach((eventType) => {
|
|
44272
|
+
element.removeEventListener(eventType, eventListeners[eventType]);
|
|
44273
|
+
});
|
|
44274
|
+
};
|
|
44275
|
+
}
|
|
44276
|
+
}, [ref]);
|
|
44277
|
+
return ref;
|
|
44278
|
+
};
|
|
44162
44279
|
class ReactGui {
|
|
44163
44280
|
//private _tooltips: BehaviorSubject<any[]> = new BehaviorSubject([] as any)
|
|
44164
44281
|
constructor(rootEl, parentGui) {
|
|
@@ -44222,6 +44339,7 @@ void main(void)
|
|
|
44222
44339
|
ReactGui,
|
|
44223
44340
|
RpgReactContext,
|
|
44224
44341
|
useCurrentPlayer,
|
|
44342
|
+
useEventPropagator,
|
|
44225
44343
|
useObjects,
|
|
44226
44344
|
useStore
|
|
44227
44345
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -44264,11 +44382,13 @@ void main(void)
|
|
|
44264
44382
|
exports2.Animation = Animation$1;
|
|
44265
44383
|
exports2.AnimationClass = Animation;
|
|
44266
44384
|
exports2.Ease = Ease;
|
|
44385
|
+
exports2.KeyboardControls = KeyboardControls;
|
|
44267
44386
|
exports2.Presets = AnimationSpritesheet;
|
|
44268
44387
|
exports2.RpgClientEngine = RpgClientEngine;
|
|
44269
44388
|
exports2.RpgComponent = RpgComponent;
|
|
44270
44389
|
exports2.RpgGlobalSound = howler.Howler;
|
|
44271
44390
|
exports2.RpgGui = RpgGui;
|
|
44391
|
+
exports2.RpgRenderer = RpgRenderer;
|
|
44272
44392
|
exports2.RpgResource = RpgResource;
|
|
44273
44393
|
exports2.RpgScene = Scene$1;
|
|
44274
44394
|
exports2.RpgSceneMap = SceneMap;
|
|
@@ -44280,6 +44400,7 @@ void main(void)
|
|
|
44280
44400
|
exports2.Timeline = Timeline;
|
|
44281
44401
|
exports2.World = World;
|
|
44282
44402
|
exports2.entryPoint = clientEntryPoint;
|
|
44403
|
+
exports2.inject = inject;
|
|
44283
44404
|
exports2.room = room;
|
|
44284
44405
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
44285
44406
|
});
|