1681-engine 0.5.10 → 0.6.1
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/CHANGELOG.md +61 -1
- package/README.md +12 -6
- package/dist/1681-engine.js +588 -522
- package/dist/ai/behaviorTree.js +198 -0
- package/dist/ai/buildTree.js +54 -0
- package/dist/audio/spatial.js +118 -0
- package/dist/cjs/electron/webPatcher.d.ts +4 -1
- package/dist/cjs/electron/webPatcher.js +9 -2
- package/dist/core/Camera.js +10 -0
- package/dist/core/ObjectFactory.js +23 -21
- package/dist/core/PixelGrid.js +47 -0
- package/dist/core/SharpText.js +72 -0
- package/dist/core/Stage.js +48 -31
- package/dist/core/gridPlacement.js +14 -0
- package/dist/dialogue/DialogueRunner.js +173 -0
- package/dist/dialogue/expr.js +137 -0
- package/dist/dialogue/validateDialogue.js +52 -0
- package/dist/ecs/prefab.js +94 -0
- package/dist/electron/webPatcher.js +16 -10
- package/dist/input/Actions.js +58 -27
- package/dist/input/InputCapture.js +98 -0
- package/dist/input/Keymap.js +32 -26
- package/dist/input/inputTape.js +68 -0
- package/dist/mobile/backButton.js +40 -0
- package/dist/mobile/capacitor.js +48 -0
- package/dist/mobile/screen.js +31 -0
- package/dist/mobile.js +12 -0
- package/dist/nav/flowField.js +58 -0
- package/dist/nav/steering.js +77 -0
- package/dist/net/InterpolationBuffer.js +30 -23
- package/dist/net/LagCompensator.js +100 -0
- package/dist/net/Room.js +122 -43
- package/dist/net/RoomHost.js +13 -4
- package/dist/net/SpatialHash.js +66 -0
- package/dist/types/ai/behaviorTree.d.ts +133 -0
- package/dist/types/ai/behaviorTree.d.ts.map +1 -0
- package/dist/types/ai/buildTree.d.ts +55 -0
- package/dist/types/ai/buildTree.d.ts.map +1 -0
- package/dist/types/audio/spatial.d.ts +107 -0
- package/dist/types/audio/spatial.d.ts.map +1 -0
- package/dist/types/core/Camera.d.ts +8 -0
- package/dist/types/core/Camera.d.ts.map +1 -1
- package/dist/types/core/ObjectFactory.d.ts.map +1 -1
- package/dist/types/core/PixelGrid.d.ts +30 -0
- package/dist/types/core/PixelGrid.d.ts.map +1 -0
- package/dist/types/core/SharpText.d.ts +32 -0
- package/dist/types/core/SharpText.d.ts.map +1 -0
- package/dist/types/core/Stage.d.ts +14 -0
- package/dist/types/core/Stage.d.ts.map +1 -1
- package/dist/types/core/gridPlacement.d.ts +20 -0
- package/dist/types/core/gridPlacement.d.ts.map +1 -0
- package/dist/types/dialogue/DialogueRunner.d.ts +78 -0
- package/dist/types/dialogue/DialogueRunner.d.ts.map +1 -0
- package/dist/types/dialogue/expr.d.ts +12 -0
- package/dist/types/dialogue/expr.d.ts.map +1 -0
- package/dist/types/dialogue/script.d.ts +78 -0
- package/dist/types/dialogue/script.d.ts.map +1 -0
- package/dist/types/dialogue/validateDialogue.d.ts +21 -0
- package/dist/types/dialogue/validateDialogue.d.ts.map +1 -0
- package/dist/types/ecs/prefab.d.ts +84 -0
- package/dist/types/ecs/prefab.d.ts.map +1 -0
- package/dist/types/electron/webPatcher.d.ts +4 -1
- package/dist/types/electron/webPatcher.d.ts.map +1 -1
- package/dist/types/index.d.ts +18 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/input/Actions.d.ts +14 -0
- package/dist/types/input/Actions.d.ts.map +1 -1
- package/dist/types/input/InputCapture.d.ts +53 -0
- package/dist/types/input/InputCapture.d.ts.map +1 -0
- package/dist/types/input/Keymap.d.ts +12 -6
- package/dist/types/input/Keymap.d.ts.map +1 -1
- package/dist/types/input/inputTape.d.ts +66 -0
- package/dist/types/input/inputTape.d.ts.map +1 -0
- package/dist/types/mobile/backButton.d.ts +30 -0
- package/dist/types/mobile/backButton.d.ts.map +1 -0
- package/dist/types/mobile/capacitor.d.ts +62 -0
- package/dist/types/mobile/capacitor.d.ts.map +1 -0
- package/dist/types/mobile/index.d.ts +4 -0
- package/dist/types/mobile/index.d.ts.map +1 -0
- package/dist/types/mobile/screen.d.ts +27 -0
- package/dist/types/mobile/screen.d.ts.map +1 -0
- package/dist/types/nav/flowField.d.ts +31 -0
- package/dist/types/nav/flowField.d.ts.map +1 -0
- package/dist/types/nav/steering.d.ts +47 -0
- package/dist/types/nav/steering.d.ts.map +1 -0
- package/dist/types/net/InterpolationBuffer.d.ts +5 -0
- package/dist/types/net/InterpolationBuffer.d.ts.map +1 -1
- package/dist/types/net/LagCompensator.d.ts +70 -0
- package/dist/types/net/LagCompensator.d.ts.map +1 -0
- package/dist/types/net/Room.d.ts +72 -3
- package/dist/types/net/Room.d.ts.map +1 -1
- package/dist/types/net/RoomHost.d.ts +8 -3
- package/dist/types/net/RoomHost.d.ts.map +1 -1
- package/dist/types/net/SpatialHash.d.ts +25 -0
- package/dist/types/net/SpatialHash.d.ts.map +1 -0
- package/dist/types/ui/ScrollView.d.ts.map +1 -1
- package/dist/ui/ScrollView.js +10 -8
- package/package.json +5 -1
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/** What a node answers each tick: done well, done badly, or not done yet. */
|
|
2
|
+
export type BtStatus = 'success' | 'failure' | 'running';
|
|
3
|
+
/**
|
|
4
|
+
* One node of a tree. Nodes hold no state of their own, so one tree drives any number of agents: what a node must
|
|
5
|
+
* remember between ticks (the child a sequence is on, when a wait began) lives in the agent's memory, `run.state`.
|
|
6
|
+
*/
|
|
7
|
+
export interface BtNode<C> {
|
|
8
|
+
readonly kind: string;
|
|
9
|
+
/** Shown in a trace; actions and conditions are named after what they do. */
|
|
10
|
+
readonly name?: string;
|
|
11
|
+
readonly children: readonly BtNode<C>[];
|
|
12
|
+
tick(ctx: C, run: BtRun<C>): BtStatus;
|
|
13
|
+
/** A running node left behind (its parent moved on, the tree was reset): undo what it started. */
|
|
14
|
+
halt?(ctx: C, run: BtRun<C>): void;
|
|
15
|
+
}
|
|
16
|
+
/** What a node may use while it ticks: the agent's clock and memory, and its children's ticks. */
|
|
17
|
+
export interface BtRun<C> {
|
|
18
|
+
/** The time this tick was given (ms), for waits, cooldowns and timeouts. */
|
|
19
|
+
readonly now: number;
|
|
20
|
+
/** This node's memory for this agent, made by `init` the first time and after a halt. */
|
|
21
|
+
state<T>(node: BtNode<C>, init: () => T): T;
|
|
22
|
+
/** Memory that outlives the node finishing (a cooldown's ready time); only `reset` clears it. */
|
|
23
|
+
lasting<T>(node: BtNode<C>, init: () => T): T;
|
|
24
|
+
/** Ticks a child; use this, never `child.tick`, so it is traced and halted right. */
|
|
25
|
+
tick(child: BtNode<C>, ctx: C): BtStatus;
|
|
26
|
+
/** Stops a child that was left running, and everything under it. */
|
|
27
|
+
halt(child: BtNode<C>, ctx: C): void;
|
|
28
|
+
}
|
|
29
|
+
/** One line of `BtAgent.trace`: a node, how deep it is, and what it last answered (null: not ticked this time). */
|
|
30
|
+
export interface BtTraceLine {
|
|
31
|
+
depth: number;
|
|
32
|
+
kind: string;
|
|
33
|
+
name: string | undefined;
|
|
34
|
+
status: BtStatus | null;
|
|
35
|
+
}
|
|
36
|
+
/** A tree's root, and the agents it drives. */
|
|
37
|
+
export declare class BehaviorTree<C> {
|
|
38
|
+
readonly root: BtNode<C>;
|
|
39
|
+
constructor(root: BtNode<C>);
|
|
40
|
+
/** A new agent on this tree, with memory of its own. */
|
|
41
|
+
agent(): BtAgent<C>;
|
|
42
|
+
}
|
|
43
|
+
/** One agent running a tree: its memory, and the tick that drives it. */
|
|
44
|
+
export declare class BtAgent<C> implements BtRun<C> {
|
|
45
|
+
readonly root: BtNode<C>;
|
|
46
|
+
now: number;
|
|
47
|
+
private memory;
|
|
48
|
+
private readonly kept;
|
|
49
|
+
/** Nodes that answered 'running' last time they ticked: the ones a halt must reach. */
|
|
50
|
+
private readonly open;
|
|
51
|
+
private last;
|
|
52
|
+
private seen;
|
|
53
|
+
constructor(root: BtNode<C>);
|
|
54
|
+
/** Ticks the tree once at time `now` (ms) and returns the root's answer. */
|
|
55
|
+
update(ctx: C, now: number): BtStatus;
|
|
56
|
+
/** Halts whatever is running and forgets all memory: the agent starts the tree afresh (it died, it was stunned). */
|
|
57
|
+
reset(ctx: C): void;
|
|
58
|
+
/** Whether a node is running for this agent now. */
|
|
59
|
+
isRunning(node: BtNode<C>): boolean;
|
|
60
|
+
state<T>(node: BtNode<C>, init: () => T): T;
|
|
61
|
+
lasting<T>(node: BtNode<C>, init: () => T): T;
|
|
62
|
+
tick(child: BtNode<C>, ctx: C): BtStatus;
|
|
63
|
+
halt(child: BtNode<C>, ctx: C): void;
|
|
64
|
+
/** The tree as it ran on the last tick, depth first: for a debug overlay. */
|
|
65
|
+
trace(): BtTraceLine[];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* A trace as text, one node a line, indented by depth, with what each answered (`·` when it was not ticked): for a
|
|
69
|
+
* debug overlay's `Text`, or a log.
|
|
70
|
+
*
|
|
71
|
+
* ```
|
|
72
|
+
* reactive-selector running
|
|
73
|
+
* sequence failure
|
|
74
|
+
* hurt failure
|
|
75
|
+
* flee ·
|
|
76
|
+
* wander running
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function formatTrace(trace: readonly BtTraceLine[]): string;
|
|
80
|
+
/**
|
|
81
|
+
* Runs its children in order until one fails: all must succeed. A running child is resumed on the next tick
|
|
82
|
+
* without asking the ones before it again (`reactiveSequence` does ask them).
|
|
83
|
+
*/
|
|
84
|
+
export declare function sequence<C>(...children: BtNode<C>[]): BtNode<C>;
|
|
85
|
+
/** Tries its children in order until one does not fail: the first that works. Resumes a running child. */
|
|
86
|
+
export declare function selector<C>(...children: BtNode<C>[]): BtNode<C>;
|
|
87
|
+
/**
|
|
88
|
+
* A sequence that asks every child from the first again on each tick: a guard in front ("still sees the player?")
|
|
89
|
+
* is checked every time, and when it fails the child that was running is halted.
|
|
90
|
+
*/
|
|
91
|
+
export declare function reactiveSequence<C>(...children: BtNode<C>[]): BtNode<C>;
|
|
92
|
+
/**
|
|
93
|
+
* A selector that asks from the first child again on each tick: a higher-priority branch ("flee when hurt") takes
|
|
94
|
+
* over the moment it can run, halting the lower one it interrupts.
|
|
95
|
+
*/
|
|
96
|
+
export declare function reactiveSelector<C>(...children: BtNode<C>[]): BtNode<C>;
|
|
97
|
+
export interface ParallelPolicy {
|
|
98
|
+
/** Children that must succeed for the whole to (default all). */
|
|
99
|
+
succeed?: number;
|
|
100
|
+
/** Children that must fail for the whole to (default 1). */
|
|
101
|
+
fail?: number;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Ticks every child each tick (walk and look about at once). Succeeds once `succeed` have succeeded, fails once
|
|
105
|
+
* `fail` have failed, halting the rest; a child that finished is not ticked again until the whole finishes.
|
|
106
|
+
*/
|
|
107
|
+
export declare function parallel<C>(policy: ParallelPolicy, ...children: BtNode<C>[]): BtNode<C>;
|
|
108
|
+
/** Swaps success and failure. */
|
|
109
|
+
export declare function invert<C>(child: BtNode<C>): BtNode<C>;
|
|
110
|
+
/** Succeeds whatever its child answers, once the child is done: an optional step. */
|
|
111
|
+
export declare function succeed<C>(child: BtNode<C>): BtNode<C>;
|
|
112
|
+
/**
|
|
113
|
+
* Runs its child `times` times in a row (Infinity: for good), stopping at the first failure. One pass per tick at
|
|
114
|
+
* most, so a child that succeeds at once cannot spin a frame.
|
|
115
|
+
*/
|
|
116
|
+
export declare function repeat<C>(times: number, child: BtNode<C>): BtNode<C>;
|
|
117
|
+
/** Tries its child up to `times` times until it succeeds, a try a tick. */
|
|
118
|
+
export declare function retry<C>(times: number, child: BtNode<C>): BtNode<C>;
|
|
119
|
+
/** Runs its child at most once every `ms`: after it finishes, it fails at once until the time is up. */
|
|
120
|
+
export declare function cooldown<C>(ms: number, child: BtNode<C>): BtNode<C>;
|
|
121
|
+
/** Fails, halting its child, when the child has run longer than `ms`. */
|
|
122
|
+
export declare function timeout<C>(ms: number, child: BtNode<C>): BtNode<C>;
|
|
123
|
+
/** Runs for `ms`, then succeeds. */
|
|
124
|
+
export declare function wait<C>(ms: number): BtNode<C>;
|
|
125
|
+
/** A test: success when `test` holds, else failure. Never runs. */
|
|
126
|
+
export declare function condition<C>(name: string, test: (ctx: C) => boolean): BtNode<C>;
|
|
127
|
+
export interface ActionOptions<C> {
|
|
128
|
+
/** The action was running and the tree left it (a higher branch took over): stop what it started. */
|
|
129
|
+
onHalt?: (ctx: C) => void;
|
|
130
|
+
}
|
|
131
|
+
/** Something the agent does: `run` answers each tick until the doing is done. */
|
|
132
|
+
export declare function action<C>(name: string, run: (ctx: C, now: number) => BtStatus, options?: ActionOptions<C>): BtNode<C>;
|
|
133
|
+
//# sourceMappingURL=behaviorTree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"behaviorTree.d.ts","sourceRoot":"","sources":["../../../src/ai/behaviorTree.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAEzD;;;GAGG;AACH,MAAM,WAAW,MAAM,CAAC,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACxC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC;IACtC,kGAAkG;IAClG,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CACpC;AAED,kGAAkG;AAClG,MAAM,WAAW,KAAK,CAAC,CAAC;IACtB,4EAA4E;IAC5E,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,yFAAyF;IACzF,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5C,iGAAiG;I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AAG,MAAM,CAAC,CAAC,CAAC,CAM7C;AAED,mEAAmE;AACnE,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAE/E;AAED,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,qGAAqG;IACrG,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,CAAC;CAC3B;AAED,iFAAiF;AACjF,wBAAgB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,KAAK,QAAQ,EAAE,OAAO,GAAE,aAAa,CAAC,CAAC,CAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAEzH"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type ActionOptions, type BtNode, type BtStatus } from './behaviorTree.js';
|
|
2
|
+
/**
|
|
3
|
+
* A tree written as data (a JSON file a designer edits): composites hold `children`, decorators one `child`, and
|
|
4
|
+
* leaves name an action or a condition the game registered.
|
|
5
|
+
*
|
|
6
|
+
* ```json
|
|
7
|
+
* { "type": "reactiveSelector", "children": [
|
|
8
|
+
* { "type": "sequence", "children": [{ "type": "condition", "name": "hurt" }, { "type": "action", "name": "flee" }] },
|
|
9
|
+
* { "type": "cooldown", "ms": 2000, "child": { "type": "action", "name": "bark" } },
|
|
10
|
+
* { "type": "action", "name": "wander" }
|
|
11
|
+
* ] }
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export type BtSpec = {
|
|
15
|
+
type: 'sequence' | 'selector' | 'reactiveSequence' | 'reactiveSelector';
|
|
16
|
+
children: BtSpec[];
|
|
17
|
+
} | {
|
|
18
|
+
type: 'parallel';
|
|
19
|
+
succeed?: number;
|
|
20
|
+
fail?: number;
|
|
21
|
+
children: BtSpec[];
|
|
22
|
+
} | {
|
|
23
|
+
type: 'invert' | 'succeed';
|
|
24
|
+
child: BtSpec;
|
|
25
|
+
} | {
|
|
26
|
+
type: 'repeat' | 'retry';
|
|
27
|
+
times: number;
|
|
28
|
+
child: BtSpec;
|
|
29
|
+
} | {
|
|
30
|
+
type: 'cooldown' | 'timeout';
|
|
31
|
+
ms: number;
|
|
32
|
+
child: BtSpec;
|
|
33
|
+
} | {
|
|
34
|
+
type: 'wait';
|
|
35
|
+
ms: number;
|
|
36
|
+
} | {
|
|
37
|
+
type: 'action' | 'condition';
|
|
38
|
+
name: string;
|
|
39
|
+
}
|
|
40
|
+
/** A named subtree of the registry, so a tree is shared by several (a "flee" every monster uses). */
|
|
41
|
+
| {
|
|
42
|
+
type: 'tree';
|
|
43
|
+
name: string;
|
|
44
|
+
};
|
|
45
|
+
/** What the leaves of a data tree name. */
|
|
46
|
+
export interface BtRegistry<C> {
|
|
47
|
+
actions?: Record<string, ((ctx: C, now: number) => BtStatus) | ({
|
|
48
|
+
run: (ctx: C, now: number) => BtStatus;
|
|
49
|
+
} & ActionOptions<C>)>;
|
|
50
|
+
conditions?: Record<string, (ctx: C) => boolean>;
|
|
51
|
+
trees?: Record<string, BtSpec>;
|
|
52
|
+
}
|
|
53
|
+
/** A tree from its data. Throws, naming the path, on an unknown type, a missing leaf or a subtree that names itself. */
|
|
54
|
+
export declare function buildTree<C>(spec: BtSpec, registry: BtRegistry<C>): BtNode<C>;
|
|
55
|
+
//# sourceMappingURL=buildTree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildTree.d.ts","sourceRoot":"","sources":["../../../src/ai/buildTree.ts"],"names":[],"mappings":"AAAA,OAAO,EAeL,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,QAAQ,EACd,MAAM,gBAAgB,CAAC;AAExB;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,MAAM,GACd;IAAE,IAAI,EAAE,UAAU,GAAG,UAAU,GAA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C,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED,wHAAwH;AACxH,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAE7E"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/** A point in the world, px. */
|
|
2
|
+
export interface Point {
|
|
3
|
+
readonly x: number;
|
|
4
|
+
readonly y: number;
|
|
5
|
+
}
|
|
6
|
+
export interface SpatialMixOptions {
|
|
7
|
+
/** Beyond this (px) the source is not heard (default 480). */
|
|
8
|
+
range?: number;
|
|
9
|
+
/** How the loudness falls off: 1 straight, higher drops faster near the edge of `range` (default 1.5). */
|
|
10
|
+
rolloff?: number;
|
|
11
|
+
/** Px off to one side at which the sound is panned fully that way (default `range / 2`). */
|
|
12
|
+
panWidth?: number;
|
|
13
|
+
/** The furthest it pans, 0–1: 1 is one ear only, which sounds wrong on headphones (default 0.8). */
|
|
14
|
+
maxPan?: number;
|
|
15
|
+
/** Low-pass cutoff (Hz) beside the listener and at the edge of `range`, so far sounds are dull; null for none. */
|
|
16
|
+
muffle?: readonly [number, number] | null;
|
|
17
|
+
}
|
|
18
|
+
/** How a source sounds from where the listener stands. */
|
|
19
|
+
export interface SpatialMix {
|
|
20
|
+
/** Within `range`. */
|
|
21
|
+
audible: boolean;
|
|
22
|
+
/** 0–1. */
|
|
23
|
+
gain: number;
|
|
24
|
+
/** −1 left … 1 right. */
|
|
25
|
+
pan: number;
|
|
26
|
+
/** The low-pass cutoff, Hz (the top of hearing when `muffle` is null). */
|
|
27
|
+
cutoffHz: number;
|
|
28
|
+
}
|
|
29
|
+
/** The mix of a source at `source` heard from `listener`: louder near, panned to its side, duller far. */
|
|
30
|
+
export declare function spatialMix(listener: Point, source: Point, options?: SpatialMixOptions): SpatialMix;
|
|
31
|
+
export interface EmitterOptions extends SpatialMixOptions {
|
|
32
|
+
/** 0–1 (default 1). */
|
|
33
|
+
volume?: number;
|
|
34
|
+
/** Plays on for good (default true); a one-shot ends by itself. */
|
|
35
|
+
loop?: boolean;
|
|
36
|
+
playbackRate?: number;
|
|
37
|
+
}
|
|
38
|
+
/** A sound placed in the world by `SpatialAudio`. */
|
|
39
|
+
export interface SpatialEmitter {
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
volume: number;
|
|
43
|
+
/** Playing now: false while out of range (a loop waits silent), and for good once stopped or ended. */
|
|
44
|
+
readonly playing: boolean;
|
|
45
|
+
readonly done: boolean;
|
|
46
|
+
stop(fadeMs?: number): void;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Sounds placed in the world, heard from a listener that moves: a waterfall, a campfire, a machine humming, or a
|
|
50
|
+
* one-shot at a spot. Each emitter is panned to its side, fades with distance and loses its highs far away
|
|
51
|
+
* (`spatialMix`), eased each `update` so a moving source does not click. A loop out of range stops its source to
|
|
52
|
+
* save the voice and starts again at the point it would have reached, so it seems to have played on.
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* const world = new SpatialAudio(audioContext);
|
|
56
|
+
* const falls = world.emitter(fallsBuffer, 320, 96, { range: 400, volume: 0.6 });
|
|
57
|
+
* // each frame: world.update(hero);
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare class SpatialAudio {
|
|
61
|
+
readonly context: BaseAudioContext;
|
|
62
|
+
/** Every emitter's gain goes through this: the game's volume setting. */
|
|
63
|
+
readonly output: GainNode;
|
|
64
|
+
private readonly emitters;
|
|
65
|
+
private here;
|
|
66
|
+
constructor(context: BaseAudioContext, destination?: AudioNode);
|
|
67
|
+
/** The listener's place as of the last `update`. */
|
|
68
|
+
get listener(): Point;
|
|
69
|
+
/** How many emitters are alive (playing or waiting out of range). */
|
|
70
|
+
get size(): number;
|
|
71
|
+
/** A sound at (x, y), looping by default. Starts at once when in range of the listener. */
|
|
72
|
+
emitter(buffer: AudioBuffer, x: number, y: number, options?: EmitterOptions): SpatialEmitter;
|
|
73
|
+
/** A one-shot at (x, y), dropped when it ends; skipped (and done at once) when out of range. */
|
|
74
|
+
play(buffer: AudioBuffer, x: number, y: number, options?: Omit<EmitterOptions, 'loop'>): SpatialEmitter;
|
|
75
|
+
/** Moves the listener and re-mixes every emitter. Call once a frame. */
|
|
76
|
+
update(listener?: Point): void;
|
|
77
|
+
/** Stops every emitter. */
|
|
78
|
+
stopAll(fadeMs?: number): void;
|
|
79
|
+
destroy(): void;
|
|
80
|
+
/** @internal */
|
|
81
|
+
forget(e: Emitter): void;
|
|
82
|
+
}
|
|
83
|
+
declare class Emitter implements SpatialEmitter {
|
|
84
|
+
private readonly owner;
|
|
85
|
+
private readonly buffer;
|
|
86
|
+
x: number;
|
|
87
|
+
y: number;
|
|
88
|
+
private readonly options;
|
|
89
|
+
volume: number;
|
|
90
|
+
done: boolean;
|
|
91
|
+
private source;
|
|
92
|
+
private readonly gain;
|
|
93
|
+
private readonly panner;
|
|
94
|
+
private readonly filter;
|
|
95
|
+
/** When the loop would have begun, had it never stopped: where a restart picks it up. */
|
|
96
|
+
private readonly origin;
|
|
97
|
+
private readonly rate;
|
|
98
|
+
constructor(owner: SpatialAudio, buffer: AudioBuffer, x: number, y: number, options: EmitterOptions);
|
|
99
|
+
get playing(): boolean;
|
|
100
|
+
refresh(listener: Point, smooth: boolean): void;
|
|
101
|
+
stop(fadeMs?: number): void;
|
|
102
|
+
private begin;
|
|
103
|
+
private halt;
|
|
104
|
+
private release;
|
|
105
|
+
}
|
|
106
|
+
export {};
|
|
107
|
+
//# sourceMappingURL=spatial.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spatial.d.ts","sourceRoot":"","sources":["../../../src/audio/spatial.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,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CAAC,QAAQ,CAAC,MAAM,CAAmB;IAC1C,yFAAyF;IACzF,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;gBAGX,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,WAAW,EAC7B,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACC,OAAO,EAAE,cAAc;IAa1C,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;IAkB/C,IAAI,CAAC,MAAM,SAAI,GAAG,IAAI;IAkBtB,OAAO,CAAC,KAAK;IAcb,OAAO,CAAC,IAAI;IAaZ,OAAO,CAAC,OAAO;CAKhB"}
|
|
@@ -34,6 +34,8 @@ export declare class Camera {
|
|
|
34
34
|
resolution: number;
|
|
35
35
|
/** Lands the view on whole backing pixels (pixel art); off, the world moves smoothly between them. */
|
|
36
36
|
roundPixels: boolean;
|
|
37
|
+
/** The world is drawn on its own pixel grid (`Stage.pixelPerfect`): `snapRoot` lands on whole world pixels. Set by the stage. */
|
|
38
|
+
pixelGrid: boolean;
|
|
37
39
|
scrollX: number;
|
|
38
40
|
scrollY: number;
|
|
39
41
|
width: number;
|
|
@@ -57,6 +59,12 @@ export declare class Camera {
|
|
|
57
59
|
setZoom(z: number): this;
|
|
58
60
|
/** A world coordinate snapped to the nearest backing pixel: one screen pixel, or a half at ×1.5. */
|
|
59
61
|
snap(v: number): number;
|
|
62
|
+
/**
|
|
63
|
+
* Where an object's root lands (a body, and whatever is laid over one): a whole world pixel while the world is drawn
|
|
64
|
+
* on its own grid (`Stage.pixelPerfect`), else `snap`. One rule for every root, so a body, what it holds and what
|
|
65
|
+
* points at it fall on the same pixel; children keep whole-pixel offsets from it.
|
|
66
|
+
*/
|
|
67
|
+
snapRoot(v: number): number;
|
|
60
68
|
setBounds(x: number, y: number, width: number, height: number): this;
|
|
61
69
|
/** Lets the view go anywhere again. */
|
|
62
70
|
clearBounds(): this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Camera.d.ts","sourceRoot":"","sources":["../../../src/core/Camera.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mGAAmG;IACnG,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mGAAmG;IACnG,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,qBAAa,MAAM;
|
|
1
|
+
{"version":3,"file":"Camera.d.ts","sourceRoot":"","sources":["../../../src/core/Camera.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mGAAmG;IACnG,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mGAAmG;IACnG,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAA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,QAAQ;IAMrD,SAAS,CAAC,CAAC,SAAI,EAAE,CAAC,SAAI,EAAE,QAAQ,GAAE,SAAS,EAAO,GAAG,KAAK;IAO1D,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,SAAS;IAM1F,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI;IAMhE,oGAAoG;IACpG,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAK,GAAG,WAAW;IAM7K,mHAAmH;IACnH,QAAQ,CAAC,CAAC,SAAS,SAAS,GAAG;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC;IAI3D,OAAO,CAAC,MAAM;CAKf"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Application, type Container } from 'pixi.js';
|
|
2
|
+
import type { Camera } from './Camera.js';
|
|
3
|
+
import { SharpText } from './SharpText.js';
|
|
4
|
+
/**
|
|
5
|
+
* A pixel-perfect world (`Stage.pixelPerfect`): the world layer is taken off the stage and drawn each frame into a
|
|
6
|
+
* texture of one texel per world pixel, whose origin sits on a whole world pixel, then shown at the camera's zoom and
|
|
7
|
+
* moved by the scroll's fraction, so the camera still glides one backing pixel at a time. Everything turned, scaled or
|
|
8
|
+
* placed between pixels lands on the same grid as the rest of the art, so no pixel on screen is drawn at another size
|
|
9
|
+
* ("mixels"); the world is also filled at 1/zoom² of the screen's pixels. Roots placed with `Camera.snapRoot` land on
|
|
10
|
+
* whole world pixels meanwhile, and text stays at screen resolution (`SharpText`).
|
|
11
|
+
*/
|
|
12
|
+
export declare class PixelGrid {
|
|
13
|
+
private readonly app;
|
|
14
|
+
private readonly world;
|
|
15
|
+
private texture;
|
|
16
|
+
private sprite;
|
|
17
|
+
readonly text: SharpText;
|
|
18
|
+
private readonly transform;
|
|
19
|
+
private on;
|
|
20
|
+
constructor(app: Application, world: Container);
|
|
21
|
+
get enabled(): boolean;
|
|
22
|
+
/** Once a frame, after the camera wrote the world's transform and before Pixi draws the screen. */
|
|
23
|
+
render(cam: Camera, enabled: boolean): void;
|
|
24
|
+
destroy(cam: Camera): void;
|
|
25
|
+
private enable;
|
|
26
|
+
private disable;
|
|
27
|
+
/** The texture at exactly this size, made again only when the screen or the zoom changed. */
|
|
28
|
+
private fit;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=PixelGrid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PixelGrid.d.ts","sourceRoot":"","sources":["../../../src/core/PixelGrid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;;;;GAOG;AACH,qBAAa,SAAS;IAQlB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK;IARxB,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,MAAM,CAAuB;IACrC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;IAC1C,OAAO,CAAC,EAAE,CAAS;gBAGA,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,SAAS;IAKnC,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,mGAAmG;IACnG,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAmB3C,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAK1B,OAAO,CAAC,MAAM;IAWd,OAAO,CAAC,OAAO;IAef,6FAA6F;IAC7F,OAAO,CAAC,GAAG;CAOZ"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Container } from 'pixi.js';
|
|
2
|
+
/**
|
|
3
|
+
* The world's text kept at screen resolution while the rest of the world is drawn one texel to a world pixel
|
|
4
|
+
* (`PixelGrid`): a small font squeezed into world pixels cannot be read. Each tracked label (every `add.text` and
|
|
5
|
+
* `add.label`; `Stage.keepSharp` for one made elsewhere) is lifted out of the container it was put in and hung on a
|
|
6
|
+
* stand-in on this layer, which copies that container's transform relative to the world, its visibility and alpha every
|
|
7
|
+
* frame, so the game keeps writing the label's own position, text and alpha as before. All of them draw over the world,
|
|
8
|
+
* sorted by the depth of the world's child they belong to; a label's container destroyed takes the label with it.
|
|
9
|
+
*/
|
|
10
|
+
export declare class SharpText {
|
|
11
|
+
private readonly world;
|
|
12
|
+
readonly layer: Container<import("pixi.js").ContainerChild>;
|
|
13
|
+
private readonly labels;
|
|
14
|
+
private readonly m;
|
|
15
|
+
/** Labels tracked since the last sweep for destroyed ones: off, nothing else sweeps them. */
|
|
16
|
+
private sinceSweep;
|
|
17
|
+
constructor(world: Container);
|
|
18
|
+
track(obj: Container): void;
|
|
19
|
+
/** Lays the layer over the world (`origin`: where the world's origin lands on screen) and every label on its home. */
|
|
20
|
+
sync(origin: {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
}, zoom: number): void;
|
|
24
|
+
/** Every label back in its home (the grid switched off), the stand-ins gone. */
|
|
25
|
+
release(): void;
|
|
26
|
+
/** Forgets labels the game destroyed while nothing synced (the grid off). */
|
|
27
|
+
prune(): void;
|
|
28
|
+
destroy(): void;
|
|
29
|
+
private place;
|
|
30
|
+
private drop;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=SharpText.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SharpText.d.ts","sourceRoot":"","sources":["../../../src/core/SharpText.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAU,MAAM,SAAS,CAAC;AAU5C;;;;;;;GAOG;AACH,qBAAa,SAAS;IAOR,OAAO,CAAC,QAAQ,CAAC,KAAK;IANlC,QAAQ,CAAC,KAAK,8CAA6C;IAC3D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoB;IAC3C,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAgB;IAClC,6FAA6F;IAC7F,OAAO,CAAC,UAAU,CAAK;gBAEM,KAAK,EAAE,SAAS;IAE7C,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI;IAK3B,sHAAsH;IACtH,IAAI,CAAC,MAAM,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IA4B1D,gFAAgF;IAChF,OAAO,IAAI,IAAI;IAiBf,6EAA6E;IAC7E,KAAK,IAAI,IAAI;IAKb,OAAO,IAAI,IAAI;IAMf,OAAO,CAAC,KAAK;IAyBb,OAAO,CAAC,IAAI;CAIb"}
|
|
@@ -25,6 +25,15 @@ export declare abstract class Stage {
|
|
|
25
25
|
readonly input: {
|
|
26
26
|
activePointer: Pointer;
|
|
27
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* Pixel-perfect: the world drawn one texel to a world pixel and scaled up by the camera's zoom (`PixelGrid`), so turned,
|
|
30
|
+
* scaled and between-pixels art lands on one grid; text made by `add.text`/`add.label` stays at screen resolution.
|
|
31
|
+
* Off (the default), the world is drawn straight at the zoom. Takes effect on the next frame; may be switched any time.
|
|
32
|
+
*/
|
|
33
|
+
pixelPerfect: boolean;
|
|
34
|
+
private readonly grid;
|
|
35
|
+
/** Whether the grid drew last frame, so the frame it is switched off still takes it down. */
|
|
36
|
+
private gridLive;
|
|
28
37
|
private readonly resizeListeners;
|
|
29
38
|
private lastWidth;
|
|
30
39
|
private lastHeight;
|
|
@@ -41,6 +50,11 @@ export declare abstract class Stage {
|
|
|
41
50
|
* good — the canvas frozen and no input reaching the server (seen on Android).
|
|
42
51
|
*/
|
|
43
52
|
frame(delta: number): void;
|
|
53
|
+
/**
|
|
54
|
+
* Keeps a piece of text made outside `add.text`/`add.label` (put on the world any way) at screen resolution while the
|
|
55
|
+
* world is pixel-perfect. Those two do it themselves.
|
|
56
|
+
*/
|
|
57
|
+
keepSharp(obj: Container): void;
|
|
44
58
|
private readonly reported;
|
|
45
59
|
/**
|
|
46
60
|
* Runs one step of a frame and swallows what it throws, so the steps after it still run. Subclasses guard the parts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Stage.d.ts","sourceRoot":"","sources":["../../../src/core/Stage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"Stage.d.ts","sourceRoot":"","sources":["../../../src/core/Stage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,OAAO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MAAM,GAAG,IAAI;IAEjD;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAc1B;;;OAGG;IACH,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI;IAI/B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAE9C;;;;OAIG;IACH,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI;IAInD,2EAA2E;IAC3E,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC;IAS/D,iIAAiI;IACjI,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI;IASlD,OAAO,IAAI,IAAI;IAUf,OAAO,CAAC,QAAQ;CAWjB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Where the world's grid texture goes this frame (`gridPlacement`). */
|
|
2
|
+
export interface GridPlacement {
|
|
3
|
+
/** The world pixel the texture's top-left texel shows. */
|
|
4
|
+
readonly tx: number;
|
|
5
|
+
readonly ty: number;
|
|
6
|
+
/** The texture's size in texels: the screen's width and height in world pixels, plus room for the fraction. */
|
|
7
|
+
readonly width: number;
|
|
8
|
+
readonly height: number;
|
|
9
|
+
/** Where the texture's top-left corner lands on screen (screen px, whole backing pixels). */
|
|
10
|
+
readonly x: number;
|
|
11
|
+
readonly y: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The pixel grid's arithmetic (`PixelGrid`). `originX/Y` is where the camera put the world's origin on screen (the
|
|
15
|
+
* scroll, plus any shake), `zoom` screen pixels a world pixel, `resolution` backing pixels a screen pixel. The texture
|
|
16
|
+
* starts on the whole world pixel at the screen's corner and is moved by what is left over, rounded to a backing pixel,
|
|
17
|
+
* so a world pixel never lands between two.
|
|
18
|
+
*/
|
|
19
|
+
export declare function gridPlacement(originX: number, originY: number, zoom: number, resolution: number, screenWidth: number, screenHeight: number): GridPlacement;
|
|
20
|
+
//# sourceMappingURL=gridPlacement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gridPlacement.d.ts","sourceRoot":"","sources":["../../../src/core/gridPlacement.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,MAAM,WAAW,aAAa;IAC5B,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,+GAA+G;IAC/G,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,6FAA6F;IAC7F,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,aAAa,CAY1J"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type ExprValue } from './expr.js';
|
|
2
|
+
import type { DialogueScript, DialogueStep } from './script.js';
|
|
3
|
+
export interface DialogueOptions {
|
|
4
|
+
/** The variables conditions read and `set` writes; shared with the game (default a fresh object). */
|
|
5
|
+
vars?: Record<string, unknown>;
|
|
6
|
+
/** Functions an expression may call, beside the built-in `visited(node)` and `chose(node, index)`. */
|
|
7
|
+
functions?: Record<string, (...args: ExprValue[]) => ExprValue>;
|
|
8
|
+
/** A `do` command: what the game does for it. */
|
|
9
|
+
onCommand?: (name: string, args: readonly unknown[], runner: DialogueRunner) => void;
|
|
10
|
+
/** A line's or a choice's text in the player's language, before `{…}` is filled in (default as written). */
|
|
11
|
+
translate?: (text: string, key: string | undefined) => string;
|
|
12
|
+
}
|
|
13
|
+
/** Where a dialogue was, and what it knew, for a save: plain data. */
|
|
14
|
+
export interface DialogueSave {
|
|
15
|
+
node: string | null;
|
|
16
|
+
line: number;
|
|
17
|
+
vars: Record<string, unknown>;
|
|
18
|
+
visits: Record<string, number>;
|
|
19
|
+
chosen: string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Runs a `DialogueScript`: hands the game one step at a time — a line, a set of choices, the end — and moves on when
|
|
23
|
+
* the game says the line was read (`next`) or a choice made (`choose`). It draws nothing: the game's own box shows a
|
|
24
|
+
* `ShownLine` however it likes (a typewriter, a portrait from `tags`).
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* const talk = new DialogueRunner(script, { vars: save.flags, onCommand: (name, args) => game.run(name, args) });
|
|
28
|
+
* let step = talk.start();
|
|
29
|
+
* // on a press: step = step.type === 'line' ? talk.next() : talk.choose(picked);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class DialogueRunner {
|
|
33
|
+
readonly script: DialogueScript;
|
|
34
|
+
private readonly options;
|
|
35
|
+
readonly vars: Record<string, unknown>;
|
|
36
|
+
private node;
|
|
37
|
+
private line;
|
|
38
|
+
private step;
|
|
39
|
+
private readonly visits;
|
|
40
|
+
private readonly chosen;
|
|
41
|
+
private readonly scope;
|
|
42
|
+
constructor(script: DialogueScript, options?: DialogueOptions);
|
|
43
|
+
/** The step showing now. */
|
|
44
|
+
get current(): DialogueStep;
|
|
45
|
+
/** The node the dialogue is in, or null once it has ended. */
|
|
46
|
+
get at(): string | null;
|
|
47
|
+
/** How many times a node was entered. */
|
|
48
|
+
visited(node: string): number;
|
|
49
|
+
/** Begins at `node` (default the script's `start`, else its first node). */
|
|
50
|
+
start(node?: string | undefined): DialogueStep;
|
|
51
|
+
/** The line showing was read: on to the next line, the choices, or wherever the node leads. */
|
|
52
|
+
next(): DialogueStep;
|
|
53
|
+
/** Picks a choice by its `index` (as shown). A locked or unknown index changes nothing. */
|
|
54
|
+
choose(index: number): DialogueStep;
|
|
55
|
+
/** Jumps to a node from outside (the game's own event broke in). */
|
|
56
|
+
jump(node: string): DialogueStep;
|
|
57
|
+
/** Ends the dialogue now. */
|
|
58
|
+
stop(): DialogueStep;
|
|
59
|
+
/** The value of an expression over this dialogue's variables, for a game that shares the language. */
|
|
60
|
+
evaluate(source: string): ExprValue;
|
|
61
|
+
save(): DialogueSave;
|
|
62
|
+
/** Puts a saved dialogue back where it was, without running the node's `set` and `do` again. */
|
|
63
|
+
restore(save: DialogueSave): DialogueStep;
|
|
64
|
+
private go;
|
|
65
|
+
private enter;
|
|
66
|
+
/** The step from the current line on: the next line that holds, else the choices, else the way on. */
|
|
67
|
+
private show;
|
|
68
|
+
private offered;
|
|
69
|
+
private wayOn;
|
|
70
|
+
private finish;
|
|
71
|
+
private nodeOf;
|
|
72
|
+
private test;
|
|
73
|
+
private assign;
|
|
74
|
+
private run;
|
|
75
|
+
/** `text` translated, with each `{expression}` replaced by its value; `{{` and `}}` are braces. */
|
|
76
|
+
private text;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=DialogueRunner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DialogueRunner.d.ts","sourceRoot":"","sources":["../../../src/dialogue/DialogueRunner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,KAAK,EAA+D,cAAc,EAAE,YAAY,EAAe,MAAM,UAAU,CAAC;AAEvI,MAAM,WAAW,eAAe;IAC9B,qGAAqG;IACrG,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,sGAAsG;IACtG,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,SAAS,EAAE,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AC5E,KAAK,CAAC,IAAI,qBAAyD,GAAG,YAAY;IAKlF,+FAA+F;IAC/F,IAAI,IAAI,YAAY;IAMpB,2FAA2F;IAC3F,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY;IAYnC,oEAAoE;IACpE,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY;IAIhC,6BAA6B;IAC7B,IAAI,IAAI,YAAY;IAIpB,sGAAsG;IACtG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS;IAInC,IAAI,IAAI,YAAY;IAUpB,gGAAgG;IAChG,OAAO,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY;IAazC,OAAO,CAAC,EAAE;IAIV,OAAO,CAAC,KAAK;IAab,sGAAsG;IACtG,OAAO,CAAC,IAAI;IAgBZ,OAAO,CAAC,OAAO;IAYf,OAAO,CAAC,KAAK;IAOb,OAAO,CAAC,MAAM;IAKd,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,IAAI;IAIZ,OAAO,CAAC,MAAM;IAOd,OAAO,CAAC,GAAG;IAOX,mGAAmG;IACnG,OAAO,CAAC,IAAI;CASb"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type ExprValue = number | string | boolean | null | undefined;
|
|
2
|
+
/** What an expression reads: variables by (dotted) name, and the functions it may call. */
|
|
3
|
+
export interface ExprScope {
|
|
4
|
+
get(name: string): unknown;
|
|
5
|
+
call(name: string, args: ExprValue[]): ExprValue;
|
|
6
|
+
}
|
|
7
|
+
export type CompiledExpr = (scope: ExprScope) => ExprValue;
|
|
8
|
+
/** Compiles `src`; throws with what and where on a syntax error. */
|
|
9
|
+
export declare function compileExpr(src: string): CompiledExpr;
|
|
10
|
+
/** `compileExpr`, kept: a script asks the same few conditions again and again. */
|
|
11
|
+
export declare function expr(src: string): CompiledExpr;
|
|
12
|
+
//# sourceMappingURL=expr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expr.d.ts","sourceRoot":"","sources":["../../../src/dialogue/expr.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAErE,2FAA2F;AAC3F,MAAM,WAAW,SAAS;IACxB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;CAClD;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,SAAS,KAAK,SAAS,CAAC;AAsD3D,oEAAoE;AACpE,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAgHrD;AAID,kFAAkF;AAClF,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAQ9C"}
|