@rpgjs/client 5.0.0-alpha.8 → 5.0.0-beta.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.
- package/dist/Game/AnimationManager.d.ts +8 -0
- package/dist/Game/AnimationManager.js +26 -0
- package/dist/Game/AnimationManager.js.map +1 -0
- package/dist/Game/Event.d.ts +1 -1
- package/dist/Game/Event.js +12 -0
- package/dist/Game/Event.js.map +1 -0
- package/dist/Game/Map.d.ts +23 -2
- package/dist/Game/Map.js +80 -0
- package/dist/Game/Map.js.map +1 -0
- package/dist/Game/Object.d.ts +157 -0
- package/dist/Game/Object.js +211 -0
- package/dist/Game/Object.js.map +1 -0
- package/dist/Game/Player.d.ts +1 -1
- package/dist/Game/Player.js +12 -0
- package/dist/Game/Player.js.map +1 -0
- package/dist/Gui/Gui.d.ts +177 -5
- package/dist/Gui/Gui.js +445 -0
- package/dist/Gui/Gui.js.map +1 -0
- package/dist/Gui/NotificationManager.d.ts +23 -0
- package/dist/Gui/NotificationManager.js +49 -0
- package/dist/Gui/NotificationManager.js.map +1 -0
- package/dist/Resource.d.ts +97 -0
- package/dist/Resource.js +133 -0
- package/dist/Resource.js.map +1 -0
- package/dist/RpgClient.d.ts +290 -58
- package/dist/RpgClientEngine.d.ts +649 -9
- package/dist/RpgClientEngine.js +1334 -0
- package/dist/RpgClientEngine.js.map +1 -0
- package/dist/Sound.d.ts +199 -0
- package/dist/Sound.js +167 -0
- package/dist/Sound.js.map +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/decorate.js +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/decorateMetadata.js +6 -0
- package/dist/components/animations/animation.ce.js +24 -0
- package/dist/components/animations/animation.ce.js.map +1 -0
- package/dist/components/animations/hit.ce.js +70 -0
- package/dist/components/animations/hit.ce.js.map +1 -0
- package/dist/components/animations/index.d.ts +4 -0
- package/dist/components/animations/index.js +11 -0
- package/dist/components/animations/index.js.map +1 -0
- package/dist/components/character.ce.js +392 -0
- package/dist/components/character.ce.js.map +1 -0
- package/dist/components/dynamics/parse-value.d.ts +1 -0
- package/dist/components/dynamics/parse-value.js +44 -0
- package/dist/components/dynamics/parse-value.js.map +1 -0
- package/dist/components/dynamics/text.ce.js +73 -0
- package/dist/components/dynamics/text.ce.js.map +1 -0
- package/dist/components/gui/box.ce.js +28 -0
- package/dist/components/gui/box.ce.js.map +1 -0
- package/dist/components/gui/dialogbox/index.ce.js +205 -0
- package/dist/components/gui/dialogbox/index.ce.js.map +1 -0
- package/dist/components/gui/gameover.ce.js +193 -0
- package/dist/components/gui/gameover.ce.js.map +1 -0
- package/dist/components/gui/hud/hud.ce.js +92 -0
- package/dist/components/gui/hud/hud.ce.js.map +1 -0
- package/dist/components/gui/index.d.ts +15 -3
- package/dist/components/gui/index.js +14 -0
- package/dist/components/gui/menu/equip-menu.ce.js +481 -0
- package/dist/components/gui/menu/equip-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/exit-menu.ce.js +54 -0
- package/dist/components/gui/menu/exit-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/items-menu.ce.js +344 -0
- package/dist/components/gui/menu/items-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/main-menu.ce.js +417 -0
- package/dist/components/gui/menu/main-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/options-menu.ce.js +48 -0
- package/dist/components/gui/menu/options-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/skills-menu.ce.js +107 -0
- package/dist/components/gui/menu/skills-menu.ce.js.map +1 -0
- package/dist/components/gui/mobile/index.d.ts +8 -0
- package/dist/components/gui/mobile/index.js +21 -0
- package/dist/components/gui/mobile/index.js.map +1 -0
- package/dist/components/gui/mobile/mobile.ce.js +78 -0
- package/dist/components/gui/mobile/mobile.ce.js.map +1 -0
- package/dist/components/gui/notification/notification.ce.js +64 -0
- package/dist/components/gui/notification/notification.ce.js.map +1 -0
- package/dist/components/gui/save-load.ce.js +389 -0
- package/dist/components/gui/save-load.ce.js.map +1 -0
- package/dist/components/gui/shop/shop.ce.js +652 -0
- package/dist/components/gui/shop/shop.ce.js.map +1 -0
- package/dist/components/gui/title-screen.ce.js +190 -0
- package/dist/components/gui/title-screen.ce.js.map +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +4 -0
- package/dist/components/prebuilt/hp-bar.ce.js +116 -0
- package/dist/components/prebuilt/hp-bar.ce.js.map +1 -0
- package/dist/components/prebuilt/index.d.ts +19 -0
- package/dist/components/prebuilt/index.js +2 -0
- package/dist/components/prebuilt/light-halo.ce.js +94 -0
- package/dist/components/prebuilt/light-halo.ce.js.map +1 -0
- package/dist/components/scenes/canvas.ce.js +60 -0
- package/dist/components/scenes/canvas.ce.js.map +1 -0
- package/dist/components/scenes/draw-map.ce.js +89 -0
- package/dist/components/scenes/draw-map.ce.js.map +1 -0
- package/dist/components/scenes/event-layer.ce.js +28 -0
- package/dist/components/scenes/event-layer.ce.js.map +1 -0
- package/dist/core/inject.js +18 -0
- package/dist/core/inject.js.map +1 -0
- package/dist/core/setup.js +16 -0
- package/dist/core/setup.js.map +1 -0
- package/dist/index.d.ts +15 -1
- package/dist/index.js +44 -14
- package/dist/module.d.ts +43 -4
- package/dist/module.js +176 -0
- package/dist/module.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_di@2.9.0/node_modules/@signe/di/dist/index.js +277 -0
- package/dist/node_modules/.pnpm/@signe_di@2.9.0/node_modules/@signe/di/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js +457 -0
- package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_reactive@2.9.0/node_modules/@signe/reactive/dist/index.js +463 -0
- package/dist/node_modules/.pnpm/@signe_reactive@2.9.0/node_modules/@signe/reactive/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js +2191 -0
- package/dist/node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js +10 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/client/index.js +91 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/client/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/index.js +325 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js +14 -0
- package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js +115 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js.map +1 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js +401 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +1 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/index.js +2 -0
- package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js +3756 -0
- package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +1 -0
- package/dist/presets/animation.d.ts +31 -0
- package/dist/presets/animation.js +39 -0
- package/dist/presets/animation.js.map +1 -0
- package/dist/presets/faceset.d.ts +30 -0
- package/dist/presets/faceset.js +51 -0
- package/dist/presets/faceset.js.map +1 -0
- package/dist/presets/icon.d.ts +20 -0
- package/dist/presets/icon.js +15 -0
- package/dist/presets/icon.js.map +1 -0
- package/dist/presets/index.d.ts +123 -0
- package/dist/presets/index.js +17 -0
- package/dist/presets/index.js.map +1 -0
- package/dist/presets/lpc.d.ts +89 -0
- package/dist/presets/lpc.js +98 -0
- package/dist/presets/lpc.js.map +1 -0
- package/dist/presets/rmspritesheet.js +42 -0
- package/dist/presets/rmspritesheet.js.map +1 -0
- package/dist/services/AbstractSocket.d.ts +9 -5
- package/dist/services/AbstractSocket.js +11 -0
- package/dist/services/AbstractSocket.js.map +1 -0
- package/dist/services/keyboardControls.d.ts +15 -0
- package/dist/services/keyboardControls.js +23 -0
- package/dist/services/keyboardControls.js.map +1 -0
- package/dist/services/loadMap.js +123 -0
- package/dist/services/loadMap.js.map +1 -0
- package/dist/services/mmorpg.d.ts +21 -9
- package/dist/services/mmorpg.js +131 -0
- package/dist/services/mmorpg.js.map +1 -0
- package/dist/services/save.d.ts +19 -0
- package/dist/services/save.js +77 -0
- package/dist/services/save.js.map +1 -0
- package/dist/services/standalone.d.ts +67 -7
- package/dist/services/standalone.js +168 -0
- package/dist/services/standalone.js.map +1 -0
- package/dist/utils/getEntityProp.d.ts +39 -0
- package/dist/utils/getEntityProp.js +52 -0
- package/dist/utils/getEntityProp.js.map +1 -0
- package/package.json +13 -9
- package/src/Game/{EffectManager.ts → AnimationManager.ts} +3 -2
- package/src/Game/Event.ts +1 -1
- package/src/Game/Map.ts +95 -3
- package/src/Game/Object.ts +330 -14
- package/src/Game/Player.ts +1 -1
- package/src/Gui/Gui.ts +506 -18
- package/src/Gui/NotificationManager.ts +69 -0
- package/src/Resource.ts +150 -0
- package/src/RpgClient.ts +300 -58
- package/src/RpgClientEngine.ts +1707 -48
- package/src/Sound.ts +253 -0
- package/src/components/{effects → animations}/animation.ce +3 -6
- package/src/components/{effects → animations}/index.ts +1 -1
- package/src/components/character.ce +406 -40
- package/src/components/dynamics/parse-value.ts +80 -0
- package/src/components/dynamics/text.ce +183 -0
- package/src/components/gui/box.ce +17 -0
- package/src/components/gui/dialogbox/index.ce +204 -187
- package/src/components/gui/gameover.ce +158 -0
- package/src/components/gui/hud/hud.ce +61 -0
- package/src/components/gui/index.ts +30 -4
- package/src/components/gui/menu/equip-menu.ce +410 -0
- package/src/components/gui/menu/exit-menu.ce +41 -0
- package/src/components/gui/menu/items-menu.ce +317 -0
- package/src/components/gui/menu/main-menu.ce +294 -0
- package/src/components/gui/menu/options-menu.ce +35 -0
- package/src/components/gui/menu/skills-menu.ce +83 -0
- package/src/components/gui/mobile/index.ts +24 -0
- package/src/components/gui/mobile/mobile.ce +80 -0
- package/src/components/gui/notification/notification.ce +51 -0
- package/src/components/gui/save-load.ce +208 -0
- package/src/components/gui/shop/shop.ce +493 -0
- package/src/components/gui/title-screen.ce +163 -0
- package/src/components/index.ts +3 -0
- package/src/components/prebuilt/hp-bar.ce +255 -0
- package/src/components/prebuilt/index.ts +24 -0
- package/src/components/prebuilt/light-halo.ce +148 -0
- package/src/components/scenes/canvas.ce +20 -15
- package/src/components/scenes/draw-map.ce +60 -13
- package/src/components/scenes/event-layer.ce +9 -2
- package/src/components/scenes/transition.ce +60 -0
- package/src/index.ts +16 -2
- package/src/module.ts +145 -9
- package/src/presets/animation.ts +46 -0
- package/src/presets/faceset.ts +60 -0
- package/src/presets/icon.ts +17 -0
- package/src/presets/index.ts +9 -1
- package/src/presets/lpc.ts +108 -0
- package/src/services/AbstractSocket.ts +10 -2
- package/src/services/keyboardControls.ts +20 -0
- package/src/services/loadMap.ts +1 -1
- package/src/services/mmorpg.ts +100 -12
- package/src/services/save.ts +103 -0
- package/src/services/standalone.ts +110 -18
- package/src/utils/getEntityProp.ts +87 -0
- package/tsconfig.json +1 -1
- package/vite.config.ts +4 -2
- package/dist/Game/EffectManager.d.ts +0 -5
- package/dist/components/effects/index.d.ts +0 -4
- package/dist/index.js.map +0 -1
- package/dist/index10.js +0 -8
- package/dist/index10.js.map +0 -1
- package/dist/index11.js +0 -10
- package/dist/index11.js.map +0 -1
- package/dist/index12.js +0 -8
- package/dist/index12.js.map +0 -1
- package/dist/index13.js +0 -17
- package/dist/index13.js.map +0 -1
- package/dist/index14.js +0 -91
- package/dist/index14.js.map +0 -1
- package/dist/index15.js +0 -50
- package/dist/index15.js.map +0 -1
- package/dist/index16.js +0 -191
- package/dist/index16.js.map +0 -1
- package/dist/index17.js +0 -9
- package/dist/index17.js.map +0 -1
- package/dist/index18.js +0 -387
- package/dist/index18.js.map +0 -1
- package/dist/index19.js +0 -31
- package/dist/index19.js.map +0 -1
- package/dist/index2.js +0 -112
- package/dist/index2.js.map +0 -1
- package/dist/index20.js +0 -24
- package/dist/index20.js.map +0 -1
- package/dist/index21.js +0 -2421
- package/dist/index21.js.map +0 -1
- package/dist/index22.js +0 -114
- package/dist/index22.js.map +0 -1
- package/dist/index23.js +0 -109
- package/dist/index23.js.map +0 -1
- package/dist/index24.js +0 -71
- package/dist/index24.js.map +0 -1
- package/dist/index25.js +0 -21
- package/dist/index25.js.map +0 -1
- package/dist/index26.js +0 -41
- package/dist/index26.js.map +0 -1
- package/dist/index27.js +0 -5
- package/dist/index27.js.map +0 -1
- package/dist/index28.js +0 -322
- package/dist/index28.js.map +0 -1
- package/dist/index29.js +0 -27
- package/dist/index29.js.map +0 -1
- package/dist/index3.js +0 -87
- package/dist/index3.js.map +0 -1
- package/dist/index30.js +0 -11
- package/dist/index30.js.map +0 -1
- package/dist/index31.js +0 -11
- package/dist/index31.js.map +0 -1
- package/dist/index32.js +0 -12
- package/dist/index32.js.map +0 -1
- package/dist/index33.js +0 -4403
- package/dist/index33.js.map +0 -1
- package/dist/index34.js +0 -316
- package/dist/index34.js.map +0 -1
- package/dist/index35.js +0 -174
- package/dist/index35.js.map +0 -1
- package/dist/index36.js +0 -501
- package/dist/index36.js.map +0 -1
- package/dist/index37.js +0 -61
- package/dist/index37.js.map +0 -1
- package/dist/index38.js +0 -20
- package/dist/index38.js.map +0 -1
- package/dist/index39.js +0 -20
- package/dist/index39.js.map +0 -1
- package/dist/index4.js +0 -67
- package/dist/index4.js.map +0 -1
- package/dist/index5.js +0 -16
- package/dist/index5.js.map +0 -1
- package/dist/index6.js +0 -17
- package/dist/index6.js.map +0 -1
- package/dist/index7.js +0 -39
- package/dist/index7.js.map +0 -1
- package/dist/index8.js +0 -90
- package/dist/index8.js.map +0 -1
- package/dist/index9.js +0 -76
- package/dist/index9.js.map +0 -1
- package/src/components/gui/dialogbox/itemMenu.ce +0 -23
- package/src/components/gui/dialogbox/selection.ce +0 -67
- /package/src/components/{effects → animations}/hit.ce +0 -0
package/src/Sound.ts
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { Howler } from 'canvasengine';
|
|
2
|
+
import { RpgClientEngine } from './RpgClientEngine';
|
|
3
|
+
import { inject } from './core/inject';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Sound decorator options
|
|
7
|
+
*
|
|
8
|
+
* Defines the configuration for a sound that can be played in the game.
|
|
9
|
+
* The sound can be a single file or multiple files (for different formats).
|
|
10
|
+
*
|
|
11
|
+
* @interface SoundOptions
|
|
12
|
+
*/
|
|
13
|
+
export interface SoundOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Sound identifier. Used to retrieve the sound later with RpgSound.get()
|
|
16
|
+
*
|
|
17
|
+
* @type {string}
|
|
18
|
+
*/
|
|
19
|
+
id?: string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Single sound file path. Use require() to wrap the path.
|
|
23
|
+
*
|
|
24
|
+
* @type {string}
|
|
25
|
+
* @example
|
|
26
|
+
* sound: require('./assets/sound.ogg')
|
|
27
|
+
*/
|
|
28
|
+
sound?: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Multiple sounds with different IDs. The key is the sound ID and the value is the file path.
|
|
32
|
+
* Use require() to wrap each path.
|
|
33
|
+
*
|
|
34
|
+
* @type {{ [id: string]: string }}
|
|
35
|
+
* @example
|
|
36
|
+
* sounds: {
|
|
37
|
+
* hero: require('./assets/hero.ogg'),
|
|
38
|
+
* monster: require('./assets/monster.ogg')
|
|
39
|
+
* }
|
|
40
|
+
*/
|
|
41
|
+
sounds?: { [id: string]: string };
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Whether the sound should loop when it finishes playing.
|
|
45
|
+
*
|
|
46
|
+
* @type {boolean}
|
|
47
|
+
* @default false
|
|
48
|
+
*/
|
|
49
|
+
loop?: boolean;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Volume level (0.0 to 1.0).
|
|
53
|
+
*
|
|
54
|
+
* @type {number}
|
|
55
|
+
* @default 1.0
|
|
56
|
+
*/
|
|
57
|
+
volume?: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Metadata stored on the class decorated with @Sound
|
|
62
|
+
*
|
|
63
|
+
* @interface SoundMetadata
|
|
64
|
+
*/
|
|
65
|
+
interface SoundMetadata {
|
|
66
|
+
id?: string;
|
|
67
|
+
sound?: string;
|
|
68
|
+
sounds?: { [id: string]: string };
|
|
69
|
+
loop?: boolean;
|
|
70
|
+
volume?: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const SOUND_METADATA_KEY = Symbol('rpgjs:sound');
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Sound decorator
|
|
77
|
+
*
|
|
78
|
+
* Decorates a class to define a sound configuration. The decorated class can be
|
|
79
|
+
* added to the RpgClient module configuration, and the sound will be automatically
|
|
80
|
+
* registered and available through RpgSound.get().
|
|
81
|
+
*
|
|
82
|
+
* ## Design
|
|
83
|
+
*
|
|
84
|
+
* The decorator stores metadata on the class that is later used by the module loader
|
|
85
|
+
* to register sounds with the engine. The sound is created using Howler.js for
|
|
86
|
+
* advanced audio features like looping, volume control, and cross-browser compatibility.
|
|
87
|
+
*
|
|
88
|
+
* @param options - Sound configuration options
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { Sound } from '@rpgjs/client'
|
|
93
|
+
*
|
|
94
|
+
* @Sound({
|
|
95
|
+
* id: 'town-music',
|
|
96
|
+
* sound: require('./sound/town.ogg'),
|
|
97
|
+
* loop: true,
|
|
98
|
+
* volume: 0.5
|
|
99
|
+
* })
|
|
100
|
+
* export class TownMusic {}
|
|
101
|
+
*
|
|
102
|
+
* // Multiple sounds in one class
|
|
103
|
+
* @Sound({
|
|
104
|
+
* sounds: {
|
|
105
|
+
* hero: require('./assets/hero.ogg'),
|
|
106
|
+
* monster: require('./assets/monster.ogg')
|
|
107
|
+
* },
|
|
108
|
+
* loop: true
|
|
109
|
+
* })
|
|
110
|
+
* export class CharacterSounds {}
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export function Sound(options: SoundOptions) {
|
|
114
|
+
return function <T extends { new (...args: any[]): {} }>(constructor: T) {
|
|
115
|
+
const metadata: SoundMetadata = {
|
|
116
|
+
id: options.id,
|
|
117
|
+
sound: options.sound,
|
|
118
|
+
sounds: options.sounds,
|
|
119
|
+
loop: options.loop,
|
|
120
|
+
volume: options.volume,
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// Store metadata on the class
|
|
124
|
+
(constructor as any)[SOUND_METADATA_KEY] = metadata;
|
|
125
|
+
|
|
126
|
+
return constructor;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Get sound metadata from a decorated class
|
|
132
|
+
*
|
|
133
|
+
* @param soundClass - The class decorated with @Sound
|
|
134
|
+
* @returns The sound metadata or undefined
|
|
135
|
+
*/
|
|
136
|
+
export function getSoundMetadata(soundClass: any): SoundMetadata | undefined {
|
|
137
|
+
return (soundClass as any)[SOUND_METADATA_KEY];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* RpgSound class
|
|
142
|
+
*
|
|
143
|
+
* Provides a unified API to manage sounds in the game. Uses Howler.js internally
|
|
144
|
+
* for advanced audio features. Sounds can be retrieved by ID and controlled
|
|
145
|
+
* using Howler.js methods.
|
|
146
|
+
*
|
|
147
|
+
* ## Design
|
|
148
|
+
*
|
|
149
|
+
* RpgSound acts as a facade over Howler.js, providing easy access to sounds
|
|
150
|
+
* registered in the engine. It supports both individual sound control and
|
|
151
|
+
* global sound management (volume, mute, etc.).
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* import { RpgSound } from '@rpgjs/client'
|
|
156
|
+
*
|
|
157
|
+
* // Play a sound
|
|
158
|
+
* RpgSound.get('town-music').play()
|
|
159
|
+
*
|
|
160
|
+
* // Control volume
|
|
161
|
+
* RpgSound.get('town-music').volume(0.5)
|
|
162
|
+
*
|
|
163
|
+
* // Stop a sound
|
|
164
|
+
* RpgSound.get('town-music').stop()
|
|
165
|
+
*
|
|
166
|
+
* // Global volume control
|
|
167
|
+
* RpgSound.global.volume(0.2)
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export class RpgSound {
|
|
171
|
+
private static engine: RpgClientEngine | null = null;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Initialize RpgSound with the engine instance
|
|
175
|
+
*
|
|
176
|
+
* This is called automatically by the engine during initialization.
|
|
177
|
+
*
|
|
178
|
+
* @param engine - The RpgClientEngine instance
|
|
179
|
+
*/
|
|
180
|
+
static init(engine: RpgClientEngine): void {
|
|
181
|
+
RpgSound.engine = engine;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Get a sound by its ID
|
|
186
|
+
*
|
|
187
|
+
* Retrieves a Howler sound instance from the engine's sound cache.
|
|
188
|
+
* The sound must be registered beforehand (via @Sound decorator or manually).
|
|
189
|
+
*
|
|
190
|
+
* @param id - The sound identifier
|
|
191
|
+
* @returns The Howler sound instance, or undefined if not found
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* // Get and play a sound
|
|
196
|
+
* const sound = RpgSound.get('town-music');
|
|
197
|
+
* if (sound) {
|
|
198
|
+
* sound.play();
|
|
199
|
+
* }
|
|
200
|
+
*
|
|
201
|
+
* // Chain methods
|
|
202
|
+
* RpgSound.get('battle-theme')?.volume(0.8).play();
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
static get(id: string): any {
|
|
206
|
+
if (!RpgSound.engine) {
|
|
207
|
+
console.warn('RpgSound not initialized. Make sure the engine has started.');
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const sound = RpgSound.engine.sounds.get(id);
|
|
212
|
+
if (!sound) {
|
|
213
|
+
console.warn(`Sound with id "${id}" not found`);
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// If the sound is a Howler instance, return it directly
|
|
218
|
+
if (sound && typeof sound.play === 'function') {
|
|
219
|
+
return sound;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// If the sound has a src property, try to create a Howler instance
|
|
223
|
+
if (sound && sound.src) {
|
|
224
|
+
// This should have been handled during addSound, but just in case
|
|
225
|
+
return sound;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return sound;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Global Howler instance for managing all sounds
|
|
233
|
+
*
|
|
234
|
+
* Provides access to Howler.js global methods for controlling all sounds
|
|
235
|
+
* at once (volume, mute, etc.).
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* // Set global volume to 20%
|
|
240
|
+
* RpgSound.global.volume(0.2)
|
|
241
|
+
*
|
|
242
|
+
* // Mute all sounds
|
|
243
|
+
* RpgSound.global.mute(true)
|
|
244
|
+
*
|
|
245
|
+
* // Unmute all sounds
|
|
246
|
+
* RpgSound.global.mute(false)
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
static get global(): typeof Howler {
|
|
250
|
+
return Howler;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
<Sprite sheet x y anchor={0.5} />
|
|
2
2
|
|
|
3
3
|
<script>
|
|
4
|
-
import { signal } from "canvasengine";
|
|
5
4
|
import { RpgClientEngine } from "../../RpgClientEngine";
|
|
6
5
|
import { inject } from "../../core/inject";
|
|
7
6
|
|
|
8
|
-
const { x, y,
|
|
7
|
+
const { x, y, animationName, graphic, onFinish } = defineProps();
|
|
9
8
|
|
|
10
9
|
const client = inject(RpgClientEngine);
|
|
11
|
-
const spritesheets = client.spritesheets;
|
|
12
10
|
|
|
13
11
|
const sheet = {
|
|
14
|
-
definition:
|
|
15
|
-
playing: 'default',
|
|
12
|
+
definition: client.getSpriteSheet(graphic()),
|
|
13
|
+
playing: animationName() ?? 'default',
|
|
16
14
|
onFinish
|
|
17
15
|
};
|
|
18
|
-
|
|
19
16
|
</script>
|