@rpgjs/client 4.3.0 → 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 -41
  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 -533
  104. package/src/RpgClient.ts +9 -5
  105. package/src/RpgClientEngine.ts +135 -818
  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 -189
  133. package/LICENSE +0 -19
  134. package/browser/React-ece4b906.js +0 -195
  135. package/browser/index-ba657126.js +0 -44229
  136. package/browser/manifest.json +0 -21
  137. package/browser/rpg.client.js +0 -40
  138. package/browser/rpg.client.umd.cjs +0 -44456
  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 -489
  183. package/lib/Gui/Gui.js.map +0 -1
  184. package/lib/Gui/React.d.ts +0 -28
  185. package/lib/Gui/React.js +0 -147
  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 -677
  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 -193
  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,677 +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< RpgClientEngine >}
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
- return this;
245
- }
246
- /**
247
- * Display the next frame. Useful for unit tests
248
- *
249
- * @title Next Frame
250
- * @since 3.0.0-beta.5
251
- * @param {number} timestamp Indicate the timestamp of the frame
252
- * @method nextFrame()
253
- * @memberof RpgClientEngine
254
- */
255
- nextFrame(timestamp) {
256
- this.scheduler.nextTick(timestamp);
257
- }
258
- async sendInput(actionName) {
259
- const player = this.player;
260
- if (!player)
261
- return;
262
- if (player.canMove) {
263
- player.pendingMove.push({
264
- input: actionName,
265
- frame: this.scheduler.frame
266
- });
267
- }
268
- }
269
- get player() {
270
- return this.gameEngine.world.getObject(this.gameEngine.playerId);
271
- }
272
- serverReconciliation(player) {
273
- let garbage = [];
274
- this.serverFrames.forEach((serverData, frame) => {
275
- const { data: serverPos, time: serverTime } = serverData;
276
- const client = this.clientFrames.get(frame);
277
- if (!client || (client && client.data.x != serverPos.x || client.data.y != serverPos.y)) {
278
- if (serverPos.x)
279
- player.position.x = serverPos.x;
280
- if (serverPos.y)
281
- player.position.y = serverPos.y;
282
- }
283
- player.position.z = serverPos.z;
284
- garbage.push(frame);
285
- });
286
- garbage.forEach(frame => {
287
- this.serverFrames.delete(frame);
288
- this.clientFrames.delete(frame);
289
- });
290
- garbage = [];
291
- }
292
- async step(t, dt) {
293
- RpgPlugin.emit(HookClient.Step, [this, t, dt], true);
294
- }
295
- async processInput() {
296
- const player = this.player;
297
- this.controls.preStep();
298
- if (player) {
299
- if (player.pendingMove.length > 0) {
300
- const { inputs: inputEvent } = await this.gameEngine.processInput(this.gameEngine.playerId, this.controls.options);
301
- if (inputEvent.length == 0)
302
- return;
303
- const frame = Date.now();
304
- this.clientFrames.set(frame, {
305
- data: player.position.copy(),
306
- time: frame
307
- });
308
- if (this.socket) {
309
- this.socket.emit('move', { input: inputEvent, frame });
310
- }
311
- RpgPlugin.emit(HookClient.SendInput, [this, inputEvent], true);
312
- }
313
- if (player.canMove)
314
- this.serverReconciliation(player);
315
- }
316
- }
317
- /**
318
- *Connect to the server
319
- *
320
- * @title Connect to server
321
- * @method connection()
322
- * @returns {void}
323
- * @memberof RpgClientEngine
324
- */
325
- async connection(uri) {
326
- const { standalone } = this.gameEngine;
327
- const { globalConfig } = this;
328
- this._serverUrl = uri || '';
329
- if (!standalone) {
330
- this.socket = this.io(uri, {
331
- auth: {
332
- token: this.session
333
- },
334
- ...(globalConfig.socketIoClient || {})
335
- });
336
- }
337
- else {
338
- this.socket = this.io;
339
- }
340
- this.socket.on('connect', () => {
341
- if (RpgGui.exists(PrebuiltGui.Disconnect))
342
- RpgGui.hide(PrebuiltGui.Disconnect);
343
- RpgPlugin.emit(HookClient.Connected, [this, this.socket], true);
344
- this.hasBeenDisconnected = false;
345
- });
346
- this.socket.on('playerJoined', (playerEvent) => {
347
- this.gameEngine.playerId = playerEvent.playerId;
348
- this.session = playerEvent.session;
349
- });
350
- this.socket.on('connect_error', (err) => {
351
- RpgPlugin.emit(HookClient.ConnectedError, [this, err, this.socket], true);
352
- });
353
- this.socket.on('preLoadScene', ({ id, reconnect }) => {
354
- if (this.lastScene == id) {
355
- return;
356
- }
357
- this.lastScene = id;
358
- this.renderer.transitionScene(id);
359
- if (reconnect) {
360
- this.roomJoin.next('');
361
- this.roomJoin.complete();
362
- }
363
- });
364
- this.socket.on(SocketEvents.GameReload, () => {
365
- window.location.reload();
366
- });
367
- this.socket.on(SocketEvents.LoadScene, ({ name, data }) => {
368
- this.renderer.loadScene(name, data);
369
- });
370
- this.socket.on(SocketEvents.ChangeServer, async ({ url, port }) => {
371
- const connection = url + ':' + port;
372
- if (this.lastConnection == connection) {
373
- return;
374
- }
375
- if (this.subscriptionWorld) {
376
- this.subscriptionWorld.unsubscribe();
377
- }
378
- this.lastConnection = connection;
379
- this.serverChanging = true;
380
- this.socket.disconnect();
381
- this.connection(connection);
382
- });
383
- this.socket.on('changeTile', ({ tiles, x, y }) => {
384
- const scene = this.renderer.getScene();
385
- scene?.changeTile(x, y, tiles);
386
- });
387
- const callMethod = ({ objectId, params, name }) => {
388
- const scene = this.renderer.getScene();
389
- const sprite = scene?.getPlayer(objectId);
390
- if (!sprite)
391
- return;
392
- switch (name) {
393
- case SocketMethods.ShowAnimation:
394
- scene?.showAnimation({
395
- attachTo: sprite,
396
- graphic: params[0],
397
- animationName: params[1],
398
- replaceGraphic: params[2]
399
- });
400
- break;
401
- case SocketMethods.CameraFollow:
402
- const [spriteId, options] = params;
403
- scene?.cameraFollowSprite(spriteId, options);
404
- break;
405
- case SocketMethods.PlaySound:
406
- RpgSound.play(params[0]);
407
- break;
408
- case SocketMethods.ModeMove:
409
- const player = this.player;
410
- const { checkCollision } = params[0];
411
- if (player) {
412
- player.checkCollision = checkCollision;
413
- }
414
- break;
415
- }
416
- };
417
- this.socket.on(SocketEvents.CallMethod, callMethod);
418
- let lastRoomId = '';
419
- this.subscriptionWorld = World.listen(this.socket)
420
- .value
421
- .subscribe(async (val) => {
422
- const scene = this.renderer.getScene();
423
- if (!val.data) {
424
- return;
425
- }
426
- const partialRoom = val.partial;
427
- if (val.roomId != lastRoomId) {
428
- this.clientFrames.clear();
429
- this.serverFrames.clear();
430
- this.gameEngine.resetObjects();
431
- lastRoomId = val.roomId;
432
- this.isTeleported = false;
433
- }
434
- const objectsChanged = {};
435
- const callAction = (objectId, paramsChanged) => {
436
- if (paramsChanged && SocketEvents.CallMethod in paramsChanged) {
437
- // Force rendering on the map (display events) and then perform actions on it (animation, etc.).
438
- this.renderer.draw(Date.now(), 1, 1, 1);
439
- callMethod({
440
- objectId,
441
- ...paramsChanged[SocketEvents.CallMethod]
442
- });
443
- }
444
- };
445
- const change = (prop, root = val, localEvent = false) => {
446
- const list = root.data[prop];
447
- const partial = root.partial[prop];
448
- const isShape = prop == 'shapes';
449
- if (!partial) {
450
- return;
451
- }
452
- if (val.resetProps.indexOf(prop) != -1) {
453
- const objects = isShape ? this.gameEngine.getShapes() : this.gameEngine.getObjects();
454
- for (let key in objects) {
455
- const obj = objects[key];
456
- if (obj) {
457
- this.gameEngine.removeObjectAndShape(key);
458
- }
459
- }
460
- }
461
- for (let key in partial) {
462
- const obj = list[key];
463
- const paramsChanged = partial ? partial[key] : undefined;
464
- if (obj == null || obj.deleted) {
465
- // perform actions on the sprite before deleting it
466
- callAction(key, paramsChanged);
467
- this.gameEngine.removeObjectAndShape(key);
468
- continue;
469
- }
470
- if (!obj)
471
- continue;
472
- if (!isShape) {
473
- obj.type = {
474
- users: PlayerType.Player,
475
- events: PlayerType.Event
476
- }[prop];
477
- }
478
- if (prop == 'users' && this.gameEngine.playerId == key) {
479
- if (obj.events) {
480
- const nbEvents = Object.values(obj.events);
481
- if (nbEvents.length == 0) {
482
- this.gameEngine.events = {};
483
- }
484
- else {
485
- change('events', {
486
- data: obj,
487
- partial: paramsChanged,
488
- time: val.time,
489
- roomId: val.roomId,
490
- resetProps: val.resetProps
491
- }, true);
492
- }
493
- }
494
- if (partialRoom?.pos && partialRoom?.frame !== undefined) {
495
- this.serverFrames.set(partialRoom.frame, {
496
- data: partialRoom.pos,
497
- time: Date.now()
498
- });
499
- }
500
- }
501
- objectsChanged[key] = this.gameEngine.updateObject({
502
- playerId: key,
503
- params: obj,
504
- localEvent,
505
- paramsChanged,
506
- isShape
507
- });
508
- // perform actions on the sprite after creation/update
509
- callAction(key, paramsChanged);
510
- }
511
- };
512
- if (partialRoom.join) {
513
- this.roomJoin.next(partialRoom);
514
- this.roomJoin.complete();
515
- }
516
- change('users');
517
- change('events');
518
- change('shapes');
519
- this.gameEngine.setObjectsChanged(objectsChanged);
520
- if (scene) {
521
- scene.update(val);
522
- }
523
- });
524
- this.socket.on('disconnect', (reason) => {
525
- if (this.serverChanging) {
526
- return;
527
- }
528
- if (RpgGui.exists(PrebuiltGui.Disconnect))
529
- RpgGui.display(PrebuiltGui.Disconnect);
530
- RpgPlugin.emit(HookClient.Disconnect, [this, reason, this.socket], true);
531
- this.hasBeenDisconnected = true;
532
- });
533
- RpgGui._setSocket(this.socket);
534
- if (standalone) {
535
- await this.socket.connection({
536
- auth: {
537
- token: this.session
538
- }
539
- });
540
- }
541
- this.serverChanging = false;
542
- }
543
- get world() {
544
- return World;
545
- }
546
- // shortcuts
547
- /**
548
- * VueJS Application instance
549
- *
550
- * [https://v3.vuejs.org/api/application-api.html](https://v3.vuejs.org/api/application-api.html)
551
- *
552
- * @prop {Vue} [vueApp]
553
- * @readonly
554
- * @memberof RpgClientEngine
555
- * */
556
- get vueApp() {
557
- return this.renderer.app;
558
- }
559
- /**
560
- * VueJS Parent component instance
561
- *
562
- * [https://v3.vuejs.org/api/instance-properties.html](https://v3.vuejs.org/api/instance-properties.html)
563
- *
564
- * @prop {Vue Instance} [vueInstance]
565
- * @readonly
566
- * @memberof RpgClientEngine
567
- * */
568
- get vueInstance() {
569
- return this.renderer.vm;
570
- }
571
- /**
572
- * retrieves the current scene (SceneMap if you are on a map)
573
- *
574
- * @prop {RpgScene} [scene]
575
- * @deprecated
576
- * @readonly
577
- * @memberof RpgClientEngine
578
- * */
579
- get scene() {
580
- return this.renderer.getScene();
581
- }
582
- /**
583
- * retrieves the current scene (SceneMap if you are on a map)
584
- *
585
- * @title Connect to server
586
- * @method getScene()
587
- * @returns {RpgScene}
588
- * @memberof RpgClientEngine
589
- */
590
- getScene() {
591
- return this.renderer.getScene();
592
- }
593
- /**
594
- * get PIXI class
595
- * @prop {PIXI} [PIXI]
596
- * @readonly
597
- * @memberof RpgClientEngine
598
- */
599
- get PIXI() {
600
- return PIXI;
601
- }
602
- /**
603
- * get player id of the current player
604
- * @prop {string} [playerId]
605
- * @readonly
606
- * @memberof RpgClientEngine
607
- */
608
- get playerId() {
609
- return this.gameEngine.playerId;
610
- }
611
- /**
612
- * Finds the game mode from the environment variables sent by the compiler.
613
- * Can be used in menus to display options according to type
614
- *
615
- * @title Game Type
616
- * @prop {string|undefined} [gameType] mmorpg | rpg or undefined if environment variable not found
617
- * @readonly
618
- * @memberof RpgClientEngine
619
- * @since 4.0.0
620
- */
621
- get gameType() {
622
- return this.envs?.['VITE_RPG_TYPE'];
623
- }
624
- /**
625
- * Find out if the game is in production or not, from the environment variables sent by the compiler.
626
- *
627
- * @title Game is dev mode
628
- * @prop {boolean} [isDev]
629
- * @readonly
630
- * @memberof RpgClientEngine
631
- * @since 4.0.0
632
- */
633
- get isDev() {
634
- return !this.envs?.['VITE_BUILT'];
635
- }
636
- /**
637
- * Get the server url. This is the url for the websocket
638
- *
639
- * To customize the URL, use the `matchMakerService` configuration
640
- *
641
- * @title Server URL
642
- * @prop {string} [serverUrl] If empty string, server url is same as client url
643
- * @readonly
644
- * @memberof RpgClientEngine
645
- * @since 4.0.0
646
- */
647
- get serverUrl() {
648
- if (!this._serverUrl.startsWith('http')) {
649
- return 'http://' + this._serverUrl;
650
- }
651
- return this._serverUrl;
652
- }
653
- get assetsPath() {
654
- return this.envs?.['VITE_ASSETS_PATH'] || 'assets';
655
- }
656
- get module() {
657
- return RpgPlugin;
658
- }
659
- reset() {
660
- this.subscriptionWorld.unsubscribe();
661
- this.world.reset();
662
- spritesheets.clear();
663
- sounds.clear();
664
- Assets.reset();
665
- utils.clearTextureCache();
666
- for (let textureUrl in utils.BaseTextureCache) {
667
- delete utils.BaseTextureCache[textureUrl];
668
- }
669
- for (let textureUrl in utils.TextureCache) {
670
- delete utils.TextureCache[textureUrl];
671
- }
672
- RpgGui.clear();
673
- RpgCommonMap.bufferClient.clear();
674
- RpgSound.clear();
675
- }
676
- }
677
- //# sourceMappingURL=RpgClientEngine.js.map