@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.
- package/dist/Game/EffectManager.d.ts +5 -0
- package/dist/Game/Event.d.ts +4 -0
- package/dist/Game/Map.d.ts +7 -0
- package/dist/Game/Player.d.ts +4 -0
- package/dist/Gui/Gui.d.ts +23 -0
- package/{lib → dist}/RpgClient.d.ts +9 -6
- package/dist/RpgClientEngine.d.ts +43 -0
- package/dist/components/effects/index.d.ts +4 -0
- package/dist/components/gui/index.d.ts +3 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/core/inject.d.ts +5 -0
- package/dist/core/setup.d.ts +6 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/index10.js +8 -0
- package/dist/index10.js.map +1 -0
- package/dist/index11.js +10 -0
- package/dist/index11.js.map +1 -0
- package/dist/index12.js +8 -0
- package/dist/index12.js.map +1 -0
- package/dist/index13.js +17 -0
- package/dist/index13.js.map +1 -0
- package/dist/index14.js +50 -0
- package/dist/index14.js.map +1 -0
- package/dist/index15.js +191 -0
- package/dist/index15.js.map +1 -0
- package/dist/index16.js +9 -0
- package/dist/index16.js.map +1 -0
- package/dist/index17.js +387 -0
- package/dist/index17.js.map +1 -0
- package/dist/index18.js +31 -0
- package/dist/index18.js.map +1 -0
- package/dist/index19.js +24 -0
- package/dist/index19.js.map +1 -0
- package/dist/index2.js +112 -0
- package/dist/index2.js.map +1 -0
- package/dist/index20.js +2421 -0
- package/dist/index20.js.map +1 -0
- package/dist/index21.js +114 -0
- package/dist/index21.js.map +1 -0
- package/dist/index22.js +109 -0
- package/dist/index22.js.map +1 -0
- package/dist/index23.js +71 -0
- package/dist/index23.js.map +1 -0
- package/dist/index24.js +21 -0
- package/dist/index24.js.map +1 -0
- package/dist/index25.js +41 -0
- package/dist/index25.js.map +1 -0
- package/dist/index26.js +5 -0
- package/dist/index26.js.map +1 -0
- package/dist/index27.js +322 -0
- package/dist/index27.js.map +1 -0
- package/dist/index28.js +25 -0
- package/dist/index28.js.map +1 -0
- package/dist/index29.js +11 -0
- package/dist/index29.js.map +1 -0
- package/dist/index3.js +87 -0
- package/dist/index3.js.map +1 -0
- package/dist/index30.js +11 -0
- package/dist/index30.js.map +1 -0
- package/dist/index31.js +174 -0
- package/dist/index31.js.map +1 -0
- package/dist/index32.js +501 -0
- package/dist/index32.js.map +1 -0
- package/dist/index33.js +12 -0
- package/dist/index33.js.map +1 -0
- package/dist/index34.js +4403 -0
- package/dist/index34.js.map +1 -0
- package/dist/index35.js +91 -0
- package/dist/index35.js.map +1 -0
- package/dist/index36.js +61 -0
- package/dist/index36.js.map +1 -0
- package/dist/index37.js +20 -0
- package/dist/index37.js.map +1 -0
- package/dist/index38.js +20 -0
- package/dist/index38.js.map +1 -0
- package/dist/index4.js +54 -0
- package/dist/index4.js.map +1 -0
- package/dist/index5.js +15 -0
- package/dist/index5.js.map +1 -0
- package/dist/index6.js +17 -0
- package/dist/index6.js.map +1 -0
- package/dist/index7.js +31 -0
- package/dist/index7.js.map +1 -0
- package/dist/index8.js +90 -0
- package/dist/index8.js.map +1 -0
- package/dist/index9.js +76 -0
- package/dist/index9.js.map +1 -0
- package/dist/module.d.ts +14 -0
- package/dist/presets/index.d.ts +22 -0
- package/{lib/Presets/AnimationSpritesheet.d.ts → dist/presets/rmspritesheet.d.ts} +6 -2
- package/dist/services/AbstractSocket.d.ts +15 -0
- package/dist/services/loadMap.d.ts +14 -0
- package/dist/services/mmorpg.d.ts +32 -0
- package/dist/services/standalone.d.ts +34 -0
- package/package.json +25 -41
- package/src/Game/EffectManager.ts +20 -0
- package/src/Game/Event.ts +5 -0
- package/src/Game/Map.ts +10 -0
- package/src/Game/Object.ts +16 -0
- package/src/Game/Player.ts +5 -0
- package/src/Gui/Gui.ts +80 -533
- package/src/RpgClient.ts +9 -5
- package/src/RpgClientEngine.ts +135 -818
- package/src/components/character.ce +104 -0
- package/src/components/effects/animation.ce +19 -0
- package/src/components/effects/hit.ce +87 -0
- package/src/components/effects/index.ts +7 -0
- package/src/components/gui/dialogbox/index.ce +194 -0
- package/src/components/gui/dialogbox/itemMenu.ce +23 -0
- package/src/components/gui/dialogbox/selection.ce +67 -0
- package/src/components/gui/index.ts +5 -0
- package/src/components/index.ts +3 -0
- package/src/components/scenes/canvas.ce +51 -0
- package/src/components/scenes/draw-map.ce +56 -0
- package/src/components/scenes/element-map.ce +23 -0
- package/src/components/scenes/event-layer.ce +20 -0
- package/src/core/inject.ts +17 -0
- package/src/core/setup.ts +18 -0
- package/src/index.ts +13 -29
- package/src/module.ts +93 -0
- package/src/presets/index.ts +5 -0
- package/src/{Presets/AnimationSpritesheet.ts → presets/rmspritesheet.ts} +4 -5
- package/src/services/AbstractSocket.ts +14 -0
- package/src/services/loadMap.ts +33 -0
- package/src/services/mmorpg.ts +64 -0
- package/src/services/standalone.ts +101 -0
- package/src/types/canvas-engine.d.ts +26 -0
- package/tsconfig.json +8 -3
- package/vite.config.ts +34 -0
- package/CHANGELOG.md +0 -189
- package/LICENSE +0 -19
- package/browser/React-ece4b906.js +0 -195
- package/browser/index-ba657126.js +0 -44229
- package/browser/manifest.json +0 -21
- package/browser/rpg.client.js +0 -40
- package/browser/rpg.client.umd.cjs +0 -44456
- package/lib/Components/AbstractComponent.d.ts +0 -32
- package/lib/Components/AbstractComponent.js +0 -93
- package/lib/Components/AbstractComponent.js.map +0 -1
- package/lib/Components/BarComponent.d.ts +0 -21
- package/lib/Components/BarComponent.js +0 -169
- package/lib/Components/BarComponent.js.map +0 -1
- package/lib/Components/Component.d.ts +0 -124
- package/lib/Components/Component.js +0 -425
- package/lib/Components/Component.js.map +0 -1
- package/lib/Components/DebugComponent.d.ts +0 -11
- package/lib/Components/DebugComponent.js +0 -32
- package/lib/Components/DebugComponent.js.map +0 -1
- package/lib/Components/ImageComponent.d.ts +0 -11
- package/lib/Components/ImageComponent.js +0 -30
- package/lib/Components/ImageComponent.js.map +0 -1
- package/lib/Components/ShapeComponent.d.ts +0 -11
- package/lib/Components/ShapeComponent.js +0 -57
- package/lib/Components/ShapeComponent.js.map +0 -1
- package/lib/Components/TextComponent.d.ts +0 -11
- package/lib/Components/TextComponent.js +0 -35
- package/lib/Components/TextComponent.js.map +0 -1
- package/lib/Components/TileComponent.d.ts +0 -10
- package/lib/Components/TileComponent.js +0 -40
- package/lib/Components/TileComponent.js.map +0 -1
- package/lib/Effects/Animation.d.ts +0 -55
- package/lib/Effects/Animation.js +0 -233
- package/lib/Effects/Animation.js.map +0 -1
- package/lib/Effects/AnimationCharacter.d.ts +0 -7
- package/lib/Effects/AnimationCharacter.js +0 -9
- package/lib/Effects/AnimationCharacter.js.map +0 -1
- package/lib/Effects/Spinner.d.ts +0 -7
- package/lib/Effects/Spinner.js +0 -18
- package/lib/Effects/Spinner.js.map +0 -1
- package/lib/Effects/Timeline.d.ts +0 -151
- package/lib/Effects/Timeline.js +0 -369
- package/lib/Effects/Timeline.js.map +0 -1
- package/lib/Effects/TransitionScene.d.ts +0 -18
- package/lib/Effects/TransitionScene.js +0 -50
- package/lib/Effects/TransitionScene.js.map +0 -1
- package/lib/GameEngine.d.ts +0 -68
- package/lib/GameEngine.js +0 -254
- package/lib/GameEngine.js.map +0 -1
- package/lib/Gui/Gui.d.ts +0 -110
- package/lib/Gui/Gui.js +0 -489
- package/lib/Gui/Gui.js.map +0 -1
- package/lib/Gui/React.d.ts +0 -28
- package/lib/Gui/React.js +0 -147
- package/lib/Gui/React.js.map +0 -1
- package/lib/Gui/Vue.d.ts +0 -13
- package/lib/Gui/Vue.js +0 -114
- package/lib/Gui/Vue.js.map +0 -1
- package/lib/Interfaces/Character.d.ts +0 -6
- package/lib/Interfaces/Character.js +0 -2
- package/lib/Interfaces/Character.js.map +0 -1
- package/lib/Interfaces/Scene.d.ts +0 -10
- package/lib/Interfaces/Scene.js +0 -2
- package/lib/Interfaces/Scene.js.map +0 -1
- package/lib/KeyboardControls.d.ts +0 -367
- package/lib/KeyboardControls.js +0 -714
- package/lib/KeyboardControls.js.map +0 -1
- package/lib/Logger.d.ts +0 -1
- package/lib/Logger.js +0 -4
- package/lib/Logger.js.map +0 -1
- package/lib/Presets/AnimationSpritesheet.js +0 -39
- package/lib/Presets/AnimationSpritesheet.js.map +0 -1
- package/lib/Presets/Scene.d.ts +0 -3
- package/lib/Presets/Scene.js +0 -5
- package/lib/Presets/Scene.js.map +0 -1
- package/lib/Renderer.d.ts +0 -62
- package/lib/Renderer.js +0 -300
- package/lib/Renderer.js.map +0 -1
- package/lib/Resources.d.ts +0 -22
- package/lib/Resources.js +0 -38
- package/lib/Resources.js.map +0 -1
- package/lib/RpgClient.js +0 -2
- package/lib/RpgClient.js.map +0 -1
- package/lib/RpgClientEngine.d.ts +0 -257
- package/lib/RpgClientEngine.js +0 -677
- package/lib/RpgClientEngine.js.map +0 -1
- package/lib/Scene/EventLayer.d.ts +0 -4
- package/lib/Scene/EventLayer.js +0 -8
- package/lib/Scene/EventLayer.js.map +0 -1
- package/lib/Scene/Map.d.ts +0 -109
- package/lib/Scene/Map.js +0 -319
- package/lib/Scene/Map.js.map +0 -1
- package/lib/Scene/Scene.d.ts +0 -184
- package/lib/Scene/Scene.js +0 -250
- package/lib/Scene/Scene.js.map +0 -1
- package/lib/Scene/SceneData.d.ts +0 -4
- package/lib/Scene/SceneData.js +0 -8
- package/lib/Scene/SceneData.js.map +0 -1
- package/lib/Sound/RpgSound.d.ts +0 -11
- package/lib/Sound/RpgSound.js +0 -46
- package/lib/Sound/RpgSound.js.map +0 -1
- package/lib/Sound/Sound.d.ts +0 -78
- package/lib/Sound/Sound.js +0 -12
- package/lib/Sound/Sound.js.map +0 -1
- package/lib/Sound/Sounds.d.ts +0 -2
- package/lib/Sound/Sounds.js +0 -6
- package/lib/Sound/Sounds.js.map +0 -1
- package/lib/Sprite/Character.d.ts +0 -18
- package/lib/Sprite/Character.js +0 -131
- package/lib/Sprite/Character.js.map +0 -1
- package/lib/Sprite/Player.d.ts +0 -3
- package/lib/Sprite/Player.js +0 -4
- package/lib/Sprite/Player.js.map +0 -1
- package/lib/Sprite/Spritesheet.d.ts +0 -365
- package/lib/Sprite/Spritesheet.js +0 -13
- package/lib/Sprite/Spritesheet.js.map +0 -1
- package/lib/Sprite/Spritesheets.d.ts +0 -3
- package/lib/Sprite/Spritesheets.js +0 -6
- package/lib/Sprite/Spritesheets.js.map +0 -1
- package/lib/Tilemap/CommonLayer.d.ts +0 -10
- package/lib/Tilemap/CommonLayer.js +0 -17
- package/lib/Tilemap/CommonLayer.js.map +0 -1
- package/lib/Tilemap/ImageLayer.d.ts +0 -4
- package/lib/Tilemap/ImageLayer.js +0 -16
- package/lib/Tilemap/ImageLayer.js.map +0 -1
- package/lib/Tilemap/Tile.d.ts +0 -21
- package/lib/Tilemap/Tile.js +0 -67
- package/lib/Tilemap/Tile.js.map +0 -1
- package/lib/Tilemap/TileLayer.d.ts +0 -13
- package/lib/Tilemap/TileLayer.js +0 -122
- package/lib/Tilemap/TileLayer.js.map +0 -1
- package/lib/Tilemap/TileSet.d.ts +0 -7
- package/lib/Tilemap/TileSet.js +0 -24
- package/lib/Tilemap/TileSet.js.map +0 -1
- package/lib/Tilemap/index.d.ts +0 -28
- package/lib/Tilemap/index.js +0 -151
- package/lib/Tilemap/index.js.map +0 -1
- package/lib/clientEntryPoint.d.ts +0 -89
- package/lib/clientEntryPoint.js +0 -48
- package/lib/clientEntryPoint.js.map +0 -1
- package/lib/index.d.ts +0 -26
- package/lib/index.js +0 -27
- package/lib/index.js.map +0 -1
- package/lib/inject.d.ts +0 -23
- package/lib/inject.js +0 -30
- package/lib/inject.js.map +0 -1
- package/rpg.toml +0 -14
- package/src/Components/AbstractComponent.ts +0 -120
- package/src/Components/BarComponent.ts +0 -181
- package/src/Components/Component.ts +0 -515
- package/src/Components/DebugComponent.ts +0 -36
- package/src/Components/ImageComponent.ts +0 -30
- package/src/Components/ShapeComponent.ts +0 -64
- package/src/Components/TextComponent.ts +0 -33
- package/src/Components/TileComponent.ts +0 -43
- package/src/Effects/Animation.ts +0 -310
- package/src/Effects/AnimationCharacter.ts +0 -7
- package/src/Effects/Spinner.ts +0 -19
- package/src/Effects/Timeline.ts +0 -378
- package/src/Effects/TransitionScene.ts +0 -59
- package/src/GameEngine.ts +0 -289
- package/src/Gui/React.ts +0 -193
- package/src/Gui/Vue.ts +0 -154
- package/src/Interfaces/Character.ts +0 -7
- package/src/Interfaces/Scene.ts +0 -9
- package/src/KeyboardControls.ts +0 -748
- package/src/Logger.ts +0 -3
- package/src/Presets/Scene.ts +0 -3
- package/src/Renderer.ts +0 -334
- package/src/Resources.ts +0 -39
- package/src/Scene/EventLayer.ts +0 -9
- package/src/Scene/Map.ts +0 -402
- package/src/Scene/Scene.ts +0 -305
- package/src/Scene/SceneData.ts +0 -13
- package/src/Sound/RpgSound.ts +0 -50
- package/src/Sound/Sound.ts +0 -91
- package/src/Sound/Sounds.ts +0 -7
- package/src/Sprite/Character.ts +0 -157
- package/src/Sprite/Player.ts +0 -3
- package/src/Sprite/Spritesheet.ts +0 -392
- package/src/Sprite/Spritesheets.ts +0 -8
- package/src/Tilemap/CommonLayer.ts +0 -20
- package/src/Tilemap/ImageLayer.ts +0 -20
- package/src/Tilemap/Tile.ts +0 -80
- package/src/Tilemap/TileLayer.ts +0 -142
- package/src/Tilemap/TileSet.ts +0 -40
- package/src/Tilemap/index.ts +0 -175
- package/src/clientEntryPoint.ts +0 -150
- package/src/inject.ts +0 -34
- 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
|
-
}
|