@automataframework/core 0.0.1-preview.16.sha-dfb9cf4 → 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.
@@ -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.16.sha-dfb9cf4",
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",