@rpgjs/client 4.1.3 → 4.2.1
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 +23 -0
- package/browser/{React-da18564b.js → React-f6f9b1de.js} +25 -0
- package/browser/index-e74a289f.js +44225 -0
- package/browser/manifest.json +10 -1
- package/browser/rpg.client.js +33 -44122
- package/browser/rpg.client.umd.cjs +470 -341
- 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/Presets/AnimationSpritesheet.d.ts +3 -3
- package/lib/Presets/AnimationSpritesheet.js +7 -3
- package/lib/Presets/AnimationSpritesheet.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 +7 -3
- 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 +6 -6
- 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/Presets/AnimationSpritesheet.ts +9 -4
- 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 +6 -4
- 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);
|
|
@@ -31969,7 +31746,11 @@ void main(void)
|
|
|
31969
31746
|
if (!tileHasZ)
|
|
31970
31747
|
return false;
|
|
31971
31748
|
if (yObject + hHitbox > tile2.y + tile2.height) {
|
|
31972
|
-
const zIntersection = intersection([
|
|
31749
|
+
const zIntersection = intersection([
|
|
31750
|
+
zObject,
|
|
31751
|
+
zObject + tile2.height
|
|
31752
|
+
/** Old code: height */
|
|
31753
|
+
], [realZ, realZ + tile2.height]);
|
|
31973
31754
|
if (!zIntersection) {
|
|
31974
31755
|
return true;
|
|
31975
31756
|
}
|
|
@@ -36149,6 +35930,259 @@ void main(void)
|
|
|
36149
35930
|
}
|
|
36150
35931
|
}
|
|
36151
35932
|
}
|
|
35933
|
+
class GameEngineClient extends common.RpgCommonGame {
|
|
35934
|
+
constructor() {
|
|
35935
|
+
super(...arguments);
|
|
35936
|
+
this._objects = new rxjs.BehaviorSubject({});
|
|
35937
|
+
this._obsObjects = {};
|
|
35938
|
+
this._obsObjectsDeleteNotifier$ = {};
|
|
35939
|
+
this._shapes = new rxjs.BehaviorSubject({});
|
|
35940
|
+
this._objectsChanged = new rxjs.BehaviorSubject({});
|
|
35941
|
+
this.world = {
|
|
35942
|
+
getObjects: this.getObjects.bind(this),
|
|
35943
|
+
getObject: (id) => {
|
|
35944
|
+
const obj = this.getObject(id);
|
|
35945
|
+
if (!obj)
|
|
35946
|
+
return null;
|
|
35947
|
+
return obj.object;
|
|
35948
|
+
},
|
|
35949
|
+
getShape: (id) => {
|
|
35950
|
+
const obj = this.getShape(id);
|
|
35951
|
+
if (!obj)
|
|
35952
|
+
return null;
|
|
35953
|
+
return obj.object;
|
|
35954
|
+
},
|
|
35955
|
+
getAll: (id) => {
|
|
35956
|
+
const obj = this.getObjectAndShape(id);
|
|
35957
|
+
if (!obj)
|
|
35958
|
+
return null;
|
|
35959
|
+
return obj.object;
|
|
35960
|
+
},
|
|
35961
|
+
removeObject: this.removeObject.bind(this),
|
|
35962
|
+
getObjectsOfGroup: () => {
|
|
35963
|
+
return {
|
|
35964
|
+
...this.getObjects(),
|
|
35965
|
+
...this.events
|
|
35966
|
+
};
|
|
35967
|
+
},
|
|
35968
|
+
getShapesOfGroup: () => {
|
|
35969
|
+
return this.getShapes();
|
|
35970
|
+
}
|
|
35971
|
+
};
|
|
35972
|
+
}
|
|
35973
|
+
initialize() {
|
|
35974
|
+
super.initialize(common.GameSide.Client);
|
|
35975
|
+
}
|
|
35976
|
+
_get(prop, id) {
|
|
35977
|
+
const objects = this[prop].value;
|
|
35978
|
+
const val = objects[id];
|
|
35979
|
+
if (!val)
|
|
35980
|
+
return null;
|
|
35981
|
+
return val;
|
|
35982
|
+
}
|
|
35983
|
+
get objectsChanged() {
|
|
35984
|
+
return this._objectsChanged.asObservable();
|
|
35985
|
+
}
|
|
35986
|
+
setObjectsChanged(val) {
|
|
35987
|
+
this._objectsChanged.next(val);
|
|
35988
|
+
}
|
|
35989
|
+
listenObject(id) {
|
|
35990
|
+
return this._obsObjects[id].asObservable();
|
|
35991
|
+
}
|
|
35992
|
+
get objects() {
|
|
35993
|
+
return this._objects.asObservable();
|
|
35994
|
+
}
|
|
35995
|
+
get shapes() {
|
|
35996
|
+
return this._shapes.asObservable();
|
|
35997
|
+
}
|
|
35998
|
+
get all() {
|
|
35999
|
+
return rxjs.combineLatest([this.objects, this.shapes]).pipe(rxjs.map(([objects, shapes]) => {
|
|
36000
|
+
return {
|
|
36001
|
+
...objects,
|
|
36002
|
+
...shapes
|
|
36003
|
+
};
|
|
36004
|
+
}));
|
|
36005
|
+
}
|
|
36006
|
+
getShapes() {
|
|
36007
|
+
return this._shapes.value;
|
|
36008
|
+
}
|
|
36009
|
+
getObjects() {
|
|
36010
|
+
return this._objects.value;
|
|
36011
|
+
}
|
|
36012
|
+
getObject(id) {
|
|
36013
|
+
return this._get("_objects", id);
|
|
36014
|
+
}
|
|
36015
|
+
getShape(id) {
|
|
36016
|
+
return this._get("_shapes", id);
|
|
36017
|
+
}
|
|
36018
|
+
getObjectAndShape(id) {
|
|
36019
|
+
let obj = this.getObject(id);
|
|
36020
|
+
if (!obj)
|
|
36021
|
+
obj = this.getShape(id);
|
|
36022
|
+
return obj;
|
|
36023
|
+
}
|
|
36024
|
+
resetObjects() {
|
|
36025
|
+
for (let id in this._obsObjectsDeleteNotifier$) {
|
|
36026
|
+
this._obsObjectsDeleteNotifier$[id].next();
|
|
36027
|
+
this._obsObjectsDeleteNotifier$[id].complete();
|
|
36028
|
+
this._obsObjects[id].complete();
|
|
36029
|
+
}
|
|
36030
|
+
this._obsObjectsDeleteNotifier$ = {};
|
|
36031
|
+
this._obsObjects = {};
|
|
36032
|
+
this._objects.next({});
|
|
36033
|
+
this._shapes.next({});
|
|
36034
|
+
}
|
|
36035
|
+
getDeleteNotifier(id) {
|
|
36036
|
+
return this._obsObjectsDeleteNotifier$[id].asObservable();
|
|
36037
|
+
}
|
|
36038
|
+
_remove(prop, id) {
|
|
36039
|
+
const logic = prop == "_objects" ? this.getObject(id) : this.getShape(id);
|
|
36040
|
+
if (logic) {
|
|
36041
|
+
const objects = {
|
|
36042
|
+
...this[prop].value
|
|
36043
|
+
};
|
|
36044
|
+
delete objects[id];
|
|
36045
|
+
this._obsObjectsDeleteNotifier$[id].next();
|
|
36046
|
+
this._obsObjectsDeleteNotifier$[id].complete();
|
|
36047
|
+
this._obsObjects[id].complete();
|
|
36048
|
+
delete this._obsObjects[id];
|
|
36049
|
+
delete this._obsObjectsDeleteNotifier$[id];
|
|
36050
|
+
this[prop].next(objects);
|
|
36051
|
+
return true;
|
|
36052
|
+
}
|
|
36053
|
+
return false;
|
|
36054
|
+
}
|
|
36055
|
+
removeObject(id) {
|
|
36056
|
+
if (this.events[id]) {
|
|
36057
|
+
delete this.events[id];
|
|
36058
|
+
}
|
|
36059
|
+
return this._remove("_objects", id);
|
|
36060
|
+
}
|
|
36061
|
+
removeShape(id) {
|
|
36062
|
+
return this._remove("_shapes", id);
|
|
36063
|
+
}
|
|
36064
|
+
removeObjectAndShape(id) {
|
|
36065
|
+
let bool = this.removeObject(id);
|
|
36066
|
+
if (!bool)
|
|
36067
|
+
bool = this.removeShape(id);
|
|
36068
|
+
return bool;
|
|
36069
|
+
}
|
|
36070
|
+
static toArray(obj, prop) {
|
|
36071
|
+
if (obj[prop])
|
|
36072
|
+
obj[prop] = Object.values(obj[prop]);
|
|
36073
|
+
}
|
|
36074
|
+
updateObject(obj) {
|
|
36075
|
+
const {
|
|
36076
|
+
playerId: id,
|
|
36077
|
+
params,
|
|
36078
|
+
localEvent,
|
|
36079
|
+
paramsChanged,
|
|
36080
|
+
isShape
|
|
36081
|
+
} = obj;
|
|
36082
|
+
if (paramsChanged.components) {
|
|
36083
|
+
paramsChanged.layout = {
|
|
36084
|
+
center: {
|
|
36085
|
+
lines: [{
|
|
36086
|
+
col: paramsChanged.components
|
|
36087
|
+
}]
|
|
36088
|
+
}
|
|
36089
|
+
};
|
|
36090
|
+
}
|
|
36091
|
+
const layoutToArray = (params2) => {
|
|
36092
|
+
const layout = params2.layout;
|
|
36093
|
+
if (layout) {
|
|
36094
|
+
["center", "top", "right", "bottom", "left"].forEach((key) => {
|
|
36095
|
+
if (!layout[key])
|
|
36096
|
+
return;
|
|
36097
|
+
GameEngineClient.toArray(layout[key], "lines");
|
|
36098
|
+
if (!layout[key].lines)
|
|
36099
|
+
return;
|
|
36100
|
+
layout[key].lines.map((layout2) => {
|
|
36101
|
+
GameEngineClient.toArray(layout2, "col");
|
|
36102
|
+
});
|
|
36103
|
+
});
|
|
36104
|
+
}
|
|
36105
|
+
};
|
|
36106
|
+
layoutToArray(params);
|
|
36107
|
+
GameEngineClient.toArray(params, "polygon");
|
|
36108
|
+
const isMe = () => id == this.playerId;
|
|
36109
|
+
let logic;
|
|
36110
|
+
const createObsForObject = (data) => {
|
|
36111
|
+
this._obsObjectsDeleteNotifier$[id] = new rxjs.Subject();
|
|
36112
|
+
this._obsObjects[id] = new rxjs.BehaviorSubject(data);
|
|
36113
|
+
};
|
|
36114
|
+
if (isShape) {
|
|
36115
|
+
logic = this.world.getShape(id);
|
|
36116
|
+
if (!logic) {
|
|
36117
|
+
logic = this.addShape(params);
|
|
36118
|
+
createObsForObject({
|
|
36119
|
+
logic
|
|
36120
|
+
});
|
|
36121
|
+
}
|
|
36122
|
+
} else {
|
|
36123
|
+
if (localEvent) {
|
|
36124
|
+
logic = this.events[id];
|
|
36125
|
+
if (!logic) {
|
|
36126
|
+
logic = this.addEvent(common.RpgCommonPlayer, id);
|
|
36127
|
+
createObsForObject({
|
|
36128
|
+
logic
|
|
36129
|
+
});
|
|
36130
|
+
this.events[id] = {
|
|
36131
|
+
object: logic
|
|
36132
|
+
};
|
|
36133
|
+
} else {
|
|
36134
|
+
logic = logic.object;
|
|
36135
|
+
}
|
|
36136
|
+
} else {
|
|
36137
|
+
logic = this.world.getObject(id);
|
|
36138
|
+
}
|
|
36139
|
+
if (!logic) {
|
|
36140
|
+
logic = this.addPlayer(common.RpgCommonPlayer, id);
|
|
36141
|
+
createObsForObject({
|
|
36142
|
+
logic
|
|
36143
|
+
});
|
|
36144
|
+
}
|
|
36145
|
+
}
|
|
36146
|
+
logic.prevParamsChanged = Object.assign({}, logic);
|
|
36147
|
+
for (let key in params) {
|
|
36148
|
+
if (!localEvent && (key == "position" || key == "direction" && paramsChanged && paramsChanged.position)) {
|
|
36149
|
+
if (isMe() && logic.canMove)
|
|
36150
|
+
continue;
|
|
36151
|
+
}
|
|
36152
|
+
logic[key] = params[key];
|
|
36153
|
+
}
|
|
36154
|
+
if (paramsChanged) {
|
|
36155
|
+
layoutToArray(paramsChanged);
|
|
36156
|
+
if (paramsChanged.layout)
|
|
36157
|
+
logic.componentChanged = paramsChanged.layout;
|
|
36158
|
+
if (paramsChanged.teleported) {
|
|
36159
|
+
logic.position = {
|
|
36160
|
+
...params.position
|
|
36161
|
+
};
|
|
36162
|
+
logic.direction = params.direction;
|
|
36163
|
+
}
|
|
36164
|
+
if (!logic.paramsChanged)
|
|
36165
|
+
logic.paramsChanged = {};
|
|
36166
|
+
logic.paramsChanged = paramsChanged;
|
|
36167
|
+
}
|
|
36168
|
+
const newObject = {
|
|
36169
|
+
object: logic,
|
|
36170
|
+
paramsChanged
|
|
36171
|
+
};
|
|
36172
|
+
this.setObject(id, newObject);
|
|
36173
|
+
return newObject;
|
|
36174
|
+
}
|
|
36175
|
+
setObject(id, newObject) {
|
|
36176
|
+
const propName = newObject.object instanceof common.RpgShape ? "_shapes" : "_objects";
|
|
36177
|
+
this[propName].next({
|
|
36178
|
+
...this[propName].value,
|
|
36179
|
+
...{
|
|
36180
|
+
[id]: newObject
|
|
36181
|
+
}
|
|
36182
|
+
});
|
|
36183
|
+
this._obsObjects[id].next(newObject);
|
|
36184
|
+
}
|
|
36185
|
+
}
|
|
36152
36186
|
const _hoisted_1 = {
|
|
36153
36187
|
id: "tooltips",
|
|
36154
36188
|
style: {
|
|
@@ -36269,8 +36303,6 @@ void main(void)
|
|
|
36269
36303
|
methods: {
|
|
36270
36304
|
tooltipPosition: parentGui.tooltipPosition.bind(parentGui),
|
|
36271
36305
|
tooltipFilter: parentGui.tooltipFilter.bind(parentGui)
|
|
36272
|
-
},
|
|
36273
|
-
mounted() {
|
|
36274
36306
|
}
|
|
36275
36307
|
};
|
|
36276
36308
|
this.app = vue.createApp(obj);
|
|
@@ -36278,6 +36310,26 @@ void main(void)
|
|
|
36278
36310
|
for (let ui of guiVue) {
|
|
36279
36311
|
this.app.component(ui.name, ui.gui);
|
|
36280
36312
|
}
|
|
36313
|
+
this.app.directive("propagate", {
|
|
36314
|
+
mounted: (el, binding2) => {
|
|
36315
|
+
el.eventListeners = {};
|
|
36316
|
+
EVENTS_MAP.MouseEvent.forEach((eventType) => {
|
|
36317
|
+
const callback = (ev) => {
|
|
36318
|
+
this.renderer.propagateEvent(ev);
|
|
36319
|
+
};
|
|
36320
|
+
el.eventListeners[eventType] = callback;
|
|
36321
|
+
el.addEventListener(eventType, callback);
|
|
36322
|
+
});
|
|
36323
|
+
},
|
|
36324
|
+
unmounted(el, binding2) {
|
|
36325
|
+
EVENTS_MAP.MouseEvent.forEach((eventType) => {
|
|
36326
|
+
const callback = el.eventListeners[eventType];
|
|
36327
|
+
if (callback) {
|
|
36328
|
+
el.removeEventListener(eventType, callback);
|
|
36329
|
+
}
|
|
36330
|
+
});
|
|
36331
|
+
}
|
|
36332
|
+
});
|
|
36281
36333
|
this.vm = this.app.mount(rootEl);
|
|
36282
36334
|
this.renderer.app = this.app;
|
|
36283
36335
|
this.renderer.vm = this.vm;
|
|
@@ -36308,11 +36360,11 @@ void main(void)
|
|
|
36308
36360
|
this.currentScene = null;
|
|
36309
36361
|
this.librariesInstances = [];
|
|
36310
36362
|
}
|
|
36311
|
-
async _initialize(
|
|
36363
|
+
async _initialize(context2, guiEl) {
|
|
36312
36364
|
var _a;
|
|
36313
|
-
this.clientEngine =
|
|
36314
|
-
this.renderer =
|
|
36315
|
-
this.gameEngine =
|
|
36365
|
+
this.clientEngine = context2.inject(RpgClientEngine);
|
|
36366
|
+
this.renderer = context2.inject(RpgRenderer);
|
|
36367
|
+
this.gameEngine = context2.inject(GameEngineClient);
|
|
36316
36368
|
const {
|
|
36317
36369
|
gui
|
|
36318
36370
|
} = this.renderer.options;
|
|
@@ -36788,20 +36840,21 @@ void main(void)
|
|
|
36788
36840
|
}
|
|
36789
36841
|
const RpgGui = new Gui();
|
|
36790
36842
|
let Scene$1 = class Scene {
|
|
36791
|
-
constructor(
|
|
36792
|
-
this.
|
|
36843
|
+
constructor(context2) {
|
|
36844
|
+
this.context = context2;
|
|
36793
36845
|
this.objects = /* @__PURE__ */ new Map();
|
|
36794
36846
|
this.animationLayer = new Container();
|
|
36847
|
+
this.controls = this.context.inject(KeyboardControls);
|
|
36795
36848
|
this.animations = [];
|
|
36796
36849
|
this._data = new rxjs.BehaviorSubject({
|
|
36797
36850
|
data: {},
|
|
36798
36851
|
partial: {}
|
|
36799
36852
|
});
|
|
36853
|
+
this.game = this.context.inject(GameEngineClient);
|
|
36800
36854
|
this.objectsMoving = new rxjs.Subject();
|
|
36801
36855
|
const {
|
|
36802
36856
|
globalConfig
|
|
36803
36857
|
} = this.game.clientEngine;
|
|
36804
|
-
this.controls = this.game.clientEngine.controls;
|
|
36805
36858
|
const mergeInputs = {
|
|
36806
36859
|
...common.DefaultInput,
|
|
36807
36860
|
...globalConfig.inputs || {}
|
|
@@ -38518,9 +38571,9 @@ void main(void)
|
|
|
38518
38571
|
Viewport: PixiViewport
|
|
38519
38572
|
} = _PixiViewport;
|
|
38520
38573
|
class SceneMap extends Scene$1 {
|
|
38521
|
-
constructor(
|
|
38522
|
-
super(
|
|
38523
|
-
this.
|
|
38574
|
+
constructor(context2, renderer, options = {}) {
|
|
38575
|
+
super(context2);
|
|
38576
|
+
this.context = context2;
|
|
38524
38577
|
this.renderer = renderer;
|
|
38525
38578
|
this.options = options;
|
|
38526
38579
|
this.players = {};
|
|
@@ -38552,7 +38605,7 @@ void main(void)
|
|
|
38552
38605
|
this.gameMap.clearCacheTilesets();
|
|
38553
38606
|
this.constructMethods();
|
|
38554
38607
|
common.RpgCommonMap.bufferClient.set(obj.id, this.gameMap);
|
|
38555
|
-
this.tilemap = new TileMap(this.
|
|
38608
|
+
this.tilemap = new TileMap(this.context, this.gameMap.getData());
|
|
38556
38609
|
Assets.reset();
|
|
38557
38610
|
let nbLoad = 0;
|
|
38558
38611
|
const objects = this.game.world.getObjectsOfGroup();
|
|
@@ -38823,6 +38876,8 @@ void main(void)
|
|
|
38823
38876
|
this.viewport.on(eventName, (...args) => {
|
|
38824
38877
|
const ev = args[0];
|
|
38825
38878
|
const pos = ev.getLocalPosition(this.viewport);
|
|
38879
|
+
if (ev.defaultPrevented)
|
|
38880
|
+
return;
|
|
38826
38881
|
cb(pos, ev);
|
|
38827
38882
|
});
|
|
38828
38883
|
}
|
|
@@ -39195,13 +39250,14 @@ void main(void)
|
|
|
39195
39250
|
}
|
|
39196
39251
|
}
|
|
39197
39252
|
class TransitionScene {
|
|
39198
|
-
constructor(
|
|
39199
|
-
this.
|
|
39253
|
+
constructor(context2, container) {
|
|
39254
|
+
this.context = context2;
|
|
39200
39255
|
this.container = container;
|
|
39201
39256
|
this.frameIndex = 0;
|
|
39202
39257
|
this.animations = [];
|
|
39203
39258
|
this.complete = () => {
|
|
39204
39259
|
};
|
|
39260
|
+
this.clientEngine = this.context.inject(RpgClientEngine);
|
|
39205
39261
|
}
|
|
39206
39262
|
addFadeIn() {
|
|
39207
39263
|
return this.addFading(1, 0);
|
|
@@ -39256,9 +39312,17 @@ void main(void)
|
|
|
39256
39312
|
const {
|
|
39257
39313
|
elementToPositionAbsolute
|
|
39258
39314
|
} = common.Utils;
|
|
39315
|
+
const EVENTS_MAP = {
|
|
39316
|
+
MouseEvent: ["click", "dblclick", "mousedown", "mouseup", "mousemove", "mouseenter", "mouseleave", "mouseover", "mouseout", "contextmenu", "wheel"],
|
|
39317
|
+
KeyboardEvent: ["keydown", "keyup", "keypress", "keydownoutside", "keyupoutside", "keypressoutside"],
|
|
39318
|
+
PointerEvent: ["pointerdown", "pointerup", "pointermove", "pointerover", "pointerout", "pointerenter", "pointerleave", "pointercancel"],
|
|
39319
|
+
TouchEvent: ["touchstart", "touchend", "touchmove", "touchcancel"]
|
|
39320
|
+
};
|
|
39259
39321
|
class RpgRenderer {
|
|
39260
|
-
constructor(
|
|
39261
|
-
this.
|
|
39322
|
+
constructor(context2) {
|
|
39323
|
+
this.context = context2;
|
|
39324
|
+
this.gameEngine = this.context.inject(GameEngineClient);
|
|
39325
|
+
this.clientEngine = this.context.inject(RpgClientEngine);
|
|
39262
39326
|
this.stage = new Container();
|
|
39263
39327
|
this.sceneContainer = new Container();
|
|
39264
39328
|
this.fadeContainer = new Graphics();
|
|
@@ -39267,7 +39331,6 @@ void main(void)
|
|
|
39267
39331
|
this.scene = null;
|
|
39268
39332
|
this._width = 800;
|
|
39269
39333
|
this._height = 400;
|
|
39270
|
-
this.gameEngine = this.clientEngine.gameEngine;
|
|
39271
39334
|
this.loadingScene = {
|
|
39272
39335
|
transitionIn: new rxjs.Subject(),
|
|
39273
39336
|
transitionOut: new rxjs.Subject()
|
|
@@ -39354,8 +39417,23 @@ void main(void)
|
|
|
39354
39417
|
this.fadeContainer.addChild(this.spinner);
|
|
39355
39418
|
this.fadeContainer.visible = false;
|
|
39356
39419
|
this.fadeContainer.alpha = 0;
|
|
39357
|
-
await RpgGui._initialize(this.
|
|
39420
|
+
await RpgGui._initialize(this.context, this.guiEl);
|
|
39358
39421
|
this.resize();
|
|
39422
|
+
this.bindMouseControls();
|
|
39423
|
+
}
|
|
39424
|
+
bindMouseControls() {
|
|
39425
|
+
const controlInstance = this.context.inject(KeyboardControls);
|
|
39426
|
+
const controls = controlInstance.getControls();
|
|
39427
|
+
for (let key in controls) {
|
|
39428
|
+
const {
|
|
39429
|
+
actionName
|
|
39430
|
+
} = controls[key];
|
|
39431
|
+
if (EVENTS_MAP.MouseEvent.includes(key)) {
|
|
39432
|
+
this.canvas.addEventListener(key, (e2) => {
|
|
39433
|
+
controlInstance.applyControl(actionName);
|
|
39434
|
+
});
|
|
39435
|
+
}
|
|
39436
|
+
}
|
|
39359
39437
|
}
|
|
39360
39438
|
/** @internal */
|
|
39361
39439
|
resize() {
|
|
@@ -39430,7 +39508,7 @@ void main(void)
|
|
|
39430
39508
|
this.loadingScene.transitionOut.complete();
|
|
39431
39509
|
};
|
|
39432
39510
|
if (this.transitionMode == 1) {
|
|
39433
|
-
new TransitionScene(this.
|
|
39511
|
+
new TransitionScene(this.context, this.fadeContainer).addFadeOut().onComplete(finish).start();
|
|
39434
39512
|
} else {
|
|
39435
39513
|
finish();
|
|
39436
39514
|
}
|
|
@@ -39457,7 +39535,7 @@ void main(void)
|
|
|
39457
39535
|
switch (name) {
|
|
39458
39536
|
case Scene.Map:
|
|
39459
39537
|
const sceneClass = scenes[Scene.Map] || SceneMap;
|
|
39460
|
-
this.scene = new sceneClass(this.
|
|
39538
|
+
this.scene = new sceneClass(this.context, this.renderer, {
|
|
39461
39539
|
screenWidth: this.renderer.screen.width,
|
|
39462
39540
|
screenHeight: this.renderer.screen.height,
|
|
39463
39541
|
drawMap: this.options.drawMap
|
|
@@ -39473,7 +39551,7 @@ void main(void)
|
|
|
39473
39551
|
common.RpgPlugin.emit(common.HookClient.AfterSceneLoading, this.scene);
|
|
39474
39552
|
};
|
|
39475
39553
|
if (this.transitionMode == 1) {
|
|
39476
|
-
new TransitionScene(this.
|
|
39554
|
+
new TransitionScene(this.context, this.fadeContainer).addFadeIn().onComplete(finish).start();
|
|
39477
39555
|
} else {
|
|
39478
39556
|
finish();
|
|
39479
39557
|
}
|
|
@@ -39492,12 +39570,18 @@ void main(void)
|
|
|
39492
39570
|
* @returns {void}
|
|
39493
39571
|
*/
|
|
39494
39572
|
propagateEvent(ev) {
|
|
39495
|
-
|
|
39573
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
39574
|
+
const canvasX = rect.left + window.scrollX;
|
|
39575
|
+
const canvasY = rect.top + window.scrollY;
|
|
39576
|
+
const realX = ev.clientX - canvasX;
|
|
39577
|
+
const realY = ev.clientY - canvasY;
|
|
39496
39578
|
const boundary = new EventBoundary(this.stage);
|
|
39497
39579
|
const event = new FederatedPointerEvent(boundary);
|
|
39498
|
-
event.global.set(
|
|
39580
|
+
event.global.set(realX, realY);
|
|
39499
39581
|
event.type = ev.type;
|
|
39500
|
-
|
|
39582
|
+
const hitTestTarget = boundary.hitTest(realX, realY);
|
|
39583
|
+
hitTestTarget == null ? void 0 : hitTestTarget.dispatchEvent(event);
|
|
39584
|
+
this.canvas.dispatchEvent(new MouseEvent(ev.type, ev));
|
|
39501
39585
|
}
|
|
39502
39586
|
/***
|
|
39503
39587
|
* Propagate events from an HTMLElement to the canvas
|
|
@@ -39509,13 +39593,7 @@ void main(void)
|
|
|
39509
39593
|
* @returns {void}
|
|
39510
39594
|
*/
|
|
39511
39595
|
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)) {
|
|
39596
|
+
for (let [_Constructor, events] of Object.entries(EVENTS_MAP)) {
|
|
39519
39597
|
for (let type of events) {
|
|
39520
39598
|
el.addEventListener(type, (e2) => {
|
|
39521
39599
|
const _class = window[_Constructor] ?? MouseEvent;
|
|
@@ -42346,15 +42424,22 @@ void main(void)
|
|
|
42346
42424
|
* @param {string} socket
|
|
42347
42425
|
* @return {World}
|
|
42348
42426
|
*/
|
|
42349
|
-
listen(socket,
|
|
42427
|
+
listen(socket, options = {}) {
|
|
42428
|
+
if (options.encoded === void 0)
|
|
42429
|
+
options.encoded = true;
|
|
42350
42430
|
this.socket = socket;
|
|
42351
42431
|
this.socket.on("uid", (response) => {
|
|
42352
42432
|
WorldClass.userId = response;
|
|
42353
42433
|
});
|
|
42434
|
+
this.socket.on("connect", () => {
|
|
42435
|
+
this.obs$.next({});
|
|
42436
|
+
});
|
|
42354
42437
|
this.socket.on("w", (response) => {
|
|
42355
|
-
|
|
42356
|
-
|
|
42357
|
-
|
|
42438
|
+
if (options.encoded) {
|
|
42439
|
+
const bufView = new Uint8Array(response);
|
|
42440
|
+
response = browser.decode(bufView);
|
|
42441
|
+
}
|
|
42442
|
+
const [roomId, time, data] = response;
|
|
42358
42443
|
const lastRoomId = this.obs$.value.roomId;
|
|
42359
42444
|
let mergeData = {};
|
|
42360
42445
|
let resetProps = [];
|
|
@@ -43361,8 +43446,8 @@ void main(void)
|
|
|
43361
43446
|
isString
|
|
43362
43447
|
} = common.Utils;
|
|
43363
43448
|
class RpgClientEngine {
|
|
43364
|
-
constructor(
|
|
43365
|
-
this.
|
|
43449
|
+
constructor(context2, options) {
|
|
43450
|
+
this.context = context2;
|
|
43366
43451
|
this.options = options;
|
|
43367
43452
|
this.globalConfig = {};
|
|
43368
43453
|
this._tick = new rxjs.BehaviorSubject({
|
|
@@ -43386,6 +43471,7 @@ void main(void)
|
|
|
43386
43471
|
this.serverFps = 60;
|
|
43387
43472
|
this.scheduler = new common.Scheduler();
|
|
43388
43473
|
this._serverUrl = "";
|
|
43474
|
+
this.gameEngine = this.context.inject(GameEngineClient);
|
|
43389
43475
|
this.objects = this.gameEngine.objects;
|
|
43390
43476
|
this.envs = {};
|
|
43391
43477
|
this.envs = options.envs || {};
|
|
@@ -43398,14 +43484,14 @@ void main(void)
|
|
|
43398
43484
|
});
|
|
43399
43485
|
}
|
|
43400
43486
|
async _init() {
|
|
43401
|
-
this.renderer =
|
|
43402
|
-
const
|
|
43487
|
+
this.renderer = this.context.inject(RpgRenderer);
|
|
43488
|
+
const pluginLoadResource = async (hookName, type) => {
|
|
43403
43489
|
const resource = this.options[type] || [];
|
|
43404
43490
|
this.options[type] = [...common.Utils.arrayFlat(await common.RpgPlugin.emit(hookName, resource)) || [], ...resource];
|
|
43405
43491
|
};
|
|
43406
|
-
await
|
|
43407
|
-
await
|
|
43408
|
-
await
|
|
43492
|
+
await pluginLoadResource(common.HookClient.AddSpriteSheet, "spritesheets");
|
|
43493
|
+
await pluginLoadResource(common.HookClient.AddGui, "gui");
|
|
43494
|
+
await pluginLoadResource(common.HookClient.AddSound, "sounds");
|
|
43409
43495
|
this.renderer.options = {
|
|
43410
43496
|
selector: "#rpg",
|
|
43411
43497
|
selectorCanvas: "#canvas",
|
|
@@ -43435,7 +43521,7 @@ void main(void)
|
|
|
43435
43521
|
});
|
|
43436
43522
|
}
|
|
43437
43523
|
}
|
|
43438
|
-
this.controls =
|
|
43524
|
+
this.controls = this.context.inject(KeyboardControls);
|
|
43439
43525
|
}
|
|
43440
43526
|
addResource(resourceClass, cb) {
|
|
43441
43527
|
let array2 = resourceClass;
|
|
@@ -43544,7 +43630,7 @@ void main(void)
|
|
|
43544
43630
|
}
|
|
43545
43631
|
}
|
|
43546
43632
|
const envUrl = this.envs.VITE_SERVER_URL;
|
|
43547
|
-
this.connection(serverUri.url ? serverUri.url + ":" + serverUri.port : envUrl ? envUrl : void 0);
|
|
43633
|
+
await this.connection(serverUri.url ? serverUri.url + ":" + serverUri.port : envUrl ? envUrl : void 0);
|
|
43548
43634
|
}
|
|
43549
43635
|
}
|
|
43550
43636
|
/**
|
|
@@ -43634,7 +43720,7 @@ void main(void)
|
|
|
43634
43720
|
* @returns {void}
|
|
43635
43721
|
* @memberof RpgClientEngine
|
|
43636
43722
|
*/
|
|
43637
|
-
connection(uri) {
|
|
43723
|
+
async connection(uri) {
|
|
43638
43724
|
const {
|
|
43639
43725
|
standalone
|
|
43640
43726
|
} = this.gameEngine;
|
|
@@ -43661,12 +43747,19 @@ void main(void)
|
|
|
43661
43747
|
this.socket.on("connect_error", (err) => {
|
|
43662
43748
|
common.RpgPlugin.emit(common.HookClient.ConnectedError, [this, err, this.socket], true);
|
|
43663
43749
|
});
|
|
43664
|
-
this.socket.on("preLoadScene", (
|
|
43665
|
-
|
|
43750
|
+
this.socket.on("preLoadScene", ({
|
|
43751
|
+
id,
|
|
43752
|
+
reconnect
|
|
43753
|
+
}) => {
|
|
43754
|
+
if (this.lastScene == id) {
|
|
43666
43755
|
return;
|
|
43667
43756
|
}
|
|
43668
|
-
this.lastScene =
|
|
43669
|
-
this.renderer.transitionScene(
|
|
43757
|
+
this.lastScene = id;
|
|
43758
|
+
this.renderer.transitionScene(id);
|
|
43759
|
+
if (reconnect) {
|
|
43760
|
+
this.roomJoin.next("");
|
|
43761
|
+
this.roomJoin.complete();
|
|
43762
|
+
}
|
|
43670
43763
|
});
|
|
43671
43764
|
this.socket.on(SocketEvents.GameReload, () => {
|
|
43672
43765
|
window.location.reload();
|
|
@@ -43677,7 +43770,7 @@ void main(void)
|
|
|
43677
43770
|
}) => {
|
|
43678
43771
|
this.renderer.loadScene(name, data);
|
|
43679
43772
|
});
|
|
43680
|
-
this.socket.on(SocketEvents.ChangeServer, ({
|
|
43773
|
+
this.socket.on(SocketEvents.ChangeServer, async ({
|
|
43681
43774
|
url: url2,
|
|
43682
43775
|
port
|
|
43683
43776
|
}) => {
|
|
@@ -43849,7 +43942,7 @@ void main(void)
|
|
|
43849
43942
|
});
|
|
43850
43943
|
RpgGui._setSocket(this.socket);
|
|
43851
43944
|
if (standalone) {
|
|
43852
|
-
this.socket.connection({
|
|
43945
|
+
await this.socket.connection({
|
|
43853
43946
|
auth: {
|
|
43854
43947
|
token: this.session
|
|
43855
43948
|
}
|
|
@@ -43994,6 +44087,13 @@ void main(void)
|
|
|
43994
44087
|
RpgSound.clear();
|
|
43995
44088
|
}
|
|
43996
44089
|
}
|
|
44090
|
+
let instanceContext = null;
|
|
44091
|
+
function inject(service, args = []) {
|
|
44092
|
+
return instanceContext.inject(service, args);
|
|
44093
|
+
}
|
|
44094
|
+
function setInject(context2) {
|
|
44095
|
+
instanceContext = context2;
|
|
44096
|
+
}
|
|
43997
44097
|
const clientEntryPoint = (modules, options) => {
|
|
43998
44098
|
if (!options.globalConfig)
|
|
43999
44099
|
options.globalConfig = {};
|
|
@@ -44034,17 +44134,21 @@ void main(void)
|
|
|
44034
44134
|
engine: relationsEngine
|
|
44035
44135
|
}
|
|
44036
44136
|
});
|
|
44037
|
-
const
|
|
44038
|
-
|
|
44039
|
-
return
|
|
44137
|
+
const context2 = new common.InjectContext();
|
|
44138
|
+
setInject(context2);
|
|
44139
|
+
return context2.inject(RpgClientEngine, [options]);
|
|
44040
44140
|
};
|
|
44041
44141
|
const RMSpritesheet = (framesWidth, framesHeight, frameStand = 1) => {
|
|
44142
|
+
if (framesWidth <= frameStand) {
|
|
44143
|
+
frameStand = framesWidth - 1;
|
|
44144
|
+
}
|
|
44042
44145
|
const frameY = (direction) => {
|
|
44146
|
+
const gap = Math.max(4 - framesHeight, 0);
|
|
44043
44147
|
return {
|
|
44044
44148
|
[common.Direction.Down]: 0,
|
|
44045
|
-
[common.Direction.Left]: 1,
|
|
44046
|
-
[common.Direction.Right]: 2,
|
|
44047
|
-
[common.Direction.Up]: 3
|
|
44149
|
+
[common.Direction.Left]: Math.max(0, 1 - gap),
|
|
44150
|
+
[common.Direction.Right]: Math.max(0, 2 - gap),
|
|
44151
|
+
[common.Direction.Up]: Math.max(0, 3 - gap)
|
|
44048
44152
|
}[direction];
|
|
44049
44153
|
};
|
|
44050
44154
|
const stand = (direction) => [{
|
|
@@ -44159,6 +44263,27 @@ void main(void)
|
|
|
44159
44263
|
}, []);
|
|
44160
44264
|
return react.useSyncExternalStore(subscribe, () => currentPlayerRef.current);
|
|
44161
44265
|
};
|
|
44266
|
+
const useEventPropagator = () => {
|
|
44267
|
+
const ref = react.useRef(null);
|
|
44268
|
+
react.useEffect(() => {
|
|
44269
|
+
if (ref.current) {
|
|
44270
|
+
const element = ref.current;
|
|
44271
|
+
const eventListeners = {};
|
|
44272
|
+
const renderer = inject(RpgRenderer);
|
|
44273
|
+
EVENTS_MAP.MouseEvent.forEach((eventType) => {
|
|
44274
|
+
const listener = (event) => renderer.propagateEvent(event);
|
|
44275
|
+
element.addEventListener(eventType, listener);
|
|
44276
|
+
eventListeners[eventType] = listener;
|
|
44277
|
+
});
|
|
44278
|
+
return () => {
|
|
44279
|
+
EVENTS_MAP.MouseEvent.forEach((eventType) => {
|
|
44280
|
+
element.removeEventListener(eventType, eventListeners[eventType]);
|
|
44281
|
+
});
|
|
44282
|
+
};
|
|
44283
|
+
}
|
|
44284
|
+
}, [ref]);
|
|
44285
|
+
return ref;
|
|
44286
|
+
};
|
|
44162
44287
|
class ReactGui {
|
|
44163
44288
|
//private _tooltips: BehaviorSubject<any[]> = new BehaviorSubject([] as any)
|
|
44164
44289
|
constructor(rootEl, parentGui) {
|
|
@@ -44222,6 +44347,7 @@ void main(void)
|
|
|
44222
44347
|
ReactGui,
|
|
44223
44348
|
RpgReactContext,
|
|
44224
44349
|
useCurrentPlayer,
|
|
44350
|
+
useEventPropagator,
|
|
44225
44351
|
useObjects,
|
|
44226
44352
|
useStore
|
|
44227
44353
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -44264,11 +44390,13 @@ void main(void)
|
|
|
44264
44390
|
exports2.Animation = Animation$1;
|
|
44265
44391
|
exports2.AnimationClass = Animation;
|
|
44266
44392
|
exports2.Ease = Ease;
|
|
44393
|
+
exports2.KeyboardControls = KeyboardControls;
|
|
44267
44394
|
exports2.Presets = AnimationSpritesheet;
|
|
44268
44395
|
exports2.RpgClientEngine = RpgClientEngine;
|
|
44269
44396
|
exports2.RpgComponent = RpgComponent;
|
|
44270
44397
|
exports2.RpgGlobalSound = howler.Howler;
|
|
44271
44398
|
exports2.RpgGui = RpgGui;
|
|
44399
|
+
exports2.RpgRenderer = RpgRenderer;
|
|
44272
44400
|
exports2.RpgResource = RpgResource;
|
|
44273
44401
|
exports2.RpgScene = Scene$1;
|
|
44274
44402
|
exports2.RpgSceneMap = SceneMap;
|
|
@@ -44280,6 +44408,7 @@ void main(void)
|
|
|
44280
44408
|
exports2.Timeline = Timeline;
|
|
44281
44409
|
exports2.World = World;
|
|
44282
44410
|
exports2.entryPoint = clientEntryPoint;
|
|
44411
|
+
exports2.inject = inject;
|
|
44283
44412
|
exports2.room = room;
|
|
44284
44413
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
44285
44414
|
});
|