@automataframework/core 0.0.1-preview.15.sha-23a3e44 → 0.0.1-preview.17.sha-d17daef
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
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Inputs } from '../game/game.ts';
|
|
2
|
+
/** A play's runs: how many ticks, and the inputs held for all of them. */
|
|
3
|
+
type Runs = [ticks: number, inputs: Inputs][];
|
|
4
|
+
/**
|
|
5
|
+
* Lets something other than a person drive a running game (the tools do, to play a recording in a real browser).
|
|
6
|
+
* `next` is called once a tick with what the keys, touch and pad gave; while a feed is on it answers with the fed
|
|
7
|
+
* inputs instead. Fed runs go one tick at a time and the feed lets go after the last run.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createFeed(): {
|
|
10
|
+
/** Holds these inputs for every tick from now on, until `hold(null)`. */
|
|
11
|
+
hold(inputs: Inputs | null): void;
|
|
12
|
+
/** Plays these runs from the next tick, then lets go. */
|
|
13
|
+
runs(runs: Runs): void;
|
|
14
|
+
next(real: () => Inputs): Inputs;
|
|
15
|
+
/** True while fed runs are still playing. */
|
|
16
|
+
busy: () => boolean;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lets something other than a person drive a running game (the tools do, to play a recording in a real browser).
|
|
3
|
+
* `next` is called once a tick with what the keys, touch and pad gave; while a feed is on it answers with the fed
|
|
4
|
+
* inputs instead. Fed runs go one tick at a time and the feed lets go after the last run.
|
|
5
|
+
*/
|
|
6
|
+
export function createFeed() {
|
|
7
|
+
let held = null;
|
|
8
|
+
let queue = [];
|
|
9
|
+
let current = null;
|
|
10
|
+
let left = 0;
|
|
11
|
+
return {
|
|
12
|
+
/** Holds these inputs for every tick from now on, until `hold(null)`. */
|
|
13
|
+
hold(inputs) {
|
|
14
|
+
held = inputs;
|
|
15
|
+
queue = [];
|
|
16
|
+
left = 0;
|
|
17
|
+
current = null;
|
|
18
|
+
},
|
|
19
|
+
/** Plays these runs from the next tick, then lets go. */
|
|
20
|
+
runs(runs) {
|
|
21
|
+
queue = structuredClone(runs);
|
|
22
|
+
left = 0;
|
|
23
|
+
current = null;
|
|
24
|
+
},
|
|
25
|
+
next(real) {
|
|
26
|
+
while (left === 0) {
|
|
27
|
+
const run = queue.shift();
|
|
28
|
+
if (!run) {
|
|
29
|
+
current = null;
|
|
30
|
+
return held ?? real();
|
|
31
|
+
}
|
|
32
|
+
left = run[0];
|
|
33
|
+
current = run[1];
|
|
34
|
+
}
|
|
35
|
+
left -= 1;
|
|
36
|
+
return current ?? held ?? real();
|
|
37
|
+
},
|
|
38
|
+
/** True while fed runs are still playing. */
|
|
39
|
+
busy: () => left > 0 || queue.length > 0,
|
|
40
|
+
};
|
|
41
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { content, loadGame } from './features/content/load.ts';
|
|
|
7
7
|
export type { Content, Read } from './features/content/load.ts';
|
|
8
8
|
export type { Manifest } from './features/content/manifest.ts';
|
|
9
9
|
export { addUpgrade, upgrade } from './features/upgrade/upgrade.ts';
|
|
10
|
+
export { createFeed } from './features/input/feed.ts';
|
|
10
11
|
export { controlsSchema, defaultBindings } from './features/input/controls.ts';
|
|
11
12
|
export type { Action, Bindings, Controls } from './features/input/controls.ts';
|
|
12
13
|
export { createSaves, slots } from './features/saves/saves.ts';
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export { step } from './features/game/tick.js';
|
|
|
4
4
|
export { defineKind, schemas } from './features/content/kinds.js';
|
|
5
5
|
export { content, loadGame } from './features/content/load.js';
|
|
6
6
|
export { addUpgrade, upgrade } from './features/upgrade/upgrade.js';
|
|
7
|
+
export { createFeed } from './features/input/feed.js';
|
|
7
8
|
export { controlsSchema, defaultBindings } from './features/input/controls.js';
|
|
8
9
|
export { createSaves, slots } from './features/saves/saves.js';
|
|
9
10
|
export { hashState } from './features/plays/hash.js';
|
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.17.sha-d17daef",
|
|
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",
|