@rpgjs/client 4.3.0 → 5.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (323) 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 +316 -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 +91 -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/index39.js +20 -0
  79. package/dist/index39.js.map +1 -0
  80. package/dist/index4.js +54 -0
  81. package/dist/index4.js.map +1 -0
  82. package/dist/index5.js +15 -0
  83. package/dist/index5.js.map +1 -0
  84. package/dist/index6.js +17 -0
  85. package/dist/index6.js.map +1 -0
  86. package/dist/index7.js +31 -0
  87. package/dist/index7.js.map +1 -0
  88. package/dist/index8.js +90 -0
  89. package/dist/index8.js.map +1 -0
  90. package/dist/index9.js +76 -0
  91. package/dist/index9.js.map +1 -0
  92. package/dist/module.d.ts +14 -0
  93. package/dist/presets/index.d.ts +22 -0
  94. package/{lib/Presets/AnimationSpritesheet.d.ts → dist/presets/rmspritesheet.d.ts} +6 -2
  95. package/dist/services/AbstractSocket.d.ts +15 -0
  96. package/dist/services/loadMap.d.ts +14 -0
  97. package/dist/services/mmorpg.d.ts +32 -0
  98. package/dist/services/standalone.d.ts +34 -0
  99. package/package.json +25 -41
  100. package/src/Game/EffectManager.ts +20 -0
  101. package/src/Game/Event.ts +5 -0
  102. package/src/Game/Map.ts +10 -0
  103. package/src/Game/Object.ts +16 -0
  104. package/src/Game/Player.ts +5 -0
  105. package/src/Gui/Gui.ts +80 -533
  106. package/src/RpgClient.ts +9 -5
  107. package/src/RpgClientEngine.ts +135 -818
  108. package/src/components/character.ce +104 -0
  109. package/src/components/effects/animation.ce +19 -0
  110. package/src/components/effects/hit.ce +87 -0
  111. package/src/components/effects/index.ts +7 -0
  112. package/src/components/gui/dialogbox/index.ce +194 -0
  113. package/src/components/gui/dialogbox/itemMenu.ce +23 -0
  114. package/src/components/gui/dialogbox/selection.ce +67 -0
  115. package/src/components/gui/index.ts +5 -0
  116. package/src/components/index.ts +3 -0
  117. package/src/components/scenes/canvas.ce +51 -0
  118. package/src/components/scenes/draw-map.ce +56 -0
  119. package/src/components/scenes/element-map.ce +23 -0
  120. package/src/components/scenes/event-layer.ce +20 -0
  121. package/src/core/inject.ts +17 -0
  122. package/src/core/setup.ts +18 -0
  123. package/src/index.ts +13 -29
  124. package/src/module.ts +93 -0
  125. package/src/presets/index.ts +5 -0
  126. package/src/{Presets/AnimationSpritesheet.ts → presets/rmspritesheet.ts} +4 -5
  127. package/src/services/AbstractSocket.ts +14 -0
  128. package/src/services/loadMap.ts +33 -0
  129. package/src/services/mmorpg.ts +64 -0
  130. package/src/services/standalone.ts +101 -0
  131. package/src/types/canvas-engine.d.ts +26 -0
  132. package/tsconfig.json +8 -3
  133. package/vite.config.ts +34 -0
  134. package/CHANGELOG.md +0 -189
  135. package/LICENSE +0 -19
  136. package/browser/React-ece4b906.js +0 -195
  137. package/browser/index-ba657126.js +0 -44229
  138. package/browser/manifest.json +0 -21
  139. package/browser/rpg.client.js +0 -40
  140. package/browser/rpg.client.umd.cjs +0 -44456
  141. package/lib/Components/AbstractComponent.d.ts +0 -32
  142. package/lib/Components/AbstractComponent.js +0 -93
  143. package/lib/Components/AbstractComponent.js.map +0 -1
  144. package/lib/Components/BarComponent.d.ts +0 -21
  145. package/lib/Components/BarComponent.js +0 -169
  146. package/lib/Components/BarComponent.js.map +0 -1
  147. package/lib/Components/Component.d.ts +0 -124
  148. package/lib/Components/Component.js +0 -425
  149. package/lib/Components/Component.js.map +0 -1
  150. package/lib/Components/DebugComponent.d.ts +0 -11
  151. package/lib/Components/DebugComponent.js +0 -32
  152. package/lib/Components/DebugComponent.js.map +0 -1
  153. package/lib/Components/ImageComponent.d.ts +0 -11
  154. package/lib/Components/ImageComponent.js +0 -30
  155. package/lib/Components/ImageComponent.js.map +0 -1
  156. package/lib/Components/ShapeComponent.d.ts +0 -11
  157. package/lib/Components/ShapeComponent.js +0 -57
  158. package/lib/Components/ShapeComponent.js.map +0 -1
  159. package/lib/Components/TextComponent.d.ts +0 -11
  160. package/lib/Components/TextComponent.js +0 -35
  161. package/lib/Components/TextComponent.js.map +0 -1
  162. package/lib/Components/TileComponent.d.ts +0 -10
  163. package/lib/Components/TileComponent.js +0 -40
  164. package/lib/Components/TileComponent.js.map +0 -1
  165. package/lib/Effects/Animation.d.ts +0 -55
  166. package/lib/Effects/Animation.js +0 -233
  167. package/lib/Effects/Animation.js.map +0 -1
  168. package/lib/Effects/AnimationCharacter.d.ts +0 -7
  169. package/lib/Effects/AnimationCharacter.js +0 -9
  170. package/lib/Effects/AnimationCharacter.js.map +0 -1
  171. package/lib/Effects/Spinner.d.ts +0 -7
  172. package/lib/Effects/Spinner.js +0 -18
  173. package/lib/Effects/Spinner.js.map +0 -1
  174. package/lib/Effects/Timeline.d.ts +0 -151
  175. package/lib/Effects/Timeline.js +0 -369
  176. package/lib/Effects/Timeline.js.map +0 -1
  177. package/lib/Effects/TransitionScene.d.ts +0 -18
  178. package/lib/Effects/TransitionScene.js +0 -50
  179. package/lib/Effects/TransitionScene.js.map +0 -1
  180. package/lib/GameEngine.d.ts +0 -68
  181. package/lib/GameEngine.js +0 -254
  182. package/lib/GameEngine.js.map +0 -1
  183. package/lib/Gui/Gui.d.ts +0 -110
  184. package/lib/Gui/Gui.js +0 -489
  185. package/lib/Gui/Gui.js.map +0 -1
  186. package/lib/Gui/React.d.ts +0 -28
  187. package/lib/Gui/React.js +0 -147
  188. package/lib/Gui/React.js.map +0 -1
  189. package/lib/Gui/Vue.d.ts +0 -13
  190. package/lib/Gui/Vue.js +0 -114
  191. package/lib/Gui/Vue.js.map +0 -1
  192. package/lib/Interfaces/Character.d.ts +0 -6
  193. package/lib/Interfaces/Character.js +0 -2
  194. package/lib/Interfaces/Character.js.map +0 -1
  195. package/lib/Interfaces/Scene.d.ts +0 -10
  196. package/lib/Interfaces/Scene.js +0 -2
  197. package/lib/Interfaces/Scene.js.map +0 -1
  198. package/lib/KeyboardControls.d.ts +0 -367
  199. package/lib/KeyboardControls.js +0 -714
  200. package/lib/KeyboardControls.js.map +0 -1
  201. package/lib/Logger.d.ts +0 -1
  202. package/lib/Logger.js +0 -4
  203. package/lib/Logger.js.map +0 -1
  204. package/lib/Presets/AnimationSpritesheet.js +0 -39
  205. package/lib/Presets/AnimationSpritesheet.js.map +0 -1
  206. package/lib/Presets/Scene.d.ts +0 -3
  207. package/lib/Presets/Scene.js +0 -5
  208. package/lib/Presets/Scene.js.map +0 -1
  209. package/lib/Renderer.d.ts +0 -62
  210. package/lib/Renderer.js +0 -300
  211. package/lib/Renderer.js.map +0 -1
  212. package/lib/Resources.d.ts +0 -22
  213. package/lib/Resources.js +0 -38
  214. package/lib/Resources.js.map +0 -1
  215. package/lib/RpgClient.js +0 -2
  216. package/lib/RpgClient.js.map +0 -1
  217. package/lib/RpgClientEngine.d.ts +0 -257
  218. package/lib/RpgClientEngine.js +0 -677
  219. package/lib/RpgClientEngine.js.map +0 -1
  220. package/lib/Scene/EventLayer.d.ts +0 -4
  221. package/lib/Scene/EventLayer.js +0 -8
  222. package/lib/Scene/EventLayer.js.map +0 -1
  223. package/lib/Scene/Map.d.ts +0 -109
  224. package/lib/Scene/Map.js +0 -319
  225. package/lib/Scene/Map.js.map +0 -1
  226. package/lib/Scene/Scene.d.ts +0 -184
  227. package/lib/Scene/Scene.js +0 -250
  228. package/lib/Scene/Scene.js.map +0 -1
  229. package/lib/Scene/SceneData.d.ts +0 -4
  230. package/lib/Scene/SceneData.js +0 -8
  231. package/lib/Scene/SceneData.js.map +0 -1
  232. package/lib/Sound/RpgSound.d.ts +0 -11
  233. package/lib/Sound/RpgSound.js +0 -46
  234. package/lib/Sound/RpgSound.js.map +0 -1
  235. package/lib/Sound/Sound.d.ts +0 -78
  236. package/lib/Sound/Sound.js +0 -12
  237. package/lib/Sound/Sound.js.map +0 -1
  238. package/lib/Sound/Sounds.d.ts +0 -2
  239. package/lib/Sound/Sounds.js +0 -6
  240. package/lib/Sound/Sounds.js.map +0 -1
  241. package/lib/Sprite/Character.d.ts +0 -18
  242. package/lib/Sprite/Character.js +0 -131
  243. package/lib/Sprite/Character.js.map +0 -1
  244. package/lib/Sprite/Player.d.ts +0 -3
  245. package/lib/Sprite/Player.js +0 -4
  246. package/lib/Sprite/Player.js.map +0 -1
  247. package/lib/Sprite/Spritesheet.d.ts +0 -365
  248. package/lib/Sprite/Spritesheet.js +0 -13
  249. package/lib/Sprite/Spritesheet.js.map +0 -1
  250. package/lib/Sprite/Spritesheets.d.ts +0 -3
  251. package/lib/Sprite/Spritesheets.js +0 -6
  252. package/lib/Sprite/Spritesheets.js.map +0 -1
  253. package/lib/Tilemap/CommonLayer.d.ts +0 -10
  254. package/lib/Tilemap/CommonLayer.js +0 -17
  255. package/lib/Tilemap/CommonLayer.js.map +0 -1
  256. package/lib/Tilemap/ImageLayer.d.ts +0 -4
  257. package/lib/Tilemap/ImageLayer.js +0 -16
  258. package/lib/Tilemap/ImageLayer.js.map +0 -1
  259. package/lib/Tilemap/Tile.d.ts +0 -21
  260. package/lib/Tilemap/Tile.js +0 -67
  261. package/lib/Tilemap/Tile.js.map +0 -1
  262. package/lib/Tilemap/TileLayer.d.ts +0 -13
  263. package/lib/Tilemap/TileLayer.js +0 -122
  264. package/lib/Tilemap/TileLayer.js.map +0 -1
  265. package/lib/Tilemap/TileSet.d.ts +0 -7
  266. package/lib/Tilemap/TileSet.js +0 -24
  267. package/lib/Tilemap/TileSet.js.map +0 -1
  268. package/lib/Tilemap/index.d.ts +0 -28
  269. package/lib/Tilemap/index.js +0 -151
  270. package/lib/Tilemap/index.js.map +0 -1
  271. package/lib/clientEntryPoint.d.ts +0 -89
  272. package/lib/clientEntryPoint.js +0 -48
  273. package/lib/clientEntryPoint.js.map +0 -1
  274. package/lib/index.d.ts +0 -26
  275. package/lib/index.js +0 -27
  276. package/lib/index.js.map +0 -1
  277. package/lib/inject.d.ts +0 -23
  278. package/lib/inject.js +0 -30
  279. package/lib/inject.js.map +0 -1
  280. package/rpg.toml +0 -14
  281. package/src/Components/AbstractComponent.ts +0 -120
  282. package/src/Components/BarComponent.ts +0 -181
  283. package/src/Components/Component.ts +0 -515
  284. package/src/Components/DebugComponent.ts +0 -36
  285. package/src/Components/ImageComponent.ts +0 -30
  286. package/src/Components/ShapeComponent.ts +0 -64
  287. package/src/Components/TextComponent.ts +0 -33
  288. package/src/Components/TileComponent.ts +0 -43
  289. package/src/Effects/Animation.ts +0 -310
  290. package/src/Effects/AnimationCharacter.ts +0 -7
  291. package/src/Effects/Spinner.ts +0 -19
  292. package/src/Effects/Timeline.ts +0 -378
  293. package/src/Effects/TransitionScene.ts +0 -59
  294. package/src/GameEngine.ts +0 -289
  295. package/src/Gui/React.ts +0 -193
  296. package/src/Gui/Vue.ts +0 -154
  297. package/src/Interfaces/Character.ts +0 -7
  298. package/src/Interfaces/Scene.ts +0 -9
  299. package/src/KeyboardControls.ts +0 -748
  300. package/src/Logger.ts +0 -3
  301. package/src/Presets/Scene.ts +0 -3
  302. package/src/Renderer.ts +0 -334
  303. package/src/Resources.ts +0 -39
  304. package/src/Scene/EventLayer.ts +0 -9
  305. package/src/Scene/Map.ts +0 -402
  306. package/src/Scene/Scene.ts +0 -305
  307. package/src/Scene/SceneData.ts +0 -13
  308. package/src/Sound/RpgSound.ts +0 -50
  309. package/src/Sound/Sound.ts +0 -91
  310. package/src/Sound/Sounds.ts +0 -7
  311. package/src/Sprite/Character.ts +0 -157
  312. package/src/Sprite/Player.ts +0 -3
  313. package/src/Sprite/Spritesheet.ts +0 -392
  314. package/src/Sprite/Spritesheets.ts +0 -8
  315. package/src/Tilemap/CommonLayer.ts +0 -20
  316. package/src/Tilemap/ImageLayer.ts +0 -20
  317. package/src/Tilemap/Tile.ts +0 -80
  318. package/src/Tilemap/TileLayer.ts +0 -142
  319. package/src/Tilemap/TileSet.ts +0 -40
  320. package/src/Tilemap/index.ts +0 -175
  321. package/src/clientEntryPoint.ts +0 -150
  322. package/src/inject.ts +0 -34
  323. package/src/types/howler.d.ts +0 -73
package/src/Logger.ts DELETED
@@ -1,3 +0,0 @@
1
- export function log(message) {
2
- return new Error(`[RPGJS] - ${message}`)
3
- }
@@ -1,3 +0,0 @@
1
- export enum Scene {
2
- Map = 'map'
3
- }
package/src/Renderer.ts DELETED
@@ -1,334 +0,0 @@
1
- import { RpgPlugin, HookClient, Utils, InjectContext } from '@rpgjs/common'
2
- import { SceneMap } from './Scene/Map'
3
- import { Scene } from './Scene/Scene'
4
- import { Scene as PresetScene } from './Presets/Scene'
5
- import { RpgGui } from './Gui/Gui'
6
- import { RpgClientEngine } from './RpgClientEngine'
7
- import type { App, ComponentPublicInstance } from 'vue'
8
- import { TransitionScene } from './Effects/TransitionScene'
9
- import { Subject, forkJoin } from 'rxjs'
10
- import { GameEngineClient } from './GameEngine'
11
- import { SpinnerGraphic } from './Effects/Spinner'
12
- import { autoDetectRenderer, Container, EventBoundary, FederatedEvent, FederatedPointerEvent, Graphics, ICanvas, IRenderer } from 'pixi.js'
13
- import { KeyboardControls } from './KeyboardControls'
14
-
15
- const { elementToPositionAbsolute } = Utils
16
-
17
- export enum TransitionMode {
18
- None,
19
- Fading
20
- }
21
-
22
- enum ContainerName {
23
- Map = 'map'
24
- }
25
-
26
- export const EVENTS_MAP = {
27
- MouseEvent: ['click', 'dblclick', 'mousedown', 'mouseup', 'mousemove', 'mouseenter', 'mouseleave', 'mouseover', 'mouseout', 'contextmenu', 'wheel'],
28
- KeyboardEvent: ['keydown', 'keyup', 'keypress', 'keydownoutside', 'keyupoutside', 'keypressoutside'],
29
- PointerEvent: ['pointerdown', 'pointerup', 'pointermove', 'pointerover', 'pointerout', 'pointerenter', 'pointerleave', 'pointercancel'],
30
- TouchEvent: ['touchstart', 'touchend', 'touchmove', 'touchcancel']
31
- };
32
-
33
- export class RpgRenderer {
34
- private gameEngine: GameEngineClient = this.context.inject(GameEngineClient)
35
- private clientEngine: RpgClientEngine = this.context.inject(RpgClientEngine)
36
-
37
- public vm: ComponentPublicInstance
38
- public app: App
39
- public readonly stage: Container = new Container()
40
- private readonly sceneContainer: Container = new Container()
41
- private readonly fadeContainer: Graphics = new Graphics()
42
- private readonly spinner: SpinnerGraphic = new SpinnerGraphic(this.clientEngine)
43
- public options: any = {}
44
- public guiEl: HTMLDivElement
45
-
46
- private scene: Scene | null = null
47
- private renderer: IRenderer
48
- private _width: number = 800
49
- private _height: number = 400
50
- private canvasEl: HTMLElement
51
- private selector: HTMLElement
52
- private loadingScene = {
53
- transitionIn: new Subject(),
54
- transitionOut: new Subject()
55
- }
56
- private freeze: boolean = false
57
- private prevObjectScene: any = {}
58
- public transitionMode: TransitionMode = TransitionMode.Fading
59
-
60
- constructor(private context: InjectContext) {
61
- this.clientEngine.tick.subscribe(({ timestamp, deltaRatio, frame, deltaTime }) => {
62
- this.draw(timestamp, deltaTime, deltaRatio, frame)
63
- })
64
- this.transitionCompleted()
65
- }
66
-
67
- /** @internal */
68
- init(): Promise<void> {
69
- return this.onDOMLoaded()
70
- }
71
-
72
- /** @internal */
73
- _resize(w: number, h: number) {
74
- if (!w) w = this.options.canvas.width
75
- if (!h) h = this.options.canvas.height
76
- const scene = this.getScene<SceneMap>()
77
- if (this.scene && scene?.viewport) {
78
- scene.viewport.screenWidth = w
79
- scene.viewport.screenHeight = h
80
- }
81
- if (this.vm) {
82
- this.vm.$el.style = `width:${w}px;height:${h}px`
83
- }
84
- this.renderer.resize(w, h)
85
- this._width = w
86
- this._height = h
87
- this.fadeContainer.beginFill(0x00000)
88
- this.fadeContainer.drawRect(0, 0, w, h)
89
- this.fadeContainer.endFill()
90
- this.spinner.x = w * 0.5
91
- this.spinner.y = h * 0.5
92
- }
93
-
94
- get canvas(): HTMLCanvasElement {
95
- return this.renderer.view as HTMLCanvasElement
96
- }
97
-
98
- get height(): number {
99
- return this._height
100
- }
101
-
102
- set height(val: number) {
103
- this._resize(this._width, val)
104
- }
105
-
106
- get width(): number {
107
- return this._width
108
- }
109
-
110
- set width(val: number) {
111
- this._resize(val, this.height)
112
- }
113
-
114
- /** @internal */
115
- async onDOMLoaded(): Promise<void> {
116
- let options = {
117
- antialias: true,
118
- ...this.options.canvas
119
- };
120
- this.renderer = autoDetectRenderer(options)
121
- this.selector = document.body.querySelector(this.options.selector)
122
- this.guiEl = this.selector.querySelector(this.options.selectorGui)
123
- this.canvasEl = this.selector.querySelector(this.options.selectorCanvas)
124
-
125
- if (!this.guiEl) {
126
- this.guiEl = document.createElement('div')
127
- this.guiEl = this.selector.appendChild(this.guiEl)
128
- }
129
-
130
- elementToPositionAbsolute(this.guiEl)
131
-
132
- if (!this.canvasEl) {
133
- this.selector.insertBefore(this.renderer.view as HTMLCanvasElement, this.selector.firstChild)
134
- const [canvas] = document.querySelector(this.options.selector).children
135
- canvas.style.position = 'absolute'
136
- }
137
- else {
138
- this.canvasEl.appendChild(this.renderer.view as HTMLCanvasElement)
139
- }
140
-
141
- this.stage.addChild(this.sceneContainer)
142
- this.stage.addChild(this.fadeContainer)
143
- this.fadeContainer.addChild(this.spinner)
144
-
145
- this.fadeContainer.visible = false
146
- this.fadeContainer.alpha = 0
147
-
148
- await RpgGui._initialize(this.context, this.guiEl)
149
-
150
- this.resize()
151
- this.bindMouseControls()
152
-
153
- }
154
-
155
- private bindMouseControls() {
156
- const controlInstance = this.context.inject(KeyboardControls)
157
- const controls = controlInstance.getControls()
158
- for (let key in controls) {
159
- const { actionName } = controls[key]
160
- if (EVENTS_MAP.MouseEvent.includes(key)) {
161
- this.canvas.addEventListener(key, (e) => {
162
- controlInstance.applyControl(actionName)
163
- })
164
- }
165
- }
166
- }
167
-
168
- /** @internal */
169
- resize() {
170
- const size = () => {
171
- const { offsetWidth, offsetHeight } = this.canvasEl || this.selector
172
- this._resize(offsetWidth, offsetHeight)
173
- RpgPlugin.emit(HookClient.WindowResize)
174
- }
175
- window.addEventListener('resize', size)
176
- size()
177
- }
178
-
179
- /** @internal */
180
- getScene<T = Scene>(): T | null {
181
- return this.scene as any
182
- }
183
-
184
- /** @internal */
185
- draw(t: number, deltaTime: number, deltaRatio: number, frame: number) {
186
- if (!this.renderer) return
187
- if (this.scene && !this.freeze) this.scene.draw(t, deltaTime, deltaRatio, frame)
188
- this.renderer.render(this.stage)
189
- }
190
-
191
- /** @internal */
192
- async loadScene(name: string, obj) {
193
- const scene = this.getScene<SceneMap | null>()
194
- if (scene && scene.data.id == obj.id) {
195
- const container = await scene.load(obj, this.prevObjectScene, true)
196
- this.sceneContainer.removeChildren()
197
- this.sceneContainer.addChild(container)
198
- scene.updateTilesOverlayAllSprites()
199
- this.scene?.update()
200
- return
201
- }
202
- this.loadingScene.transitionIn.next({ name, obj })
203
- this.loadingScene.transitionIn.complete()
204
- }
205
-
206
- private async createScene(name: string, obj) {
207
- const container = await this.getScene<SceneMap>()?.load(obj, this.prevObjectScene)
208
- this.prevObjectScene = { ...obj }
209
- this.sceneContainer.children.forEach(child => {
210
- if (child.name === ContainerName.Map) this.sceneContainer.removeChild(child)
211
- })
212
- if (container) {
213
- container.name = ContainerName.Map
214
- this.sceneContainer.addChild(container)
215
- }
216
- this.scene?.update()
217
- }
218
-
219
- /** @internal */
220
- transitionScene(name: string) {
221
- this.freeze = true
222
- this.fadeContainer.visible = true
223
- RpgPlugin.emit(HookClient.BeforeSceneLoading, {
224
- name
225
- })
226
- this.clientEngine.controls.stopInputs()
227
- const finish = () => {
228
- this.clearScene()
229
- this.loadingScene.transitionOut.next(name)
230
- this.loadingScene.transitionOut.complete()
231
- }
232
- if (this.transitionMode == TransitionMode.Fading) {
233
- new TransitionScene(this.context, this.fadeContainer)
234
- .addFadeOut()
235
- .onComplete(finish)
236
- .start()
237
- }
238
- else {
239
- finish()
240
- }
241
- }
242
-
243
- /** @internal */
244
- transitionCompleted() {
245
- this.loadingScene = {
246
- transitionIn: new Subject(),
247
- transitionOut: new Subject()
248
- }
249
- this.clientEngine.roomJoin = new Subject()
250
- forkJoin({
251
- in: this.loadingScene.transitionIn,
252
- out: this.loadingScene.transitionOut,
253
- room: this.clientEngine.roomJoin
254
- }).subscribe(async (data: { in: any }) => {
255
- const { in: { obj, name } } = data
256
- const scenes = this.options.scenes || {}
257
- switch (name) {
258
- case PresetScene.Map:
259
- const sceneClass = scenes[PresetScene.Map] || SceneMap
260
- this.scene = new sceneClass(this.context, this.renderer, {
261
- screenWidth: this.renderer.screen.width,
262
- screenHeight: this.renderer.screen.height,
263
- drawMap: this.options.drawMap
264
- })
265
- break;
266
- }
267
- await this.createScene(name, obj)
268
- this.freeze = false
269
- const finish = () => {
270
- this.clientEngine.controls.listenInputs()
271
- this.fadeContainer.visible = false
272
- this.transitionCompleted()
273
- RpgPlugin.emit(HookClient.AfterSceneLoading, this.scene)
274
- }
275
- if (this.transitionMode == TransitionMode.Fading) {
276
- new TransitionScene(this.context, this.fadeContainer)
277
- .addFadeIn()
278
- .onComplete(finish)
279
- .start()
280
- }
281
- else {
282
- finish()
283
- }
284
- })
285
- }
286
-
287
- /** @internal */
288
- clearScene() {
289
- this.scene = null
290
- this.sceneContainer.removeChildren()
291
- }
292
-
293
- /**
294
- * @title Propagate mouse event to Viewport
295
- * @method propagateEvent(ev)
296
- * @stability 1
297
- * @memberof RpgRenderer
298
- * @returns {void}
299
- */
300
- propagateEvent(ev: MouseEvent) {
301
- const rect = this.canvas.getBoundingClientRect();
302
- const canvasX = rect.left + window.scrollX;
303
- const canvasY = rect.top + window.scrollY;
304
- const realX = ev.clientX - canvasX;
305
- const realY = ev.clientY - canvasY;
306
- const boundary = new EventBoundary(this.stage);
307
- const event = new FederatedPointerEvent(boundary)
308
- event.global.set(realX, realY);
309
- event.type = ev.type;
310
- const hitTestTarget = boundary.hitTest(realX, realY);
311
- hitTestTarget?.dispatchEvent(event)
312
- this.canvas.dispatchEvent(new MouseEvent(ev.type, ev))
313
- }
314
-
315
- /***
316
- * Propagate events from an HTMLElement to the canvas
317
- *
318
- * @title Propagate events
319
- * @method addPropagateEventsFrom(el)
320
- * @stability 1
321
- * @memberof RpgRenderer
322
- * @returns {void}
323
- */
324
- addPropagateEventsFrom(el: HTMLElement) {
325
- for (let [_Constructor, events] of Object.entries(EVENTS_MAP)) {
326
- for (let type of events) {
327
- el.addEventListener(type, (e) => {
328
- const _class = window[_Constructor] ?? MouseEvent
329
- this.canvas.dispatchEvent(new _class(type, e))
330
- });
331
- }
332
- }
333
- }
334
- }
package/src/Resources.ts DELETED
@@ -1,39 +0,0 @@
1
- import { RpgClientEngine } from "./RpgClientEngine"
2
-
3
- /**
4
- * Get/Set images in resources
5
- ```ts
6
- import { RpgResource } from '@rpg/client'
7
- const fileLink = RpgResource.spritesheets.get('resource_id')
8
- ```
9
- * @title Get/Set image link
10
- * @prop { Map< string, string > } spritesheets
11
- * @memberof Resources
12
- */
13
- /**
14
- * Get/Set sounds in resources
15
- ```ts
16
- import { RpgResource } from '@rpg/client'
17
- const fileLink = RpgResource.sounds.get('resource_id')
18
- ```
19
- * @title Get/Set sound link
20
- * @prop { Map< string, string > } sounds
21
- * @memberof Resources
22
- */
23
- export function _initResource(memory: Map<string, any>, _resources, prop: string, engine: RpgClientEngine) {
24
- for (let resource of _resources) {
25
- const pluralProp = prop + 's'
26
- if (resource[pluralProp]) {
27
- for (let key in resource[pluralProp]) {
28
- const instance = new resource()
29
- instance[prop] = engine.getResourceUrl(resource[pluralProp][key])
30
- memory.set(key, instance)
31
- }
32
- }
33
- else {
34
- const instance = new resource(engine)
35
- instance[prop] = engine.getResourceUrl(instance[prop])
36
- memory.set(resource.id, instance)
37
- }
38
- }
39
- }
@@ -1,9 +0,0 @@
1
- import { TiledLayer } from "@rpgjs/tiled";
2
- import { Container } from "pixi.js";
3
-
4
- export class EventLayer extends Container {
5
- constructor() {
6
- super()
7
- this.sortableChildren = true
8
- }
9
- }