@rpgjs/client 3.3.2 → 4.0.0-beta.10
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 +3 -1
- package/lib/RpgClientEngine.js +194 -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.d.ts +1 -0
- 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 +712 -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 +143 -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
|
*
|
|
@@ -76,49 +66,58 @@ class RpgClientEngine {
|
|
|
76
66
|
* @memberof RpgClientEngine
|
|
77
67
|
*/
|
|
78
68
|
this.objects = this.gameEngine.objects;
|
|
69
|
+
this.envs = {};
|
|
70
|
+
this.envs = options.envs || {};
|
|
79
71
|
this.tick.subscribe(({ timestamp, deltaTime }) => {
|
|
80
72
|
if (timestamp != -1)
|
|
81
73
|
this.step(timestamp, deltaTime);
|
|
82
74
|
});
|
|
83
75
|
}
|
|
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
|
-
|
|
76
|
+
async _init() {
|
|
77
|
+
this.renderer = new RpgRenderer(this);
|
|
78
|
+
const pluginLoadRessource = async (hookName, type) => {
|
|
79
|
+
const resource = this.options[type] || [];
|
|
80
|
+
this.options[type] = [
|
|
81
|
+
...Utils.arrayFlat(await RpgPlugin.emit(hookName, resource)) || [],
|
|
82
|
+
...resource
|
|
83
|
+
];
|
|
84
|
+
};
|
|
85
|
+
await pluginLoadRessource(HookClient.AddSpriteSheet, 'spritesheets');
|
|
86
|
+
await pluginLoadRessource(HookClient.AddGui, 'gui');
|
|
87
|
+
await pluginLoadRessource(HookClient.AddSound, 'sounds');
|
|
88
|
+
this.renderer.options = {
|
|
89
|
+
selector: '#rpg',
|
|
90
|
+
selectorCanvas: '#canvas',
|
|
91
|
+
selectorGui: '#gui',
|
|
92
|
+
canvas: {},
|
|
93
|
+
gui: [],
|
|
94
|
+
spritesheets: [],
|
|
95
|
+
sounds: [],
|
|
96
|
+
...this.options
|
|
97
|
+
};
|
|
98
|
+
this.io = this.options.io;
|
|
99
|
+
if (this.options.serverFps)
|
|
100
|
+
this.serverFps = this.options.serverFps;
|
|
101
|
+
this.globalConfig = this.options.globalConfig;
|
|
102
|
+
if (this.globalConfig.assetsPath)
|
|
103
|
+
this.assetsPath = this.globalConfig.assetsPath;
|
|
104
|
+
this.gameEngine.standalone = this.options.standalone;
|
|
105
|
+
this.gameEngine.renderer = this.renderer;
|
|
106
|
+
this.gameEngine.clientEngine = this;
|
|
107
|
+
this.addSpriteSheet(this.renderer.options.spritesheets);
|
|
108
|
+
this.addSound(this.renderer.options.sounds);
|
|
109
|
+
if (typeof __RPGJS_PRODUCTION__ != 'undefined' && __RPGJS_PRODUCTION__) {
|
|
110
|
+
if ('serviceWorker' in navigator) {
|
|
111
|
+
window.addEventListener('load', () => {
|
|
112
|
+
navigator.serviceWorker.register('/service-worker.js');
|
|
113
|
+
});
|
|
115
114
|
}
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
}
|
|
116
|
+
this.controls = new KeyboardControls(this);
|
|
118
117
|
}
|
|
119
118
|
addResource(resourceClass, cb) {
|
|
120
119
|
let array = resourceClass;
|
|
121
|
-
if (!
|
|
120
|
+
if (!Utils.isArray(resourceClass)) {
|
|
122
121
|
array = [resourceClass];
|
|
123
122
|
}
|
|
124
123
|
cb(array, this);
|
|
@@ -144,44 +143,49 @@ class RpgClientEngine {
|
|
|
144
143
|
addSpriteSheet(spritesheetClass, id) {
|
|
145
144
|
if (typeof spritesheetClass === 'string') {
|
|
146
145
|
if (!id) {
|
|
147
|
-
throw
|
|
146
|
+
throw log('Please, specify the resource ID (second parameter)');
|
|
148
147
|
}
|
|
149
148
|
let AutoSpritesheet = class AutoSpritesheet {
|
|
150
149
|
};
|
|
151
150
|
AutoSpritesheet = __decorate([
|
|
152
|
-
|
|
151
|
+
Spritesheet({
|
|
153
152
|
id,
|
|
154
153
|
image: this.getResourceUrl(spritesheetClass)
|
|
155
154
|
})
|
|
156
155
|
], AutoSpritesheet);
|
|
157
156
|
spritesheetClass = AutoSpritesheet;
|
|
158
157
|
}
|
|
159
|
-
this.addResource(spritesheetClass,
|
|
158
|
+
this.addResource(spritesheetClass, _initSpritesheet);
|
|
160
159
|
return spritesheetClass;
|
|
161
160
|
}
|
|
162
161
|
addSound(soundClass, id) {
|
|
163
162
|
if (typeof soundClass === 'string') {
|
|
164
163
|
if (!id) {
|
|
165
|
-
throw
|
|
164
|
+
throw log('Please, specify the resource ID (second parameter)');
|
|
166
165
|
}
|
|
167
166
|
let AutoSound = class AutoSound {
|
|
168
167
|
};
|
|
169
168
|
AutoSound = __decorate([
|
|
170
|
-
|
|
169
|
+
Sound({
|
|
171
170
|
id,
|
|
172
171
|
sound: this.getResourceUrl(soundClass)
|
|
173
172
|
})
|
|
174
173
|
], AutoSound);
|
|
175
174
|
soundClass = AutoSound;
|
|
176
175
|
}
|
|
177
|
-
this.addResource(soundClass,
|
|
176
|
+
this.addResource(soundClass, _initSound);
|
|
178
177
|
return soundClass;
|
|
179
178
|
}
|
|
180
179
|
getResourceUrl(source) {
|
|
181
180
|
if (source.startsWith('data:')) {
|
|
182
181
|
return source;
|
|
183
182
|
}
|
|
184
|
-
|
|
183
|
+
// @ts-ignore
|
|
184
|
+
const staticDir = this.envs.VITE_BUILT;
|
|
185
|
+
if (staticDir) {
|
|
186
|
+
return this.assetsPath + '/' + Utils.basename(source);
|
|
187
|
+
}
|
|
188
|
+
return source;
|
|
185
189
|
}
|
|
186
190
|
/**
|
|
187
191
|
* Starts the client side and connects to the server
|
|
@@ -191,40 +195,39 @@ class RpgClientEngine {
|
|
|
191
195
|
* @returns {Promise< void >}
|
|
192
196
|
* @memberof RpgClientEngine
|
|
193
197
|
*/
|
|
194
|
-
start(options = {
|
|
198
|
+
async start(options = {
|
|
195
199
|
renderLoop: true
|
|
196
200
|
}) {
|
|
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
|
-
}
|
|
201
|
+
await this._init();
|
|
202
|
+
await this.renderer.init();
|
|
203
|
+
const { maxFps } = this.options;
|
|
204
|
+
if (options.renderLoop) {
|
|
205
|
+
this.scheduler.start({
|
|
206
|
+
maxFps
|
|
207
|
+
});
|
|
208
|
+
// 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
|
|
209
|
+
setInterval(() => {
|
|
210
|
+
this.processInput();
|
|
211
|
+
}, Utils.fps2ms(this.serverFps));
|
|
212
|
+
}
|
|
213
|
+
const ret = await RpgPlugin.emit(HookClient.Start, this);
|
|
214
|
+
this.matchMakerService = this.options.globalConfig.matchMakerService;
|
|
215
|
+
const hasFalseValue = ret.findIndex(el => el === false) != -1;
|
|
216
|
+
if (!hasFalseValue) {
|
|
217
|
+
let serverUri = {};
|
|
218
|
+
if (this.matchMakerService) {
|
|
219
|
+
if (Utils.isFunction(this.matchMakerService)) {
|
|
220
|
+
serverUri = this.matchMakerService();
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
serverUri = await lastValueFrom(ajax.getJSON(this.matchMakerService));
|
|
224
224
|
}
|
|
225
|
-
this.connection(serverUri.url ? serverUri.url + ':' + serverUri.port : undefined);
|
|
226
225
|
}
|
|
227
|
-
|
|
226
|
+
// @ts-ignore
|
|
227
|
+
const envUrl = this.envs.VITE_SERVER_URL;
|
|
228
|
+
this.connection(serverUri.url ? serverUri.url + ':' + serverUri.port :
|
|
229
|
+
envUrl ? envUrl : undefined);
|
|
230
|
+
}
|
|
228
231
|
}
|
|
229
232
|
/**
|
|
230
233
|
* Display the next frame. Useful for unit tests
|
|
@@ -238,18 +241,16 @@ class RpgClientEngine {
|
|
|
238
241
|
nextFrame(timestamp) {
|
|
239
242
|
this.scheduler.nextTick(timestamp);
|
|
240
243
|
}
|
|
241
|
-
sendInput(actionName) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
});
|
|
244
|
+
async sendInput(actionName) {
|
|
245
|
+
const player = this.player;
|
|
246
|
+
if (!player)
|
|
247
|
+
return;
|
|
248
|
+
if (player.canMove) {
|
|
249
|
+
player.pendingMove.push({
|
|
250
|
+
input: actionName,
|
|
251
|
+
frame: this.scheduler.frame
|
|
252
|
+
});
|
|
253
|
+
}
|
|
253
254
|
}
|
|
254
255
|
get player() {
|
|
255
256
|
return this.gameEngine.world.getObject(this.gameEngine.playerId);
|
|
@@ -274,34 +275,30 @@ class RpgClientEngine {
|
|
|
274
275
|
});
|
|
275
276
|
garbage = [];
|
|
276
277
|
}
|
|
277
|
-
step(t, dt) {
|
|
278
|
-
|
|
279
|
-
common_1.RpgPlugin.emit(common_1.HookClient.Step, [this, t, dt], true);
|
|
280
|
-
});
|
|
278
|
+
async step(t, dt) {
|
|
279
|
+
RpgPlugin.emit(HookClient.Step, [this, t, dt], true);
|
|
281
280
|
}
|
|
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);
|
|
281
|
+
async processInput() {
|
|
282
|
+
const player = this.player;
|
|
283
|
+
this.controls.preStep();
|
|
284
|
+
if (player) {
|
|
285
|
+
if (player.pendingMove.length > 0) {
|
|
286
|
+
const { inputs: inputEvent } = await this.gameEngine.processInput(this.gameEngine.playerId, this.controls.options);
|
|
287
|
+
if (inputEvent.length == 0)
|
|
288
|
+
return;
|
|
289
|
+
const frame = Date.now();
|
|
290
|
+
this.clientFrames.set(frame, {
|
|
291
|
+
data: player.position.copy(),
|
|
292
|
+
time: frame
|
|
293
|
+
});
|
|
294
|
+
if (this.socket) {
|
|
295
|
+
this.socket.emit('move', { input: inputEvent, frame });
|
|
300
296
|
}
|
|
301
|
-
|
|
302
|
-
this.serverReconciliation(player);
|
|
297
|
+
RpgPlugin.emit(HookClient.SendInput, [this, inputEvent], true);
|
|
303
298
|
}
|
|
304
|
-
|
|
299
|
+
if (player.canMove)
|
|
300
|
+
this.serverReconciliation(player);
|
|
301
|
+
}
|
|
305
302
|
}
|
|
306
303
|
/**
|
|
307
304
|
*Connect to the server
|
|
@@ -324,9 +321,9 @@ class RpgClientEngine {
|
|
|
324
321
|
this.socket = this.io;
|
|
325
322
|
}
|
|
326
323
|
this.socket.on('connect', () => {
|
|
327
|
-
if (
|
|
328
|
-
|
|
329
|
-
|
|
324
|
+
if (RpgGui.exists(PrebuiltGui.Disconnect))
|
|
325
|
+
RpgGui.hide(PrebuiltGui.Disconnect);
|
|
326
|
+
RpgPlugin.emit(HookClient.Connected, [this, this.socket], true);
|
|
330
327
|
this.hasBeenDisconnected = false;
|
|
331
328
|
});
|
|
332
329
|
this.socket.on('playerJoined', (playerEvent) => {
|
|
@@ -334,7 +331,7 @@ class RpgClientEngine {
|
|
|
334
331
|
this.session = playerEvent.session;
|
|
335
332
|
});
|
|
336
333
|
this.socket.on('connect_error', (err) => {
|
|
337
|
-
|
|
334
|
+
RpgPlugin.emit(HookClient.ConnectedError, [this, err, this.socket], true);
|
|
338
335
|
});
|
|
339
336
|
this.socket.on('preLoadScene', (name) => {
|
|
340
337
|
if (this.lastScene == name) {
|
|
@@ -343,10 +340,13 @@ class RpgClientEngine {
|
|
|
343
340
|
this.lastScene = name;
|
|
344
341
|
this.renderer.transitionScene(name);
|
|
345
342
|
});
|
|
346
|
-
this.socket.on(
|
|
343
|
+
this.socket.on(SocketEvents.GameReload, () => {
|
|
344
|
+
window.location.reload();
|
|
345
|
+
});
|
|
346
|
+
this.socket.on(SocketEvents.LoadScene, ({ name, data }) => {
|
|
347
347
|
this.renderer.loadScene(name, data);
|
|
348
348
|
});
|
|
349
|
-
this.socket.on(
|
|
349
|
+
this.socket.on(SocketEvents.ChangeServer, ({ url, port }) => {
|
|
350
350
|
const connection = url + ':' + port;
|
|
351
351
|
if (this.lastConnection == connection) {
|
|
352
352
|
return;
|
|
@@ -361,30 +361,30 @@ class RpgClientEngine {
|
|
|
361
361
|
});
|
|
362
362
|
this.socket.on('changeTile', ({ tiles, x, y }) => {
|
|
363
363
|
const scene = this.renderer.getScene();
|
|
364
|
-
scene
|
|
364
|
+
scene?.changeTile(x, y, tiles);
|
|
365
365
|
});
|
|
366
|
-
this.socket.on(
|
|
366
|
+
this.socket.on(SocketEvents.CallMethod, ({ objectId, params, name }) => {
|
|
367
367
|
const scene = this.renderer.getScene();
|
|
368
|
-
const sprite = scene
|
|
368
|
+
const sprite = scene?.getPlayer(objectId);
|
|
369
369
|
if (!sprite)
|
|
370
370
|
return;
|
|
371
371
|
switch (name) {
|
|
372
|
-
case
|
|
373
|
-
scene
|
|
372
|
+
case SocketMethods.ShowAnimation:
|
|
373
|
+
scene?.showAnimation({
|
|
374
374
|
attachTo: sprite,
|
|
375
375
|
graphic: params[0],
|
|
376
376
|
animationName: params[1],
|
|
377
377
|
replaceGraphic: params[2]
|
|
378
378
|
});
|
|
379
379
|
break;
|
|
380
|
-
case
|
|
380
|
+
case SocketMethods.CameraFollow:
|
|
381
381
|
const [spriteId, options] = params;
|
|
382
|
-
scene
|
|
382
|
+
scene?.cameraFollowSprite(spriteId, options);
|
|
383
383
|
break;
|
|
384
|
-
case
|
|
385
|
-
|
|
384
|
+
case SocketMethods.PlaySound:
|
|
385
|
+
RpgSound.play(params[0]);
|
|
386
386
|
break;
|
|
387
|
-
case
|
|
387
|
+
case SocketMethods.ModeMove:
|
|
388
388
|
const player = this.player;
|
|
389
389
|
const { checkCollision } = params[0];
|
|
390
390
|
if (player) {
|
|
@@ -394,9 +394,9 @@ class RpgClientEngine {
|
|
|
394
394
|
}
|
|
395
395
|
});
|
|
396
396
|
let lastRoomId = '';
|
|
397
|
-
this.subscriptionWorld =
|
|
397
|
+
this.subscriptionWorld = World.listen(this.socket)
|
|
398
398
|
.value
|
|
399
|
-
.subscribe((val) =>
|
|
399
|
+
.subscribe(async (val) => {
|
|
400
400
|
const scene = this.renderer.getScene();
|
|
401
401
|
if (!val.data) {
|
|
402
402
|
return;
|
|
@@ -413,6 +413,19 @@ class RpgClientEngine {
|
|
|
413
413
|
const change = (prop, root = val, localEvent = false) => {
|
|
414
414
|
const list = root.data[prop];
|
|
415
415
|
const partial = root.partial[prop];
|
|
416
|
+
const isShape = prop == 'shapes';
|
|
417
|
+
if (!partial) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
if (val.resetProps.indexOf(prop) != -1) {
|
|
421
|
+
const objects = isShape ? this.gameEngine.getShapes() : this.gameEngine.getObjects();
|
|
422
|
+
for (let key in objects) {
|
|
423
|
+
const obj = objects[key];
|
|
424
|
+
if (obj) {
|
|
425
|
+
this.gameEngine.removeObjectAndShape(key);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
416
429
|
for (let key in partial) {
|
|
417
430
|
const obj = list[key];
|
|
418
431
|
const paramsChanged = partial ? partial[key] : undefined;
|
|
@@ -421,11 +434,10 @@ class RpgClientEngine {
|
|
|
421
434
|
}
|
|
422
435
|
if (!obj)
|
|
423
436
|
continue;
|
|
424
|
-
const isShape = prop == 'shapes';
|
|
425
437
|
if (!isShape) {
|
|
426
438
|
obj.type = {
|
|
427
|
-
users:
|
|
428
|
-
events:
|
|
439
|
+
users: PlayerType.Player,
|
|
440
|
+
events: PlayerType.Event
|
|
429
441
|
}[prop];
|
|
430
442
|
}
|
|
431
443
|
if (prop == 'users' && this.gameEngine.playerId == key) {
|
|
@@ -439,11 +451,12 @@ class RpgClientEngine {
|
|
|
439
451
|
data: obj,
|
|
440
452
|
partial: paramsChanged,
|
|
441
453
|
time: val.time,
|
|
442
|
-
roomId: val.roomId
|
|
454
|
+
roomId: val.roomId,
|
|
455
|
+
resetProps: val.resetProps
|
|
443
456
|
}, true);
|
|
444
457
|
}
|
|
445
458
|
}
|
|
446
|
-
if (
|
|
459
|
+
if (partialRoom?.pos && partialRoom?.frame !== undefined) {
|
|
447
460
|
this.serverFrames.set(partialRoom.frame, {
|
|
448
461
|
data: partialRoom.pos,
|
|
449
462
|
time: Date.now()
|
|
@@ -470,17 +483,17 @@ class RpgClientEngine {
|
|
|
470
483
|
if (scene) {
|
|
471
484
|
scene.update(val);
|
|
472
485
|
}
|
|
473
|
-
})
|
|
486
|
+
});
|
|
474
487
|
this.socket.on('disconnect', (reason) => {
|
|
475
488
|
if (this.serverChanging) {
|
|
476
489
|
return;
|
|
477
490
|
}
|
|
478
|
-
if (
|
|
479
|
-
|
|
480
|
-
|
|
491
|
+
if (RpgGui.exists(PrebuiltGui.Disconnect))
|
|
492
|
+
RpgGui.display(PrebuiltGui.Disconnect);
|
|
493
|
+
RpgPlugin.emit(HookClient.Disconnect, [this, reason, this.socket], true);
|
|
481
494
|
this.hasBeenDisconnected = true;
|
|
482
495
|
});
|
|
483
|
-
|
|
496
|
+
RpgGui._setSocket(this.socket);
|
|
484
497
|
if (standalone) {
|
|
485
498
|
this.socket.connection({
|
|
486
499
|
auth: {
|
|
@@ -491,7 +504,7 @@ class RpgClientEngine {
|
|
|
491
504
|
this.serverChanging = false;
|
|
492
505
|
}
|
|
493
506
|
get world() {
|
|
494
|
-
return
|
|
507
|
+
return World;
|
|
495
508
|
}
|
|
496
509
|
// shortcuts
|
|
497
510
|
/**
|
|
@@ -549,14 +562,19 @@ class RpgClientEngine {
|
|
|
549
562
|
reset() {
|
|
550
563
|
this.subscriptionWorld.unsubscribe();
|
|
551
564
|
this.world.reset();
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
565
|
+
spritesheets.clear();
|
|
566
|
+
sounds.clear();
|
|
567
|
+
Assets.reset();
|
|
568
|
+
utils.clearTextureCache();
|
|
569
|
+
for (let textureUrl in utils.BaseTextureCache) {
|
|
570
|
+
delete utils.BaseTextureCache[textureUrl];
|
|
571
|
+
}
|
|
572
|
+
for (let textureUrl in utils.TextureCache) {
|
|
573
|
+
delete utils.TextureCache[textureUrl];
|
|
574
|
+
}
|
|
575
|
+
RpgGui.clear();
|
|
576
|
+
RpgCommonMap.bufferClient.clear();
|
|
577
|
+
RpgSound.clear();
|
|
559
578
|
}
|
|
560
579
|
}
|
|
561
|
-
exports.RpgClientEngine = RpgClientEngine;
|
|
562
580
|
//# sourceMappingURL=RpgClientEngine.js.map
|