@rpgjs/client 4.2.2 → 5.0.0-alpha.0

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 (321) hide show
  1. package/dist/Game/EffectManager.d.ts +5 -0
  2. package/dist/Game/Event.d.ts +4 -0
  3. package/dist/Game/Map.d.ts +7 -0
  4. package/dist/Game/Player.d.ts +4 -0
  5. package/dist/Gui/Gui.d.ts +23 -0
  6. package/{lib → dist}/RpgClient.d.ts +9 -6
  7. package/dist/RpgClientEngine.d.ts +43 -0
  8. package/dist/components/effects/index.d.ts +4 -0
  9. package/dist/components/gui/index.d.ts +3 -0
  10. package/dist/components/index.d.ts +2 -0
  11. package/dist/core/inject.d.ts +5 -0
  12. package/dist/core/setup.d.ts +6 -0
  13. package/dist/index.d.ts +13 -0
  14. package/dist/index.js +13 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/index10.js +8 -0
  17. package/dist/index10.js.map +1 -0
  18. package/dist/index11.js +10 -0
  19. package/dist/index11.js.map +1 -0
  20. package/dist/index12.js +8 -0
  21. package/dist/index12.js.map +1 -0
  22. package/dist/index13.js +17 -0
  23. package/dist/index13.js.map +1 -0
  24. package/dist/index14.js +50 -0
  25. package/dist/index14.js.map +1 -0
  26. package/dist/index15.js +191 -0
  27. package/dist/index15.js.map +1 -0
  28. package/dist/index16.js +9 -0
  29. package/dist/index16.js.map +1 -0
  30. package/dist/index17.js +387 -0
  31. package/dist/index17.js.map +1 -0
  32. package/dist/index18.js +31 -0
  33. package/dist/index18.js.map +1 -0
  34. package/dist/index19.js +24 -0
  35. package/dist/index19.js.map +1 -0
  36. package/dist/index2.js +112 -0
  37. package/dist/index2.js.map +1 -0
  38. package/dist/index20.js +2421 -0
  39. package/dist/index20.js.map +1 -0
  40. package/dist/index21.js +114 -0
  41. package/dist/index21.js.map +1 -0
  42. package/dist/index22.js +109 -0
  43. package/dist/index22.js.map +1 -0
  44. package/dist/index23.js +71 -0
  45. package/dist/index23.js.map +1 -0
  46. package/dist/index24.js +21 -0
  47. package/dist/index24.js.map +1 -0
  48. package/dist/index25.js +41 -0
  49. package/dist/index25.js.map +1 -0
  50. package/dist/index26.js +5 -0
  51. package/dist/index26.js.map +1 -0
  52. package/dist/index27.js +322 -0
  53. package/dist/index27.js.map +1 -0
  54. package/dist/index28.js +25 -0
  55. package/dist/index28.js.map +1 -0
  56. package/dist/index29.js +11 -0
  57. package/dist/index29.js.map +1 -0
  58. package/dist/index3.js +87 -0
  59. package/dist/index3.js.map +1 -0
  60. package/dist/index30.js +11 -0
  61. package/dist/index30.js.map +1 -0
  62. package/dist/index31.js +174 -0
  63. package/dist/index31.js.map +1 -0
  64. package/dist/index32.js +501 -0
  65. package/dist/index32.js.map +1 -0
  66. package/dist/index33.js +12 -0
  67. package/dist/index33.js.map +1 -0
  68. package/dist/index34.js +4403 -0
  69. package/dist/index34.js.map +1 -0
  70. package/dist/index35.js +91 -0
  71. package/dist/index35.js.map +1 -0
  72. package/dist/index36.js +61 -0
  73. package/dist/index36.js.map +1 -0
  74. package/dist/index37.js +20 -0
  75. package/dist/index37.js.map +1 -0
  76. package/dist/index38.js +20 -0
  77. package/dist/index38.js.map +1 -0
  78. package/dist/index4.js +54 -0
  79. package/dist/index4.js.map +1 -0
  80. package/dist/index5.js +15 -0
  81. package/dist/index5.js.map +1 -0
  82. package/dist/index6.js +17 -0
  83. package/dist/index6.js.map +1 -0
  84. package/dist/index7.js +31 -0
  85. package/dist/index7.js.map +1 -0
  86. package/dist/index8.js +90 -0
  87. package/dist/index8.js.map +1 -0
  88. package/dist/index9.js +76 -0
  89. package/dist/index9.js.map +1 -0
  90. package/dist/module.d.ts +14 -0
  91. package/dist/presets/index.d.ts +22 -0
  92. package/{lib/Presets/AnimationSpritesheet.d.ts → dist/presets/rmspritesheet.d.ts} +6 -2
  93. package/dist/services/AbstractSocket.d.ts +15 -0
  94. package/dist/services/loadMap.d.ts +14 -0
  95. package/dist/services/mmorpg.d.ts +32 -0
  96. package/dist/services/standalone.d.ts +34 -0
  97. package/package.json +25 -42
  98. package/src/Game/EffectManager.ts +20 -0
  99. package/src/Game/Event.ts +5 -0
  100. package/src/Game/Map.ts +10 -0
  101. package/src/Game/Object.ts +16 -0
  102. package/src/Game/Player.ts +5 -0
  103. package/src/Gui/Gui.ts +80 -534
  104. package/src/RpgClient.ts +9 -5
  105. package/src/RpgClientEngine.ts +135 -815
  106. package/src/components/character.ce +104 -0
  107. package/src/components/effects/animation.ce +19 -0
  108. package/src/components/effects/hit.ce +87 -0
  109. package/src/components/effects/index.ts +7 -0
  110. package/src/components/gui/dialogbox/index.ce +194 -0
  111. package/src/components/gui/dialogbox/itemMenu.ce +23 -0
  112. package/src/components/gui/dialogbox/selection.ce +67 -0
  113. package/src/components/gui/index.ts +5 -0
  114. package/src/components/index.ts +3 -0
  115. package/src/components/scenes/canvas.ce +51 -0
  116. package/src/components/scenes/draw-map.ce +56 -0
  117. package/src/components/scenes/element-map.ce +23 -0
  118. package/src/components/scenes/event-layer.ce +20 -0
  119. package/src/core/inject.ts +17 -0
  120. package/src/core/setup.ts +18 -0
  121. package/src/index.ts +13 -29
  122. package/src/module.ts +93 -0
  123. package/src/presets/index.ts +5 -0
  124. package/src/{Presets/AnimationSpritesheet.ts → presets/rmspritesheet.ts} +4 -5
  125. package/src/services/AbstractSocket.ts +14 -0
  126. package/src/services/loadMap.ts +33 -0
  127. package/src/services/mmorpg.ts +64 -0
  128. package/src/services/standalone.ts +101 -0
  129. package/src/types/canvas-engine.d.ts +26 -0
  130. package/tsconfig.json +8 -3
  131. package/vite.config.ts +34 -0
  132. package/CHANGELOG.md +0 -177
  133. package/LICENSE +0 -19
  134. package/browser/React-f6f9b1de.js +0 -157
  135. package/browser/index-e74a289f.js +0 -44225
  136. package/browser/manifest.json +0 -21
  137. package/browser/rpg.client.js +0 -40
  138. package/browser/rpg.client.umd.cjs +0 -44414
  139. package/lib/Components/AbstractComponent.d.ts +0 -32
  140. package/lib/Components/AbstractComponent.js +0 -93
  141. package/lib/Components/AbstractComponent.js.map +0 -1
  142. package/lib/Components/BarComponent.d.ts +0 -21
  143. package/lib/Components/BarComponent.js +0 -169
  144. package/lib/Components/BarComponent.js.map +0 -1
  145. package/lib/Components/Component.d.ts +0 -124
  146. package/lib/Components/Component.js +0 -425
  147. package/lib/Components/Component.js.map +0 -1
  148. package/lib/Components/DebugComponent.d.ts +0 -11
  149. package/lib/Components/DebugComponent.js +0 -32
  150. package/lib/Components/DebugComponent.js.map +0 -1
  151. package/lib/Components/ImageComponent.d.ts +0 -11
  152. package/lib/Components/ImageComponent.js +0 -30
  153. package/lib/Components/ImageComponent.js.map +0 -1
  154. package/lib/Components/ShapeComponent.d.ts +0 -11
  155. package/lib/Components/ShapeComponent.js +0 -57
  156. package/lib/Components/ShapeComponent.js.map +0 -1
  157. package/lib/Components/TextComponent.d.ts +0 -11
  158. package/lib/Components/TextComponent.js +0 -35
  159. package/lib/Components/TextComponent.js.map +0 -1
  160. package/lib/Components/TileComponent.d.ts +0 -10
  161. package/lib/Components/TileComponent.js +0 -40
  162. package/lib/Components/TileComponent.js.map +0 -1
  163. package/lib/Effects/Animation.d.ts +0 -55
  164. package/lib/Effects/Animation.js +0 -233
  165. package/lib/Effects/Animation.js.map +0 -1
  166. package/lib/Effects/AnimationCharacter.d.ts +0 -7
  167. package/lib/Effects/AnimationCharacter.js +0 -9
  168. package/lib/Effects/AnimationCharacter.js.map +0 -1
  169. package/lib/Effects/Spinner.d.ts +0 -7
  170. package/lib/Effects/Spinner.js +0 -18
  171. package/lib/Effects/Spinner.js.map +0 -1
  172. package/lib/Effects/Timeline.d.ts +0 -151
  173. package/lib/Effects/Timeline.js +0 -369
  174. package/lib/Effects/Timeline.js.map +0 -1
  175. package/lib/Effects/TransitionScene.d.ts +0 -18
  176. package/lib/Effects/TransitionScene.js +0 -50
  177. package/lib/Effects/TransitionScene.js.map +0 -1
  178. package/lib/GameEngine.d.ts +0 -68
  179. package/lib/GameEngine.js +0 -254
  180. package/lib/GameEngine.js.map +0 -1
  181. package/lib/Gui/Gui.d.ts +0 -110
  182. package/lib/Gui/Gui.js +0 -490
  183. package/lib/Gui/Gui.js.map +0 -1
  184. package/lib/Gui/React.d.ts +0 -15
  185. package/lib/Gui/React.js +0 -113
  186. package/lib/Gui/React.js.map +0 -1
  187. package/lib/Gui/Vue.d.ts +0 -13
  188. package/lib/Gui/Vue.js +0 -114
  189. package/lib/Gui/Vue.js.map +0 -1
  190. package/lib/Interfaces/Character.d.ts +0 -6
  191. package/lib/Interfaces/Character.js +0 -2
  192. package/lib/Interfaces/Character.js.map +0 -1
  193. package/lib/Interfaces/Scene.d.ts +0 -10
  194. package/lib/Interfaces/Scene.js +0 -2
  195. package/lib/Interfaces/Scene.js.map +0 -1
  196. package/lib/KeyboardControls.d.ts +0 -367
  197. package/lib/KeyboardControls.js +0 -714
  198. package/lib/KeyboardControls.js.map +0 -1
  199. package/lib/Logger.d.ts +0 -1
  200. package/lib/Logger.js +0 -4
  201. package/lib/Logger.js.map +0 -1
  202. package/lib/Presets/AnimationSpritesheet.js +0 -39
  203. package/lib/Presets/AnimationSpritesheet.js.map +0 -1
  204. package/lib/Presets/Scene.d.ts +0 -3
  205. package/lib/Presets/Scene.js +0 -5
  206. package/lib/Presets/Scene.js.map +0 -1
  207. package/lib/Renderer.d.ts +0 -62
  208. package/lib/Renderer.js +0 -300
  209. package/lib/Renderer.js.map +0 -1
  210. package/lib/Resources.d.ts +0 -22
  211. package/lib/Resources.js +0 -38
  212. package/lib/Resources.js.map +0 -1
  213. package/lib/RpgClient.js +0 -2
  214. package/lib/RpgClient.js.map +0 -1
  215. package/lib/RpgClientEngine.d.ts +0 -257
  216. package/lib/RpgClientEngine.js +0 -674
  217. package/lib/RpgClientEngine.js.map +0 -1
  218. package/lib/Scene/EventLayer.d.ts +0 -4
  219. package/lib/Scene/EventLayer.js +0 -8
  220. package/lib/Scene/EventLayer.js.map +0 -1
  221. package/lib/Scene/Map.d.ts +0 -109
  222. package/lib/Scene/Map.js +0 -319
  223. package/lib/Scene/Map.js.map +0 -1
  224. package/lib/Scene/Scene.d.ts +0 -184
  225. package/lib/Scene/Scene.js +0 -250
  226. package/lib/Scene/Scene.js.map +0 -1
  227. package/lib/Scene/SceneData.d.ts +0 -4
  228. package/lib/Scene/SceneData.js +0 -8
  229. package/lib/Scene/SceneData.js.map +0 -1
  230. package/lib/Sound/RpgSound.d.ts +0 -11
  231. package/lib/Sound/RpgSound.js +0 -46
  232. package/lib/Sound/RpgSound.js.map +0 -1
  233. package/lib/Sound/Sound.d.ts +0 -78
  234. package/lib/Sound/Sound.js +0 -12
  235. package/lib/Sound/Sound.js.map +0 -1
  236. package/lib/Sound/Sounds.d.ts +0 -2
  237. package/lib/Sound/Sounds.js +0 -6
  238. package/lib/Sound/Sounds.js.map +0 -1
  239. package/lib/Sprite/Character.d.ts +0 -18
  240. package/lib/Sprite/Character.js +0 -131
  241. package/lib/Sprite/Character.js.map +0 -1
  242. package/lib/Sprite/Player.d.ts +0 -3
  243. package/lib/Sprite/Player.js +0 -4
  244. package/lib/Sprite/Player.js.map +0 -1
  245. package/lib/Sprite/Spritesheet.d.ts +0 -365
  246. package/lib/Sprite/Spritesheet.js +0 -13
  247. package/lib/Sprite/Spritesheet.js.map +0 -1
  248. package/lib/Sprite/Spritesheets.d.ts +0 -3
  249. package/lib/Sprite/Spritesheets.js +0 -6
  250. package/lib/Sprite/Spritesheets.js.map +0 -1
  251. package/lib/Tilemap/CommonLayer.d.ts +0 -10
  252. package/lib/Tilemap/CommonLayer.js +0 -17
  253. package/lib/Tilemap/CommonLayer.js.map +0 -1
  254. package/lib/Tilemap/ImageLayer.d.ts +0 -4
  255. package/lib/Tilemap/ImageLayer.js +0 -16
  256. package/lib/Tilemap/ImageLayer.js.map +0 -1
  257. package/lib/Tilemap/Tile.d.ts +0 -21
  258. package/lib/Tilemap/Tile.js +0 -67
  259. package/lib/Tilemap/Tile.js.map +0 -1
  260. package/lib/Tilemap/TileLayer.d.ts +0 -13
  261. package/lib/Tilemap/TileLayer.js +0 -122
  262. package/lib/Tilemap/TileLayer.js.map +0 -1
  263. package/lib/Tilemap/TileSet.d.ts +0 -7
  264. package/lib/Tilemap/TileSet.js +0 -24
  265. package/lib/Tilemap/TileSet.js.map +0 -1
  266. package/lib/Tilemap/index.d.ts +0 -28
  267. package/lib/Tilemap/index.js +0 -151
  268. package/lib/Tilemap/index.js.map +0 -1
  269. package/lib/clientEntryPoint.d.ts +0 -89
  270. package/lib/clientEntryPoint.js +0 -48
  271. package/lib/clientEntryPoint.js.map +0 -1
  272. package/lib/index.d.ts +0 -26
  273. package/lib/index.js +0 -27
  274. package/lib/index.js.map +0 -1
  275. package/lib/inject.d.ts +0 -23
  276. package/lib/inject.js +0 -30
  277. package/lib/inject.js.map +0 -1
  278. package/rpg.toml +0 -14
  279. package/src/Components/AbstractComponent.ts +0 -120
  280. package/src/Components/BarComponent.ts +0 -181
  281. package/src/Components/Component.ts +0 -515
  282. package/src/Components/DebugComponent.ts +0 -36
  283. package/src/Components/ImageComponent.ts +0 -30
  284. package/src/Components/ShapeComponent.ts +0 -64
  285. package/src/Components/TextComponent.ts +0 -33
  286. package/src/Components/TileComponent.ts +0 -43
  287. package/src/Effects/Animation.ts +0 -310
  288. package/src/Effects/AnimationCharacter.ts +0 -7
  289. package/src/Effects/Spinner.ts +0 -19
  290. package/src/Effects/Timeline.ts +0 -378
  291. package/src/Effects/TransitionScene.ts +0 -59
  292. package/src/GameEngine.ts +0 -289
  293. package/src/Gui/React.ts +0 -145
  294. package/src/Gui/Vue.ts +0 -154
  295. package/src/Interfaces/Character.ts +0 -7
  296. package/src/Interfaces/Scene.ts +0 -9
  297. package/src/KeyboardControls.ts +0 -748
  298. package/src/Logger.ts +0 -3
  299. package/src/Presets/Scene.ts +0 -3
  300. package/src/Renderer.ts +0 -334
  301. package/src/Resources.ts +0 -39
  302. package/src/Scene/EventLayer.ts +0 -9
  303. package/src/Scene/Map.ts +0 -402
  304. package/src/Scene/Scene.ts +0 -305
  305. package/src/Scene/SceneData.ts +0 -13
  306. package/src/Sound/RpgSound.ts +0 -50
  307. package/src/Sound/Sound.ts +0 -91
  308. package/src/Sound/Sounds.ts +0 -7
  309. package/src/Sprite/Character.ts +0 -157
  310. package/src/Sprite/Player.ts +0 -3
  311. package/src/Sprite/Spritesheet.ts +0 -392
  312. package/src/Sprite/Spritesheets.ts +0 -8
  313. package/src/Tilemap/CommonLayer.ts +0 -20
  314. package/src/Tilemap/ImageLayer.ts +0 -20
  315. package/src/Tilemap/Tile.ts +0 -80
  316. package/src/Tilemap/TileLayer.ts +0 -142
  317. package/src/Tilemap/TileSet.ts +0 -40
  318. package/src/Tilemap/index.ts +0 -175
  319. package/src/clientEntryPoint.ts +0 -150
  320. package/src/inject.ts +0 -34
  321. package/src/types/howler.d.ts +0 -73
@@ -1,674 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { KeyboardControls } from './KeyboardControls.js';
8
- import { RpgRenderer } from './Renderer.js';
9
- import { _initSpritesheet, spritesheets } from './Sprite/Spritesheets.js';
10
- import { _initSound, sounds } from './Sound/Sounds.js';
11
- import { World } from 'simple-room-client';
12
- import { BehaviorSubject, Subject, lastValueFrom } from 'rxjs';
13
- import { ajax } from 'rxjs/ajax';
14
- import { RpgGui } from './Gui/Gui.js';
15
- import { PrebuiltGui, Utils, RpgPlugin, HookClient, RpgCommonMap, Scheduler, } from '@rpgjs/common';
16
- import { RpgSound } from './Sound/RpgSound.js';
17
- import { GameEngineClient } from './GameEngine.js';
18
- import { Spritesheet } from './Sprite/Spritesheet.js';
19
- import { log } from './Logger.js';
20
- import { Sound } from './Sound/Sound.js';
21
- import { PlayerType, SocketEvents, SocketMethods } from '@rpgjs/types';
22
- import { Assets, utils } from 'pixi.js';
23
- import * as PIXI from 'pixi.js';
24
- const { extractId, isString } = Utils;
25
- export class RpgClientEngine {
26
- constructor(context, options) {
27
- this.context = context;
28
- this.options = options;
29
- /**
30
- * retrieve the global configurations assigned at the entry point
31
- *
32
- * @prop {object} [globalConfig]
33
- * @readonly
34
- * @memberof RpgClientEngine
35
- * */
36
- this.globalConfig = {};
37
- this._tick = new BehaviorSubject({
38
- timestamp: -1,
39
- deltaTime: 0,
40
- frame: 0,
41
- deltaRatio: 1
42
- });
43
- this.keyChange = new Subject();
44
- this.roomJoin = new Subject();
45
- this.hasBeenDisconnected = false;
46
- this.serverChanging = false;
47
- this.isTeleported = false;
48
- this.lastTimestamp = 0;
49
- this.clientFrames = new Map();
50
- this.serverFrames = new Map();
51
- this.session = null;
52
- this.lastConnection = '';
53
- this.lastScene = '';
54
- this.matchMakerService = null;
55
- this.serverFps = 60;
56
- this.scheduler = new Scheduler();
57
- this._serverUrl = '';
58
- /**
59
- * * @deprecated Use `inject(GameEngineClient)` instead. Will be removed in v5
60
- */
61
- this.gameEngine = this.context.inject(GameEngineClient);
62
- /**
63
- * Read objects synchronized with the server
64
- *
65
- * @prop {Observable< {
66
- [id: string]: {
67
- object: any,
68
- paramsChanged: any
69
- }
70
- } >} [objects]
71
- * @readonly
72
- * @memberof RpgClientEngine
73
- */
74
- this.objects = this.gameEngine.objects;
75
- this.envs = {};
76
- this.envs = options.envs || {};
77
- this.tick.subscribe(({ timestamp, deltaTime }) => {
78
- if (timestamp != -1)
79
- this.step(timestamp, deltaTime);
80
- });
81
- }
82
- async _init() {
83
- this.renderer = this.context.inject(RpgRenderer);
84
- const pluginLoadResource = async (hookName, type) => {
85
- const resource = this.options[type] || [];
86
- this.options[type] = [
87
- ...Utils.arrayFlat(await RpgPlugin.emit(hookName, resource)) || [],
88
- ...resource
89
- ];
90
- };
91
- await pluginLoadResource(HookClient.AddSpriteSheet, 'spritesheets');
92
- await pluginLoadResource(HookClient.AddGui, 'gui');
93
- await pluginLoadResource(HookClient.AddSound, 'sounds');
94
- this.renderer.options = {
95
- selector: '#rpg',
96
- selectorCanvas: '#canvas',
97
- selectorGui: '#gui',
98
- canvas: {},
99
- gui: [],
100
- spritesheets: [],
101
- sounds: [],
102
- ...this.options
103
- };
104
- this.io = this.options.io;
105
- if (this.options.serverFps)
106
- this.serverFps = this.options.serverFps;
107
- this.globalConfig = this.options.globalConfig;
108
- this.gameEngine.standalone = this.options.standalone;
109
- this.gameEngine.renderer = this.renderer;
110
- this.gameEngine.clientEngine = this;
111
- this.addSpriteSheet(this.renderer.options.spritesheets);
112
- (this.renderer.options.sounds || []).forEach(sound => {
113
- const id = isString(sound) ? extractId(sound) : undefined;
114
- this.addSound(sound, id);
115
- });
116
- // deprecated
117
- if (typeof __RPGJS_PRODUCTION__ != 'undefined' && __RPGJS_PRODUCTION__) {
118
- if ('serviceWorker' in navigator) {
119
- window.addEventListener('load', () => {
120
- navigator.serviceWorker.register('/service-worker.js');
121
- });
122
- }
123
- }
124
- this.controls = this.context.inject(KeyboardControls);
125
- }
126
- addResource(resourceClass, cb) {
127
- let array = resourceClass;
128
- if (!Utils.isArray(resourceClass)) {
129
- array = [resourceClass];
130
- }
131
- cb(array, this);
132
- }
133
- /**
134
- * Listen to each frame
135
- *
136
- * @prop {Observable<{ timestamp: number, deltaTime: number, frame: number }>} tick
137
- * @readonly
138
- * @since 3.0.0-beta.5
139
- * @memberof RpgClientEngine
140
- * @example
141
- *
142
- * ```ts
143
- * client.tick.subscribe(({ timestamp, deltaTime, frame }) => {
144
- *
145
- * })
146
- * ```
147
- * */
148
- get tick() {
149
- return this.scheduler.tick;
150
- }
151
- addSpriteSheet(spritesheetClass, id) {
152
- if (typeof spritesheetClass === 'string') {
153
- if (!id) {
154
- throw log('Please, specify the resource ID (second parameter)');
155
- }
156
- let AutoSpritesheet = class AutoSpritesheet {
157
- };
158
- AutoSpritesheet = __decorate([
159
- Spritesheet({
160
- id,
161
- image: this.getResourceUrl(spritesheetClass)
162
- })
163
- ], AutoSpritesheet);
164
- spritesheetClass = AutoSpritesheet;
165
- }
166
- this.addResource(spritesheetClass, _initSpritesheet);
167
- return spritesheetClass;
168
- }
169
- addSound(soundClass, id) {
170
- if (typeof soundClass === 'string') {
171
- if (!id) {
172
- throw log('Please, specify the resource ID (second parameter)');
173
- }
174
- let AutoSound = class AutoSound {
175
- };
176
- AutoSound = __decorate([
177
- Sound({
178
- id,
179
- sound: this.getResourceUrl(soundClass)
180
- })
181
- ], AutoSound);
182
- soundClass = AutoSound;
183
- }
184
- this.addResource(soundClass, _initSound);
185
- return soundClass;
186
- }
187
- getResourceUrl(source) {
188
- // @ts-ignore
189
- if (window.urlCache && window.urlCache[source]) {
190
- // @ts-ignore
191
- return window.urlCache[source];
192
- }
193
- if (source.startsWith('data:')) {
194
- return source;
195
- }
196
- // @ts-ignore
197
- const staticDir = this.envs.VITE_BUILT;
198
- if (staticDir) {
199
- return this.assetsPath + '/' + Utils.basename(source);
200
- }
201
- return source;
202
- }
203
- /**
204
- * Starts the client side and connects to the server
205
- *
206
- * @title Start Client Engine
207
- * @method start()
208
- * @returns {Promise< void >}
209
- * @memberof RpgClientEngine
210
- */
211
- async start(options = {
212
- renderLoop: true
213
- }) {
214
- await this._init();
215
- await this.renderer.init();
216
- const { maxFps } = this.options;
217
- if (options.renderLoop) {
218
- this.scheduler.start({
219
- maxFps
220
- });
221
- // 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
222
- setInterval(() => {
223
- this.processInput();
224
- }, Utils.fps2ms(this.serverFps));
225
- }
226
- const ret = await RpgPlugin.emit(HookClient.Start, this);
227
- this.matchMakerService = this.options.globalConfig.matchMakerService;
228
- const hasFalseValue = ret.findIndex(el => el === false) != -1;
229
- if (!hasFalseValue) {
230
- let serverUri = {};
231
- if (this.matchMakerService) {
232
- if (Utils.isFunction(this.matchMakerService)) {
233
- serverUri = this.matchMakerService();
234
- }
235
- else {
236
- serverUri = await lastValueFrom(ajax.getJSON(this.matchMakerService));
237
- }
238
- }
239
- // @ts-ignore
240
- const envUrl = this.envs.VITE_SERVER_URL;
241
- await this.connection(serverUri.url ? serverUri.url + ':' + serverUri.port :
242
- envUrl ? envUrl : undefined);
243
- }
244
- }
245
- /**
246
- * Display the next frame. Useful for unit tests
247
- *
248
- * @title Next Frame
249
- * @since 3.0.0-beta.5
250
- * @param {number} timestamp Indicate the timestamp of the frame
251
- * @method nextFrame()
252
- * @memberof RpgClientEngine
253
- */
254
- nextFrame(timestamp) {
255
- this.scheduler.nextTick(timestamp);
256
- }
257
- async sendInput(actionName) {
258
- const player = this.player;
259
- if (!player)
260
- return;
261
- if (player.canMove) {
262
- player.pendingMove.push({
263
- input: actionName,
264
- frame: this.scheduler.frame
265
- });
266
- }
267
- }
268
- get player() {
269
- return this.gameEngine.world.getObject(this.gameEngine.playerId);
270
- }
271
- serverReconciliation(player) {
272
- let garbage = [];
273
- this.serverFrames.forEach((serverData, frame) => {
274
- const { data: serverPos, time: serverTime } = serverData;
275
- const client = this.clientFrames.get(frame);
276
- if (!client || (client && client.data.x != serverPos.x || client.data.y != serverPos.y)) {
277
- if (serverPos.x)
278
- player.position.x = serverPos.x;
279
- if (serverPos.y)
280
- player.position.y = serverPos.y;
281
- }
282
- player.position.z = serverPos.z;
283
- garbage.push(frame);
284
- });
285
- garbage.forEach(frame => {
286
- this.serverFrames.delete(frame);
287
- this.clientFrames.delete(frame);
288
- });
289
- garbage = [];
290
- }
291
- async step(t, dt) {
292
- RpgPlugin.emit(HookClient.Step, [this, t, dt], true);
293
- }
294
- async processInput() {
295
- const player = this.player;
296
- this.controls.preStep();
297
- if (player) {
298
- if (player.pendingMove.length > 0) {
299
- const { inputs: inputEvent } = await this.gameEngine.processInput(this.gameEngine.playerId, this.controls.options);
300
- if (inputEvent.length == 0)
301
- return;
302
- const frame = Date.now();
303
- this.clientFrames.set(frame, {
304
- data: player.position.copy(),
305
- time: frame
306
- });
307
- if (this.socket) {
308
- this.socket.emit('move', { input: inputEvent, frame });
309
- }
310
- RpgPlugin.emit(HookClient.SendInput, [this, inputEvent], true);
311
- }
312
- if (player.canMove)
313
- this.serverReconciliation(player);
314
- }
315
- }
316
- /**
317
- *Connect to the server
318
- *
319
- * @title Connect to server
320
- * @method connection()
321
- * @returns {void}
322
- * @memberof RpgClientEngine
323
- */
324
- async connection(uri) {
325
- const { standalone } = this.gameEngine;
326
- this._serverUrl = uri || '';
327
- if (!standalone) {
328
- this.socket = this.io(uri, {
329
- auth: {
330
- token: this.session
331
- }
332
- });
333
- }
334
- else {
335
- this.socket = this.io;
336
- }
337
- this.socket.on('connect', () => {
338
- if (RpgGui.exists(PrebuiltGui.Disconnect))
339
- RpgGui.hide(PrebuiltGui.Disconnect);
340
- RpgPlugin.emit(HookClient.Connected, [this, this.socket], true);
341
- this.hasBeenDisconnected = false;
342
- });
343
- this.socket.on('playerJoined', (playerEvent) => {
344
- this.gameEngine.playerId = playerEvent.playerId;
345
- this.session = playerEvent.session;
346
- });
347
- this.socket.on('connect_error', (err) => {
348
- RpgPlugin.emit(HookClient.ConnectedError, [this, err, this.socket], true);
349
- });
350
- this.socket.on('preLoadScene', ({ id, reconnect }) => {
351
- if (this.lastScene == id) {
352
- return;
353
- }
354
- this.lastScene = id;
355
- this.renderer.transitionScene(id);
356
- if (reconnect) {
357
- this.roomJoin.next('');
358
- this.roomJoin.complete();
359
- }
360
- });
361
- this.socket.on(SocketEvents.GameReload, () => {
362
- window.location.reload();
363
- });
364
- this.socket.on(SocketEvents.LoadScene, ({ name, data }) => {
365
- this.renderer.loadScene(name, data);
366
- });
367
- this.socket.on(SocketEvents.ChangeServer, async ({ url, port }) => {
368
- const connection = url + ':' + port;
369
- if (this.lastConnection == connection) {
370
- return;
371
- }
372
- if (this.subscriptionWorld) {
373
- this.subscriptionWorld.unsubscribe();
374
- }
375
- this.lastConnection = connection;
376
- this.serverChanging = true;
377
- this.socket.disconnect();
378
- this.connection(connection);
379
- });
380
- this.socket.on('changeTile', ({ tiles, x, y }) => {
381
- const scene = this.renderer.getScene();
382
- scene?.changeTile(x, y, tiles);
383
- });
384
- const callMethod = ({ objectId, params, name }) => {
385
- const scene = this.renderer.getScene();
386
- const sprite = scene?.getPlayer(objectId);
387
- if (!sprite)
388
- return;
389
- switch (name) {
390
- case SocketMethods.ShowAnimation:
391
- scene?.showAnimation({
392
- attachTo: sprite,
393
- graphic: params[0],
394
- animationName: params[1],
395
- replaceGraphic: params[2]
396
- });
397
- break;
398
- case SocketMethods.CameraFollow:
399
- const [spriteId, options] = params;
400
- scene?.cameraFollowSprite(spriteId, options);
401
- break;
402
- case SocketMethods.PlaySound:
403
- RpgSound.play(params[0]);
404
- break;
405
- case SocketMethods.ModeMove:
406
- const player = this.player;
407
- const { checkCollision } = params[0];
408
- if (player) {
409
- player.checkCollision = checkCollision;
410
- }
411
- break;
412
- }
413
- };
414
- this.socket.on(SocketEvents.CallMethod, callMethod);
415
- let lastRoomId = '';
416
- this.subscriptionWorld = World.listen(this.socket)
417
- .value
418
- .subscribe(async (val) => {
419
- const scene = this.renderer.getScene();
420
- if (!val.data) {
421
- return;
422
- }
423
- const partialRoom = val.partial;
424
- if (val.roomId != lastRoomId) {
425
- this.clientFrames.clear();
426
- this.serverFrames.clear();
427
- this.gameEngine.resetObjects();
428
- lastRoomId = val.roomId;
429
- this.isTeleported = false;
430
- }
431
- const objectsChanged = {};
432
- const callAction = (objectId, paramsChanged) => {
433
- if (paramsChanged && SocketEvents.CallMethod in paramsChanged) {
434
- // Force rendering on the map (display events) and then perform actions on it (animation, etc.).
435
- this.renderer.draw(Date.now(), 1, 1, 1);
436
- callMethod({
437
- objectId,
438
- ...paramsChanged[SocketEvents.CallMethod]
439
- });
440
- }
441
- };
442
- const change = (prop, root = val, localEvent = false) => {
443
- const list = root.data[prop];
444
- const partial = root.partial[prop];
445
- const isShape = prop == 'shapes';
446
- if (!partial) {
447
- return;
448
- }
449
- if (val.resetProps.indexOf(prop) != -1) {
450
- const objects = isShape ? this.gameEngine.getShapes() : this.gameEngine.getObjects();
451
- for (let key in objects) {
452
- const obj = objects[key];
453
- if (obj) {
454
- this.gameEngine.removeObjectAndShape(key);
455
- }
456
- }
457
- }
458
- for (let key in partial) {
459
- const obj = list[key];
460
- const paramsChanged = partial ? partial[key] : undefined;
461
- if (obj == null || obj.deleted) {
462
- // perform actions on the sprite before deleting it
463
- callAction(key, paramsChanged);
464
- this.gameEngine.removeObjectAndShape(key);
465
- continue;
466
- }
467
- if (!obj)
468
- continue;
469
- if (!isShape) {
470
- obj.type = {
471
- users: PlayerType.Player,
472
- events: PlayerType.Event
473
- }[prop];
474
- }
475
- if (prop == 'users' && this.gameEngine.playerId == key) {
476
- if (obj.events) {
477
- const nbEvents = Object.values(obj.events);
478
- if (nbEvents.length == 0) {
479
- this.gameEngine.events = {};
480
- }
481
- else {
482
- change('events', {
483
- data: obj,
484
- partial: paramsChanged,
485
- time: val.time,
486
- roomId: val.roomId,
487
- resetProps: val.resetProps
488
- }, true);
489
- }
490
- }
491
- if (partialRoom?.pos && partialRoom?.frame !== undefined) {
492
- this.serverFrames.set(partialRoom.frame, {
493
- data: partialRoom.pos,
494
- time: Date.now()
495
- });
496
- }
497
- }
498
- objectsChanged[key] = this.gameEngine.updateObject({
499
- playerId: key,
500
- params: obj,
501
- localEvent,
502
- paramsChanged,
503
- isShape
504
- });
505
- // perform actions on the sprite after creation/update
506
- callAction(key, paramsChanged);
507
- }
508
- };
509
- if (partialRoom.join) {
510
- this.roomJoin.next(partialRoom);
511
- this.roomJoin.complete();
512
- }
513
- change('users');
514
- change('events');
515
- change('shapes');
516
- this.gameEngine.setObjectsChanged(objectsChanged);
517
- if (scene) {
518
- scene.update(val);
519
- }
520
- });
521
- this.socket.on('disconnect', (reason) => {
522
- if (this.serverChanging) {
523
- return;
524
- }
525
- if (RpgGui.exists(PrebuiltGui.Disconnect))
526
- RpgGui.display(PrebuiltGui.Disconnect);
527
- RpgPlugin.emit(HookClient.Disconnect, [this, reason, this.socket], true);
528
- this.hasBeenDisconnected = true;
529
- });
530
- RpgGui._setSocket(this.socket);
531
- if (standalone) {
532
- await this.socket.connection({
533
- auth: {
534
- token: this.session
535
- }
536
- });
537
- }
538
- this.serverChanging = false;
539
- }
540
- get world() {
541
- return World;
542
- }
543
- // shortcuts
544
- /**
545
- * VueJS Application instance
546
- *
547
- * [https://v3.vuejs.org/api/application-api.html](https://v3.vuejs.org/api/application-api.html)
548
- *
549
- * @prop {Vue} [vueApp]
550
- * @readonly
551
- * @memberof RpgClientEngine
552
- * */
553
- get vueApp() {
554
- return this.renderer.app;
555
- }
556
- /**
557
- * VueJS Parent component instance
558
- *
559
- * [https://v3.vuejs.org/api/instance-properties.html](https://v3.vuejs.org/api/instance-properties.html)
560
- *
561
- * @prop {Vue Instance} [vueInstance]
562
- * @readonly
563
- * @memberof RpgClientEngine
564
- * */
565
- get vueInstance() {
566
- return this.renderer.vm;
567
- }
568
- /**
569
- * retrieves the current scene (SceneMap if you are on a map)
570
- *
571
- * @prop {RpgScene} [scene]
572
- * @deprecated
573
- * @readonly
574
- * @memberof RpgClientEngine
575
- * */
576
- get scene() {
577
- return this.renderer.getScene();
578
- }
579
- /**
580
- * retrieves the current scene (SceneMap if you are on a map)
581
- *
582
- * @title Connect to server
583
- * @method getScene()
584
- * @returns {RpgScene}
585
- * @memberof RpgClientEngine
586
- */
587
- getScene() {
588
- return this.renderer.getScene();
589
- }
590
- /**
591
- * get PIXI class
592
- * @prop {PIXI} [PIXI]
593
- * @readonly
594
- * @memberof RpgClientEngine
595
- */
596
- get PIXI() {
597
- return PIXI;
598
- }
599
- /**
600
- * get player id of the current player
601
- * @prop {string} [playerId]
602
- * @readonly
603
- * @memberof RpgClientEngine
604
- */
605
- get playerId() {
606
- return this.gameEngine.playerId;
607
- }
608
- /**
609
- * Finds the game mode from the environment variables sent by the compiler.
610
- * Can be used in menus to display options according to type
611
- *
612
- * @title Game Type
613
- * @prop {string|undefined} [gameType] mmorpg | rpg or undefined if environment variable not found
614
- * @readonly
615
- * @memberof RpgClientEngine
616
- * @since 4.0.0
617
- */
618
- get gameType() {
619
- return this.envs?.['VITE_RPG_TYPE'];
620
- }
621
- /**
622
- * Find out if the game is in production or not, from the environment variables sent by the compiler.
623
- *
624
- * @title Game is dev mode
625
- * @prop {boolean} [isDev]
626
- * @readonly
627
- * @memberof RpgClientEngine
628
- * @since 4.0.0
629
- */
630
- get isDev() {
631
- return !this.envs?.['VITE_BUILT'];
632
- }
633
- /**
634
- * Get the server url. This is the url for the websocket
635
- *
636
- * To customize the URL, use the `matchMakerService` configuration
637
- *
638
- * @title Server URL
639
- * @prop {string} [serverUrl] If empty string, server url is same as client url
640
- * @readonly
641
- * @memberof RpgClientEngine
642
- * @since 4.0.0
643
- */
644
- get serverUrl() {
645
- if (!this._serverUrl.startsWith('http')) {
646
- return 'http://' + this._serverUrl;
647
- }
648
- return this._serverUrl;
649
- }
650
- get assetsPath() {
651
- return this.envs?.['VITE_ASSETS_PATH'] || 'assets';
652
- }
653
- get module() {
654
- return RpgPlugin;
655
- }
656
- reset() {
657
- this.subscriptionWorld.unsubscribe();
658
- this.world.reset();
659
- spritesheets.clear();
660
- sounds.clear();
661
- Assets.reset();
662
- utils.clearTextureCache();
663
- for (let textureUrl in utils.BaseTextureCache) {
664
- delete utils.BaseTextureCache[textureUrl];
665
- }
666
- for (let textureUrl in utils.TextureCache) {
667
- delete utils.TextureCache[textureUrl];
668
- }
669
- RpgGui.clear();
670
- RpgCommonMap.bufferClient.clear();
671
- RpgSound.clear();
672
- }
673
- }
674
- //# sourceMappingURL=RpgClientEngine.js.map