@rpgjs/client 3.3.2 → 4.0.0-beta.3
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 -1
- package/lib/RpgClientEngine.js +192 -176
- 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 +19 -19
- package/src/Components/AbstractComponent.ts +120 -0
- package/src/Components/BarComponent.ts +179 -0
- package/src/Components/Component.ts +506 -0
- package/src/Components/DebugComponent.ts +36 -0
- package/src/Components/ImageComponent.ts +30 -0
- package/src/Components/ShapeComponent.ts +64 -0
- package/src/Components/TextComponent.ts +33 -0
- package/src/Components/TileComponent.ts +43 -0
- package/src/Effects/Animation.ts +297 -0
- package/src/Effects/AnimationCharacter.ts +7 -0
- package/src/Effects/Spinner.ts +19 -0
- package/src/Effects/Timeline.ts +294 -0
- package/src/Effects/TransitionScene.ts +57 -0
- package/src/GameEngine.ts +284 -0
- package/src/Interfaces/Character.ts +7 -0
- package/src/Interfaces/Scene.ts +9 -0
- package/src/KeyboardControls.ts +552 -0
- package/src/Logger.ts +3 -0
- package/src/Presets/AnimationSpritesheet.ts +36 -0
- package/src/Presets/Scene.ts +3 -0
- package/src/Renderer.ts +263 -0
- package/src/Resources.ts +40 -0
- package/src/RpgClient.ts +333 -0
- package/src/RpgClientEngine.ts +709 -0
- package/src/RpgGui.ts +553 -0
- package/src/RpgGuiCompiled.ts +43 -0
- package/src/Scene/EventLayer.ts +9 -0
- package/src/Scene/Map.ts +393 -0
- package/src/Scene/Scene.ts +270 -0
- package/src/Scene/SceneData.ts +13 -0
- package/src/Sound/RpgSound.ts +50 -0
- package/src/Sound/Sound.ts +91 -0
- package/src/Sound/Sounds.ts +7 -0
- package/src/Sprite/Character.ts +149 -0
- package/src/Sprite/Player.ts +3 -0
- package/src/Sprite/Spritesheet.ts +392 -0
- package/src/Sprite/Spritesheets.ts +8 -0
- package/src/Tilemap/CommonLayer.ts +20 -0
- package/src/Tilemap/ImageLayer.ts +20 -0
- package/src/Tilemap/Tile.ts +80 -0
- package/src/Tilemap/TileLayer.ts +142 -0
- package/src/Tilemap/TileSet.ts +40 -0
- package/src/Tilemap/index.ts +173 -0
- package/src/clientEntryPoint.ts +141 -0
- package/src/index.ts +25 -0
- package/src/types/howler.d.ts +73 -0
- package/tsconfig.json +30 -0
- 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,14 +32,14 @@ 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;
|
|
@@ -62,7 +52,7 @@ class RpgClientEngine {
|
|
|
62
52
|
this.matchMakerService = null;
|
|
63
53
|
this.assetsPath = 'assets';
|
|
64
54
|
this.serverFps = 60;
|
|
65
|
-
this.scheduler = new
|
|
55
|
+
this.scheduler = new Scheduler();
|
|
66
56
|
/**
|
|
67
57
|
* Read objects synchronized with the server
|
|
68
58
|
*
|
|
@@ -81,44 +71,51 @@ class RpgClientEngine {
|
|
|
81
71
|
this.step(timestamp, deltaTime);
|
|
82
72
|
});
|
|
83
73
|
}
|
|
84
|
-
_init() {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
this.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
+
});
|
|
115
112
|
}
|
|
116
|
-
|
|
117
|
-
|
|
113
|
+
}
|
|
114
|
+
this.controls = new KeyboardControls(this);
|
|
118
115
|
}
|
|
119
116
|
addResource(resourceClass, cb) {
|
|
120
117
|
let array = resourceClass;
|
|
121
|
-
if (!
|
|
118
|
+
if (!Utils.isArray(resourceClass)) {
|
|
122
119
|
array = [resourceClass];
|
|
123
120
|
}
|
|
124
121
|
cb(array, this);
|
|
@@ -144,44 +141,49 @@ class RpgClientEngine {
|
|
|
144
141
|
addSpriteSheet(spritesheetClass, id) {
|
|
145
142
|
if (typeof spritesheetClass === 'string') {
|
|
146
143
|
if (!id) {
|
|
147
|
-
throw
|
|
144
|
+
throw log('Please, specify the resource ID (second parameter)');
|
|
148
145
|
}
|
|
149
146
|
let AutoSpritesheet = class AutoSpritesheet {
|
|
150
147
|
};
|
|
151
148
|
AutoSpritesheet = __decorate([
|
|
152
|
-
|
|
149
|
+
Spritesheet({
|
|
153
150
|
id,
|
|
154
151
|
image: this.getResourceUrl(spritesheetClass)
|
|
155
152
|
})
|
|
156
153
|
], AutoSpritesheet);
|
|
157
154
|
spritesheetClass = AutoSpritesheet;
|
|
158
155
|
}
|
|
159
|
-
this.addResource(spritesheetClass,
|
|
156
|
+
this.addResource(spritesheetClass, _initSpritesheet);
|
|
160
157
|
return spritesheetClass;
|
|
161
158
|
}
|
|
162
159
|
addSound(soundClass, id) {
|
|
163
160
|
if (typeof soundClass === 'string') {
|
|
164
161
|
if (!id) {
|
|
165
|
-
throw
|
|
162
|
+
throw log('Please, specify the resource ID (second parameter)');
|
|
166
163
|
}
|
|
167
164
|
let AutoSound = class AutoSound {
|
|
168
165
|
};
|
|
169
166
|
AutoSound = __decorate([
|
|
170
|
-
|
|
167
|
+
Sound({
|
|
171
168
|
id,
|
|
172
169
|
sound: this.getResourceUrl(soundClass)
|
|
173
170
|
})
|
|
174
171
|
], AutoSound);
|
|
175
172
|
soundClass = AutoSound;
|
|
176
173
|
}
|
|
177
|
-
this.addResource(soundClass,
|
|
174
|
+
this.addResource(soundClass, _initSound);
|
|
178
175
|
return soundClass;
|
|
179
176
|
}
|
|
180
177
|
getResourceUrl(source) {
|
|
181
178
|
if (source.startsWith('data:')) {
|
|
182
179
|
return source;
|
|
183
180
|
}
|
|
184
|
-
|
|
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;
|
|
185
187
|
}
|
|
186
188
|
/**
|
|
187
189
|
* Starts the client side and connects to the server
|
|
@@ -191,40 +193,39 @@ class RpgClientEngine {
|
|
|
191
193
|
* @returns {Promise< void >}
|
|
192
194
|
* @memberof RpgClientEngine
|
|
193
195
|
*/
|
|
194
|
-
start(options = {
|
|
196
|
+
async start(options = {
|
|
195
197
|
renderLoop: true
|
|
196
198
|
}) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
if (
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
else {
|
|
221
|
-
// todo: change toPromise (RXJS v7+)
|
|
222
|
-
serverUri = yield ajax_1.ajax.getJSON(this.matchMakerService).toPromise();
|
|
223
|
-
}
|
|
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));
|
|
224
222
|
}
|
|
225
|
-
this.connection(serverUri.url ? serverUri.url + ':' + serverUri.port : undefined);
|
|
226
223
|
}
|
|
227
|
-
|
|
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
|
+
}
|
|
228
229
|
}
|
|
229
230
|
/**
|
|
230
231
|
* Display the next frame. Useful for unit tests
|
|
@@ -238,18 +239,16 @@ class RpgClientEngine {
|
|
|
238
239
|
nextFrame(timestamp) {
|
|
239
240
|
this.scheduler.nextTick(timestamp);
|
|
240
241
|
}
|
|
241
|
-
sendInput(actionName) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
});
|
|
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
|
+
}
|
|
253
252
|
}
|
|
254
253
|
get player() {
|
|
255
254
|
return this.gameEngine.world.getObject(this.gameEngine.playerId);
|
|
@@ -274,34 +273,30 @@ class RpgClientEngine {
|
|
|
274
273
|
});
|
|
275
274
|
garbage = [];
|
|
276
275
|
}
|
|
277
|
-
step(t, dt) {
|
|
278
|
-
|
|
279
|
-
common_1.RpgPlugin.emit(common_1.HookClient.Step, [this, t, dt], true);
|
|
280
|
-
});
|
|
276
|
+
async step(t, dt) {
|
|
277
|
+
RpgPlugin.emit(HookClient.Step, [this, t, dt], true);
|
|
281
278
|
}
|
|
282
|
-
processInput() {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
if (player) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
this.socket.emit('move', { input: inputEvent, frame });
|
|
298
|
-
}
|
|
299
|
-
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 });
|
|
300
294
|
}
|
|
301
|
-
|
|
302
|
-
this.serverReconciliation(player);
|
|
295
|
+
RpgPlugin.emit(HookClient.SendInput, [this, inputEvent], true);
|
|
303
296
|
}
|
|
304
|
-
|
|
297
|
+
if (player.canMove)
|
|
298
|
+
this.serverReconciliation(player);
|
|
299
|
+
}
|
|
305
300
|
}
|
|
306
301
|
/**
|
|
307
302
|
*Connect to the server
|
|
@@ -324,9 +319,9 @@ class RpgClientEngine {
|
|
|
324
319
|
this.socket = this.io;
|
|
325
320
|
}
|
|
326
321
|
this.socket.on('connect', () => {
|
|
327
|
-
if (
|
|
328
|
-
|
|
329
|
-
|
|
322
|
+
if (RpgGui.exists(PrebuiltGui.Disconnect))
|
|
323
|
+
RpgGui.hide(PrebuiltGui.Disconnect);
|
|
324
|
+
RpgPlugin.emit(HookClient.Connected, [this, this.socket], true);
|
|
330
325
|
this.hasBeenDisconnected = false;
|
|
331
326
|
});
|
|
332
327
|
this.socket.on('playerJoined', (playerEvent) => {
|
|
@@ -334,7 +329,7 @@ class RpgClientEngine {
|
|
|
334
329
|
this.session = playerEvent.session;
|
|
335
330
|
});
|
|
336
331
|
this.socket.on('connect_error', (err) => {
|
|
337
|
-
|
|
332
|
+
RpgPlugin.emit(HookClient.ConnectedError, [this, err, this.socket], true);
|
|
338
333
|
});
|
|
339
334
|
this.socket.on('preLoadScene', (name) => {
|
|
340
335
|
if (this.lastScene == name) {
|
|
@@ -343,10 +338,13 @@ class RpgClientEngine {
|
|
|
343
338
|
this.lastScene = name;
|
|
344
339
|
this.renderer.transitionScene(name);
|
|
345
340
|
});
|
|
346
|
-
this.socket.on(
|
|
341
|
+
this.socket.on(SocketEvents.GameReload, () => {
|
|
342
|
+
window.location.reload();
|
|
343
|
+
});
|
|
344
|
+
this.socket.on(SocketEvents.LoadScene, ({ name, data }) => {
|
|
347
345
|
this.renderer.loadScene(name, data);
|
|
348
346
|
});
|
|
349
|
-
this.socket.on(
|
|
347
|
+
this.socket.on(SocketEvents.ChangeServer, ({ url, port }) => {
|
|
350
348
|
const connection = url + ':' + port;
|
|
351
349
|
if (this.lastConnection == connection) {
|
|
352
350
|
return;
|
|
@@ -361,30 +359,30 @@ class RpgClientEngine {
|
|
|
361
359
|
});
|
|
362
360
|
this.socket.on('changeTile', ({ tiles, x, y }) => {
|
|
363
361
|
const scene = this.renderer.getScene();
|
|
364
|
-
scene
|
|
362
|
+
scene?.changeTile(x, y, tiles);
|
|
365
363
|
});
|
|
366
|
-
this.socket.on(
|
|
364
|
+
this.socket.on(SocketEvents.CallMethod, ({ objectId, params, name }) => {
|
|
367
365
|
const scene = this.renderer.getScene();
|
|
368
|
-
const sprite = scene
|
|
366
|
+
const sprite = scene?.getPlayer(objectId);
|
|
369
367
|
if (!sprite)
|
|
370
368
|
return;
|
|
371
369
|
switch (name) {
|
|
372
|
-
case
|
|
373
|
-
scene
|
|
370
|
+
case SocketMethods.ShowAnimation:
|
|
371
|
+
scene?.showAnimation({
|
|
374
372
|
attachTo: sprite,
|
|
375
373
|
graphic: params[0],
|
|
376
374
|
animationName: params[1],
|
|
377
375
|
replaceGraphic: params[2]
|
|
378
376
|
});
|
|
379
377
|
break;
|
|
380
|
-
case
|
|
378
|
+
case SocketMethods.CameraFollow:
|
|
381
379
|
const [spriteId, options] = params;
|
|
382
|
-
scene
|
|
380
|
+
scene?.cameraFollowSprite(spriteId, options);
|
|
383
381
|
break;
|
|
384
|
-
case
|
|
385
|
-
|
|
382
|
+
case SocketMethods.PlaySound:
|
|
383
|
+
RpgSound.play(params[0]);
|
|
386
384
|
break;
|
|
387
|
-
case
|
|
385
|
+
case SocketMethods.ModeMove:
|
|
388
386
|
const player = this.player;
|
|
389
387
|
const { checkCollision } = params[0];
|
|
390
388
|
if (player) {
|
|
@@ -394,9 +392,9 @@ class RpgClientEngine {
|
|
|
394
392
|
}
|
|
395
393
|
});
|
|
396
394
|
let lastRoomId = '';
|
|
397
|
-
this.subscriptionWorld =
|
|
395
|
+
this.subscriptionWorld = World.listen(this.socket)
|
|
398
396
|
.value
|
|
399
|
-
.subscribe((val) =>
|
|
397
|
+
.subscribe(async (val) => {
|
|
400
398
|
const scene = this.renderer.getScene();
|
|
401
399
|
if (!val.data) {
|
|
402
400
|
return;
|
|
@@ -413,6 +411,19 @@ class RpgClientEngine {
|
|
|
413
411
|
const change = (prop, root = val, localEvent = false) => {
|
|
414
412
|
const list = root.data[prop];
|
|
415
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
|
+
}
|
|
416
427
|
for (let key in partial) {
|
|
417
428
|
const obj = list[key];
|
|
418
429
|
const paramsChanged = partial ? partial[key] : undefined;
|
|
@@ -421,11 +432,10 @@ class RpgClientEngine {
|
|
|
421
432
|
}
|
|
422
433
|
if (!obj)
|
|
423
434
|
continue;
|
|
424
|
-
const isShape = prop == 'shapes';
|
|
425
435
|
if (!isShape) {
|
|
426
436
|
obj.type = {
|
|
427
|
-
users:
|
|
428
|
-
events:
|
|
437
|
+
users: PlayerType.Player,
|
|
438
|
+
events: PlayerType.Event
|
|
429
439
|
}[prop];
|
|
430
440
|
}
|
|
431
441
|
if (prop == 'users' && this.gameEngine.playerId == key) {
|
|
@@ -439,11 +449,12 @@ class RpgClientEngine {
|
|
|
439
449
|
data: obj,
|
|
440
450
|
partial: paramsChanged,
|
|
441
451
|
time: val.time,
|
|
442
|
-
roomId: val.roomId
|
|
452
|
+
roomId: val.roomId,
|
|
453
|
+
resetProps: val.resetProps
|
|
443
454
|
}, true);
|
|
444
455
|
}
|
|
445
456
|
}
|
|
446
|
-
if (
|
|
457
|
+
if (partialRoom?.pos && partialRoom?.frame !== undefined) {
|
|
447
458
|
this.serverFrames.set(partialRoom.frame, {
|
|
448
459
|
data: partialRoom.pos,
|
|
449
460
|
time: Date.now()
|
|
@@ -470,17 +481,17 @@ class RpgClientEngine {
|
|
|
470
481
|
if (scene) {
|
|
471
482
|
scene.update(val);
|
|
472
483
|
}
|
|
473
|
-
})
|
|
484
|
+
});
|
|
474
485
|
this.socket.on('disconnect', (reason) => {
|
|
475
486
|
if (this.serverChanging) {
|
|
476
487
|
return;
|
|
477
488
|
}
|
|
478
|
-
if (
|
|
479
|
-
|
|
480
|
-
|
|
489
|
+
if (RpgGui.exists(PrebuiltGui.Disconnect))
|
|
490
|
+
RpgGui.display(PrebuiltGui.Disconnect);
|
|
491
|
+
RpgPlugin.emit(HookClient.Disconnect, [this, reason, this.socket], true);
|
|
481
492
|
this.hasBeenDisconnected = true;
|
|
482
493
|
});
|
|
483
|
-
|
|
494
|
+
RpgGui._setSocket(this.socket);
|
|
484
495
|
if (standalone) {
|
|
485
496
|
this.socket.connection({
|
|
486
497
|
auth: {
|
|
@@ -491,7 +502,7 @@ class RpgClientEngine {
|
|
|
491
502
|
this.serverChanging = false;
|
|
492
503
|
}
|
|
493
504
|
get world() {
|
|
494
|
-
return
|
|
505
|
+
return World;
|
|
495
506
|
}
|
|
496
507
|
// shortcuts
|
|
497
508
|
/**
|
|
@@ -549,14 +560,19 @@ class RpgClientEngine {
|
|
|
549
560
|
reset() {
|
|
550
561
|
this.subscriptionWorld.unsubscribe();
|
|
551
562
|
this.world.reset();
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
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();
|
|
559
576
|
}
|
|
560
577
|
}
|
|
561
|
-
exports.RpgClientEngine = RpgClientEngine;
|
|
562
578
|
//# sourceMappingURL=RpgClientEngine.js.map
|