@rpgjs/client 5.0.0-alpha.21 → 5.0.0-alpha.23

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 (135) hide show
  1. package/dist/Game/Object.d.ts +111 -0
  2. package/dist/Game/TransitionManager.d.ts +56 -0
  3. package/dist/RpgClientEngine.d.ts +306 -9
  4. package/dist/components/gui/mobile/index.d.ts +8 -0
  5. package/dist/components/prebuilt/index.d.ts +1 -0
  6. package/dist/index.d.ts +7 -1
  7. package/dist/index.js +14 -8
  8. package/dist/index.js.map +1 -1
  9. package/dist/index10.js +1 -1
  10. package/dist/index11.js +6 -5
  11. package/dist/index11.js.map +1 -1
  12. package/dist/index12.js +2 -2
  13. package/dist/index13.js +102 -10
  14. package/dist/index13.js.map +1 -1
  15. package/dist/index14.js +68 -9
  16. package/dist/index14.js.map +1 -1
  17. package/dist/index15.js +10 -224
  18. package/dist/index15.js.map +1 -1
  19. package/dist/index16.js +9 -97
  20. package/dist/index16.js.map +1 -1
  21. package/dist/index17.js +300 -89
  22. package/dist/index17.js.map +1 -1
  23. package/dist/index18.js +63 -80
  24. package/dist/index18.js.map +1 -1
  25. package/dist/index19.js +96 -348
  26. package/dist/index19.js.map +1 -1
  27. package/dist/index2.js +387 -21
  28. package/dist/index2.js.map +1 -1
  29. package/dist/index20.js +361 -5
  30. package/dist/index20.js.map +1 -1
  31. package/dist/index21.js +19 -50
  32. package/dist/index21.js.map +1 -1
  33. package/dist/index22.js +212 -5
  34. package/dist/index22.js.map +1 -1
  35. package/dist/index23.js +6 -395
  36. package/dist/index23.js.map +1 -1
  37. package/dist/index24.js +4 -39
  38. package/dist/index24.js.map +1 -1
  39. package/dist/index25.js +19 -20
  40. package/dist/index25.js.map +1 -1
  41. package/dist/index26.js +44 -2624
  42. package/dist/index26.js.map +1 -1
  43. package/dist/index27.js +5 -110
  44. package/dist/index27.js.map +1 -1
  45. package/dist/index28.js +394 -65
  46. package/dist/index28.js.map +1 -1
  47. package/dist/index29.js +40 -15
  48. package/dist/index29.js.map +1 -1
  49. package/dist/index3.js +3 -3
  50. package/dist/index30.js +21 -23
  51. package/dist/index30.js.map +1 -1
  52. package/dist/index31.js +49 -91
  53. package/dist/index31.js.map +1 -1
  54. package/dist/index32.js +2624 -32
  55. package/dist/index32.js.map +1 -1
  56. package/dist/index33.js +108 -18
  57. package/dist/index33.js.map +1 -1
  58. package/dist/index34.js +69 -3
  59. package/dist/index34.js.map +1 -1
  60. package/dist/index35.js +17 -331
  61. package/dist/index35.js.map +1 -1
  62. package/dist/index36.js +24 -24
  63. package/dist/index36.js.map +1 -1
  64. package/dist/index37.js +92 -8
  65. package/dist/index37.js.map +1 -1
  66. package/dist/index38.js +37 -7
  67. package/dist/index38.js.map +1 -1
  68. package/dist/index39.js +22 -10
  69. package/dist/index39.js.map +1 -1
  70. package/dist/index4.js +3 -3
  71. package/dist/index40.js +140 -6
  72. package/dist/index40.js.map +1 -1
  73. package/dist/index41.js +31 -3678
  74. package/dist/index41.js.map +1 -1
  75. package/dist/index42.js +3 -185
  76. package/dist/index42.js.map +1 -1
  77. package/dist/index43.js +172 -489
  78. package/dist/index43.js.map +1 -1
  79. package/dist/index44.js +498 -71
  80. package/dist/index44.js.map +1 -1
  81. package/dist/index45.js +331 -2
  82. package/dist/index45.js.map +1 -1
  83. package/dist/index46.js +25 -11
  84. package/dist/index46.js.map +1 -1
  85. package/dist/index47.js +70 -139
  86. package/dist/index47.js.map +1 -1
  87. package/dist/index48.js +9 -9
  88. package/dist/index48.js.map +1 -1
  89. package/dist/index49.js +6 -112
  90. package/dist/index49.js.map +1 -1
  91. package/dist/index5.js +1 -1
  92. package/dist/index50.js +3678 -124
  93. package/dist/index50.js.map +1 -1
  94. package/dist/index51.js +48 -131
  95. package/dist/index51.js.map +1 -1
  96. package/dist/index52.js +17 -109
  97. package/dist/index52.js.map +1 -1
  98. package/dist/index53.js +3 -138
  99. package/dist/index53.js.map +1 -1
  100. package/dist/index54.js +10 -7
  101. package/dist/index54.js.map +1 -1
  102. package/dist/index55.js +107 -48
  103. package/dist/index55.js.map +1 -1
  104. package/dist/index56.js +136 -0
  105. package/dist/index56.js.map +1 -0
  106. package/dist/index57.js +137 -0
  107. package/dist/index57.js.map +1 -0
  108. package/dist/index58.js +112 -0
  109. package/dist/index58.js.map +1 -0
  110. package/dist/index59.js +9 -0
  111. package/dist/index59.js.map +1 -0
  112. package/dist/index6.js +1 -1
  113. package/dist/index7.js +1 -1
  114. package/dist/index8.js +20 -2
  115. package/dist/index8.js.map +1 -1
  116. package/dist/index9.js +11 -27
  117. package/dist/index9.js.map +1 -1
  118. package/dist/module.d.ts +43 -4
  119. package/dist/services/keyboardControls.d.ts +11 -1
  120. package/package.json +11 -10
  121. package/src/Game/Object.ts +90 -8
  122. package/src/Game/TransitionManager.ts +75 -0
  123. package/src/Gui/Gui.ts +5 -31
  124. package/src/RpgClientEngine.ts +430 -16
  125. package/src/components/character.ce +212 -11
  126. package/src/components/gui/mobile/index.ts +24 -0
  127. package/src/components/gui/mobile/mobile.ce +95 -0
  128. package/src/components/prebuilt/index.ts +2 -0
  129. package/src/components/prebuilt/light-halo.ce +217 -0
  130. package/src/components/scenes/canvas.ce +12 -2
  131. package/src/components/scenes/draw-map.ce +12 -3
  132. package/src/components/scenes/transition.ce +60 -0
  133. package/src/index.ts +7 -1
  134. package/src/module.ts +66 -2
  135. package/src/services/keyboardControls.ts +14 -2
package/dist/index18.js CHANGED
@@ -1,114 +1,97 @@
1
- class RpgResource {
1
+ import { Howler } from 'canvasengine';
2
+
3
+ const SOUND_METADATA_KEY = Symbol("rpgjs:sound");
4
+ function Sound(options) {
5
+ return function(constructor) {
6
+ const metadata = {
7
+ id: options.id,
8
+ sound: options.sound,
9
+ sounds: options.sounds,
10
+ loop: options.loop,
11
+ volume: options.volume
12
+ };
13
+ constructor[SOUND_METADATA_KEY] = metadata;
14
+ return constructor;
15
+ };
16
+ }
17
+ function getSoundMetadata(soundClass) {
18
+ return soundClass[SOUND_METADATA_KEY];
19
+ }
20
+ class RpgSound {
2
21
  static {
3
22
  this.engine = null;
4
23
  }
5
- static {
6
- this._spritesheets = /* @__PURE__ */ new Map();
7
- }
8
- static {
9
- this._sounds = /* @__PURE__ */ new Map();
10
- }
11
24
  /**
12
- * Initialize RpgResource with the engine instance
25
+ * Initialize RpgSound with the engine instance
13
26
  *
14
27
  * This is called automatically by the engine during initialization.
15
- * It synchronizes the resource Maps with the engine's internal storage.
16
28
  *
17
29
  * @param engine - The RpgClientEngine instance
18
30
  */
19
31
  static init(engine) {
20
- RpgResource.engine = engine;
21
- RpgResource.syncResources();
32
+ RpgSound.engine = engine;
22
33
  }
23
34
  /**
24
- * Synchronize resource Maps with the engine's internal storage
35
+ * Get a sound by its ID
25
36
  *
26
- * Extracts file links from spritesheets and sounds stored in the engine
27
- * and updates the Maps accordingly.
37
+ * Retrieves a Howler sound instance from the engine's sound cache.
38
+ * The sound must be registered beforehand (via @Sound decorator or manually).
28
39
  *
29
- * @private
30
- */
31
- static syncResources() {
32
- if (!RpgResource.engine) {
33
- return;
34
- }
35
- RpgResource._spritesheets.clear();
36
- RpgResource.engine.spritesheets.forEach((spritesheet, id) => {
37
- const imageLink = spritesheet?.image || spritesheet?.imageSource || void 0;
38
- if (imageLink) {
39
- RpgResource._spritesheets.set(id, imageLink);
40
- }
41
- });
42
- RpgResource._sounds.clear();
43
- RpgResource.engine.sounds.forEach((sound, id) => {
44
- let soundLink;
45
- if (sound && typeof sound === "object") {
46
- if (sound._src && Array.isArray(sound._src) && sound._src.length > 0) {
47
- soundLink = sound._src[0];
48
- } else if (sound.src && typeof sound.src === "string") {
49
- soundLink = sound.src;
50
- } else if (sound.src && Array.isArray(sound.src) && sound.src.length > 0) {
51
- soundLink = sound.src[0];
52
- }
53
- }
54
- if (soundLink) {
55
- RpgResource._sounds.set(id, soundLink);
56
- }
57
- });
58
- }
59
- /**
60
- * Get/Set image links for spritesheets
61
- *
62
- * Map of spritesheet IDs to their image file paths/URLs.
63
- * This Map is synchronized with the engine's spritesheet storage.
64
- *
65
- * @type {Map<string, string>}
40
+ * @param id - The sound identifier
41
+ * @returns The Howler sound instance, or undefined if not found
66
42
  *
67
43
  * @example
68
44
  * ```ts
69
- * // Get an image link
70
- * const imageLink = RpgResource.spritesheets.get('hero')
71
- *
72
- * // Set a new image link
73
- * RpgResource.spritesheets.set('new-sprite', './assets/new-sprite.png')
74
- *
75
- * // Check if a spritesheet exists
76
- * if (RpgResource.spritesheets.has('monster')) {
77
- * const link = RpgResource.spritesheets.get('monster')
45
+ * // Get and play a sound
46
+ * const sound = RpgSound.get('town-music');
47
+ * if (sound) {
48
+ * sound.play();
78
49
  * }
50
+ *
51
+ * // Chain methods
52
+ * RpgSound.get('battle-theme')?.volume(0.8).play();
79
53
  * ```
80
54
  */
81
- static get spritesheets() {
82
- RpgResource.syncResources();
83
- return RpgResource._spritesheets;
55
+ static get(id) {
56
+ if (!RpgSound.engine) {
57
+ console.warn("RpgSound not initialized. Make sure the engine has started.");
58
+ return void 0;
59
+ }
60
+ const sound = RpgSound.engine.sounds.get(id);
61
+ if (!sound) {
62
+ console.warn(`Sound with id "${id}" not found`);
63
+ return void 0;
64
+ }
65
+ if (sound && typeof sound.play === "function") {
66
+ return sound;
67
+ }
68
+ if (sound && sound.src) {
69
+ return sound;
70
+ }
71
+ return sound;
84
72
  }
85
73
  /**
86
- * Get/Set sound file links
87
- *
88
- * Map of sound IDs to their audio file paths/URLs.
89
- * This Map is synchronized with the engine's sound storage.
74
+ * Global Howler instance for managing all sounds
90
75
  *
91
- * @type {Map<string, string>}
76
+ * Provides access to Howler.js global methods for controlling all sounds
77
+ * at once (volume, mute, etc.).
92
78
  *
93
79
  * @example
94
80
  * ```ts
95
- * // Get a sound link
96
- * const soundLink = RpgResource.sounds.get('town-music')
81
+ * // Set global volume to 20%
82
+ * RpgSound.global.volume(0.2)
97
83
  *
98
- * // Set a new sound link
99
- * RpgResource.sounds.set('new-sound', './assets/new-sound.ogg')
84
+ * // Mute all sounds
85
+ * RpgSound.global.mute(true)
100
86
  *
101
- * // Iterate over all sounds
102
- * RpgResource.sounds.forEach((link, id) => {
103
- * console.log(`Sound ${id}: ${link}`)
104
- * })
87
+ * // Unmute all sounds
88
+ * RpgSound.global.mute(false)
105
89
  * ```
106
90
  */
107
- static get sounds() {
108
- RpgResource.syncResources();
109
- return RpgResource._sounds;
91
+ static get global() {
92
+ return Howler;
110
93
  }
111
94
  }
112
95
 
113
- export { RpgResource };
96
+ export { RpgSound, Sound, getSoundMetadata };
114
97
  //# sourceMappingURL=index18.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index18.js","sources":["../src/Resource.ts"],"sourcesContent":["import { RpgClientEngine } from './RpgClientEngine';\n\n/**\n * RpgResource class\n * \n * Provides a unified API to access resource file links (images and sounds) in the game.\n * Resources are stored as Maps of resource IDs to file paths/URLs.\n * \n * ## Design\n * \n * RpgResource acts as a facade over the engine's resource storage, providing\n * easy access to resource file links. It maintains Maps that are synchronized\n * with the engine's internal storage, but only stores the file paths/URLs,\n * not the full resource objects.\n * \n * @example\n * ```ts\n * import { RpgResource } from '@rpgjs/client'\n * \n * // Get spritesheet image link\n * const imageLink = RpgResource.spritesheets.get('hero')\n * \n * // Get sound file link\n * const soundLink = RpgResource.sounds.get('town-music')\n * \n * // Set a new resource link\n * RpgResource.spritesheets.set('new-sprite', './assets/new-sprite.png')\n * ```\n */\nexport class RpgResource {\n private static engine: RpgClientEngine | null = null;\n private static _spritesheets: Map<string, string> = new Map();\n private static _sounds: Map<string, string> = new Map();\n\n /**\n * Initialize RpgResource with the engine instance\n * \n * This is called automatically by the engine during initialization.\n * It synchronizes the resource Maps with the engine's internal storage.\n * \n * @param engine - The RpgClientEngine instance\n */\n static init(engine: RpgClientEngine): void {\n RpgResource.engine = engine;\n RpgResource.syncResources();\n }\n\n /**\n * Synchronize resource Maps with the engine's internal storage\n * \n * Extracts file links from spritesheets and sounds stored in the engine\n * and updates the Maps accordingly.\n * \n * @private\n */\n private static syncResources(): void {\n if (!RpgResource.engine) {\n return;\n }\n\n // Sync spritesheets\n RpgResource._spritesheets.clear();\n RpgResource.engine.spritesheets.forEach((spritesheet, id) => {\n // Extract image path from spritesheet\n const imageLink = spritesheet?.image || spritesheet?.imageSource || undefined;\n if (imageLink) {\n RpgResource._spritesheets.set(id, imageLink);\n }\n });\n\n // Sync sounds\n RpgResource._sounds.clear();\n RpgResource.engine.sounds.forEach((sound, id) => {\n // Extract src path from sound\n let soundLink: string | undefined;\n \n // If it's a Howler instance, try to get src from _src or src property\n if (sound && typeof sound === 'object') {\n if (sound._src && Array.isArray(sound._src) && sound._src.length > 0) {\n soundLink = sound._src[0];\n } else if (sound.src && typeof sound.src === 'string') {\n soundLink = sound.src;\n } else if (sound.src && Array.isArray(sound.src) && sound.src.length > 0) {\n soundLink = sound.src[0];\n }\n }\n \n if (soundLink) {\n RpgResource._sounds.set(id, soundLink);\n }\n });\n }\n\n /**\n * Get/Set image links for spritesheets\n * \n * Map of spritesheet IDs to their image file paths/URLs.\n * This Map is synchronized with the engine's spritesheet storage.\n * \n * @type {Map<string, string>}\n * \n * @example\n * ```ts\n * // Get an image link\n * const imageLink = RpgResource.spritesheets.get('hero')\n * \n * // Set a new image link\n * RpgResource.spritesheets.set('new-sprite', './assets/new-sprite.png')\n * \n * // Check if a spritesheet exists\n * if (RpgResource.spritesheets.has('monster')) {\n * const link = RpgResource.spritesheets.get('monster')\n * }\n * ```\n */\n static get spritesheets(): Map<string, string> {\n // Sync before returning to ensure we have the latest data\n RpgResource.syncResources();\n return RpgResource._spritesheets;\n }\n\n /**\n * Get/Set sound file links\n * \n * Map of sound IDs to their audio file paths/URLs.\n * This Map is synchronized with the engine's sound storage.\n * \n * @type {Map<string, string>}\n * \n * @example\n * ```ts\n * // Get a sound link\n * const soundLink = RpgResource.sounds.get('town-music')\n * \n * // Set a new sound link\n * RpgResource.sounds.set('new-sound', './assets/new-sound.ogg')\n * \n * // Iterate over all sounds\n * RpgResource.sounds.forEach((link, id) => {\n * console.log(`Sound ${id}: ${link}`)\n * })\n * ```\n */\n static get sounds(): Map<string, string> {\n // Sync before returning to ensure we have the latest data\n RpgResource.syncResources();\n return RpgResource._sounds;\n }\n}\n\n"],"names":[],"mappings":"AA6BO,MAAM,WAAA,CAAY;AAAA,EACvB;AAAA,IAAA,IAAA,CAAe,MAAA,GAAiC,IAAA;AAAA;AAAA,EAChD;AAAA,IAAA,IAAA,CAAe,aAAA,uBAAyC,GAAA,EAAI;AAAA;AAAA,EAC5D;AAAA,IAAA,IAAA,CAAe,OAAA,uBAAmC,GAAA,EAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUtD,OAAO,KAAK,MAAA,EAA+B;AACzC,IAAA,WAAA,CAAY,MAAA,GAAS,MAAA;AACrB,IAAA,WAAA,CAAY,aAAA,EAAc;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAe,aAAA,GAAsB;AACnC,IAAA,IAAI,CAAC,YAAY,MAAA,EAAQ;AACvB,MAAA;AAAA,IACF;AAGA,IAAA,WAAA,CAAY,cAAc,KAAA,EAAM;AAChC,IAAA,WAAA,CAAY,MAAA,CAAO,YAAA,CAAa,OAAA,CAAQ,CAAC,aAAa,EAAA,KAAO;AAE3D,MAAA,MAAM,SAAA,GAAY,WAAA,EAAa,KAAA,IAAS,WAAA,EAAa,WAAA,IAAe,MAAA;AACpE,MAAA,IAAI,SAAA,EAAW;AACb,QAAA,WAAA,CAAY,aAAA,CAAc,GAAA,CAAI,EAAA,EAAI,SAAS,CAAA;AAAA,MAC7C;AAAA,IACF,CAAC,CAAA;AAGD,IAAA,WAAA,CAAY,QAAQ,KAAA,EAAM;AAC1B,IAAA,WAAA,CAAY,MAAA,CAAO,MAAA,CAAO,OAAA,CAAQ,CAAC,OAAO,EAAA,KAAO;AAE/C,MAAA,IAAI,SAAA;AAGJ,MAAA,IAA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AY,OAAA;AAAA,EACrB;AACF;;;;"}
1
+ {"version":3,"file":"index18.js","sources":["../src/Sound.ts"],"sourcesContent":["import { Howler } from 'canvasengine';\nimport { RpgClientEngine } from './RpgClientEngine';\nimport { inject } from './core/inject';\n\n/**\n * Sound decorator options\n * \n * Defines the configuration for a sound that can be played in the game.\n * The sound can be a single file or multiple files (for different formats).\n * \n * @interface SoundOptions\n */\nexport interface SoundOptions {\n /**\n * Sound identifier. Used to retrieve the sound later with RpgSound.get()\n * \n * @type {string}\n */\n id?: string;\n\n /**\n * Single sound file path. Use require() to wrap the path.\n * \n * @type {string}\n * @example\n * sound: require('./assets/sound.ogg')\n */\n sound?: string;\n\n /**\n * Multiple sounds with different IDs. The key is the sound ID and the value is the file path.\n * Use require() to wrap each path.\n * \n * @type {{ [id: string]: string }}\n * @example\n * sounds: {\n * hero: require('./assets/hero.ogg'),\n * monster: require('./assets/monster.ogg')\n * }\n */\n sounds?: { [id: string]: string };\n\n /**\n * Whether the sound should loop when it finishes playing.\n * \n * @type {boolean}\n * @default false\n */\n loop?: boolean;\n\n /**\n * Volume level (0.0 to 1.0).\n * \n * @type {number}\n * @default 1.0\n */\n volume?: number;\n}\n\n/**\n * Metadata stored on the class decorated with @Sound\n * \n * @interface SoundMetadata\n */\ninterface SoundMetadata {\n id?: string;\n sound?: string;\n sounds?: { [id: string]: string };\n loop?: boolean;\n volume?: number;\n}\n\nconst SOUND_METADATA_KEY = Symbol('rpgjs:sound');\n\n/**\n * Sound decorator\n * \n * Decorates a class to define a sound configuration. The decorated class can be\n * added to the RpgClient module configuration, and the sound will be automatically\n * registered and available through RpgSound.get().\n * \n * ## Design\n * \n * The decorator stores metadata on the class that is later used by the module loader\n * to register sounds with the engine. The sound is created using Howler.js for\n * advanced audio features like looping, volume control, and cross-browser compatibility.\n * \n * @param options - Sound configuration options\n * \n * @example\n * ```ts\n * import { Sound } from '@rpgjs/client'\n * \n * @Sound({\n * id: 'town-music',\n * sound: require('./sound/town.ogg'),\n * loop: true,\n * volume: 0.5\n * })\n * export class TownMusic {}\n * \n * // Multiple sounds in one class\n * @Sound({\n * sounds: {\n * hero: require('./assets/hero.ogg'),\n * monster: require('./assets/monster.ogg')\n * },\n * loop: true\n * })\n * export class CharacterSounds {}\n * ```\n */\nexport function Sound(options: SoundOptions) {\n return function <T extends { new (...args: any[]): {} }>(constructor: T) {\n const metadata: SoundMetadata = {\n id: options.id,\n sound: options.sound,\n sounds: options.sounds,\n loop: options.loop,\n volume: options.volume,\n };\n\n // Store metadata on the class\n (constructor as any)[SOUND_METADATA_KEY] = metadata;\n\n return constructor;\n };\n}\n\n/**\n * Get sound metadata from a decorated class\n * \n * @param soundClass - The class decorated with @Sound\n * @returns The sound metadata or undefined\n */\nexport function getSoundMetadata(soundClass: any): SoundMetadata | undefined {\n return (soundClass as any)[SOUND_METADATA_KEY];\n}\n\n/**\n * RpgSound class\n * \n * Provides a unified API to manage sounds in the game. Uses Howler.js internally\n * for advanced audio features. Sounds can be retrieved by ID and controlled\n * using Howler.js methods.\n * \n * ## Design\n * \n * RpgSound acts as a facade over Howler.js, providing easy access to sounds\n * registered in the engine. It supports both individual sound control and\n * global sound management (volume, mute, etc.).\n * \n * @example\n * ```ts\n * import { RpgSound } from '@rpgjs/client'\n * \n * // Play a sound\n * RpgSound.get('town-music').play()\n * \n * // Control volume\n * RpgSound.get('town-music').volume(0.5)\n * \n * // Stop a sound\n * RpgSound.get('town-music').stop()\n * \n * // Global volume control\n * RpgSound.global.volume(0.2)\n * ```\n */\nexport class RpgSound {\n private static engine: RpgClientEngine | null = null;\n\n /**\n * Initialize RpgSound with the engine instance\n * \n * This is called automatically by the engine during initialization.\n * \n * @param engine - The RpgClientEngine instance\n */\n static init(engine: RpgClientEngine): void {\n RpgSound.engine = engine;\n }\n\n /**\n * Get a sound by its ID\n * \n * Retrieves a Howler sound instance from the engine's sound cache.\n * The sound must be registered beforehand (via @Sound decorator or manually).\n * \n * @param id - The sound identifier\n * @returns The Howler sound instance, or undefined if not found\n * \n * @example\n * ```ts\n * // Get and play a sound\n * const sound = RpgSound.get('town-music');\n * if (sound) {\n * sound.play();\n * }\n * \n * // Chain methods\n * RpgSound.get('battle-theme')?.volume(0.8).play();\n * ```\n */\n static get(id: string): any {\n if (!RpgSound.engine) {\n console.warn('RpgSound not initialized. Make sure the engine has started.');\n return undefined;\n }\n\n const sound = RpgSound.engine.sounds.get(id);\n if (!sound) {\n console.warn(`Sound with id \"${id}\" not found`);\n return undefined;\n }\n\n // If the sound is a Howler instance, return it directly\n if (sound && typeof sound.play === 'function') {\n return sound;\n }\n\n // If the sound has a src property, try to create a Howler instance\n if (sound && sound.src) {\n // This should have been handled during addSound, but just in case\n return sound;\n }\n\n return sound;\n }\n\n /**\n * Global Howler instance for managing all sounds\n * \n * Provides access to Howler.js global methods for controlling all sounds\n * at once (volume, mute, etc.).\n * \n * @example\n * ```ts\n * // Set global volume to 20%\n * RpgSound.global.volume(0.2)\n * \n * // Mute all sounds\n * RpgSound.global.mute(true)\n * \n * // Unmute all sounds\n * RpgSound.global.mute(false)\n * ```\n */\n static get global(): typeof Howler {\n return Howler;\n }\n}\n\n"],"names":[],"mappings":";;AAwEA,MAAM,kBAAA,GAAqB,OAAO,aAAa,CAAA;AAwCxC,SAAS,MAAM,OAAA,EAAuB;AAC3C,EAAA,OAAO,SAAkD,WAAA,EAAgB;AACvE,IAAA,MAAM,QAAA,GAA0B;AAAA,MAC9B,IAAI,OAAA,CAAQ,EAAA;AAAA,MACZ,OAAO,OAAA,CAAQ,KAAA;AAAA,MACf,QAAQ,OAAA,CAAQ,MAAA;AAAA,MAChB,MAAM,OAAA,CAAQ,IAAA;AAAA,MACd,QAAQ,OAAA,CAAQ;AAAA,KAClB;AAGA,IAAC,WAAA,CAAoB,kBAAkB,CAAA,GAAI,QAAA;AAE3C,IAAA,OAAO,WAAA;AAAA,EACT,CAAA;AACF;AAQO,SAAS,iBAAiB,UAAA,EAA4C;AAC3E,EAAA,OAAQ,WAAmB,kBAAk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