@rpgjs/client 5.0.0-alpha.43 → 5.0.0-alpha.44
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.js +25 -24
- package/dist/Game/AnimationManager.js.map +1 -1
- package/dist/Game/Event.js +11 -10
- package/dist/Game/Event.js.map +1 -1
- package/dist/Game/Map.js +78 -94
- package/dist/Game/Map.js.map +1 -1
- package/dist/Game/Object.js +182 -216
- package/dist/Game/Object.js.map +1 -1
- package/dist/Game/Player.js +11 -10
- package/dist/Game/Player.js.map +1 -1
- package/dist/Gui/Gui.js +440 -473
- package/dist/Gui/Gui.js.map +1 -1
- package/dist/Gui/NotificationManager.js +48 -50
- package/dist/Gui/NotificationManager.js.map +1 -1
- package/dist/Resource.js +132 -113
- package/dist/Resource.js.map +1 -1
- package/dist/RpgClientEngine.js +1333 -1486
- package/dist/RpgClientEngine.js.map +1 -1
- package/dist/Sound.js +162 -92
- package/dist/Sound.js.map +1 -1
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/decorate.js +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/decorateMetadata.js +6 -0
- package/dist/components/animations/animation.ce.js +22 -19
- package/dist/components/animations/animation.ce.js.map +1 -1
- package/dist/components/animations/hit.ce.js +67 -68
- package/dist/components/animations/hit.ce.js.map +1 -1
- package/dist/components/animations/index.js +9 -8
- package/dist/components/animations/index.js.map +1 -1
- package/dist/components/character.ce.js +390 -314
- package/dist/components/character.ce.js.map +1 -1
- package/dist/components/dynamics/parse-value.js +42 -52
- package/dist/components/dynamics/parse-value.js.map +1 -1
- package/dist/components/dynamics/text.ce.js +71 -139
- package/dist/components/dynamics/text.ce.js.map +1 -1
- package/dist/components/gui/box.ce.js +26 -25
- package/dist/components/gui/box.ce.js.map +1 -1
- package/dist/components/gui/dialogbox/index.ce.js +202 -149
- package/dist/components/gui/dialogbox/index.ce.js.map +1 -1
- package/dist/components/gui/gameover.ce.js +190 -138
- package/dist/components/gui/gameover.ce.js.map +1 -1
- package/dist/components/gui/hud/hud.ce.js +90 -33
- package/dist/components/gui/hud/hud.ce.js.map +1 -1
- package/dist/components/gui/index.js +14 -0
- package/dist/components/gui/menu/equip-menu.ce.js +478 -346
- package/dist/components/gui/menu/equip-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/exit-menu.ce.js +52 -33
- package/dist/components/gui/menu/exit-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/items-menu.ce.js +341 -226
- package/dist/components/gui/menu/items-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/main-menu.ce.js +414 -205
- package/dist/components/gui/menu/main-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/options-menu.ce.js +46 -26
- package/dist/components/gui/menu/options-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/skills-menu.ce.js +104 -50
- package/dist/components/gui/menu/skills-menu.ce.js.map +1 -1
- package/dist/components/gui/mobile/index.js +18 -21
- package/dist/components/gui/mobile/index.js.map +1 -1
- package/dist/components/gui/mobile/mobile.ce.js +76 -15
- package/dist/components/gui/mobile/mobile.ce.js.map +1 -1
- package/dist/components/gui/notification/notification.ce.js +62 -36
- package/dist/components/gui/notification/notification.ce.js.map +1 -1
- package/dist/components/gui/save-load.ce.js +386 -239
- package/dist/components/gui/save-load.ce.js.map +1 -1
- package/dist/components/gui/shop/shop.ce.js +649 -319
- package/dist/components/gui/shop/shop.ce.js.map +1 -1
- package/dist/components/gui/title-screen.ce.js +187 -145
- package/dist/components/gui/title-screen.ce.js.map +1 -1
- package/dist/components/index.js +4 -0
- package/dist/components/prebuilt/hp-bar.ce.js +114 -104
- package/dist/components/prebuilt/hp-bar.ce.js.map +1 -1
- package/dist/components/prebuilt/index.js +2 -0
- package/dist/components/prebuilt/light-halo.ce.js +92 -74
- package/dist/components/prebuilt/light-halo.ce.js.map +1 -1
- package/dist/components/scenes/canvas.ce.js +58 -42
- package/dist/components/scenes/canvas.ce.js.map +1 -1
- package/dist/components/scenes/draw-map.ce.js +87 -64
- package/dist/components/scenes/draw-map.ce.js.map +1 -1
- package/dist/components/scenes/event-layer.ce.js +26 -16
- package/dist/components/scenes/event-layer.ce.js.map +1 -1
- package/dist/core/inject.js +11 -10
- package/dist/core/inject.js.map +1 -1
- package/dist/core/setup.js +13 -13
- package/dist/core/setup.js.map +1 -1
- package/dist/index.js +44 -41
- package/dist/module.js +169 -168
- package/dist/module.js.map +1 -1
- package/dist/node_modules/.pnpm/@signe_di@2.8.3/node_modules/@signe/di/dist/index.js +209 -298
- package/dist/node_modules/.pnpm/@signe_di@2.8.3/node_modules/@signe/di/dist/index.js.map +1 -1
- package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js +430 -507
- package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js.map +1 -1
- package/dist/node_modules/.pnpm/@signe_room@2.8.3/node_modules/@signe/room/dist/index.js +2062 -2571
- package/dist/node_modules/.pnpm/@signe_room@2.8.3/node_modules/@signe/room/dist/index.js.map +1 -1
- package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/chunk-7QVYU63E.js +8 -3
- package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/chunk-7QVYU63E.js.map +1 -1
- package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/client/index.js +78 -101
- package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/client/index.js.map +1 -1
- package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/index.js +264 -401
- package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/index.js.map +1 -1
- package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js +9 -7
- package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js.map +1 -1
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js +106 -165
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js.map +1 -1
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js +361 -461
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +1 -1
- 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 +3633 -4280
- package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +1 -1
- package/dist/presets/animation.js +37 -25
- package/dist/presets/animation.js.map +1 -1
- package/dist/presets/faceset.js +49 -22
- package/dist/presets/faceset.js.map +1 -1
- package/dist/presets/icon.js +13 -13
- package/dist/presets/icon.js.map +1 -1
- package/dist/presets/index.js +15 -14
- package/dist/presets/index.js.map +1 -1
- package/dist/presets/lpc.js +96 -93
- package/dist/presets/lpc.js.map +1 -1
- package/dist/presets/rmspritesheet.js +40 -39
- package/dist/presets/rmspritesheet.js.map +1 -1
- package/dist/services/AbstractSocket.js +10 -8
- package/dist/services/AbstractSocket.js.map +1 -1
- package/dist/services/keyboardControls.js +20 -18
- package/dist/services/keyboardControls.js.map +1 -1
- package/dist/services/loadMap.js +120 -36
- package/dist/services/loadMap.js.map +1 -1
- package/dist/services/mmorpg.js +128 -136
- package/dist/services/mmorpg.js.map +1 -1
- package/dist/services/save.js +74 -66
- package/dist/services/save.js.map +1 -1
- package/dist/services/standalone.js +165 -167
- package/dist/services/standalone.js.map +1 -1
- package/dist/utils/getEntityProp.js +49 -51
- package/dist/utils/getEntityProp.js.map +1 -1
- package/package.json +8 -8
- package/src/components/character.ce +1 -1
- package/src/components/scenes/draw-map.ce +3 -1
- package/dist/index.js.map +0 -1
package/dist/Sound.js
CHANGED
|
@@ -1,97 +1,167 @@
|
|
|
1
|
-
import { Howler } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Howler } from "canvasengine";
|
|
2
|
+
//#region src/Sound.ts
|
|
3
|
+
var SOUND_METADATA_KEY = Symbol("rpgjs:sound");
|
|
4
|
+
/**
|
|
5
|
+
* Sound decorator
|
|
6
|
+
*
|
|
7
|
+
* Decorates a class to define a sound configuration. The decorated class can be
|
|
8
|
+
* added to the RpgClient module configuration, and the sound will be automatically
|
|
9
|
+
* registered and available through RpgSound.get().
|
|
10
|
+
*
|
|
11
|
+
* ## Design
|
|
12
|
+
*
|
|
13
|
+
* The decorator stores metadata on the class that is later used by the module loader
|
|
14
|
+
* to register sounds with the engine. The sound is created using Howler.js for
|
|
15
|
+
* advanced audio features like looping, volume control, and cross-browser compatibility.
|
|
16
|
+
*
|
|
17
|
+
* @param options - Sound configuration options
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { Sound } from '@rpgjs/client'
|
|
22
|
+
*
|
|
23
|
+
* @Sound({
|
|
24
|
+
* id: 'town-music',
|
|
25
|
+
* sound: require('./sound/town.ogg'),
|
|
26
|
+
* loop: true,
|
|
27
|
+
* volume: 0.5
|
|
28
|
+
* })
|
|
29
|
+
* export class TownMusic {}
|
|
30
|
+
*
|
|
31
|
+
* // Multiple sounds in one class
|
|
32
|
+
* @Sound({
|
|
33
|
+
* sounds: {
|
|
34
|
+
* hero: require('./assets/hero.ogg'),
|
|
35
|
+
* monster: require('./assets/monster.ogg')
|
|
36
|
+
* },
|
|
37
|
+
* loop: true
|
|
38
|
+
* })
|
|
39
|
+
* export class CharacterSounds {}
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
4
42
|
function Sound(options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
43
|
+
return function(constructor) {
|
|
44
|
+
constructor[SOUND_METADATA_KEY] = {
|
|
45
|
+
id: options.id,
|
|
46
|
+
sound: options.sound,
|
|
47
|
+
sounds: options.sounds,
|
|
48
|
+
loop: options.loop,
|
|
49
|
+
volume: options.volume
|
|
50
|
+
};
|
|
51
|
+
return constructor;
|
|
52
|
+
};
|
|
16
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Get sound metadata from a decorated class
|
|
56
|
+
*
|
|
57
|
+
* @param soundClass - The class decorated with @Sound
|
|
58
|
+
* @returns The sound metadata or undefined
|
|
59
|
+
*/
|
|
17
60
|
function getSoundMetadata(soundClass) {
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
class RpgSound {
|
|
21
|
-
static {
|
|
22
|
-
this.engine = null;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Initialize RpgSound with the engine instance
|
|
26
|
-
*
|
|
27
|
-
* This is called automatically by the engine during initialization.
|
|
28
|
-
*
|
|
29
|
-
* @param engine - The RpgClientEngine instance
|
|
30
|
-
*/
|
|
31
|
-
static init(engine) {
|
|
32
|
-
RpgSound.engine = engine;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Get a sound by its ID
|
|
36
|
-
*
|
|
37
|
-
* Retrieves a Howler sound instance from the engine's sound cache.
|
|
38
|
-
* The sound must be registered beforehand (via @Sound decorator or manually).
|
|
39
|
-
*
|
|
40
|
-
* @param id - The sound identifier
|
|
41
|
-
* @returns The Howler sound instance, or undefined if not found
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```ts
|
|
45
|
-
* // Get and play a sound
|
|
46
|
-
* const sound = RpgSound.get('town-music');
|
|
47
|
-
* if (sound) {
|
|
48
|
-
* sound.play();
|
|
49
|
-
* }
|
|
50
|
-
*
|
|
51
|
-
* // Chain methods
|
|
52
|
-
* RpgSound.get('battle-theme')?.volume(0.8).play();
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
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;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Global Howler instance for managing all sounds
|
|
75
|
-
*
|
|
76
|
-
* Provides access to Howler.js global methods for controlling all sounds
|
|
77
|
-
* at once (volume, mute, etc.).
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```ts
|
|
81
|
-
* // Set global volume to 20%
|
|
82
|
-
* RpgSound.global.volume(0.2)
|
|
83
|
-
*
|
|
84
|
-
* // Mute all sounds
|
|
85
|
-
* RpgSound.global.mute(true)
|
|
86
|
-
*
|
|
87
|
-
* // Unmute all sounds
|
|
88
|
-
* RpgSound.global.mute(false)
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
static get global() {
|
|
92
|
-
return Howler;
|
|
93
|
-
}
|
|
61
|
+
return soundClass[SOUND_METADATA_KEY];
|
|
94
62
|
}
|
|
95
|
-
|
|
63
|
+
/**
|
|
64
|
+
* RpgSound class
|
|
65
|
+
*
|
|
66
|
+
* Provides a unified API to manage sounds in the game. Uses Howler.js internally
|
|
67
|
+
* for advanced audio features. Sounds can be retrieved by ID and controlled
|
|
68
|
+
* using Howler.js methods.
|
|
69
|
+
*
|
|
70
|
+
* ## Design
|
|
71
|
+
*
|
|
72
|
+
* RpgSound acts as a facade over Howler.js, providing easy access to sounds
|
|
73
|
+
* registered in the engine. It supports both individual sound control and
|
|
74
|
+
* global sound management (volume, mute, etc.).
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { RpgSound } from '@rpgjs/client'
|
|
79
|
+
*
|
|
80
|
+
* // Play a sound
|
|
81
|
+
* RpgSound.get('town-music').play()
|
|
82
|
+
*
|
|
83
|
+
* // Control volume
|
|
84
|
+
* RpgSound.get('town-music').volume(0.5)
|
|
85
|
+
*
|
|
86
|
+
* // Stop a sound
|
|
87
|
+
* RpgSound.get('town-music').stop()
|
|
88
|
+
*
|
|
89
|
+
* // Global volume control
|
|
90
|
+
* RpgSound.global.volume(0.2)
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
var RpgSound = class RpgSound {
|
|
94
|
+
static {
|
|
95
|
+
this.engine = null;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Initialize RpgSound with the engine instance
|
|
99
|
+
*
|
|
100
|
+
* This is called automatically by the engine during initialization.
|
|
101
|
+
*
|
|
102
|
+
* @param engine - The RpgClientEngine instance
|
|
103
|
+
*/
|
|
104
|
+
static init(engine) {
|
|
105
|
+
RpgSound.engine = engine;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get a sound by its ID
|
|
109
|
+
*
|
|
110
|
+
* Retrieves a Howler sound instance from the engine's sound cache.
|
|
111
|
+
* The sound must be registered beforehand (via @Sound decorator or manually).
|
|
112
|
+
*
|
|
113
|
+
* @param id - The sound identifier
|
|
114
|
+
* @returns The Howler sound instance, or undefined if not found
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* // Get and play a sound
|
|
119
|
+
* const sound = RpgSound.get('town-music');
|
|
120
|
+
* if (sound) {
|
|
121
|
+
* sound.play();
|
|
122
|
+
* }
|
|
123
|
+
*
|
|
124
|
+
* // Chain methods
|
|
125
|
+
* RpgSound.get('battle-theme')?.volume(0.8).play();
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
static get(id) {
|
|
129
|
+
if (!RpgSound.engine) {
|
|
130
|
+
console.warn("RpgSound not initialized. Make sure the engine has started.");
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const sound = RpgSound.engine.sounds.get(id);
|
|
134
|
+
if (!sound) {
|
|
135
|
+
console.warn(`Sound with id "${id}" not found`);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (sound && typeof sound.play === "function") return sound;
|
|
139
|
+
if (sound && sound.src) return sound;
|
|
140
|
+
return sound;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Global Howler instance for managing all sounds
|
|
144
|
+
*
|
|
145
|
+
* Provides access to Howler.js global methods for controlling all sounds
|
|
146
|
+
* at once (volume, mute, etc.).
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* // Set global volume to 20%
|
|
151
|
+
* RpgSound.global.volume(0.2)
|
|
152
|
+
*
|
|
153
|
+
* // Mute all sounds
|
|
154
|
+
* RpgSound.global.mute(true)
|
|
155
|
+
*
|
|
156
|
+
* // Unmute all sounds
|
|
157
|
+
* RpgSound.global.mute(false)
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
static get global() {
|
|
161
|
+
return Howler;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
//#endregion
|
|
96
165
|
export { RpgSound, Sound, getSoundMetadata };
|
|
97
|
-
|
|
166
|
+
|
|
167
|
+
//# sourceMappingURL=Sound.js.map
|
package/dist/Sound.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sound.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"],"
|
|
1
|
+
{"version":3,"file":"Sound.js","names":[],"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"],"mappings":";;AAwEA,IAAM,qBAAqB,OAAO,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwChD,SAAgB,MAAM,SAAuB;AAC3C,QAAO,SAAkD,aAAgB;AAUtE,cAAoB,sBATW;GAC9B,IAAI,QAAQ;GACZ,OAAO,QAAQ;GACf,QAAQ,QAAQ;GAChB,MAAM,QAAQ;GACd,QAAQ,QAAQ;GACjB;AAKD,SAAO;;;;;;;;;AAUX,SAAgB,iBAAiB,YAA4C;AAC3E,QAAQ,WAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiC7B,IAAa,WAAb,MAAa,SAAS;;gBAC4B;;;;;;;;;CAShD,OAAO,KAAK,QAA+B;AACzC,WAAS,SAAS;;;;;;;;;;;;;;;;;;;;;;;CAwBpB,OAAO,IAAI,IAAiB;AAC1B,MAAI,CAAC,SAAS,QAAQ;AACpB,WAAQ,KAAK,8DAA8D;AAC3E;;EAGF,MAAM,QAAQ,SAAS,OAAO,OAAO,IAAI,GAAG;AAC5C,MAAI,CAAC,OAAO;AACV,WAAQ,KAAK,kBAAkB,GAAG,aAAa;AAC/C;;AAIF,MAAI,SAAS,OAAO,MAAM,SAAS,WACjC,QAAO;AAIT,MAAI,SAAS,MAAM,IAEjB,QAAO;AAGT,SAAO;;;;;;;;;;;;;;;;;;;;CAqBT,WAAW,SAAwB;AACjC,SAAO"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.115.0/helpers/decorate.js
|
|
2
|
+
function __decorate(decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { __decorate };
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { RpgClientEngine } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { inject } from "../../core/inject.js";
|
|
2
|
+
import { RpgClientEngine } from "../../RpgClientEngine.js";
|
|
3
|
+
import { Sprite, h, useDefineProps, useProps } from "canvasengine";
|
|
4
|
+
//#region src/components/animations/animation.ce
|
|
5
5
|
function component($$props) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _b = defineProps(), x = _b.x, y = _b.y, animationName = _b.animationName, graphic = _b.graphic, onFinish = _b.onFinish;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
useProps($$props);
|
|
7
|
+
const defineProps = useDefineProps($$props);
|
|
8
|
+
var _a;
|
|
9
|
+
var _b = defineProps(), x = _b.x, y = _b.y, animationName = _b.animationName, graphic = _b.graphic, onFinish = _b.onFinish;
|
|
10
|
+
return h(Sprite, {
|
|
11
|
+
sheet: {
|
|
12
|
+
definition: inject(RpgClientEngine).getSpriteSheet(graphic()),
|
|
13
|
+
playing: (_a = animationName()) !== null && _a !== void 0 ? _a : "default",
|
|
14
|
+
onFinish
|
|
15
|
+
},
|
|
16
|
+
x,
|
|
17
|
+
y,
|
|
18
|
+
anchor: .5
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
20
22
|
export { component as default };
|
|
21
|
-
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=animation.ce.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"animation.ce.js","sources":["../../../src/components/animations/animation.ce"],"sourcesContent":["<Sprite sheet x y anchor={0.5} />\n\n<script>\n import { RpgClientEngine } from \"../../RpgClientEngine\";\n import { inject } from \"../../core/inject\";\n\n const { x, y, animationName, graphic, onFinish } = defineProps();\n\n const client = inject(RpgClientEngine);\n\n const sheet = {\n definition: client.getSpriteSheet(graphic()),\n playing: animationName() ?? 'default',\n onFinish\n };\n</script>\n"],"
|
|
1
|
+
{"version":3,"file":"animation.ce.js","names":[],"sources":["../../../src/components/animations/animation.ce"],"sourcesContent":["<Sprite sheet x y anchor={0.5} />\n\n<script>\n import { RpgClientEngine } from \"../../RpgClientEngine\";\n import { inject } from \"../../core/inject\";\n\n const { x, y, animationName, graphic, onFinish } = defineProps();\n\n const client = inject(RpgClientEngine);\n\n const sheet = {\n definition: client.getSpriteSheet(graphic()),\n playing: animationName() ?? 'default',\n onFinish\n };\n</script>\n"],"mappings":";;;;;AAQuB,UAAC,QAAgB;;CAEhC,IAAA;CACR,IAAI,KAAA,aAAkB,EAAC,IAAA,GAAA,GAAA,IAAe,GAAA,GAAA,gBAAU,GAAA,eAAA,UAAA,GAAA,SAAA,WAAA,GAAA;;SAE5C;GACD,YAFU,OAAA,gBAAoB,CAE9B,eAAA,SAAA,CAAA;GACD,UAAM,KAAA,eAAA,MAAA,QAAA,OAAA,KAAA,IAAA,KAAA"}
|
|
@@ -1,71 +1,70 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Direction } from
|
|
3
|
-
|
|
1
|
+
import { Text, animatedSignal, h, mount, signal, tick, useDefineProps, useProps } from "canvasengine";
|
|
2
|
+
import { Direction } from "@rpgjs/common";
|
|
3
|
+
//#region src/components/animations/hit.ce
|
|
4
4
|
function component($$props) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
5
|
+
useProps($$props);
|
|
6
|
+
var _a = useDefineProps($$props)({
|
|
7
|
+
duration: { default: 1e3 },
|
|
8
|
+
color: { default: "black" }
|
|
9
|
+
}), text = _a.text, direction = _a.direction, onFinish = _a.onFinish, duration = _a.duration, color = _a.color, positionX = _a.x, positionY = _a.y;
|
|
10
|
+
var scale = animatedSignal(1, { duration: duration() });
|
|
11
|
+
var randomPosition = function() {
|
|
12
|
+
return Math.floor(Math.random() * 60);
|
|
13
|
+
};
|
|
14
|
+
var initialY = randomPosition();
|
|
15
|
+
var x = signal(positionX());
|
|
16
|
+
var y = signal(positionY() - initialY);
|
|
17
|
+
var velocityX = 0;
|
|
18
|
+
var velocityY = 0;
|
|
19
|
+
var speed = 200;
|
|
20
|
+
switch (direction()) {
|
|
21
|
+
case Direction.Left:
|
|
22
|
+
velocityX = speed;
|
|
23
|
+
break;
|
|
24
|
+
case Direction.Right:
|
|
25
|
+
velocityX = -speed;
|
|
26
|
+
break;
|
|
27
|
+
case Direction.Up:
|
|
28
|
+
velocityY = speed;
|
|
29
|
+
break;
|
|
30
|
+
case Direction.Down:
|
|
31
|
+
velocityY = -speed;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
velocityX += (Math.random() - .5) * 100;
|
|
35
|
+
velocityY += (Math.random() - .5) * 100;
|
|
36
|
+
var gravity = 500;
|
|
37
|
+
var deceleration = .98;
|
|
38
|
+
mount(function() {
|
|
39
|
+
scale.set(.1);
|
|
40
|
+
});
|
|
41
|
+
var elapsedTime = 0;
|
|
42
|
+
tick(function(_a) {
|
|
43
|
+
var deltaTime = _a.deltaTime;
|
|
44
|
+
elapsedTime += deltaTime;
|
|
45
|
+
if (elapsedTime < duration()) {
|
|
46
|
+
x.update(function(x) {
|
|
47
|
+
return x + velocityX * deltaTime / 1e3;
|
|
48
|
+
});
|
|
49
|
+
y.update(function(y) {
|
|
50
|
+
return y + velocityY * deltaTime / 1e3;
|
|
51
|
+
});
|
|
52
|
+
velocityY += gravity * deltaTime / 1e3;
|
|
53
|
+
velocityX *= deceleration;
|
|
54
|
+
velocityY *= deceleration;
|
|
55
|
+
} else if (onFinish) onFinish();
|
|
56
|
+
});
|
|
57
|
+
return h(Text, {
|
|
58
|
+
x,
|
|
59
|
+
y,
|
|
60
|
+
zIndex: 1e4,
|
|
61
|
+
color,
|
|
62
|
+
scale,
|
|
63
|
+
size: 30,
|
|
64
|
+
text
|
|
65
|
+
});
|
|
38
66
|
}
|
|
39
|
-
|
|
40
|
-
velocityY += (Math.random() - 0.5) * 100;
|
|
41
|
-
var gravity = 500;
|
|
42
|
-
var deceleration = 0.98;
|
|
43
|
-
mount(function () {
|
|
44
|
-
scale.set(0.1);
|
|
45
|
-
});
|
|
46
|
-
var elapsedTime = 0;
|
|
47
|
-
tick(function (_a) {
|
|
48
|
-
var deltaTime = _a.deltaTime;
|
|
49
|
-
elapsedTime += deltaTime;
|
|
50
|
-
if (elapsedTime < duration()) {
|
|
51
|
-
// Update position
|
|
52
|
-
x.update(function (x) { return x + (velocityX * deltaTime) / 1000; });
|
|
53
|
-
y.update(function (y) { return y + (velocityY * deltaTime) / 1000; });
|
|
54
|
-
// Apply gravity
|
|
55
|
-
velocityY += (gravity * deltaTime) / 1000;
|
|
56
|
-
// Apply deceleration
|
|
57
|
-
velocityX *= deceleration;
|
|
58
|
-
velocityY *= deceleration;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
if (onFinish) {
|
|
62
|
-
onFinish();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
let $this = h(Text, { x, y, zIndex: 10000, color, scale, size: 30, text });
|
|
67
|
-
return $this
|
|
68
|
-
}
|
|
69
|
-
|
|
67
|
+
//#endregion
|
|
70
68
|
export { component as default };
|
|
71
|
-
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=hit.ce.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hit.ce.js","sources":["../../../src/components/animations/hit.ce"],"sourcesContent":["<Text x y zIndex={10000} color scale size={30} text />\n\n<script>\n import { animatedSignal, mount, signal, tick } from \"canvasengine\";\n import { Direction } from \"@rpgjs/common\";\n const {\n text,\n direction,\n onFinish,\n duration,\n color,\n x: positionX,\n y: positionY\n } = defineProps({\n duration: {\n default: 1000\n },\n color: {\n default: 'black'\n }\n });\n\n const scale = animatedSignal(1, {\n duration: duration(),\n });\n\n // Generate random initial position\n const randomPosition = () => Math.floor(Math.random() * 60);\n const initialY = randomPosition();\n const x = signal(positionX());\n const y = signal(positionY() - initialY);\n\n // Initial velocity\n let velocityX = 0;\n let velocityY = 0;\n\n // Set initial velocity based on direction\n const speed = 200;\n switch (direction()) {\n case Direction.Left:\n velocityX = speed;\n break;\n case Direction.Right:\n velocityX = -speed;\n break;\n case Direction.Up:\n velocityY = speed;\n break;\n case Direction.Down:\n velocityY = -speed;\n break;\n }\n\n // Add some randomness to the velocity\n velocityX += (Math.random() - 0.5) * 100;\n velocityY += (Math.random() - 0.5) * 100;\n\n const gravity = 500; // Gravity effect\n const deceleration = 0.98; // Deceleration factor\n\n mount(() => {\n scale.set(0.1);\n });\n\n let elapsedTime = 0;\n\n tick(({ deltaTime }) => {\n elapsedTime += deltaTime;\n \n if (elapsedTime < duration()) {\n // Update position\n x.update((x) => x + (velocityX * deltaTime) / 1000);\n y.update((y) => y + (velocityY * deltaTime) / 1000);\n\n // Apply gravity\n velocityY += (gravity * deltaTime) / 1000;\n\n // Apply deceleration\n velocityX *= deceleration;\n velocityY *= deceleration;\n } else {\n if (onFinish) {\n onFinish();\n }\n }\n });\n</script>\n"],"
|
|
1
|
+
{"version":3,"file":"hit.ce.js","names":[],"sources":["../../../src/components/animations/hit.ce"],"sourcesContent":["<Text x y zIndex={10000} color scale size={30} text />\n\n<script>\n import { animatedSignal, mount, signal, tick } from \"canvasengine\";\n import { Direction } from \"@rpgjs/common\";\n const {\n text,\n direction,\n onFinish,\n duration,\n color,\n x: positionX,\n y: positionY\n } = defineProps({\n duration: {\n default: 1000\n },\n color: {\n default: 'black'\n }\n });\n\n const scale = animatedSignal(1, {\n duration: duration(),\n });\n\n // Generate random initial position\n const randomPosition = () => Math.floor(Math.random() * 60);\n const initialY = randomPosition();\n const x = signal(positionX());\n const y = signal(positionY() - initialY);\n\n // Initial velocity\n let velocityX = 0;\n let velocityY = 0;\n\n // Set initial velocity based on direction\n const speed = 200;\n switch (direction()) {\n case Direction.Left:\n velocityX = speed;\n break;\n case Direction.Right:\n velocityX = -speed;\n break;\n case Direction.Up:\n velocityY = speed;\n break;\n case Direction.Down:\n velocityY = -speed;\n break;\n }\n\n // Add some randomness to the velocity\n velocityX += (Math.random() - 0.5) * 100;\n velocityY += (Math.random() - 0.5) * 100;\n\n const gravity = 500; // Gravity effect\n const deceleration = 0.98; // Deceleration factor\n\n mount(() => {\n scale.set(0.1);\n });\n\n let elapsedTime = 0;\n\n tick(({ deltaTime }) => {\n elapsedTime += deltaTime;\n \n if (elapsedTime < duration()) {\n // Update position\n x.update((x) => x + (velocityX * deltaTime) / 1000);\n y.update((y) => y + (velocityY * deltaTime) / 1000);\n\n // Apply gravity\n velocityY += (gravity * deltaTime) / 1000;\n\n // Apply deceleration\n velocityX *= deceleration;\n velocityY *= deceleration;\n } else {\n if (onFinish) {\n onFinish();\n }\n }\n });\n</script>\n"],"mappings":";;;AAOI,SAAS,UAAA,SAAA;AACD,UAAA,QAAA;CAER,IAAK,KADG,eAAA,QAAA,CACH;EACL,UAAG,EACA,SAAA,KACF;EACD,OAAA,EACE,SAAS,SACV;EACJ,CAAC,EAAE,OAAO,GAAA,MAAA,YAAA,GAAA,WAAA,WAAA,GAAA,UAAA,WAAA,GAAA,UAAA,QAAA,GAAA,OAAA,YAAA,GAAA,GAAA,YAAA,GAAA;CACX,IAAI,QAAE,eAAe,GAAA,EACjB,UAAA,UAAA,EACH,CAAC;;;;CAEF,IAAE,WAAa,gBAAgB;CAC/B,IAAI,IAAA,OAAU,WAAU,CAAA;CACxB,IAAI,IAAA,OAAA,WAAA,GAAA,SAAA;;CAEJ,IAAI,YAAU;CACd,IAAE,QAAM;AACR,SAAQ,WAAW,EAAnB;EACE,KAAO,UAAU;AACX,eAAW;;EAEf,KAAC,UAAQ;AACP,eAAa,CAAA;AACb;;AAEE,eAAS;AACT;EACN,KAAO,UAAU;AACX,eAAW,CAAA;AACb;;AAEN,eAAS,KAAU,QAAK,GAAA,MAAA;AACxB,eAAM,KAAa,QAAK,GAAA,MAAA;CACxB,IAAI,UAAO;CACX,IAAI,eAAe;AACnB,OAAM,WAAY;AACd,QAAE,IAAK,GAAA;GACT;CACF,IAAI,cAAc;AAClB,MAAK,SAAM,IAAA;EACT,IAAA,YAAA,GAAA;;AAEE,MAAI,cAAM,UAAkB,EAAA;AAE9B,KAAA,OAAc,SAAW,GAAG;AAAE,WAAO,IAAG,YAAA,YAAA;KAAA;;;;AAGlC,gBAAc,UAAU,YAAa;AAErC,gBAAM;AACV,gBAAc;aAGZ,SAAA,WAAA;GAIJ;AAEM,QADY,EAAE,MAAA;EAAQ;EAAG;EAAC,QAAA;EAAA;EAAA;EAAA,MAAA;EAAA;EAAA,CAAA"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import component
|
|
2
|
-
import component from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import component from "./hit.ce.js";
|
|
2
|
+
import component$1 from "./animation.ce.js";
|
|
3
|
+
//#region src/components/animations/index.ts
|
|
4
|
+
var PrebuiltComponentAnimations = {
|
|
5
|
+
Hit: component,
|
|
6
|
+
Animation: component$1
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
//#endregion
|
|
9
9
|
export { PrebuiltComponentAnimations };
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/components/animations/index.ts"],"sourcesContent":["import Hit from \"./hit.ce\";\nimport Animation from \"./animation.ce\";\n\nexport const PrebuiltComponentAnimations = {\n Hit,\n Animation\n}"],"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/animations/index.ts"],"sourcesContent":["import Hit from \"./hit.ce\";\nimport Animation from \"./animation.ce\";\n\nexport const PrebuiltComponentAnimations = {\n Hit,\n Animation\n}"],"mappings":";;;AAGA,IAAa,8BAA8B;CACvC,KAAA;CACA,WAAA"}
|