@rpgjs/client 3.3.1 → 4.0.0-beta.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/LICENSE +19 -0
- package/lib/Components/AbstractComponent.d.ts +3 -2
- package/lib/Components/AbstractComponent.js +17 -28
- package/lib/Components/AbstractComponent.js.map +1 -1
- package/lib/Components/BarComponent.d.ts +2 -1
- package/lib/Components/BarComponent.js +32 -33
- package/lib/Components/BarComponent.js.map +1 -1
- package/lib/Components/Component.d.ts +3 -3
- package/lib/Components/Component.js +84 -96
- package/lib/Components/Component.js.map +1 -1
- package/lib/Components/DebugComponent.d.ts +2 -1
- package/lib/Components/DebugComponent.js +9 -10
- package/lib/Components/DebugComponent.js.map +1 -1
- package/lib/Components/ImageComponent.d.ts +2 -1
- package/lib/Components/ImageComponent.js +5 -7
- package/lib/Components/ImageComponent.js.map +1 -1
- package/lib/Components/ShapeComponent.d.ts +2 -1
- package/lib/Components/ShapeComponent.js +14 -14
- package/lib/Components/ShapeComponent.js.map +1 -1
- package/lib/Components/TextComponent.d.ts +3 -2
- package/lib/Components/TextComponent.js +10 -9
- package/lib/Components/TextComponent.js.map +1 -1
- package/lib/Components/TileComponent.d.ts +2 -1
- package/lib/Components/TileComponent.js +12 -16
- package/lib/Components/TileComponent.js.map +1 -1
- package/lib/Effects/Animation.d.ts +10 -9
- package/lib/Effects/Animation.js +36 -36
- package/lib/Effects/Animation.js.map +1 -1
- package/lib/Effects/AnimationCharacter.js +2 -5
- package/lib/Effects/AnimationCharacter.js.map +1 -1
- package/lib/Effects/Spinner.d.ts +3 -2
- package/lib/Effects/Spinner.js +2 -5
- package/lib/Effects/Spinner.js.map +1 -1
- package/lib/Effects/Timeline.d.ts +1 -1
- package/lib/Effects/Timeline.js +6 -10
- package/lib/Effects/Timeline.js.map +1 -1
- package/lib/Effects/TransitionScene.d.ts +2 -1
- package/lib/Effects/TransitionScene.js +3 -7
- package/lib/Effects/TransitionScene.js.map +1 -1
- package/lib/GameEngine.js +51 -26
- package/lib/GameEngine.js.map +1 -1
- package/lib/Interfaces/Character.js +1 -2
- package/lib/Interfaces/Scene.js +1 -2
- package/lib/KeyboardControls.d.ts +2 -1
- package/lib/KeyboardControls.js +47 -45
- package/lib/KeyboardControls.js.map +1 -1
- package/lib/Logger.js +1 -5
- package/lib/Logger.js.map +1 -1
- package/lib/Presets/AnimationSpritesheet.js +9 -13
- package/lib/Presets/AnimationSpritesheet.js.map +1 -1
- package/lib/Presets/Scene.js +2 -5
- package/lib/Presets/Scene.js.map +1 -1
- package/lib/Renderer.d.ts +5 -3
- package/lib/Renderer.js +68 -60
- package/lib/Renderer.js.map +1 -1
- package/lib/Resources.js +1 -5
- package/lib/Resources.js.map +1 -1
- package/lib/RpgClient.d.ts +3 -2
- package/lib/RpgClient.js +1 -2
- package/lib/RpgClientEngine.d.ts +2 -2
- package/lib/RpgClientEngine.js +196 -175
- package/lib/RpgClientEngine.js.map +1 -1
- package/lib/RpgGui.js +40 -41
- package/lib/RpgGui.js.map +1 -1
- package/lib/Scene/EventLayer.d.ts +4 -0
- package/lib/Scene/EventLayer.js +8 -0
- package/lib/Scene/EventLayer.js.map +1 -0
- package/lib/Scene/Map.d.ts +17 -3
- package/lib/Scene/Map.js +157 -113
- package/lib/Scene/Map.js.map +1 -1
- package/lib/Scene/Scene.d.ts +3 -3
- package/lib/Scene/Scene.js +24 -20
- package/lib/Scene/Scene.js.map +1 -1
- package/lib/Scene/SceneData.js +1 -5
- package/lib/Scene/SceneData.js.map +1 -1
- package/lib/Sound/RpgSound.js +8 -11
- package/lib/Sound/RpgSound.js.map +1 -1
- package/lib/Sound/Sound.d.ts +2 -2
- package/lib/Sound/Sound.js +1 -5
- package/lib/Sound/Sound.js.map +1 -1
- package/lib/Sound/Sounds.js +4 -8
- package/lib/Sound/Sounds.js.map +1 -1
- package/lib/Sprite/Character.d.ts +3 -2
- package/lib/Sprite/Character.js +15 -16
- package/lib/Sprite/Character.js.map +1 -1
- package/lib/Sprite/Player.js +2 -9
- package/lib/Sprite/Player.js.map +1 -1
- package/lib/Sprite/Spritesheet.d.ts +4 -4
- package/lib/Sprite/Spritesheet.js +1 -5
- package/lib/Sprite/Spritesheet.js.map +1 -1
- package/lib/Sprite/Spritesheets.js +4 -8
- package/lib/Sprite/Spritesheets.js.map +1 -1
- package/lib/Tilemap/CommonLayer.d.ts +2 -1
- package/lib/Tilemap/CommonLayer.js +7 -11
- package/lib/Tilemap/CommonLayer.js.map +1 -1
- package/lib/Tilemap/ImageLayer.js +5 -7
- package/lib/Tilemap/ImageLayer.js.map +1 -1
- package/lib/Tilemap/Tile.d.ts +5 -5
- package/lib/Tilemap/Tile.js +19 -21
- package/lib/Tilemap/Tile.js.map +1 -1
- package/lib/Tilemap/TileLayer.d.ts +0 -7
- package/lib/Tilemap/TileLayer.js +27 -29
- package/lib/Tilemap/TileLayer.js.map +1 -1
- package/lib/Tilemap/TileSet.d.ts +2 -1
- package/lib/Tilemap/TileSet.js +9 -12
- package/lib/Tilemap/TileSet.js.map +1 -1
- package/lib/Tilemap/index.d.ts +3 -11
- package/lib/Tilemap/index.js +22 -61
- package/lib/Tilemap/index.js.map +1 -1
- package/lib/clientEntryPoint.js +26 -28
- package/lib/clientEntryPoint.js.map +1 -1
- package/lib/index.js +21 -75
- package/lib/index.js.map +1 -1
- package/package.json +16 -14
- package/lib/Components/ColorComponent.d.ts +0 -9
- package/lib/Components/ColorComponent.js +0 -18
- package/lib/Components/ColorComponent.js.map +0 -1
package/lib/RpgClientEngine.js
CHANGED
|
@@ -1,36 +1,26 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
6
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const ajax_1 = require("rxjs/ajax");
|
|
26
|
-
const RpgGui_1 = require("./RpgGui");
|
|
27
|
-
const common_1 = require("@rpgjs/common");
|
|
28
|
-
const RpgSound_1 = require("./Sound/RpgSound");
|
|
29
|
-
const Spritesheet_1 = require("./Sprite/Spritesheet");
|
|
30
|
-
const Logger_1 = require("./Logger");
|
|
31
|
-
const Sound_1 = require("./Sound/Sound");
|
|
32
|
-
const types_1 = require("@rpgjs/types");
|
|
33
|
-
class RpgClientEngine {
|
|
7
|
+
import { KeyboardControls } from './KeyboardControls';
|
|
8
|
+
import { RpgRenderer } from './Renderer';
|
|
9
|
+
import { _initSpritesheet, spritesheets } from './Sprite/Spritesheets';
|
|
10
|
+
import { _initSound, sounds } from './Sound/Sounds';
|
|
11
|
+
import { World } from 'simple-room-client';
|
|
12
|
+
import { BehaviorSubject, Subject, lastValueFrom } from 'rxjs';
|
|
13
|
+
import { ajax } from 'rxjs/ajax';
|
|
14
|
+
import { RpgGui } from './RpgGui';
|
|
15
|
+
import { PrebuiltGui, Utils, RpgPlugin, HookClient, RpgCommonMap, Scheduler, } from '@rpgjs/common';
|
|
16
|
+
import { RpgSound } from './Sound/RpgSound';
|
|
17
|
+
import { Spritesheet } from './Sprite/Spritesheet';
|
|
18
|
+
import { log } from './Logger';
|
|
19
|
+
import { Sound } from './Sound/Sound';
|
|
20
|
+
import { PlayerType, SocketEvents, SocketMethods } from '@rpgjs/types';
|
|
21
|
+
import { Assets, utils } from 'pixi.js';
|
|
22
|
+
import * as PIXI from 'pixi.js';
|
|
23
|
+
export class RpgClientEngine {
|
|
34
24
|
constructor(gameEngine, options) {
|
|
35
25
|
this.gameEngine = gameEngine;
|
|
36
26
|
this.options = options;
|
|
@@ -42,19 +32,18 @@ class RpgClientEngine {
|
|
|
42
32
|
* @memberof RpgClientEngine
|
|
43
33
|
* */
|
|
44
34
|
this.globalConfig = {};
|
|
45
|
-
this._tick = new
|
|
35
|
+
this._tick = new BehaviorSubject({
|
|
46
36
|
timestamp: -1,
|
|
47
37
|
deltaTime: 0,
|
|
48
38
|
frame: 0,
|
|
49
39
|
deltaRatio: 1
|
|
50
40
|
});
|
|
51
|
-
this.keyChange = new
|
|
52
|
-
this.roomJoin = new
|
|
41
|
+
this.keyChange = new Subject();
|
|
42
|
+
this.roomJoin = new Subject();
|
|
53
43
|
this.hasBeenDisconnected = false;
|
|
54
44
|
this.serverChanging = false;
|
|
55
45
|
this.isTeleported = false;
|
|
56
46
|
this.lastTimestamp = 0;
|
|
57
|
-
this.frame = 0;
|
|
58
47
|
this.clientFrames = new Map();
|
|
59
48
|
this.serverFrames = new Map();
|
|
60
49
|
this.session = null;
|
|
@@ -63,7 +52,7 @@ class RpgClientEngine {
|
|
|
63
52
|
this.matchMakerService = null;
|
|
64
53
|
this.assetsPath = 'assets';
|
|
65
54
|
this.serverFps = 60;
|
|
66
|
-
this.scheduler = new
|
|
55
|
+
this.scheduler = new Scheduler();
|
|
67
56
|
/**
|
|
68
57
|
* Read objects synchronized with the server
|
|
69
58
|
*
|
|
@@ -82,44 +71,51 @@ class RpgClientEngine {
|
|
|
82
71
|
this.step(timestamp, deltaTime);
|
|
83
72
|
});
|
|
84
73
|
}
|
|
85
|
-
_init() {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
this.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
74
|
+
async _init() {
|
|
75
|
+
this.renderer = new RpgRenderer(this);
|
|
76
|
+
const pluginLoadRessource = async (hookName, type) => {
|
|
77
|
+
const resource = this.options[type] || [];
|
|
78
|
+
this.options[type] = [
|
|
79
|
+
...Utils.arrayFlat(await RpgPlugin.emit(hookName, resource)) || [],
|
|
80
|
+
...resource
|
|
81
|
+
];
|
|
82
|
+
};
|
|
83
|
+
await pluginLoadRessource(HookClient.AddSpriteSheet, 'spritesheets');
|
|
84
|
+
await pluginLoadRessource(HookClient.AddGui, 'gui');
|
|
85
|
+
await pluginLoadRessource(HookClient.AddSound, 'sounds');
|
|
86
|
+
this.renderer.options = {
|
|
87
|
+
selector: '#rpg',
|
|
88
|
+
selectorCanvas: '#canvas',
|
|
89
|
+
selectorGui: '#gui',
|
|
90
|
+
canvas: {},
|
|
91
|
+
gui: [],
|
|
92
|
+
spritesheets: [],
|
|
93
|
+
sounds: [],
|
|
94
|
+
...this.options
|
|
95
|
+
};
|
|
96
|
+
this.io = this.options.io;
|
|
97
|
+
if (this.options.serverFps)
|
|
98
|
+
this.serverFps = this.options.serverFps;
|
|
99
|
+
this.globalConfig = this.options.globalConfig;
|
|
100
|
+
if (this.globalConfig.assetsPath)
|
|
101
|
+
this.assetsPath = this.globalConfig.assetsPath;
|
|
102
|
+
this.gameEngine.standalone = this.options.standalone;
|
|
103
|
+
this.gameEngine.renderer = this.renderer;
|
|
104
|
+
this.gameEngine.clientEngine = this;
|
|
105
|
+
this.addSpriteSheet(this.renderer.options.spritesheets);
|
|
106
|
+
this.addSound(this.renderer.options.sounds);
|
|
107
|
+
if (typeof __RPGJS_PRODUCTION__ != 'undefined' && __RPGJS_PRODUCTION__) {
|
|
108
|
+
if ('serviceWorker' in navigator) {
|
|
109
|
+
window.addEventListener('load', () => {
|
|
110
|
+
navigator.serviceWorker.register('/service-worker.js');
|
|
111
|
+
});
|
|
116
112
|
}
|
|
117
|
-
|
|
118
|
-
|
|
113
|
+
}
|
|
114
|
+
this.controls = new KeyboardControls(this);
|
|
119
115
|
}
|
|
120
116
|
addResource(resourceClass, cb) {
|
|
121
117
|
let array = resourceClass;
|
|
122
|
-
if (!
|
|
118
|
+
if (!Utils.isArray(resourceClass)) {
|
|
123
119
|
array = [resourceClass];
|
|
124
120
|
}
|
|
125
121
|
cb(array, this);
|
|
@@ -145,44 +141,49 @@ class RpgClientEngine {
|
|
|
145
141
|
addSpriteSheet(spritesheetClass, id) {
|
|
146
142
|
if (typeof spritesheetClass === 'string') {
|
|
147
143
|
if (!id) {
|
|
148
|
-
throw
|
|
144
|
+
throw log('Please, specify the resource ID (second parameter)');
|
|
149
145
|
}
|
|
150
146
|
let AutoSpritesheet = class AutoSpritesheet {
|
|
151
147
|
};
|
|
152
148
|
AutoSpritesheet = __decorate([
|
|
153
|
-
|
|
149
|
+
Spritesheet({
|
|
154
150
|
id,
|
|
155
151
|
image: this.getResourceUrl(spritesheetClass)
|
|
156
152
|
})
|
|
157
153
|
], AutoSpritesheet);
|
|
158
154
|
spritesheetClass = AutoSpritesheet;
|
|
159
155
|
}
|
|
160
|
-
this.addResource(spritesheetClass,
|
|
156
|
+
this.addResource(spritesheetClass, _initSpritesheet);
|
|
161
157
|
return spritesheetClass;
|
|
162
158
|
}
|
|
163
159
|
addSound(soundClass, id) {
|
|
164
160
|
if (typeof soundClass === 'string') {
|
|
165
161
|
if (!id) {
|
|
166
|
-
throw
|
|
162
|
+
throw log('Please, specify the resource ID (second parameter)');
|
|
167
163
|
}
|
|
168
164
|
let AutoSound = class AutoSound {
|
|
169
165
|
};
|
|
170
166
|
AutoSound = __decorate([
|
|
171
|
-
|
|
167
|
+
Sound({
|
|
172
168
|
id,
|
|
173
169
|
sound: this.getResourceUrl(soundClass)
|
|
174
170
|
})
|
|
175
171
|
], AutoSound);
|
|
176
172
|
soundClass = AutoSound;
|
|
177
173
|
}
|
|
178
|
-
this.addResource(soundClass,
|
|
174
|
+
this.addResource(soundClass, _initSound);
|
|
179
175
|
return soundClass;
|
|
180
176
|
}
|
|
181
177
|
getResourceUrl(source) {
|
|
182
178
|
if (source.startsWith('data:')) {
|
|
183
179
|
return source;
|
|
184
180
|
}
|
|
185
|
-
|
|
181
|
+
// @ts-ignore
|
|
182
|
+
const staticDir = import.meta.env.VITE_BUILT;
|
|
183
|
+
if (staticDir) {
|
|
184
|
+
return this.assetsPath + '/' + Utils.basename(source);
|
|
185
|
+
}
|
|
186
|
+
return source;
|
|
186
187
|
}
|
|
187
188
|
/**
|
|
188
189
|
* Starts the client side and connects to the server
|
|
@@ -192,40 +193,39 @@ class RpgClientEngine {
|
|
|
192
193
|
* @returns {Promise< void >}
|
|
193
194
|
* @memberof RpgClientEngine
|
|
194
195
|
*/
|
|
195
|
-
start(options = {
|
|
196
|
+
async start(options = {
|
|
196
197
|
renderLoop: true
|
|
197
198
|
}) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
else {
|
|
222
|
-
// todo: change toPromise (RXJS v7+)
|
|
223
|
-
serverUri = yield ajax_1.ajax.getJSON(this.matchMakerService).toPromise();
|
|
224
|
-
}
|
|
199
|
+
await this._init();
|
|
200
|
+
await this.renderer.init();
|
|
201
|
+
const { maxFps } = this.options;
|
|
202
|
+
if (options.renderLoop) {
|
|
203
|
+
this.scheduler.start({
|
|
204
|
+
maxFps
|
|
205
|
+
});
|
|
206
|
+
// The processing is outside the rendering loop because if the FPS are lower (or higher) then the sending to the server would be slower or faster. Here it is constant
|
|
207
|
+
setInterval(() => {
|
|
208
|
+
this.processInput();
|
|
209
|
+
}, Utils.fps2ms(this.serverFps));
|
|
210
|
+
}
|
|
211
|
+
const ret = await RpgPlugin.emit(HookClient.Start, this);
|
|
212
|
+
this.matchMakerService = this.options.globalConfig.matchMakerService;
|
|
213
|
+
const hasFalseValue = ret.findIndex(el => el === false) != -1;
|
|
214
|
+
if (!hasFalseValue) {
|
|
215
|
+
let serverUri = {};
|
|
216
|
+
if (this.matchMakerService) {
|
|
217
|
+
if (Utils.isFunction(this.matchMakerService)) {
|
|
218
|
+
serverUri = this.matchMakerService();
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
serverUri = await lastValueFrom(ajax.getJSON(this.matchMakerService));
|
|
225
222
|
}
|
|
226
|
-
this.connection(serverUri.url ? serverUri.url + ':' + serverUri.port : undefined);
|
|
227
223
|
}
|
|
228
|
-
|
|
224
|
+
// @ts-ignore
|
|
225
|
+
const envUrl = import.meta.env.VITE_SERVER_URL;
|
|
226
|
+
this.connection(serverUri.url ? serverUri.url + ':' + serverUri.port :
|
|
227
|
+
envUrl ? envUrl : undefined);
|
|
228
|
+
}
|
|
229
229
|
}
|
|
230
230
|
/**
|
|
231
231
|
* Display the next frame. Useful for unit tests
|
|
@@ -239,23 +239,22 @@ class RpgClientEngine {
|
|
|
239
239
|
nextFrame(timestamp) {
|
|
240
240
|
this.scheduler.nextTick(timestamp);
|
|
241
241
|
}
|
|
242
|
-
sendInput(actionName) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
});
|
|
242
|
+
async sendInput(actionName) {
|
|
243
|
+
const player = this.player;
|
|
244
|
+
if (!player)
|
|
245
|
+
return;
|
|
246
|
+
if (player.canMove) {
|
|
247
|
+
player.pendingMove.push({
|
|
248
|
+
input: actionName,
|
|
249
|
+
frame: this.scheduler.frame
|
|
250
|
+
});
|
|
251
|
+
}
|
|
254
252
|
}
|
|
255
253
|
get player() {
|
|
256
254
|
return this.gameEngine.world.getObject(this.gameEngine.playerId);
|
|
257
255
|
}
|
|
258
256
|
serverReconciliation(player) {
|
|
257
|
+
let garbage = [];
|
|
259
258
|
this.serverFrames.forEach((serverData, frame) => {
|
|
260
259
|
const { data: serverPos, time: serverTime } = serverData;
|
|
261
260
|
const client = this.clientFrames.get(frame);
|
|
@@ -266,37 +265,38 @@ class RpgClientEngine {
|
|
|
266
265
|
player.position.y = serverPos.y;
|
|
267
266
|
}
|
|
268
267
|
player.position.z = serverPos.z;
|
|
268
|
+
garbage.push(frame);
|
|
269
|
+
});
|
|
270
|
+
garbage.forEach(frame => {
|
|
269
271
|
this.serverFrames.delete(frame);
|
|
270
272
|
this.clientFrames.delete(frame);
|
|
271
273
|
});
|
|
274
|
+
garbage = [];
|
|
272
275
|
}
|
|
273
|
-
step(t, dt) {
|
|
274
|
-
|
|
275
|
-
common_1.RpgPlugin.emit(common_1.HookClient.Step, [this, t, dt], true);
|
|
276
|
-
});
|
|
276
|
+
async step(t, dt) {
|
|
277
|
+
RpgPlugin.emit(HookClient.Step, [this, t, dt], true);
|
|
277
278
|
}
|
|
278
|
-
processInput() {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
if (player) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
common_1.RpgPlugin.emit(common_1.HookClient.SendInput, [this, inputEvent], true);
|
|
279
|
+
async processInput() {
|
|
280
|
+
const player = this.player;
|
|
281
|
+
this.controls.preStep();
|
|
282
|
+
if (player) {
|
|
283
|
+
if (player.pendingMove.length > 0) {
|
|
284
|
+
const { inputs: inputEvent } = await this.gameEngine.processInput(this.gameEngine.playerId, this.controls.options);
|
|
285
|
+
if (inputEvent.length == 0)
|
|
286
|
+
return;
|
|
287
|
+
const frame = Date.now();
|
|
288
|
+
this.clientFrames.set(frame, {
|
|
289
|
+
data: player.position.copy(),
|
|
290
|
+
time: frame
|
|
291
|
+
});
|
|
292
|
+
if (this.socket) {
|
|
293
|
+
this.socket.emit('move', { input: inputEvent, frame });
|
|
295
294
|
}
|
|
296
|
-
|
|
297
|
-
this.serverReconciliation(player);
|
|
295
|
+
RpgPlugin.emit(HookClient.SendInput, [this, inputEvent], true);
|
|
298
296
|
}
|
|
299
|
-
|
|
297
|
+
if (player.canMove)
|
|
298
|
+
this.serverReconciliation(player);
|
|
299
|
+
}
|
|
300
300
|
}
|
|
301
301
|
/**
|
|
302
302
|
*Connect to the server
|
|
@@ -319,9 +319,9 @@ class RpgClientEngine {
|
|
|
319
319
|
this.socket = this.io;
|
|
320
320
|
}
|
|
321
321
|
this.socket.on('connect', () => {
|
|
322
|
-
if (
|
|
323
|
-
|
|
324
|
-
|
|
322
|
+
if (RpgGui.exists(PrebuiltGui.Disconnect))
|
|
323
|
+
RpgGui.hide(PrebuiltGui.Disconnect);
|
|
324
|
+
RpgPlugin.emit(HookClient.Connected, [this, this.socket], true);
|
|
325
325
|
this.hasBeenDisconnected = false;
|
|
326
326
|
});
|
|
327
327
|
this.socket.on('playerJoined', (playerEvent) => {
|
|
@@ -329,7 +329,7 @@ class RpgClientEngine {
|
|
|
329
329
|
this.session = playerEvent.session;
|
|
330
330
|
});
|
|
331
331
|
this.socket.on('connect_error', (err) => {
|
|
332
|
-
|
|
332
|
+
RpgPlugin.emit(HookClient.ConnectedError, [this, err, this.socket], true);
|
|
333
333
|
});
|
|
334
334
|
this.socket.on('preLoadScene', (name) => {
|
|
335
335
|
if (this.lastScene == name) {
|
|
@@ -338,10 +338,13 @@ class RpgClientEngine {
|
|
|
338
338
|
this.lastScene = name;
|
|
339
339
|
this.renderer.transitionScene(name);
|
|
340
340
|
});
|
|
341
|
-
this.socket.on(
|
|
341
|
+
this.socket.on(SocketEvents.GameReload, () => {
|
|
342
|
+
window.location.reload();
|
|
343
|
+
});
|
|
344
|
+
this.socket.on(SocketEvents.LoadScene, ({ name, data }) => {
|
|
342
345
|
this.renderer.loadScene(name, data);
|
|
343
346
|
});
|
|
344
|
-
this.socket.on(
|
|
347
|
+
this.socket.on(SocketEvents.ChangeServer, ({ url, port }) => {
|
|
345
348
|
const connection = url + ':' + port;
|
|
346
349
|
if (this.lastConnection == connection) {
|
|
347
350
|
return;
|
|
@@ -356,30 +359,30 @@ class RpgClientEngine {
|
|
|
356
359
|
});
|
|
357
360
|
this.socket.on('changeTile', ({ tiles, x, y }) => {
|
|
358
361
|
const scene = this.renderer.getScene();
|
|
359
|
-
scene
|
|
362
|
+
scene?.changeTile(x, y, tiles);
|
|
360
363
|
});
|
|
361
|
-
this.socket.on(
|
|
364
|
+
this.socket.on(SocketEvents.CallMethod, ({ objectId, params, name }) => {
|
|
362
365
|
const scene = this.renderer.getScene();
|
|
363
|
-
const sprite = scene
|
|
366
|
+
const sprite = scene?.getPlayer(objectId);
|
|
364
367
|
if (!sprite)
|
|
365
368
|
return;
|
|
366
369
|
switch (name) {
|
|
367
|
-
case
|
|
368
|
-
scene
|
|
370
|
+
case SocketMethods.ShowAnimation:
|
|
371
|
+
scene?.showAnimation({
|
|
369
372
|
attachTo: sprite,
|
|
370
373
|
graphic: params[0],
|
|
371
374
|
animationName: params[1],
|
|
372
375
|
replaceGraphic: params[2]
|
|
373
376
|
});
|
|
374
377
|
break;
|
|
375
|
-
case
|
|
378
|
+
case SocketMethods.CameraFollow:
|
|
376
379
|
const [spriteId, options] = params;
|
|
377
|
-
scene
|
|
380
|
+
scene?.cameraFollowSprite(spriteId, options);
|
|
378
381
|
break;
|
|
379
|
-
case
|
|
380
|
-
|
|
382
|
+
case SocketMethods.PlaySound:
|
|
383
|
+
RpgSound.play(params[0]);
|
|
381
384
|
break;
|
|
382
|
-
case
|
|
385
|
+
case SocketMethods.ModeMove:
|
|
383
386
|
const player = this.player;
|
|
384
387
|
const { checkCollision } = params[0];
|
|
385
388
|
if (player) {
|
|
@@ -389,9 +392,9 @@ class RpgClientEngine {
|
|
|
389
392
|
}
|
|
390
393
|
});
|
|
391
394
|
let lastRoomId = '';
|
|
392
|
-
this.subscriptionWorld =
|
|
395
|
+
this.subscriptionWorld = World.listen(this.socket)
|
|
393
396
|
.value
|
|
394
|
-
.subscribe((val) => {
|
|
397
|
+
.subscribe(async (val) => {
|
|
395
398
|
const scene = this.renderer.getScene();
|
|
396
399
|
if (!val.data) {
|
|
397
400
|
return;
|
|
@@ -408,6 +411,19 @@ class RpgClientEngine {
|
|
|
408
411
|
const change = (prop, root = val, localEvent = false) => {
|
|
409
412
|
const list = root.data[prop];
|
|
410
413
|
const partial = root.partial[prop];
|
|
414
|
+
const isShape = prop == 'shapes';
|
|
415
|
+
if (!partial) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
if (val.resetProps.indexOf(prop) != -1) {
|
|
419
|
+
const objects = isShape ? this.gameEngine.getShapes() : this.gameEngine.getObjects();
|
|
420
|
+
for (let key in objects) {
|
|
421
|
+
const obj = objects[key];
|
|
422
|
+
if (obj) {
|
|
423
|
+
this.gameEngine.removeObjectAndShape(key);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
411
427
|
for (let key in partial) {
|
|
412
428
|
const obj = list[key];
|
|
413
429
|
const paramsChanged = partial ? partial[key] : undefined;
|
|
@@ -416,11 +432,10 @@ class RpgClientEngine {
|
|
|
416
432
|
}
|
|
417
433
|
if (!obj)
|
|
418
434
|
continue;
|
|
419
|
-
const isShape = prop == 'shapes';
|
|
420
435
|
if (!isShape) {
|
|
421
436
|
obj.type = {
|
|
422
|
-
users:
|
|
423
|
-
events:
|
|
437
|
+
users: PlayerType.Player,
|
|
438
|
+
events: PlayerType.Event
|
|
424
439
|
}[prop];
|
|
425
440
|
}
|
|
426
441
|
if (prop == 'users' && this.gameEngine.playerId == key) {
|
|
@@ -434,11 +449,12 @@ class RpgClientEngine {
|
|
|
434
449
|
data: obj,
|
|
435
450
|
partial: paramsChanged,
|
|
436
451
|
time: val.time,
|
|
437
|
-
roomId: val.roomId
|
|
452
|
+
roomId: val.roomId,
|
|
453
|
+
resetProps: val.resetProps
|
|
438
454
|
}, true);
|
|
439
455
|
}
|
|
440
456
|
}
|
|
441
|
-
if (
|
|
457
|
+
if (partialRoom?.pos && partialRoom?.frame !== undefined) {
|
|
442
458
|
this.serverFrames.set(partialRoom.frame, {
|
|
443
459
|
data: partialRoom.pos,
|
|
444
460
|
time: Date.now()
|
|
@@ -470,12 +486,12 @@ class RpgClientEngine {
|
|
|
470
486
|
if (this.serverChanging) {
|
|
471
487
|
return;
|
|
472
488
|
}
|
|
473
|
-
if (
|
|
474
|
-
|
|
475
|
-
|
|
489
|
+
if (RpgGui.exists(PrebuiltGui.Disconnect))
|
|
490
|
+
RpgGui.display(PrebuiltGui.Disconnect);
|
|
491
|
+
RpgPlugin.emit(HookClient.Disconnect, [this, reason, this.socket], true);
|
|
476
492
|
this.hasBeenDisconnected = true;
|
|
477
493
|
});
|
|
478
|
-
|
|
494
|
+
RpgGui._setSocket(this.socket);
|
|
479
495
|
if (standalone) {
|
|
480
496
|
this.socket.connection({
|
|
481
497
|
auth: {
|
|
@@ -486,7 +502,7 @@ class RpgClientEngine {
|
|
|
486
502
|
this.serverChanging = false;
|
|
487
503
|
}
|
|
488
504
|
get world() {
|
|
489
|
-
return
|
|
505
|
+
return World;
|
|
490
506
|
}
|
|
491
507
|
// shortcuts
|
|
492
508
|
/**
|
|
@@ -544,14 +560,19 @@ class RpgClientEngine {
|
|
|
544
560
|
reset() {
|
|
545
561
|
this.subscriptionWorld.unsubscribe();
|
|
546
562
|
this.world.reset();
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
563
|
+
spritesheets.clear();
|
|
564
|
+
sounds.clear();
|
|
565
|
+
Assets.reset();
|
|
566
|
+
utils.clearTextureCache();
|
|
567
|
+
for (let textureUrl in utils.BaseTextureCache) {
|
|
568
|
+
delete utils.BaseTextureCache[textureUrl];
|
|
569
|
+
}
|
|
570
|
+
for (let textureUrl in utils.TextureCache) {
|
|
571
|
+
delete utils.TextureCache[textureUrl];
|
|
572
|
+
}
|
|
573
|
+
RpgGui.clear();
|
|
574
|
+
RpgCommonMap.bufferClient.clear();
|
|
575
|
+
RpgSound.clear();
|
|
554
576
|
}
|
|
555
577
|
}
|
|
556
|
-
exports.RpgClientEngine = RpgClientEngine;
|
|
557
578
|
//# sourceMappingURL=RpgClientEngine.js.map
|