@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
package/lib/inject.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import { InjectContext } from "@rpgjs/common";
2
- /**
3
- * Dependency injection function for RPGJS client side.
4
- *
5
- * This client-side `inject` function is used to retrieve instances of various classes within the RPGJS framework,
6
- * specifically for client-side modules. It enables developers to access singleton instances of key classes such as
7
- * `RpgClientEngine`, `KeyboardControls`, and `RpgRenderer`. Utilizing `inject` on the client side promotes modular
8
- * and maintainable code by simplifying dependency management.
9
- *
10
- * @template T The class type that you want to retrieve an instance of, relevant to client-side modules.
11
- * @returns {T} Returns the singleton instance of the specified class, ensuring only one instance is used client-side.
12
- * @since 4.2.0
13
- *
14
- * @example
15
- * ```ts
16
- * // Example of injecting the RpgClientEngine
17
- * import { inject, RpgClientEngine } from '@rpgjs/client'
18
- * const client = inject(RpgClientEngine)
19
- * ```
20
- */
21
- export declare function inject<T>(service: new (...args: any[]) => T, args?: any[]): T;
22
- export declare function setInject(context: InjectContext): void;
23
- export declare function clearInject(): void;
package/lib/inject.js DELETED
@@ -1,30 +0,0 @@
1
- let instanceContext = null;
2
- /**
3
- * Dependency injection function for RPGJS client side.
4
- *
5
- * This client-side `inject` function is used to retrieve instances of various classes within the RPGJS framework,
6
- * specifically for client-side modules. It enables developers to access singleton instances of key classes such as
7
- * `RpgClientEngine`, `KeyboardControls`, and `RpgRenderer`. Utilizing `inject` on the client side promotes modular
8
- * and maintainable code by simplifying dependency management.
9
- *
10
- * @template T The class type that you want to retrieve an instance of, relevant to client-side modules.
11
- * @returns {T} Returns the singleton instance of the specified class, ensuring only one instance is used client-side.
12
- * @since 4.2.0
13
- *
14
- * @example
15
- * ```ts
16
- * // Example of injecting the RpgClientEngine
17
- * import { inject, RpgClientEngine } from '@rpgjs/client'
18
- * const client = inject(RpgClientEngine)
19
- * ```
20
- */
21
- export function inject(service, args = []) {
22
- return instanceContext.inject(service, args);
23
- }
24
- export function setInject(context) {
25
- instanceContext = context;
26
- }
27
- export function clearInject() {
28
- instanceContext = null;
29
- }
30
- //# sourceMappingURL=inject.js.map
package/lib/inject.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"inject.js","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":"AAEA,IAAI,eAAe,GAAyB,IAAI,CAAA;AAEhD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,MAAM,CAAI,OAAkC,EAAE,OAAc,EAAE;IAC1E,OAAO,eAAgB,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,OAAsB;IAC5C,eAAe,GAAG,OAAO,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,WAAW;IACvB,eAAe,GAAG,IAAI,CAAA;AAC1B,CAAC"}
package/rpg.toml DELETED
@@ -1,14 +0,0 @@
1
- [compilerOptions.build]
2
- pwaEnabled = false
3
- outputDir = "./browser"
4
-
5
- [vite.build.lib]
6
- entry = "src/index.ts"
7
- name = "RpgClient"
8
- fileName = "rpg.client"
9
-
10
- [vite.build.rollupOptions.output]
11
- format = "umd"
12
-
13
- [vite.build.rollupOptions]
14
- external = ["@rpgjs/common", "vue", "rxjs", "react", "react-dom"]
@@ -1,120 +0,0 @@
1
- import { ComponentObject } from "@rpgjs/types"
2
- import { Subject, filter, takeUntil } from "rxjs"
3
- import { RpgComponent } from "./Component"
4
- import get from 'lodash.get'
5
- import { GameEngineClient } from "../GameEngine"
6
- import { Container, Graphics, Sprite } from "pixi.js"
7
-
8
- const REGEXP_VAR = /{([^\}]+)}/g
9
-
10
- export type CellInfo = { x?: number, y?: number, width: number, height: number }
11
-
12
- export abstract class AbstractComponent<
13
- TypeComponent extends ComponentObject<any>,
14
- ContainerType extends Container | Text | Sprite | Graphics
15
- > extends Container {
16
- private _onRender$: Subject<AbstractComponent<TypeComponent, ContainerType>> = new Subject()
17
- private _onDestroy$: Subject<void> = new Subject()
18
- readonly onRender$ = this._onRender$.asObservable()
19
- protected readonly game: GameEngineClient = this.component.game
20
- protected firstRender: boolean = true
21
- private style = this.value?.style
22
- private cacheText: {
23
- [key: string]: string
24
- } = {}
25
- protected cell?: CellInfo
26
-
27
- constructor(protected component: RpgComponent, protected value: TypeComponent['value']) {
28
- super()
29
- }
30
-
31
- getStyle<T>(): T {
32
- return this.style || {}
33
- }
34
-
35
- protected parseTextAndCache(text: string): string[] {
36
- // parse text to get varariable in {} format et cache it
37
- const matches = text.matchAll(REGEXP_VAR)
38
- this.cacheParams = [
39
- ...this.cacheParams,
40
- ...Array.from(matches).map(match => match[1])
41
- ]
42
- return this.cacheParams
43
- }
44
-
45
- protected replaceText(object: any, text: string): string {
46
- return text.replace(REGEXP_VAR, (match, key) => {
47
- const value = get(object, key)
48
- if (value !== undefined) {
49
- this.cacheText[key] = value
50
- return value ?? ''
51
- }
52
- return value ?? this.cacheText[key] ?? ''
53
- })
54
- }
55
-
56
- protected getValue(object: any, expression: any): any {
57
- if (typeof expression === 'string') {
58
- const value = get(object, expression)
59
- if (value !== undefined) {
60
- if (this.cacheParams.indexOf(expression) === -1) this.cacheParams.push(expression)
61
- return value
62
- }
63
- }
64
- return expression
65
- }
66
-
67
- private verifyParams(): void | never {
68
- const params = this.component.logic
69
- for (const param of this.cacheParams) {
70
- if (get(params, param) === undefined) {
71
- throw new Error(`Param ${param} not found in object ${this.component.logic?.id}`)
72
- }
73
- }
74
- }
75
-
76
- public onInit(cell: CellInfo): void {
77
- this.cell = cell
78
-
79
- this.verifyParams()
80
-
81
- const render= (object) => {
82
- const opacity = this.getValue(object, this.getStyle<{ opacity: number | undefined }>().opacity || this.value.opacity)
83
-
84
- if (opacity !== undefined) {
85
- this.alpha = Math.min(opacity, 1)
86
- }
87
- }
88
-
89
- render(this.component.logic)
90
-
91
- const objectId = this.component.logic?.id
92
-
93
- this.game.listenObject(objectId)
94
- .pipe(
95
- takeUntil(this._onDestroy$),
96
- filter(object => {
97
- const params = object?.paramsChanged
98
- if (!params) return false
99
- for (const param of this.cacheParams) {
100
- if (get(params, param)) return true
101
- }
102
- return false
103
- })
104
- )
105
- .subscribe(({ object }) => {
106
- this.updateRender(object, this.firstRender)
107
- render(object)
108
- this.firstRender = false
109
- this._onRender$.next(this)
110
- })
111
- }
112
-
113
- abstract updateRender(object: any, firstRender: boolean): void
114
- abstract cacheParams: string[]
115
-
116
- onRemove() {
117
- this._onDestroy$.next()
118
- this._onDestroy$.complete()
119
- }
120
- }
@@ -1,181 +0,0 @@
1
- import { BarComponentObject } from "@rpgjs/types"
2
- import { Utils, transitionColor } from "@rpgjs/common"
3
- import { AbstractComponent, CellInfo } from "./AbstractComponent"
4
- import get from 'lodash.get'
5
- import { Subject, takeUntil } from "rxjs"
6
- import { Container, Graphics, Text } from "pixi.js"
7
-
8
- const DEFAULT_COLOR = '#000000'
9
-
10
- export class BarComponent extends AbstractComponent<BarComponentObject, Container> {
11
- static readonly id: string = 'bar'
12
- private barContainer: Graphics = new Graphics();
13
- private barFill: Graphics = new Graphics();
14
- private textContainer: Text = new Text('')
15
- private barHeight: number = this.value.style?.height || 7;
16
- private text: string = this.value.text || ''
17
- private barStyle = this.getStyle<BarComponentObject['value']['style']>()
18
- private currentValue: number = 0;
19
- private maxValue: number = 0;
20
- private nextValue: number = 0;
21
- private notifier: Subject<void> = new Subject()
22
- cacheParams: string[] = []
23
-
24
- private get barWidth() {
25
- return this.barStyle?.width || this.cell?.width || 0
26
- }
27
-
28
- onInit(cell: CellInfo) {
29
- if (!this.value.style) {
30
- this.value.style = {
31
- fillColor: '#ffffff',
32
- }
33
- }
34
- const { bgColor = DEFAULT_COLOR, borderColor = DEFAULT_COLOR, borderWidth = 1, borderRadius = 0 } = this.barStyle || {}
35
- this.cell = cell
36
- const { value: color, alpha } = Utils.hexaToNumber(bgColor)
37
- this.barContainer.beginFill(color, alpha)
38
- const paramsRect: [number, number, number, number] = [0, 0, this.barWidth, this.barHeight]
39
- if (borderWidth) {
40
- const { value: color, alpha } = Utils.hexaToNumber(borderColor)
41
- this.barContainer.lineStyle(borderWidth, color, alpha);
42
- }
43
- if (borderRadius) {
44
- this.barContainer.drawRoundedRect(...paramsRect, borderRadius);
45
- }
46
- else {
47
- this.barContainer.drawRect(...paramsRect);
48
- }
49
- this.barContainer.endFill();
50
- this.textContainer.style = {
51
- fontSize: 10,
52
- fill: '#ffffff',
53
- fontWeight: 'bold'
54
- }
55
- // 5 is the padding
56
- this.textContainer.y -= this.barHeight + this.textContainer.height - 5
57
- if (this.text) this.addChild(this.textContainer)
58
- this.addChild(this.barContainer);
59
- this.barContainer.addChild(this.barFill);
60
- this.cacheParams = [this.value.current, this.value.max]
61
- this.updateRender(this.component.logic, true)
62
- this.firstRender = false
63
- super.onInit(cell)
64
- }
65
-
66
- updateRender(object: any, firstRender: boolean) {
67
- this.currentValue = this.nextValue;
68
- this.nextValue = get(object, this.value.current) ?? this.nextValue ?? 0;
69
- this.maxValue = get(object, this.value.max) ?? this.maxValue;
70
- const style = this.barStyle
71
- const borderRadius = style?.borderRadius ?? 0
72
- const borderWidth = style?.borderWidth ?? 0
73
-
74
- // first render
75
- if (firstRender) {
76
- this.currentValue = this.nextValue;
77
- }
78
-
79
- const getColor = (value: number) => {
80
- let determineLastColor = DEFAULT_COLOR
81
- const percent = Math.max(0, (value / this.maxValue) * 100);
82
- const perPercent = (style as any).perPercent;
83
- if (perPercent) {
84
- for (const p in perPercent) {
85
- if (percent <= +p) {
86
- determineLastColor = perPercent[p].fillColor;
87
- break;
88
- }
89
- }
90
- } else {
91
- determineLastColor = (this.value.style as any).fillColor;
92
- }
93
- return determineLastColor
94
- }
95
-
96
- let colors: string[] = []
97
- if (style) {
98
- // TODO: add transition color
99
- colors = transitionColor(getColor(this.currentValue), getColor(this.nextValue), 1)
100
- }
101
- else {
102
- colors = transitionColor(DEFAULT_COLOR, DEFAULT_COLOR, 1)
103
- }
104
-
105
- const render = (up = false) => {
106
- let currentValue = ~~this.currentValue
107
- if (currentValue < 0) currentValue = 0
108
- if (currentValue > this.maxValue) currentValue = this.maxValue
109
- const percentBetween = ~~Math.max(0, ((currentValue - this.nextValue) * 100) / this.nextValue)
110
- const colorIndex = Math.max(Math.floor((100 - percentBetween) / (100 / (colors.length - 1))), 0)
111
- let fillColor = colors[colorIndex]
112
- this.barFill.clear()
113
- const { value: color, alpha } = Utils.hexaToNumber(fillColor ?? DEFAULT_COLOR)
114
- this.barFill.beginFill(color, alpha)
115
- const percent = Math.max(0, (currentValue / this.maxValue))
116
- const bWidth = borderWidth / 4
117
- const paramsRect: [number, number, number, number] = [bWidth, bWidth, percent * this.barWidth - bWidth, this.barHeight - bWidth]
118
- if (percent > 0) {
119
- if (borderRadius) {
120
- this.barFill.drawRoundedRect(...paramsRect, borderRadius)
121
- }
122
- else {
123
- this.barFill.drawRect(...paramsRect)
124
- }
125
- }
126
- this.textContainer.text = this.replaceText({
127
- ...object,
128
- $current: currentValue,
129
- $percent: Math.round(percent * 100),
130
- $max: this.maxValue
131
- }, this.text)
132
- this.barFill.endFill();
133
- }
134
-
135
- if (firstRender) {
136
- render();
137
- return;
138
- }
139
-
140
- this.notifier.next()
141
-
142
- this.game.clientEngine.tick
143
- .pipe(
144
- takeUntil(this.notifier)
145
- )
146
- .subscribe(() => {
147
- // speed of animation, calculate the difference between the current value and the next value to determine the speed
148
- const speed = Math.abs(this.currentValue - this.nextValue) / 10;
149
- let up: boolean = false;
150
-
151
- // if the current value is less than the next value, add the speed to the current value
152
- if (this.currentValue < this.nextValue) {
153
- this.currentValue += speed
154
- up = true;
155
- }
156
-
157
- // if the current value is greater than the next value, subtract the speed from the current value
158
- else if (this.currentValue > this.nextValue) {
159
- this.currentValue -= speed
160
- up = false;
161
- }
162
-
163
- render(up)
164
-
165
- const currentValue = Math.round(this.currentValue)
166
-
167
- if (!up && (~~currentValue <= ~~this.nextValue || currentValue <= 0)) {
168
- this.notifier.next()
169
- }
170
- else if (up && (~~currentValue >= ~~this.nextValue || currentValue >= this.maxValue)) {
171
- this.notifier.next()
172
- }
173
- })
174
- }
175
-
176
- onRemove() {
177
- this.notifier.next()
178
- this.notifier.complete()
179
- super.onRemove()
180
- }
181
- }