@automataframework/core 0.0.1-preview.14.sha-2273a46 → 0.0.1-preview.16.sha-dfb9cf4
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.
|
@@ -13,6 +13,7 @@ export declare function createAudio(): {
|
|
|
13
13
|
stop(id: string): void;
|
|
14
14
|
setGain(bus: Bus, value: number): void;
|
|
15
15
|
mute(on: boolean): void;
|
|
16
|
+
/** The volume a bus is set to, between 0 and 1: what its gain node is given. The master reads 0 while muted. */
|
|
16
17
|
gain: (bus: string) => number;
|
|
17
18
|
};
|
|
18
19
|
export {};
|
|
@@ -12,8 +12,14 @@ export function createAudio() {
|
|
|
12
12
|
bus.connect(master);
|
|
13
13
|
const sounds = new Map();
|
|
14
14
|
const playing = new Map();
|
|
15
|
-
|
|
15
|
+
// The volumes as they were last set. `gain` answers from these, not from the nodes: while sound is running, reading a
|
|
16
|
+
// node's `gain.value` straight after setting it can give the value from before, because the audio thread writes it too.
|
|
17
|
+
const levels = { master: 1, music: 1, effects: 1 };
|
|
16
18
|
let muted = false;
|
|
19
|
+
const level = (bus) => (bus === 'master' && muted ? 0 : levels[bus]);
|
|
20
|
+
const apply = (bus) => {
|
|
21
|
+
buses[bus].gain.value = level(bus);
|
|
22
|
+
};
|
|
17
23
|
const wake = () => void context.resume().catch(() => { });
|
|
18
24
|
for (const type of ['pointerdown', 'keydown'])
|
|
19
25
|
globalThis.addEventListener?.(type, wake, { once: true });
|
|
@@ -49,19 +55,14 @@ export function createAudio() {
|
|
|
49
55
|
source.stop();
|
|
50
56
|
},
|
|
51
57
|
setGain(bus, value) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
masterVolume = clamped;
|
|
55
|
-
if (!muted)
|
|
56
|
-
master.gain.value = clamped;
|
|
57
|
-
}
|
|
58
|
-
else
|
|
59
|
-
buses[bus].gain.value = clamped;
|
|
58
|
+
levels[bus] = Math.min(1, Math.max(0, value));
|
|
59
|
+
apply(bus);
|
|
60
60
|
},
|
|
61
61
|
mute(on) {
|
|
62
62
|
muted = on;
|
|
63
|
-
master
|
|
63
|
+
apply('master');
|
|
64
64
|
},
|
|
65
|
-
|
|
65
|
+
/** The volume a bus is set to, between 0 and 1: what its gain node is given. The master reads 0 while muted. */
|
|
66
|
+
gain: (bus) => (Object.hasOwn(levels, bus) ? level(bus) : 0),
|
|
66
67
|
};
|
|
67
68
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automataframework/core",
|
|
3
|
-
"version": "0.0.1-preview.
|
|
3
|
+
"version": "0.0.1-preview.16.sha-dfb9cf4",
|
|
4
4
|
"description": "What a game's update uses: the tick, input, content files and their schemas. Formats may change.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "McThayDT",
|