@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.
Files changed (164) 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 -1
  61. package/lib/RpgClientEngine.js +192 -176
  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 +19 -19
  115. package/src/Components/AbstractComponent.ts +120 -0
  116. package/src/Components/BarComponent.ts +179 -0
  117. package/src/Components/Component.ts +506 -0
  118. package/src/Components/DebugComponent.ts +36 -0
  119. package/src/Components/ImageComponent.ts +30 -0
  120. package/src/Components/ShapeComponent.ts +64 -0
  121. package/src/Components/TextComponent.ts +33 -0
  122. package/src/Components/TileComponent.ts +43 -0
  123. package/src/Effects/Animation.ts +297 -0
  124. package/src/Effects/AnimationCharacter.ts +7 -0
  125. package/src/Effects/Spinner.ts +19 -0
  126. package/src/Effects/Timeline.ts +294 -0
  127. package/src/Effects/TransitionScene.ts +57 -0
  128. package/src/GameEngine.ts +284 -0
  129. package/src/Interfaces/Character.ts +7 -0
  130. package/src/Interfaces/Scene.ts +9 -0
  131. package/src/KeyboardControls.ts +552 -0
  132. package/src/Logger.ts +3 -0
  133. package/src/Presets/AnimationSpritesheet.ts +36 -0
  134. package/src/Presets/Scene.ts +3 -0
  135. package/src/Renderer.ts +263 -0
  136. package/src/Resources.ts +40 -0
  137. package/src/RpgClient.ts +333 -0
  138. package/src/RpgClientEngine.ts +709 -0
  139. package/src/RpgGui.ts +553 -0
  140. package/src/RpgGuiCompiled.ts +43 -0
  141. package/src/Scene/EventLayer.ts +9 -0
  142. package/src/Scene/Map.ts +393 -0
  143. package/src/Scene/Scene.ts +270 -0
  144. package/src/Scene/SceneData.ts +13 -0
  145. package/src/Sound/RpgSound.ts +50 -0
  146. package/src/Sound/Sound.ts +91 -0
  147. package/src/Sound/Sounds.ts +7 -0
  148. package/src/Sprite/Character.ts +149 -0
  149. package/src/Sprite/Player.ts +3 -0
  150. package/src/Sprite/Spritesheet.ts +392 -0
  151. package/src/Sprite/Spritesheets.ts +8 -0
  152. package/src/Tilemap/CommonLayer.ts +20 -0
  153. package/src/Tilemap/ImageLayer.ts +20 -0
  154. package/src/Tilemap/Tile.ts +80 -0
  155. package/src/Tilemap/TileLayer.ts +142 -0
  156. package/src/Tilemap/TileSet.ts +40 -0
  157. package/src/Tilemap/index.ts +173 -0
  158. package/src/clientEntryPoint.ts +141 -0
  159. package/src/index.ts +25 -0
  160. package/src/types/howler.d.ts +73 -0
  161. package/tsconfig.json +30 -0
  162. package/lib/Components/ColorComponent.d.ts +0 -9
  163. package/lib/Components/ColorComponent.js +0 -18
  164. 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,14 +32,14 @@ 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;
@@ -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 common_1.Scheduler();
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
- return __awaiter(this, void 0, void 0, function* () {
86
- this.renderer = new Renderer_1.RpgRenderer(this);
87
- const pluginLoadRessource = (hookName, type) => __awaiter(this, void 0, void 0, function* () {
88
- const resource = this.options[type] || [];
89
- this.options[type] = [
90
- ...common_1.Utils.arrayFlat(yield common_1.RpgPlugin.emit(hookName, resource)) || [],
91
- ...resource
92
- ];
93
- });
94
- yield pluginLoadRessource(common_1.HookClient.AddSpriteSheet, 'spritesheets');
95
- yield pluginLoadRessource(common_1.HookClient.AddGui, 'gui');
96
- yield pluginLoadRessource(common_1.HookClient.AddSound, 'sounds');
97
- this.renderer.options = Object.assign({ selector: '#rpg', selectorCanvas: '#canvas', selectorGui: '#gui', canvas: {}, gui: [], spritesheets: [], sounds: [] }, this.options);
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
- });
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
- this.controls = new KeyboardControls_1.KeyboardControls(this);
117
- });
113
+ }
114
+ this.controls = new KeyboardControls(this);
118
115
  }
119
116
  addResource(resourceClass, cb) {
120
117
  let array = resourceClass;
121
- if (!common_1.Utils.isArray(resourceClass)) {
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 (0, Logger_1.log)('Please, specify the resource ID (second parameter)');
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
- (0, Spritesheet_1.Spritesheet)({
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, Spritesheets_1._initSpritesheet);
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 (0, Logger_1.log)('Please, specify the resource ID (second parameter)');
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
- (0, Sound_1.Sound)({
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, Sounds_1._initSound);
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
- 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;
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
- return __awaiter(this, void 0, void 0, function* () {
198
- PIXI.utils.skipHello();
199
- yield this._init();
200
- yield 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
- }, common_1.Utils.fps2ms(this.serverFps));
210
- }
211
- const ret = yield common_1.RpgPlugin.emit(common_1.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 (common_1.Utils.isFunction(this.matchMakerService)) {
218
- serverUri = this.matchMakerService();
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
- return __awaiter(this, void 0, void 0, function* () {
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
- }
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
- return __awaiter(this, void 0, void 0, function* () {
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
- return __awaiter(this, void 0, void 0, function* () {
284
- const player = this.player;
285
- this.controls.preStep();
286
- if (player) {
287
- if (player.pendingMove.length > 0) {
288
- const { inputs: inputEvent } = yield this.gameEngine.processInput(this.gameEngine.playerId, this.controls.options);
289
- if (inputEvent.length == 0)
290
- return;
291
- const frame = Date.now();
292
- this.clientFrames.set(frame, {
293
- data: player.position.copy(),
294
- time: frame
295
- });
296
- if (this.socket) {
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
- if (player.canMove)
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 (RpgGui_1.RpgGui.exists(common_1.PrebuiltGui.Disconnect))
328
- RpgGui_1.RpgGui.hide(common_1.PrebuiltGui.Disconnect);
329
- 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);
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
- common_1.RpgPlugin.emit(common_1.HookClient.ConnectedError, [this, err, this.socket], true);
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('loadScene', ({ name, data }) => {
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('changeServer', ({ url, port }) => {
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 === null || scene === void 0 ? void 0 : scene.changeTile(x, y, tiles);
362
+ scene?.changeTile(x, y, tiles);
365
363
  });
366
- this.socket.on(types_1.SocketEvents.CallMethod, ({ objectId, params, name }) => {
364
+ this.socket.on(SocketEvents.CallMethod, ({ objectId, params, name }) => {
367
365
  const scene = this.renderer.getScene();
368
- const sprite = scene === null || scene === void 0 ? void 0 : scene.getPlayer(objectId);
366
+ const sprite = scene?.getPlayer(objectId);
369
367
  if (!sprite)
370
368
  return;
371
369
  switch (name) {
372
- case types_1.SocketMethods.ShowAnimation:
373
- scene === null || scene === void 0 ? void 0 : scene.showAnimation({
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 types_1.SocketMethods.CameraFollow:
378
+ case SocketMethods.CameraFollow:
381
379
  const [spriteId, options] = params;
382
- scene === null || scene === void 0 ? void 0 : scene.cameraFollowSprite(spriteId, options);
380
+ scene?.cameraFollowSprite(spriteId, options);
383
381
  break;
384
- case types_1.SocketMethods.PlaySound:
385
- RpgSound_1.RpgSound.play(params[0]);
382
+ case SocketMethods.PlaySound:
383
+ RpgSound.play(params[0]);
386
384
  break;
387
- case types_1.SocketMethods.ModeMove:
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 = simple_room_client_1.World.listen(this.socket)
395
+ this.subscriptionWorld = World.listen(this.socket)
398
396
  .value
399
- .subscribe((val) => __awaiter(this, void 0, void 0, function* () {
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: types_1.PlayerType.Player,
428
- events: types_1.PlayerType.Event
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 ((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) {
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 (RpgGui_1.RpgGui.exists(common_1.PrebuiltGui.Disconnect))
479
- RpgGui_1.RpgGui.display(common_1.PrebuiltGui.Disconnect);
480
- 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);
481
492
  this.hasBeenDisconnected = true;
482
493
  });
483
- RpgGui_1.RpgGui._setSocket(this.socket);
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 simple_room_client_1.World;
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
- Spritesheets_1.spritesheets.clear();
553
- Sounds_1.sounds.clear();
554
- PIXI.Loader.shared.reset();
555
- PIXI.utils.clearTextureCache();
556
- RpgGui_1.RpgGui.clear();
557
- common_1.RpgCommonMap.bufferClient.clear();
558
- 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();
559
576
  }
560
577
  }
561
- exports.RpgClientEngine = RpgClientEngine;
562
578
  //# sourceMappingURL=RpgClientEngine.js.map