@momo2555/koppeliajs 0.0.156 → 0.0.157
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.
|
@@ -3,12 +3,18 @@ declare class AudioInstance {
|
|
|
3
3
|
private id;
|
|
4
4
|
protected path: string;
|
|
5
5
|
private loop;
|
|
6
|
+
private volume;
|
|
6
7
|
constructor(id: string, loop?: boolean);
|
|
7
8
|
fetch(): void;
|
|
8
9
|
play(): void;
|
|
9
10
|
pause(): void;
|
|
10
11
|
stop(): void;
|
|
11
12
|
setLoop(loop: boolean): void;
|
|
13
|
+
/**
|
|
14
|
+
* Change le volume de l'instance
|
|
15
|
+
* @param volume Nombre entre 0 et 100
|
|
16
|
+
*/
|
|
17
|
+
setVolume(volume: number): void;
|
|
12
18
|
isPlaying(): boolean | undefined;
|
|
13
19
|
getId(): string;
|
|
14
20
|
getDuration(): number | undefined;
|
|
@@ -19,6 +25,12 @@ export declare class AudioManager {
|
|
|
19
25
|
* Play an audio by id (creates it if doesn't exist)
|
|
20
26
|
*/
|
|
21
27
|
play(id: string, loop?: boolean, url?: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Change le volume d'un audio spécifique
|
|
30
|
+
* @param id L'identifiant du son
|
|
31
|
+
* @param volume Le volume entre 0 et 100
|
|
32
|
+
*/
|
|
33
|
+
setVolume(id: string, volume: number): void;
|
|
22
34
|
/**
|
|
23
35
|
* Pause a specific audio by id
|
|
24
36
|
*/
|
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
import { writable } from
|
|
1
|
+
import { writable } from "svelte/store";
|
|
2
2
|
class AudioInstance {
|
|
3
3
|
audio;
|
|
4
4
|
id;
|
|
5
5
|
path;
|
|
6
6
|
loop;
|
|
7
|
+
volume; // Stocke le volume entre 0 et 100
|
|
7
8
|
constructor(id, loop = false) {
|
|
8
9
|
this.id = id;
|
|
9
10
|
this.path = `/audios/${id}.mp3`;
|
|
10
11
|
this.loop = loop;
|
|
12
|
+
this.volume = 100; // Volume par défaut au max
|
|
11
13
|
}
|
|
12
14
|
fetch() {
|
|
13
15
|
this.audio = new Audio(this.path);
|
|
14
16
|
this.audio.loop = this.loop;
|
|
17
|
+
// Appliquer le volume stocké lors de la création de l'élément audio
|
|
18
|
+
this.audio.volume = this.volume / 100;
|
|
15
19
|
}
|
|
16
20
|
play() {
|
|
17
21
|
if (this.audio != undefined) {
|
|
18
|
-
this.audio.play().catch(err => console.error(`Error playing ${this.id}:`, err));
|
|
22
|
+
this.audio.play().catch((err) => console.error(`Error playing ${this.id}:`, err));
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
25
|
pause() {
|
|
@@ -30,10 +34,24 @@ class AudioInstance {
|
|
|
30
34
|
}
|
|
31
35
|
}
|
|
32
36
|
setLoop(loop) {
|
|
37
|
+
this.loop = loop; // Met à jour l'état interne
|
|
33
38
|
if (this.audio != undefined) {
|
|
34
39
|
this.audio.loop = loop;
|
|
35
40
|
}
|
|
36
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Change le volume de l'instance
|
|
44
|
+
* @param volume Nombre entre 0 et 100
|
|
45
|
+
*/
|
|
46
|
+
setVolume(volume) {
|
|
47
|
+
// On s'assure que le volume reste entre 0 et 100
|
|
48
|
+
const safeVolume = Math.max(0, Math.min(100, volume));
|
|
49
|
+
this.volume = safeVolume;
|
|
50
|
+
if (this.audio != undefined) {
|
|
51
|
+
// HTMLAudioElement utilise une plage de 0.0 à 1.0
|
|
52
|
+
this.audio.volume = safeVolume / 100;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
37
55
|
isPlaying() {
|
|
38
56
|
if (this.audio != undefined) {
|
|
39
57
|
return !this.audio.paused;
|
|
@@ -72,10 +90,19 @@ export class AudioManager {
|
|
|
72
90
|
this.players.set(id, player);
|
|
73
91
|
}
|
|
74
92
|
else {
|
|
93
|
+
// Si le joueur existe déjà, on met à jour la boucle au cas où
|
|
75
94
|
player.setLoop(loop);
|
|
76
95
|
}
|
|
77
96
|
player.play();
|
|
78
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Change le volume d'un audio spécifique
|
|
100
|
+
* @param id L'identifiant du son
|
|
101
|
+
* @param volume Le volume entre 0 et 100
|
|
102
|
+
*/
|
|
103
|
+
setVolume(id, volume) {
|
|
104
|
+
this.players.get(id)?.setVolume(volume);
|
|
105
|
+
}
|
|
79
106
|
/**
|
|
80
107
|
* Pause a specific audio by id
|
|
81
108
|
*/
|
|
@@ -92,13 +119,13 @@ export class AudioManager {
|
|
|
92
119
|
* Stop all audios
|
|
93
120
|
*/
|
|
94
121
|
stopAll() {
|
|
95
|
-
this.players.forEach(player => player.stop());
|
|
122
|
+
this.players.forEach((player) => player.stop());
|
|
96
123
|
}
|
|
97
124
|
/**
|
|
98
125
|
* Pause all audios
|
|
99
126
|
*/
|
|
100
127
|
pauseAll() {
|
|
101
|
-
this.players.forEach(player => player.pause());
|
|
128
|
+
this.players.forEach((player) => player.pause());
|
|
102
129
|
}
|
|
103
130
|
/**
|
|
104
131
|
* Check if a specific audio is playing
|