@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.
Files changed (117) hide show
  1. package/LICENSE +19 -0
  2. package/lib/Components/AbstractComponent.d.ts +3 -2
  3. package/lib/Components/AbstractComponent.js +17 -28
  4. package/lib/Components/AbstractComponent.js.map +1 -1
  5. package/lib/Components/BarComponent.d.ts +2 -1
  6. package/lib/Components/BarComponent.js +32 -33
  7. package/lib/Components/BarComponent.js.map +1 -1
  8. package/lib/Components/Component.d.ts +3 -3
  9. package/lib/Components/Component.js +84 -96
  10. package/lib/Components/Component.js.map +1 -1
  11. package/lib/Components/DebugComponent.d.ts +2 -1
  12. package/lib/Components/DebugComponent.js +9 -10
  13. package/lib/Components/DebugComponent.js.map +1 -1
  14. package/lib/Components/ImageComponent.d.ts +2 -1
  15. package/lib/Components/ImageComponent.js +5 -7
  16. package/lib/Components/ImageComponent.js.map +1 -1
  17. package/lib/Components/ShapeComponent.d.ts +2 -1
  18. package/lib/Components/ShapeComponent.js +14 -14
  19. package/lib/Components/ShapeComponent.js.map +1 -1
  20. package/lib/Components/TextComponent.d.ts +3 -2
  21. package/lib/Components/TextComponent.js +10 -9
  22. package/lib/Components/TextComponent.js.map +1 -1
  23. package/lib/Components/TileComponent.d.ts +2 -1
  24. package/lib/Components/TileComponent.js +12 -16
  25. package/lib/Components/TileComponent.js.map +1 -1
  26. package/lib/Effects/Animation.d.ts +10 -9
  27. package/lib/Effects/Animation.js +36 -36
  28. package/lib/Effects/Animation.js.map +1 -1
  29. package/lib/Effects/AnimationCharacter.js +2 -5
  30. package/lib/Effects/AnimationCharacter.js.map +1 -1
  31. package/lib/Effects/Spinner.d.ts +3 -2
  32. package/lib/Effects/Spinner.js +2 -5
  33. package/lib/Effects/Spinner.js.map +1 -1
  34. package/lib/Effects/Timeline.d.ts +1 -1
  35. package/lib/Effects/Timeline.js +6 -10
  36. package/lib/Effects/Timeline.js.map +1 -1
  37. package/lib/Effects/TransitionScene.d.ts +2 -1
  38. package/lib/Effects/TransitionScene.js +3 -7
  39. package/lib/Effects/TransitionScene.js.map +1 -1
  40. package/lib/GameEngine.js +51 -26
  41. package/lib/GameEngine.js.map +1 -1
  42. package/lib/Interfaces/Character.js +1 -2
  43. package/lib/Interfaces/Scene.js +1 -2
  44. package/lib/KeyboardControls.d.ts +2 -1
  45. package/lib/KeyboardControls.js +47 -45
  46. package/lib/KeyboardControls.js.map +1 -1
  47. package/lib/Logger.js +1 -5
  48. package/lib/Logger.js.map +1 -1
  49. package/lib/Presets/AnimationSpritesheet.js +9 -13
  50. package/lib/Presets/AnimationSpritesheet.js.map +1 -1
  51. package/lib/Presets/Scene.js +2 -5
  52. package/lib/Presets/Scene.js.map +1 -1
  53. package/lib/Renderer.d.ts +5 -3
  54. package/lib/Renderer.js +68 -60
  55. package/lib/Renderer.js.map +1 -1
  56. package/lib/Resources.js +1 -5
  57. package/lib/Resources.js.map +1 -1
  58. package/lib/RpgClient.d.ts +3 -2
  59. package/lib/RpgClient.js +1 -2
  60. package/lib/RpgClientEngine.d.ts +2 -2
  61. package/lib/RpgClientEngine.js +196 -175
  62. package/lib/RpgClientEngine.js.map +1 -1
  63. package/lib/RpgGui.js +40 -41
  64. package/lib/RpgGui.js.map +1 -1
  65. package/lib/Scene/EventLayer.d.ts +4 -0
  66. package/lib/Scene/EventLayer.js +8 -0
  67. package/lib/Scene/EventLayer.js.map +1 -0
  68. package/lib/Scene/Map.d.ts +17 -3
  69. package/lib/Scene/Map.js +157 -113
  70. package/lib/Scene/Map.js.map +1 -1
  71. package/lib/Scene/Scene.d.ts +3 -3
  72. package/lib/Scene/Scene.js +24 -20
  73. package/lib/Scene/Scene.js.map +1 -1
  74. package/lib/Scene/SceneData.js +1 -5
  75. package/lib/Scene/SceneData.js.map +1 -1
  76. package/lib/Sound/RpgSound.js +8 -11
  77. package/lib/Sound/RpgSound.js.map +1 -1
  78. package/lib/Sound/Sound.d.ts +2 -2
  79. package/lib/Sound/Sound.js +1 -5
  80. package/lib/Sound/Sound.js.map +1 -1
  81. package/lib/Sound/Sounds.js +4 -8
  82. package/lib/Sound/Sounds.js.map +1 -1
  83. package/lib/Sprite/Character.d.ts +3 -2
  84. package/lib/Sprite/Character.js +15 -16
  85. package/lib/Sprite/Character.js.map +1 -1
  86. package/lib/Sprite/Player.js +2 -9
  87. package/lib/Sprite/Player.js.map +1 -1
  88. package/lib/Sprite/Spritesheet.d.ts +4 -4
  89. package/lib/Sprite/Spritesheet.js +1 -5
  90. package/lib/Sprite/Spritesheet.js.map +1 -1
  91. package/lib/Sprite/Spritesheets.js +4 -8
  92. package/lib/Sprite/Spritesheets.js.map +1 -1
  93. package/lib/Tilemap/CommonLayer.d.ts +2 -1
  94. package/lib/Tilemap/CommonLayer.js +7 -11
  95. package/lib/Tilemap/CommonLayer.js.map +1 -1
  96. package/lib/Tilemap/ImageLayer.js +5 -7
  97. package/lib/Tilemap/ImageLayer.js.map +1 -1
  98. package/lib/Tilemap/Tile.d.ts +5 -5
  99. package/lib/Tilemap/Tile.js +19 -21
  100. package/lib/Tilemap/Tile.js.map +1 -1
  101. package/lib/Tilemap/TileLayer.d.ts +0 -7
  102. package/lib/Tilemap/TileLayer.js +27 -29
  103. package/lib/Tilemap/TileLayer.js.map +1 -1
  104. package/lib/Tilemap/TileSet.d.ts +2 -1
  105. package/lib/Tilemap/TileSet.js +9 -12
  106. package/lib/Tilemap/TileSet.js.map +1 -1
  107. package/lib/Tilemap/index.d.ts +3 -11
  108. package/lib/Tilemap/index.js +22 -61
  109. package/lib/Tilemap/index.js.map +1 -1
  110. package/lib/clientEntryPoint.js +26 -28
  111. package/lib/clientEntryPoint.js.map +1 -1
  112. package/lib/index.js +21 -75
  113. package/lib/index.js.map +1 -1
  114. package/package.json +16 -14
  115. package/lib/Components/ColorComponent.d.ts +0 -9
  116. package/lib/Components/ColorComponent.js +0 -18
  117. package/lib/Components/ColorComponent.js.map +0 -1
@@ -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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.RpgClientEngine = void 0;
19
- const KeyboardControls_1 = require("./KeyboardControls");
20
- const Renderer_1 = require("./Renderer");
21
- const Spritesheets_1 = require("./Sprite/Spritesheets");
22
- const Sounds_1 = require("./Sound/Sounds");
23
- const simple_room_client_1 = require("simple-room-client");
24
- const rxjs_1 = require("rxjs");
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 rxjs_1.BehaviorSubject({
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 rxjs_1.Subject();
52
- this.roomJoin = new rxjs_1.Subject();
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 common_1.Scheduler();
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
- return __awaiter(this, void 0, void 0, function* () {
87
- this.renderer = new Renderer_1.RpgRenderer(this);
88
- const pluginLoadRessource = (hookName, type) => __awaiter(this, void 0, void 0, function* () {
89
- const resource = this.options[type] || [];
90
- this.options[type] = [
91
- ...common_1.Utils.arrayFlat(yield common_1.RpgPlugin.emit(hookName, resource)) || [],
92
- ...resource
93
- ];
94
- });
95
- yield pluginLoadRessource(common_1.HookClient.AddSpriteSheet, 'spritesheets');
96
- yield pluginLoadRessource(common_1.HookClient.AddGui, 'gui');
97
- yield pluginLoadRessource(common_1.HookClient.AddSound, 'sounds');
98
- this.renderer.options = Object.assign({ selector: '#rpg', selectorCanvas: '#canvas', selectorGui: '#gui', canvas: {}, gui: [], spritesheets: [], sounds: [] }, this.options);
99
- this.io = this.options.io;
100
- if (this.options.serverFps)
101
- this.serverFps = this.options.serverFps;
102
- this.globalConfig = this.options.globalConfig;
103
- if (this.globalConfig.assetsPath)
104
- this.assetsPath = this.globalConfig.assetsPath;
105
- this.gameEngine.standalone = this.options.standalone;
106
- this.gameEngine.renderer = this.renderer;
107
- this.gameEngine.clientEngine = this;
108
- this.addSpriteSheet(this.renderer.options.spritesheets);
109
- this.addSound(this.renderer.options.sounds);
110
- if (typeof __RPGJS_PRODUCTION__ != 'undefined' && __RPGJS_PRODUCTION__) {
111
- if ('serviceWorker' in navigator) {
112
- window.addEventListener('load', () => {
113
- navigator.serviceWorker.register('/service-worker.js');
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
- this.controls = new KeyboardControls_1.KeyboardControls(this);
118
- });
113
+ }
114
+ this.controls = new KeyboardControls(this);
119
115
  }
120
116
  addResource(resourceClass, cb) {
121
117
  let array = resourceClass;
122
- if (!common_1.Utils.isArray(resourceClass)) {
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 (0, Logger_1.log)('Please, specify the resource ID (second parameter)');
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
- (0, Spritesheet_1.Spritesheet)({
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, Spritesheets_1._initSpritesheet);
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 (0, Logger_1.log)('Please, specify the resource ID (second parameter)');
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
- (0, Sound_1.Sound)({
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, Sounds_1._initSound);
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
- return this.assetsPath + '/' + common_1.Utils.basename(source);
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
- return __awaiter(this, void 0, void 0, function* () {
199
- PIXI.utils.skipHello();
200
- yield this._init();
201
- yield this.renderer.init();
202
- const { maxFps } = this.options;
203
- if (options.renderLoop) {
204
- this.scheduler.start({
205
- maxFps
206
- });
207
- // 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
208
- setInterval(() => {
209
- this.processInput();
210
- }, common_1.Utils.fps2ms(this.serverFps));
211
- }
212
- const ret = yield common_1.RpgPlugin.emit(common_1.HookClient.Start, this);
213
- this.matchMakerService = this.options.globalConfig.matchMakerService;
214
- const hasFalseValue = ret.findIndex(el => el === false) != -1;
215
- if (!hasFalseValue) {
216
- let serverUri = {};
217
- if (this.matchMakerService) {
218
- if (common_1.Utils.isFunction(this.matchMakerService)) {
219
- serverUri = this.matchMakerService();
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
- return __awaiter(this, void 0, void 0, function* () {
244
- const player = this.player;
245
- if (!player)
246
- return;
247
- if (player.canMove) {
248
- player.pendingMove.push({
249
- input: actionName,
250
- frame: this.frame
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
- return __awaiter(this, void 0, void 0, function* () {
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
- return __awaiter(this, void 0, void 0, function* () {
280
- const player = this.player;
281
- this.controls.preStep();
282
- if (player) {
283
- if (player.pendingMove.length > 0) {
284
- const { inputs: inputEvent } = yield this.gameEngine.processInput(this.gameEngine.playerId, this.controls.options);
285
- if (inputEvent.length == 0)
286
- return;
287
- this.clientFrames.set(this.frame, {
288
- data: player.position,
289
- time: Date.now()
290
- });
291
- if (this.socket) {
292
- this.socket.emit('move', { input: inputEvent, frame: this.frame });
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
- if (player.canMove)
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 (RpgGui_1.RpgGui.exists(common_1.PrebuiltGui.Disconnect))
323
- RpgGui_1.RpgGui.hide(common_1.PrebuiltGui.Disconnect);
324
- common_1.RpgPlugin.emit(common_1.HookClient.Connected, [this, this.socket], true);
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
- common_1.RpgPlugin.emit(common_1.HookClient.ConnectedError, [this, err, this.socket], true);
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('loadScene', ({ name, data }) => {
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('changeServer', ({ url, port }) => {
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 === null || scene === void 0 ? void 0 : scene.changeTile(x, y, tiles);
362
+ scene?.changeTile(x, y, tiles);
360
363
  });
361
- this.socket.on(types_1.SocketEvents.CallMethod, ({ objectId, params, name }) => {
364
+ this.socket.on(SocketEvents.CallMethod, ({ objectId, params, name }) => {
362
365
  const scene = this.renderer.getScene();
363
- const sprite = scene === null || scene === void 0 ? void 0 : scene.getPlayer(objectId);
366
+ const sprite = scene?.getPlayer(objectId);
364
367
  if (!sprite)
365
368
  return;
366
369
  switch (name) {
367
- case types_1.SocketMethods.ShowAnimation:
368
- scene === null || scene === void 0 ? void 0 : scene.showAnimation({
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 types_1.SocketMethods.CameraFollow:
378
+ case SocketMethods.CameraFollow:
376
379
  const [spriteId, options] = params;
377
- scene === null || scene === void 0 ? void 0 : scene.cameraFollowSprite(spriteId, options);
380
+ scene?.cameraFollowSprite(spriteId, options);
378
381
  break;
379
- case types_1.SocketMethods.PlaySound:
380
- RpgSound_1.RpgSound.play(params[0]);
382
+ case SocketMethods.PlaySound:
383
+ RpgSound.play(params[0]);
381
384
  break;
382
- case types_1.SocketMethods.ModeMove:
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 = simple_room_client_1.World.listen(this.socket)
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: types_1.PlayerType.Player,
423
- events: types_1.PlayerType.Event
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 ((partialRoom === null || partialRoom === void 0 ? void 0 : partialRoom.pos) && (partialRoom === null || partialRoom === void 0 ? void 0 : partialRoom.frame) !== undefined) {
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 (RpgGui_1.RpgGui.exists(common_1.PrebuiltGui.Disconnect))
474
- RpgGui_1.RpgGui.display(common_1.PrebuiltGui.Disconnect);
475
- common_1.RpgPlugin.emit(common_1.HookClient.Disconnect, [this, reason, this.socket], true);
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
- RpgGui_1.RpgGui._setSocket(this.socket);
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 simple_room_client_1.World;
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
- Spritesheets_1.spritesheets.clear();
548
- Sounds_1.sounds.clear();
549
- PIXI.Loader.shared.reset();
550
- PIXI.utils.clearTextureCache();
551
- RpgGui_1.RpgGui.clear();
552
- common_1.RpgCommonMap.bufferClient.clear();
553
- RpgSound_1.RpgSound.clear();
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