@rpgjs/client 5.0.0-alpha.22 → 5.0.0-alpha.24
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/Object.d.ts +2 -0
- package/dist/RpgClientEngine.d.ts +115 -9
- package/dist/components/gui/mobile/index.d.ts +8 -0
- package/dist/components/prebuilt/index.d.ts +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +13 -8
- package/dist/index.js.map +1 -1
- package/dist/index10.js +1 -1
- package/dist/index11.js +6 -5
- package/dist/index11.js.map +1 -1
- package/dist/index12.js +2 -2
- package/dist/index13.js +102 -10
- package/dist/index13.js.map +1 -1
- package/dist/index14.js +67 -9
- package/dist/index14.js.map +1 -1
- package/dist/index15.js +10 -263
- package/dist/index15.js.map +1 -1
- package/dist/index16.js +9 -97
- package/dist/index16.js.map +1 -1
- package/dist/index17.js +300 -89
- package/dist/index17.js.map +1 -1
- package/dist/index18.js +63 -80
- package/dist/index18.js.map +1 -1
- package/dist/index19.js +96 -348
- package/dist/index19.js.map +1 -1
- package/dist/index2.js +176 -24
- package/dist/index2.js.map +1 -1
- package/dist/index20.js +360 -17
- package/dist/index20.js.map +1 -1
- package/dist/index21.js +19 -50
- package/dist/index21.js.map +1 -1
- package/dist/index22.js +212 -5
- package/dist/index22.js.map +1 -1
- package/dist/index23.js +6 -395
- package/dist/index23.js.map +1 -1
- package/dist/index24.js +4 -39
- package/dist/index24.js.map +1 -1
- package/dist/index25.js +19 -20
- package/dist/index25.js.map +1 -1
- package/dist/index26.js +43 -2624
- package/dist/index26.js.map +1 -1
- package/dist/index27.js +5 -110
- package/dist/index27.js.map +1 -1
- package/dist/index28.js +394 -65
- package/dist/index28.js.map +1 -1
- package/dist/index29.js +40 -15
- package/dist/index29.js.map +1 -1
- package/dist/index3.js +3 -3
- package/dist/index30.js +21 -23
- package/dist/index30.js.map +1 -1
- package/dist/index31.js +2624 -86
- package/dist/index31.js.map +1 -1
- package/dist/index32.js +107 -34
- package/dist/index32.js.map +1 -1
- package/dist/index33.js +69 -22
- package/dist/index33.js.map +1 -1
- package/dist/index34.js +19 -3
- package/dist/index34.js.map +1 -1
- package/dist/index35.js +21 -329
- package/dist/index35.js.map +1 -1
- package/dist/index36.js +91 -30
- package/dist/index36.js.map +1 -1
- package/dist/index37.js +37 -7
- package/dist/index37.js.map +1 -1
- package/dist/index38.js +22 -9
- package/dist/index38.js.map +1 -1
- package/dist/index39.js +139 -10
- package/dist/index39.js.map +1 -1
- package/dist/index4.js +3 -3
- package/dist/index40.js +16 -6
- package/dist/index40.js.map +1 -1
- package/dist/index41.js +1 -325
- package/dist/index41.js.map +1 -1
- package/dist/index42.js +530 -3680
- package/dist/index42.js.map +1 -1
- package/dist/index43.js +24 -67
- package/dist/index43.js.map +1 -1
- package/dist/index44.js +9 -184
- package/dist/index44.js.map +1 -1
- package/dist/index45.js +6 -503
- package/dist/index45.js.map +1 -1
- package/dist/index46.js +325 -2
- package/dist/index46.js.map +1 -1
- package/dist/index47.js +3687 -17
- package/dist/index47.js.map +1 -1
- package/dist/index48.js +69 -202
- package/dist/index48.js.map +1 -1
- package/dist/index49.js +182 -7
- package/dist/index49.js.map +1 -1
- package/dist/index5.js +1 -1
- package/dist/index50.js +497 -106
- package/dist/index50.js.map +1 -1
- package/dist/index51.js +48 -130
- package/dist/index51.js.map +1 -1
- package/dist/index52.js +17 -134
- package/dist/index52.js.map +1 -1
- package/dist/index53.js +3 -109
- package/dist/index53.js.map +1 -1
- package/dist/index54.js +9 -138
- package/dist/index54.js.map +1 -1
- package/dist/index55.js +111 -7
- package/dist/index55.js.map +1 -1
- package/dist/index56.js +130 -48
- package/dist/index56.js.map +1 -1
- package/dist/index57.js +137 -0
- package/dist/index57.js.map +1 -0
- package/dist/index58.js +112 -0
- package/dist/index58.js.map +1 -0
- package/dist/index59.js +9 -0
- package/dist/index59.js.map +1 -0
- package/dist/index6.js +1 -1
- package/dist/index7.js +1 -1
- package/dist/index8.js +17 -2
- package/dist/index8.js.map +1 -1
- package/dist/index9.js +10 -27
- package/dist/index9.js.map +1 -1
- package/dist/services/keyboardControls.d.ts +1 -2
- package/dist/services/mmorpg.d.ts +1 -1
- package/dist/services/standalone.d.ts +1 -1
- package/package.json +9 -9
- package/src/Game/Object.ts +8 -0
- package/src/Gui/Gui.ts +4 -31
- package/src/RpgClientEngine.ts +193 -20
- package/src/components/character.ce +146 -9
- package/src/components/gui/mobile/index.ts +24 -0
- package/src/components/gui/mobile/mobile.ce +80 -0
- package/src/components/prebuilt/index.ts +1 -0
- package/src/components/prebuilt/light-halo.ce +148 -0
- package/src/components/scenes/canvas.ce +2 -2
- package/src/components/scenes/event-layer.ce +1 -0
- package/src/components/scenes/transition.ce +60 -0
- package/src/index.ts +6 -1
- package/src/module.ts +15 -0
- package/src/services/keyboardControls.ts +1 -1
package/dist/index18.js
CHANGED
|
@@ -1,114 +1,97 @@
|
|
|
1
|
-
|
|
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
|
|
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
|
-
|
|
21
|
-
RpgResource.syncResources();
|
|
32
|
+
RpgSound.engine = engine;
|
|
22
33
|
}
|
|
23
34
|
/**
|
|
24
|
-
*
|
|
35
|
+
* Get a sound by its ID
|
|
25
36
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
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
|
-
* @
|
|
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
|
|
70
|
-
* const
|
|
71
|
-
*
|
|
72
|
-
*
|
|
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
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
* //
|
|
96
|
-
*
|
|
81
|
+
* // Set global volume to 20%
|
|
82
|
+
* RpgSound.global.volume(0.2)
|
|
97
83
|
*
|
|
98
|
-
* //
|
|
99
|
-
*
|
|
84
|
+
* // Mute all sounds
|
|
85
|
+
* RpgSound.global.mute(true)
|
|
100
86
|
*
|
|
101
|
-
* //
|
|
102
|
-
*
|
|
103
|
-
* console.log(`Sound ${id}: ${link}`)
|
|
104
|
-
* })
|
|
87
|
+
* // Unmute all sounds
|
|
88
|
+
* RpgSound.global.mute(false)
|
|
105
89
|
* ```
|
|
106
90
|
*/
|
|
107
|
-
static get
|
|
108
|
-
|
|
109
|
-
return RpgResource._sounds;
|
|
91
|
+
static get global() {
|
|
92
|
+
return Howler;
|
|
110
93
|
}
|
|
111
94
|
}
|
|
112
95
|
|
|
113
|
-
export {
|
|
96
|
+
export { RpgSound, Sound, getSoundMetadata };
|
|
114
97
|
//# sourceMappingURL=index18.js.map
|
package/dist/index18.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index18.js","sources":["../src/
|
|
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,kBAAkB,CAAA;AAC/C;AAgCO,MAAM,QAAA,CAAS;AAAA,EACpB;AAAA,IAAA,IAAA,CAAe,MAAA,GAAiC,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAShD,OAAO,KAAK,MAAA,EAA+B;AACzC,IAAA,QAAA,CAAS,MAAA,GAAS,MAAA;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuBA,OAAO,IAAI,EAAA,EAAiB;AAC1B,IAAA,IAAI,CAAC,SAAS,MAAA,EAAQ;AACpB,MAAA,OAAA,CAAQ,KAAK,6DAA6D,CAAA;AAC1E,MAAA,OAAO,MAAA;AAAA,IACT;AAEA,IAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,MAAA,CAAO,MAAA,CAAO,IAAI,EAAE,CAAA;AAC3C,IAAA,IAAI,CAAC,KAAA,EAAO;AACV,MAAA,OAAA,CAAQ,IAAA,CAAK,CAAA,eAAA,EAAkB,EAAE,CAAA,WAAA,CAAa,CAAA;AAC9C,MAAA,OAAO,MAAA;AAAA,IACT;AAGA,IAAA,IAAI,KAAA,IAAS,OAAO,KAAA,CAAM,IAAA,KAAS,UAAA,EAAY;AAC7C,MAAA,OAAO,KAAA;AAAA,IACT;AAGA,IAAA,IAAI,KAAA,IAAS,MAAM,GAAA,EAAK;AAEtB,MAAA,OAAO,KAAA;AAAA,IACT;AAEA,IAAA,OAAO,KAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBA,WAAW,MAAA,GAAwB;AACjC,IAAA,OAAO,MAAA;AAAA,EACT;AACF;;;;"}
|