@yaks/stage 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +73 -2
- package/_dist/aim.d.ts +14 -0
- package/_dist/aim.d.ts.map +1 -0
- package/_dist/air.d.ts +23 -0
- package/_dist/air.d.ts.map +1 -0
- package/_dist/bus.d.ts +8 -0
- package/_dist/bus.d.ts.map +1 -0
- package/_dist/cam.d.ts +75 -0
- package/_dist/cam.d.ts.map +1 -0
- package/_dist/ears.d.ts +71 -0
- package/_dist/ears.d.ts.map +1 -0
- package/_dist/flames.d.ts +10 -0
- package/_dist/flames.d.ts.map +1 -0
- package/_dist/fx.d.ts +27 -0
- package/_dist/fx.d.ts.map +1 -0
- package/_dist/halo.d.ts +4 -0
- package/_dist/halo.d.ts.map +1 -0
- package/_dist/instances.d.ts +24 -0
- package/_dist/instances.d.ts.map +1 -0
- package/_dist/mod.d.ts +7 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/pace.d.ts +19 -0
- package/_dist/pace.d.ts.map +1 -0
- package/_dist/render.d.ts +7 -0
- package/_dist/render.d.ts.map +1 -0
- package/_dist/samples.d.ts +27 -0
- package/_dist/samples.d.ts.map +1 -0
- package/_dist/scene.d.ts +28 -0
- package/_dist/scene.d.ts.map +1 -0
- package/_dist/sound.d.ts +13 -0
- package/_dist/sound.d.ts.map +1 -0
- package/aim.js +63 -0
- package/aim.js.map +1 -0
- package/aim.ts +71 -0
- package/air.js +40 -0
- package/air.js.map +1 -0
- package/air.ts +66 -0
- package/bus.js +36 -0
- package/bus.js.map +1 -0
- package/bus.ts +51 -0
- package/cam.js +110 -0
- package/cam.js.map +1 -0
- package/cam.ts +181 -0
- package/deno.json +1 -0
- package/ears.js +123 -0
- package/ears.js.map +1 -0
- package/ears.ts +131 -0
- package/flames.js +61 -0
- package/flames.js.map +1 -0
- package/flames.ts +69 -0
- package/fx.js +235 -0
- package/fx.js.map +1 -0
- package/fx.ts +330 -0
- package/halo.js +22 -0
- package/halo.js.map +1 -0
- package/halo.ts +23 -0
- package/instances.js +131 -0
- package/instances.js.map +1 -0
- package/instances.ts +166 -0
- package/mod.js +5 -0
- package/mod.js.map +1 -0
- package/mod.ts +7 -0
- package/pace.js +63 -0
- package/pace.js.map +1 -0
- package/pace.ts +86 -0
- package/package.json +73 -4
- package/render.js +50 -0
- package/render.js.map +1 -0
- package/render.ts +68 -0
- package/samples.js +162 -0
- package/samples.js.map +1 -0
- package/samples.ts +204 -0
- package/scene.js +80 -0
- package/scene.js.map +1 -0
- package/scene.ts +112 -0
- package/sound.js +117 -0
- package/sound.js.map +1 -0
- package/sound.ts +175 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** The audible region of one decoded clip, in seconds. */ export interface Audible {
|
|
2
|
+
offset: number;
|
|
3
|
+
dur: number;
|
|
4
|
+
}
|
|
5
|
+
/** Independent keyed voices that may steal only their own previous action. */ export interface OneShots {
|
|
6
|
+
prune(): void;
|
|
7
|
+
play(voice: Voice, key?: string): void;
|
|
8
|
+
}
|
|
9
|
+
/** A URL-addressed audio cache, isolated by audio context. */ export interface Clips {
|
|
10
|
+
loaded(ctx: BaseAudioContext, url: string | URL): AudioBuffer | undefined;
|
|
11
|
+
load(ctx: AudioContext, url: string | URL): Promise<AudioBuffer | null>;
|
|
12
|
+
}
|
|
13
|
+
export declare let audible: (buffer: AudioBuffer) => Audible;
|
|
14
|
+
/** Overlap a recording's end with its start, then loop at adjacent samples. */ export declare let blendLoop: (input: Float32Array, fade: number) => Float32Array<ArrayBuffer>;
|
|
15
|
+
/** A decoded ambient clip made seamless once, shared by its nearby sources. */ export declare let looping: (ctx: AudioContext, source: AudioBuffer) => AudioBuffer;
|
|
16
|
+
/** A sound: how long it lasts in seconds, how loud it is at its source, and
|
|
17
|
+
* how it is made into `o`. */ export type Voice = {
|
|
18
|
+
dur: number;
|
|
19
|
+
loud: number;
|
|
20
|
+
key?: string;
|
|
21
|
+
play: (o: AudioNode) => void | (() => void);
|
|
22
|
+
};
|
|
23
|
+
export declare let oneShots: (into: AudioNode) => OneShots;
|
|
24
|
+
export declare let recorded: (buffer: AudioBuffer, fallback: Voice, gain: number, key: string) => Voice;
|
|
25
|
+
/** Decode URL-addressed clips once per context. Failures leave callers' fallback
|
|
26
|
+
* voices in use and may be retried; pending requests are shared. */ export declare let clips: (failed?: (error: unknown) => void) => Clips;
|
|
27
|
+
//# sourceMappingURL=samples.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"samples.d.ts","sources":["../samples.ts"],"names":[],"mappings":"AAAA,wDAAwD,GACxD,iBAAiB;EACf,QAAQ,MAAM;EACd,KAAK,MAAM;;AAEb,4EAA4E,GAC5E,iBAAiB;EACf,SAAS,IAAI;EACb,KAAK,OAAO,OAAO,MAAM,MAAM,GAAG,IAAI;;AAExC,4DAA4D,GAC5D,iBAAiB;EACf,OAAO,KAAK,kBAAkB,KAAK,MAAM,GAAG,MAAM,cAAc,SAAS;EACzE,KAAK,KAAK,cAAc,KAAK,MAAM,GAAG,MAAM,QAAQ,cAAc,IAAI;;AAQxE,OAAO,YAAI,UAAW,QAAQ,gBAAc,QA4B3C;AAED,6EAA6E,GAC7E,OAAO,YAAI,YACT,OAAO,cACP,MAAM,MAAM,KACX,aAAa,aAQf;AAED,6EAA6E,GAC7E,OAAO,YAAI,UAAW,KAAK,cAAc,QAAQ,gBAAc,YAkB9D;AAED;4BAC4B,GAC5B,YAAY;EACV,KAAK,MAAM;EACX,MAAM,MAAM;EACZ,MAAM,MAAM;EACZ,OAAO,GAAG,cAAc,IAAI,UAAU,IAAI;;AAK5C,OAAO,YAAI,WAAY,MAAM,cAAY,SA0BxC;AAED,OAAO,YAAI,WACT,QAAQ,aACR,UAAU,OACV,MAAM,MAAM,EACZ,KAAK,MAAM,KACV,MA4BF;AAOD;kEACkE,GAClE,OAAO,YAAI,QAAS,UAAS,OAAO,OAAO,KAAK,IAAI,KAAiB,MAoCpE"}
|
package/_dist/scene.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// @ts-types="npm:@types/three@^0.186.0"
|
|
2
|
+
import * as THREE from "@types/three";
|
|
3
|
+
import { type CameraIntent } from "./cam.js";
|
|
4
|
+
/** Where the followed actor stands and which way it faces, in world units and
|
|
5
|
+
* radians. */ export type Pose = {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
z: number;
|
|
9
|
+
yaw: number;
|
|
10
|
+
};
|
|
11
|
+
export type FollowOptions = {
|
|
12
|
+
/** Whether the camera may not stand at a point (walls, terrain). */ blocked?: (point: THREE.Vector3) => boolean;
|
|
13
|
+
/** The sky and fog colour. */ sky?: number;
|
|
14
|
+
};
|
|
15
|
+
/** What {@link followScene} answers. */ export type FollowScene = {
|
|
16
|
+
scene: THREE.Scene;
|
|
17
|
+
camera: THREE.PerspectiveCamera;
|
|
18
|
+
/** `elapsed` is the frame's uncapped wall time, which paces quality. */ draw(pose: Pose, input: CameraIntent, dt: number, elapsed: number): void;
|
|
19
|
+
pick(x: number, y: number): THREE.Vector3 | null;
|
|
20
|
+
dispose(): void;
|
|
21
|
+
};
|
|
22
|
+
/** A lit Three.js scene around the caller's `world`, with a camera that
|
|
23
|
+
* follows `actor`. `draw` places the actor at a pose, steers the camera by a
|
|
24
|
+
* camera intent, renders, and on slow frames sheds pixels and then shadows
|
|
25
|
+
* (`keepUp(quality(...))`). `pick` answers the ground point under a screen
|
|
26
|
+
* position, for tapping where to go. The scene owns the GPU lifetime of every
|
|
27
|
+
* mesh it holds: `dispose` frees them with the renderer. */ export declare let followScene: (canvas: HTMLCanvasElement, world: THREE.Object3D, actor: THREE.Object3D, _dts_1: never) => FollowScene;
|
|
28
|
+
//# sourceMappingURL=scene.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scene.d.ts","sources":["../scene.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,YAAY,0BAA+B;AAC3C,SAAwB,KAAK,YAAY,mBAAyB;AAGlE;YACY,GACZ,YAAY;EAAS,GAAG,MAAM;EAAE,GAAG,MAAM;EAAE,GAAG,MAAM;EAAE,KAAK,MAAM;;AAEjE,YAAY;EACV,kEAAkE,GAClE,WAAW,OAAO,MAAM,YAAY,OAAO;EAC3C,4BAA4B,GAC5B,MAAM,MAAM;;AAGd,sCAAsC,GACtC,YAAY;EACV,OAAO,MAAM;EACb,QAAQ,MAAM;EACd,sEAAsE,GACtE,KAAK,MAAM,MAAM,OAAO,cAAc,IAAI,MAAM,EAAE,SAAS,MAAM,GAAG,IAAI;EACxE,KAAK,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,UAAU,IAAI;EAChD,WAAW,IAAI;;AAGjB;;;;;0DAK0D,GAC1D,OAAO,YAAI,cACT,QAAQ,mBACR,OAAO,MAAM,UACb,OAAO,MAAM,UACb,kBACC,YA0EF"}
|
package/_dist/sound.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Ear, type Falloff, type Vec3 } from "./ears.js";
|
|
2
|
+
import { type Voice } from "./samples.js";
|
|
3
|
+
/** Where a sound is made: at a moving source identified by a caller-supplied key, at a point, or nowhere, straight to the ears. */ export type From = string | Vec3 | null;
|
|
4
|
+
/** A sound that keeps going into `into` once made, until it is stopped by
|
|
5
|
+
* what this returns. */ export type Keep = (ctx: AudioContext, into: AudioNode) => () => void;
|
|
6
|
+
/** Sources owned by one audio context, updated with locations each frame. */ export interface Sources<Channel extends string> {
|
|
7
|
+
make(from: From, voice: Voice, key?: string): void;
|
|
8
|
+
keep(id: string, sound: Keep, falloff?: Falloff, channel?: Channel): () => void;
|
|
9
|
+
playing(id: string, channel?: Channel): boolean;
|
|
10
|
+
listen(ears: Ear, locations: ReadonlyMap<string, Vec3>): void;
|
|
11
|
+
}
|
|
12
|
+
/** A source bank for one context and a set of named output buses. */ export declare let sources: <Channel extends string>(ctx: AudioContext, destination: Record<Channel, AudioNode>, effects: Channel) => Sources<Channel>;
|
|
13
|
+
//# sourceMappingURL=sound.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sound.d.ts","sources":["../sound.ts"],"names":[],"mappings":"AAEA,SACE,KAAK,GAAG,EAER,KAAK,OAAO,EAGZ,KAAK,IAAI,oBACO;AAClB,SAAmB,KAAK,KAAK,uBAAsB;AAEnD,iIAAiI,GACjI,YAAY,OAAO,MAAM,GAAG,OAAO,IAAI;AAEvC;sBACsB,GACtB,YAAY,QAAQ,KAAK,cAAc,MAAM,oBAAoB,IAAI;AAerE,2EAA2E,GAC3E,iBAAiB,QAAQ,gBAAgB,MAAM;EAC7C,KAAK,MAAM,MAAM,OAAO,OAAO,MAAM,MAAM,GAAG,IAAI;EAClD,KACE,IAAI,MAAM,EACV,OAAO,MACP,UAAU,SACV,UAAU,gBACH,IAAI;EACb,QAAQ,IAAI,MAAM,EAAE,UAAU,UAAU,OAAO;EAC/C,OAAO,MAAM,KAAK,WAAW,YAAY,MAAM,EAAE,QAAQ,IAAI;;AAG/D,mEAAmE,GACnE,OAAO,YAAI,UAAW,gBAAgB,MAAM,EAC1C,KAAK,cACL,aAAa,OAAO,SAAS,YAC7B,SAAS,YACR,QAAQ,SA4HV"}
|
package/aim.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Mouse aiming shared by the input, simulation and stage. Rays meet terrain;
|
|
2
|
+
// a cast keeps its landing point even when the mouse moves during the swing.
|
|
3
|
+
export let cursor = (x, y, width, height, locked)=>locked ? [
|
|
4
|
+
0,
|
|
5
|
+
0
|
|
6
|
+
] : [
|
|
7
|
+
x / width * 2 - 1,
|
|
8
|
+
1 - y / height * 2
|
|
9
|
+
];
|
|
10
|
+
export let groundRay = (from, ray, height, far = 120)=>{
|
|
11
|
+
let at = (d)=>({
|
|
12
|
+
x: from.x + ray.x * d,
|
|
13
|
+
y: from.y + ray.y * d,
|
|
14
|
+
z: from.z + ray.z * d
|
|
15
|
+
});
|
|
16
|
+
let above = (d)=>{
|
|
17
|
+
let p = at(d);
|
|
18
|
+
return p.y - height(p.x, p.z);
|
|
19
|
+
};
|
|
20
|
+
for(let d = 0.5; d <= far; d += 0.5){
|
|
21
|
+
if (above(d) > 0) continue;
|
|
22
|
+
let lo = d - 0.5, hi = d;
|
|
23
|
+
for(let n = 0; n < 10; n++){
|
|
24
|
+
let mid = (lo + hi) / 2;
|
|
25
|
+
if (above(mid) > 0) lo = mid;
|
|
26
|
+
else hi = mid;
|
|
27
|
+
}
|
|
28
|
+
let p = at(hi);
|
|
29
|
+
return {
|
|
30
|
+
...p,
|
|
31
|
+
y: height(p.x, p.z)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
let p = at(far);
|
|
35
|
+
return {
|
|
36
|
+
...p,
|
|
37
|
+
y: height(p.x, p.z)
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export let landing = (from, to, reach)=>{
|
|
41
|
+
let d = Math.hypot(to.x - from.x, to.z - from.z);
|
|
42
|
+
let k = Math.min(1, reach / (d || 1));
|
|
43
|
+
return {
|
|
44
|
+
x: from.x + (to.x - from.x) * k,
|
|
45
|
+
y: from.y + (to.y - from.y) * k,
|
|
46
|
+
z: from.z + (to.z - from.z) * k
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
/** First entity under a ray, before the terrain; independent of array order. */ export let pickRay = (marks, from, ray, far = Infinity)=>{
|
|
50
|
+
let best = null, near = far;
|
|
51
|
+
for (let m of marks){
|
|
52
|
+
let x = m.body.x - from.x, y = m.body.y - from.y, z = m.body.z - from.z;
|
|
53
|
+
let along = x * ray.x + y * ray.y + z * ray.z;
|
|
54
|
+
let across = x * x + y * y + z * z - along * along;
|
|
55
|
+
if (across > m.radius * m.radius) continue;
|
|
56
|
+
let hit = along - Math.sqrt(m.radius * m.radius - across);
|
|
57
|
+
if (hit < 0 || hit >= near) continue;
|
|
58
|
+
best = m;
|
|
59
|
+
near = hit;
|
|
60
|
+
}
|
|
61
|
+
return best;
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=aim.js.map
|
package/aim.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aim.js","sources":["./aim.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,6EAA6E;AAE7E,OAAO,IAAI,SAAS,CAClB,GACA,GACA,OACA,QACA,SACqB,SAAS;IAAC;IAAG;GAAE,GAAG;IAAC,IAAI,QAAQ,IAAI;IAAG,IAAI,IAAI,SAAS;GAAE,CAAA;AAEhF,OAAO,IAAI,YAAY,CACrB,MACA,KACA,QACA,MAAM,GAAG;EAET,IAAI,KAAK,CAAC,IAAc,CAAC;MACvB,GAAG,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG;MACpB,GAAG,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG;MACpB,GAAG,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG;IACtB,CAAC;EACD,IAAI,QAAQ,CAAC;IACX,IAAI,IAAI,GAAG;IACX,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC;EAC9B;EACA,IAAK,IAAI,IAAI,KAAK,KAAK,KAAK,KAAK,IAAK;IACpC,IAAI,MAAM,KAAK,GAAG;IAClB,IAAI,KAAK,IAAI,KAAK,KAAK;IACvB,IAAK,IAAI,IAAI,GAAG,IAAI,IAAI,IAAK;MAC3B,IAAI,MAAM,CAAC,KAAK,EAAE,IAAI;MACtB,IAAI,MAAM,OAAO,GAAG,KAAK;WACpB,KAAK;IACZ;IACA,IAAI,IAAI,GAAG;IACX,OAAO;MAAE,GAAG,CAAC;MAAE,GAAG,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC;IAAE;EACrC;EACA,IAAI,IAAI,GAAG;EACX,OAAO;IAAE,GAAG,CAAC;IAAE,GAAG,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC;EAAE;AACrC,EAAC;AA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+
// a cast keeps its landing point even when the mouse moves during the swing.
|
|
3
|
+
export type Point = { x: number; y: number; z: number }
|
|
4
|
+
export let cursor = (
|
|
5
|
+
x: number,
|
|
6
|
+
y: number,
|
|
7
|
+
width: number,
|
|
8
|
+
height: number,
|
|
9
|
+
locked: boolean,
|
|
10
|
+
): [number, number] => locked ? [0, 0] : [x / width * 2 - 1, 1 - y / height * 2]
|
|
11
|
+
|
|
12
|
+
export let groundRay = (
|
|
13
|
+
from: Point,
|
|
14
|
+
ray: Point,
|
|
15
|
+
height: (x: number, z: number) => number,
|
|
16
|
+
far = 120,
|
|
17
|
+
): Point => {
|
|
18
|
+
let at = (d: number) => ({
|
|
19
|
+
x: from.x + ray.x * d,
|
|
20
|
+
y: from.y + ray.y * d,
|
|
21
|
+
z: from.z + ray.z * d,
|
|
22
|
+
})
|
|
23
|
+
let above = (d: number) => {
|
|
24
|
+
let p = at(d)
|
|
25
|
+
return p.y - height(p.x, p.z)
|
|
26
|
+
}
|
|
27
|
+
for (let d = 0.5; d <= far; d += 0.5) {
|
|
28
|
+
if (above(d) > 0) continue
|
|
29
|
+
let lo = d - 0.5, hi = d
|
|
30
|
+
for (let n = 0; n < 10; n++) {
|
|
31
|
+
let mid = (lo + hi) / 2
|
|
32
|
+
if (above(mid) > 0) lo = mid
|
|
33
|
+
else hi = mid
|
|
34
|
+
}
|
|
35
|
+
let p = at(hi)
|
|
36
|
+
return { ...p, y: height(p.x, p.z) }
|
|
37
|
+
}
|
|
38
|
+
let p = at(far)
|
|
39
|
+
return { ...p, y: height(p.x, p.z) }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export let landing = (from: Point, to: Point, reach: number): Point => {
|
|
43
|
+
let d = Math.hypot(to.x - from.x, to.z - from.z)
|
|
44
|
+
let k = Math.min(1, reach / (d || 1))
|
|
45
|
+
return {
|
|
46
|
+
x: from.x + (to.x - from.x) * k,
|
|
47
|
+
y: from.y + (to.y - from.y) * k,
|
|
48
|
+
z: from.z + (to.z - from.z) * k,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** First entity under a ray, before the terrain; independent of array order. */
|
|
53
|
+
export let pickRay = <M extends { eid: string; body: Point; radius: number }>(
|
|
54
|
+
marks: M[],
|
|
55
|
+
from: Point,
|
|
56
|
+
ray: Point,
|
|
57
|
+
far = Infinity,
|
|
58
|
+
): M | null => {
|
|
59
|
+
let best: M | null = null, near = far
|
|
60
|
+
for (let m of marks) {
|
|
61
|
+
let x = m.body.x - from.x, y = m.body.y - from.y, z = m.body.z - from.z
|
|
62
|
+
let along = x * ray.x + y * ray.y + z * ray.z
|
|
63
|
+
let across = x * x + y * y + z * z - along * along
|
|
64
|
+
if (across > m.radius * m.radius) continue
|
|
65
|
+
let hit = along - Math.sqrt(m.radius * m.radius - across)
|
|
66
|
+
if (hit < 0 || hit >= near) continue
|
|
67
|
+
best = m
|
|
68
|
+
near = hit
|
|
69
|
+
}
|
|
70
|
+
return best
|
|
71
|
+
}
|
package/air.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Particle weather from a caller's catalogue of emitter values.
|
|
2
|
+
// @ts-types="npm:@types/three@^0.186.0"
|
|
3
|
+
import * as THREE from "three";
|
|
4
|
+
import { bits } from "./fx.js";
|
|
5
|
+
/** The air over `scene`: `tick` sends what drifts in the air named, if
|
|
6
|
+
* any, round `at`, and lets what drifts in any other it sent settle, so a
|
|
7
|
+
* focus moving between emitter kinds sees the one air give way to the
|
|
8
|
+
* other. */ export let airOf = (scene, airs)=>{
|
|
9
|
+
let blowing = new Map();
|
|
10
|
+
let p = new THREE.Vector3();
|
|
11
|
+
return {
|
|
12
|
+
tick: (at, dt, name)=>{
|
|
13
|
+
let a = name ? airs[name] : undefined;
|
|
14
|
+
if (a && name && !blowing.has(name)) {
|
|
15
|
+
let pool = bits(scene, !a.glow, Math.ceil(a.rate * a.life * 1.2));
|
|
16
|
+
blowing.set(name, {
|
|
17
|
+
pool,
|
|
18
|
+
owed: 0
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
for (let [n, b] of blowing){
|
|
22
|
+
let air = airs[n];
|
|
23
|
+
if (n == name) b.owed += air.rate * Math.min(dt, 0.1);
|
|
24
|
+
for(; b.owed >= 1; b.owed--){
|
|
25
|
+
let r = air.spread * Math.sqrt(Math.random()), t = Math.random() * 7;
|
|
26
|
+
p.set(at.x + Math.cos(t) * r, at.y + air.low + Math.random() * (air.high - air.low), at.z + Math.sin(t) * r);
|
|
27
|
+
b.pool.emit(p, air.color, 1, {
|
|
28
|
+
speed: air.speed,
|
|
29
|
+
up: air.up,
|
|
30
|
+
fall: air.fall,
|
|
31
|
+
life: air.life,
|
|
32
|
+
size: air.size
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
b.pool.tick(dt);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=air.js.map
|
package/air.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"air.js","sources":["./air.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,wCAAwC;AACxC,YAAY,mBAA+B;AAC3C,SAAS,IAAI,kBAAiB;AAoB9B;;;UAGU,GACV,OAAO,IAAI,QAAQ,CACjB,OACA;EAEA,IAAI,UAAU,IAAI;EAIlB,IAAI,IAAI,IAAI,MAAM,OAAO;EACzB,OAAO;IACL,MAAM,CAAC,IAAmB,IAAY;MACpC,IAAI,IAAI,OAAO,IAAI,CAAC,KAAK,GAAG;MAC5B,IAAI,KAAK,QAAQ,CAAC,QAAQ,GAAG,CAAC,OAAO;QACnC,IAAI,OAAO,KAAK,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC,EAAE,IAAI,GAAG,EAAE,IAAI,GAAG;QAC5D,QAAQ,GAAG,CAAC,MAAM;UAAE;UAAM,MAAM;QAAE;MACpC;MACA,KAAK,IAAI,CAAC,GAAG,EAAE,IAAI,QAAS;QAC1B,IAAI,MAAM,IAAI,CAAC,EAAE;QACjB,IAAI,KAAK,MAAM,EAAE,IAAI,IAAI,IAAI,IAAI,GAAG,KAAK,GAAG,CAAC,IAAI;QACjD,MAAO,EAAE,IAAI,IAAI,GAAG,EAAE,IAAI,GAAI;UAC5B,IAAI,IAAI,IAAI,MAAM,GAAG,KAAK,IAAI,CAAC,KAAK,MAAM,KAAK,IAAI,KAAK,MAAM,KAAK;UACnE,EAAE,GAAG,CACH,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK,GACrB,GAAG,CAAC,GAAG,IAAI,GAAG,GAAG,KAAK,MAAM,KAAK,CAAC,IAAI,IAAI,GAAG,IAAI,GAAG,GACpD,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK;UAEvB,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,KAAK,EAAE,GAAG;YAC3B,OAAO,IAAI,KAAK;YAChB,IAAI,IAAI,EAAE;YACV,MAAM,IAAI,IAAI;YACd,MAAM,IAAI,IAAI;YACd,MAAM,IAAI,IAAI;UAChB;QACF;QACA,EAAE,IAAI,CAAC,IAAI,CAAC;MACd;IACF;EACF;AACF,EAAC"}
|
package/air.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Particle weather from a caller's catalogue of emitter values.
|
|
2
|
+
// @ts-types="npm:@types/three@^0.186.0"
|
|
3
|
+
import * as THREE from 'three'
|
|
4
|
+
import { bits } from './fx.js'
|
|
5
|
+
|
|
6
|
+
export type Air = {
|
|
7
|
+
color: number
|
|
8
|
+
glow?: boolean
|
|
9
|
+
rate: number
|
|
10
|
+
spread: number
|
|
11
|
+
low: number
|
|
12
|
+
high: number
|
|
13
|
+
speed: number
|
|
14
|
+
up: number
|
|
15
|
+
fall: number
|
|
16
|
+
life: number
|
|
17
|
+
size: number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type AirView = {
|
|
21
|
+
tick: (at: THREE.Vector3, dt: number, name?: string) => void
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The air over `scene`: `tick` sends what drifts in the air named, if
|
|
25
|
+
* any, round `at`, and lets what drifts in any other it sent settle, so a
|
|
26
|
+
* focus moving between emitter kinds sees the one air give way to the
|
|
27
|
+
* other. */
|
|
28
|
+
export let airOf = (
|
|
29
|
+
scene: THREE.Scene,
|
|
30
|
+
airs: Readonly<Record<string, Air>>,
|
|
31
|
+
): AirView => {
|
|
32
|
+
let blowing = new Map<
|
|
33
|
+
string,
|
|
34
|
+
{ pool: ReturnType<typeof bits>; owed: number }
|
|
35
|
+
>()
|
|
36
|
+
let p = new THREE.Vector3()
|
|
37
|
+
return {
|
|
38
|
+
tick: (at: THREE.Vector3, dt: number, name?: string) => {
|
|
39
|
+
let a = name ? airs[name] : undefined
|
|
40
|
+
if (a && name && !blowing.has(name)) {
|
|
41
|
+
let pool = bits(scene, !a.glow, Math.ceil(a.rate * a.life * 1.2))
|
|
42
|
+
blowing.set(name, { pool, owed: 0 })
|
|
43
|
+
}
|
|
44
|
+
for (let [n, b] of blowing) {
|
|
45
|
+
let air = airs[n]
|
|
46
|
+
if (n == name) b.owed += air.rate * Math.min(dt, 0.1)
|
|
47
|
+
for (; b.owed >= 1; b.owed--) {
|
|
48
|
+
let r = air.spread * Math.sqrt(Math.random()), t = Math.random() * 7
|
|
49
|
+
p.set(
|
|
50
|
+
at.x + Math.cos(t) * r,
|
|
51
|
+
at.y + air.low + Math.random() * (air.high - air.low),
|
|
52
|
+
at.z + Math.sin(t) * r,
|
|
53
|
+
)
|
|
54
|
+
b.pool.emit(p, air.color, 1, {
|
|
55
|
+
speed: air.speed,
|
|
56
|
+
up: air.up,
|
|
57
|
+
fall: air.fall,
|
|
58
|
+
life: air.life,
|
|
59
|
+
size: air.size,
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
b.pool.tick(dt)
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
}
|
package/bus.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// One volume control per kind of sound. Its owner supplies the setting and
|
|
2
|
+
// persistence; the gain belongs in the audio graph so changes reach sounds in flight.
|
|
3
|
+
let clamp = (value, fallback)=>Number.isFinite(value) ? Math.max(0, Math.min(1, value)) : fallback;
|
|
4
|
+
export let bus = (fallback, { save, boost = 1 } = {})=>{
|
|
5
|
+
let level = fallback;
|
|
6
|
+
let gain = null;
|
|
7
|
+
// Hearing compresses amplitude: spread audible changes across the slider.
|
|
8
|
+
let amplitude = ()=>boost * level ** 3;
|
|
9
|
+
return {
|
|
10
|
+
get level () {
|
|
11
|
+
return level;
|
|
12
|
+
},
|
|
13
|
+
set: (value)=>{
|
|
14
|
+
level = clamp(value, fallback);
|
|
15
|
+
save?.(level);
|
|
16
|
+
if (gain) {
|
|
17
|
+
let at = gain.context.currentTime;
|
|
18
|
+
gain.gain.cancelScheduledValues(at);
|
|
19
|
+
gain.gain.setValueAtTime(gain.gain.value, at);
|
|
20
|
+
gain.gain.linearRampToValueAtTime(amplitude(), at + 0.02);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
into: (ctx, out)=>{
|
|
24
|
+
if (!gain || gain.context != ctx) {
|
|
25
|
+
gain?.disconnect();
|
|
26
|
+
gain = new GainNode(ctx, {
|
|
27
|
+
gain: amplitude()
|
|
28
|
+
});
|
|
29
|
+
gain.connect(out);
|
|
30
|
+
}
|
|
31
|
+
return gain;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
/** A relative level while a higher-priority channel is active. */ export let duckLevel = (active, level = 0.22)=>active ? level : 1;
|
|
36
|
+
//# sourceMappingURL=bus.js.map
|
package/bus.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bus.js","sources":["./bus.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,sFAAsF;AACtF,IAAI,QAAQ,CAAC,OAAe,WAC1B,OAAO,QAAQ,CAAC,SAAS,KAAK,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,UAAU;AAS7D,OAAO,IAAI,MAAM,CACf,UACA,EAAE,IAAI,EAAE,QAAQ,CAAC,EAGhB,GAAG,CAAC,CAAC;EAEN,IAAI,QAAQ;EACZ,IAAI,OAAwB;EAC5B,0EAA0E;EAC1E,IAAI,YAAY,IAAM,QAAQ,SAAS;EACvC,OAAO;IACL,IAAI,SAAQ;MACV,OAAO;IACT;IACA,KAAK,CAAC;MACJ,QAAQ,MAAM,OAAO;MACrB,OAAO;MACP,IAAI,MAAM;QACR,IAAI,KAAK,KAAK,OAAO,CAAC,WAAW;QACjC,KAAK,IAAI,CAAC,qBAAqB,CAAC;QAChC,KAAK,IAAI,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC,KAAK,EAAE;QAC1C,KAAK,IAAI,CAAC,uBAAuB,CAAC,aAAa,KAAK;MACtD;IACF;IACA,MAAM,CAAC,KAAmB;MACxB,IAAI,CAAC,QAAQ,KAAK,OAAO,IAAI,KAAK;QAChC,MAAM;QACN,OAAO,IAAI,SAAS,KAAK;UAAE,MAAM;QAAY;QAC7C,KAAK,OAAO,CAAC;MACf;MACA,OAAO;IACT;EACF;AACF,EAAC;AAED,gEAAgE,GAChE,OAAO,IAAI,YAAY,CAAC,QAAiB,QAAQ,IAAI,GACnD,SAAS,QAAQ,EAAC"}
|
package/bus.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// One volume control per kind of sound. Its owner supplies the setting and
|
|
2
|
+
// persistence; the gain belongs in the audio graph so changes reach sounds in flight.
|
|
3
|
+
let clamp = (value: number, fallback: number) =>
|
|
4
|
+
Number.isFinite(value) ? Math.max(0, Math.min(1, value)) : fallback
|
|
5
|
+
|
|
6
|
+
/** One volume control and its audio-graph gain. */
|
|
7
|
+
export interface Bus {
|
|
8
|
+
readonly level: number
|
|
9
|
+
set(value: number): void
|
|
10
|
+
into(ctx: AudioContext, out: AudioNode): GainNode
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export let bus = (
|
|
14
|
+
fallback: number,
|
|
15
|
+
{ save, boost = 1 }: {
|
|
16
|
+
save?: (level: number) => void
|
|
17
|
+
boost?: number
|
|
18
|
+
} = {},
|
|
19
|
+
): Bus => {
|
|
20
|
+
let level = fallback
|
|
21
|
+
let gain: GainNode | null = null
|
|
22
|
+
// Hearing compresses amplitude: spread audible changes across the slider.
|
|
23
|
+
let amplitude = () => boost * level ** 3
|
|
24
|
+
return {
|
|
25
|
+
get level() {
|
|
26
|
+
return level
|
|
27
|
+
},
|
|
28
|
+
set: (value: number) => {
|
|
29
|
+
level = clamp(value, fallback)
|
|
30
|
+
save?.(level)
|
|
31
|
+
if (gain) {
|
|
32
|
+
let at = gain.context.currentTime
|
|
33
|
+
gain.gain.cancelScheduledValues(at)
|
|
34
|
+
gain.gain.setValueAtTime(gain.gain.value, at)
|
|
35
|
+
gain.gain.linearRampToValueAtTime(amplitude(), at + 0.02)
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
into: (ctx: AudioContext, out: AudioNode) => {
|
|
39
|
+
if (!gain || gain.context != ctx) {
|
|
40
|
+
gain?.disconnect()
|
|
41
|
+
gain = new GainNode(ctx, { gain: amplitude() })
|
|
42
|
+
gain.connect(out)
|
|
43
|
+
}
|
|
44
|
+
return gain
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A relative level while a higher-priority channel is active. */
|
|
50
|
+
export let duckLevel = (active: boolean, level = 0.22): number =>
|
|
51
|
+
active ? level : 1
|
package/cam.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// The camera: behind and above the hero, turned by dragging and pulled in or
|
|
2
|
+
// out by the wheel. It keeps the chosen orbit until asked to swing behind the
|
|
3
|
+
// hero (`snap`). It keeps its distance unless a hill or a house is in the way,
|
|
4
|
+
// when it comes in at once, and it eases back
|
|
5
|
+
// out after. While the hero is in a building it rises to look down into it
|
|
6
|
+
// over the walls, the roof and the floors over them faded (solid.ts
|
|
7
|
+
// `cutaway`), and that building's walls never pull it in. It sees from a
|
|
8
|
+
// little way before it out to where the fog hides everything, and no further
|
|
9
|
+
// (`depth`).
|
|
10
|
+
// @ts-types="npm:@types/three@^0.186.0"
|
|
11
|
+
import * as THREE from "three";
|
|
12
|
+
let clamp = (n, lo, hi)=>Math.max(lo, Math.min(hi, n));
|
|
13
|
+
/** How near the camera comes to the hero, in metres, when the level is in
|
|
14
|
+
* the way. */ export let CLOSEST = 1.2;
|
|
15
|
+
/** How near the camera sees, in metres: as far out as the hero's nearest side
|
|
16
|
+
* ever comes, at its closest, so the depth buffer is as fine as it can be
|
|
17
|
+
* Nearer surfaces are clipped by the camera. */ export let NEAR = 0.5;
|
|
18
|
+
/** Fit `camera`'s depth to what it can see: from NEAR out to the far edge of
|
|
19
|
+
* the level's fog, past which nothing shows. */ export let depth = (camera, fog)=>{
|
|
20
|
+
if (camera.near == NEAR && camera.far == fog.far) return;
|
|
21
|
+
camera.near = NEAR;
|
|
22
|
+
camera.far = fog.far;
|
|
23
|
+
camera.updateProjectionMatrix();
|
|
24
|
+
};
|
|
25
|
+
// How fast it swings behind the hero when asked.
|
|
26
|
+
let SNAP = 12;
|
|
27
|
+
/** Turn the camera for a frame: as the hands turned and pulled it, or round
|
|
28
|
+
* behind a hero facing `yaw` when asked. Holding the stick sideways cannot
|
|
29
|
+
* make the view spin.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { assertAlmostEquals, assertEquals } from '@std/assert'
|
|
33
|
+
* let hands = (move: [number, number], more = {}) => ({
|
|
34
|
+
* move, turn: 0, faceMove: false, jump: false, strike: false, ability: 0,
|
|
35
|
+
* dodge: false, talk: false, gather: false, drink: false, snap: false,
|
|
36
|
+
* mic: false,
|
|
37
|
+
* orbit: [0, 0] as [number, number], look: false, zoom: 0, ...more,
|
|
38
|
+
* })
|
|
39
|
+
* let cam = () => ({
|
|
40
|
+
* yaw: 0, pitch: 0.4, dist: 9, reach: 9, x: 0, y: 0, z: 0, shake: 0,
|
|
41
|
+
* snap: false, orbiting: false, lift: 0,
|
|
42
|
+
* })
|
|
43
|
+
* // A hero facing +x has the camera behind them at -x, which is yaw -π/2.
|
|
44
|
+
* let run = (c: ReturnType<typeof cam>, i: ReturnType<typeof hands>) => {
|
|
45
|
+
* for (let f = 0; f < 60; f++) steer(c, f ? { ...i, snap: false } : i, Math.PI / 2, 1 / 60)
|
|
46
|
+
* return c.yaw
|
|
47
|
+
* }
|
|
48
|
+
* assertAlmostEquals(run(cam(), hands([0, 0], { snap: true })), -Math.PI / 2, 1e-9)
|
|
49
|
+
* assertEquals(run(cam(), hands([1, 0])), 0)
|
|
50
|
+
* assertEquals(run(cam(), hands([1, 0], { faceMove: true })), 0)
|
|
51
|
+
* assertEquals(run(cam(), hands([0, 1], { look: true })), 0)
|
|
52
|
+
* let turned = cam()
|
|
53
|
+
* steer(turned, hands([0, 0], { turn: -6 }), Math.PI, 0.1)
|
|
54
|
+
* assertAlmostEquals(turned.yaw, 0.6)
|
|
55
|
+
* ```
|
|
56
|
+
*/ export let steer = (cam, i, yaw, dt)=>{
|
|
57
|
+
let [dx, dy] = i.orbit;
|
|
58
|
+
cam.yaw += dx - i.turn * dt;
|
|
59
|
+
cam.pitch = clamp(cam.pitch + dy, 0.1, 1.3);
|
|
60
|
+
cam.dist = clamp(cam.dist * (1 + i.zoom * 0.12), 4, 22);
|
|
61
|
+
if (i.look && (dx || dy)) cam.orbiting = true;
|
|
62
|
+
else if (dx || dy) cam.orbiting = false;
|
|
63
|
+
if (i.snap) cam.snap = true;
|
|
64
|
+
else if (dx || dy || i.turn || i.faceMove || i.look) cam.snap = false;
|
|
65
|
+
let off = Math.atan2(Math.sin(yaw + Math.PI - cam.yaw), Math.cos(yaw + Math.PI - cam.yaw));
|
|
66
|
+
// A snap ends where it meant to: right behind the hero.
|
|
67
|
+
if (cam.snap && Math.abs(off) < 0.02) {
|
|
68
|
+
cam.yaw += off;
|
|
69
|
+
cam.snap = false;
|
|
70
|
+
cam.orbiting = false;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (cam.snap) cam.yaw += off * (1 - Math.exp(-dt * SNAP));
|
|
74
|
+
};
|
|
75
|
+
/** Free orbit changes the view, not where the keys say forward is. A turning
|
|
76
|
+
* key changes both the camera and the hero's heading this frame. The stick
|
|
77
|
+
* keeps moving in screen space so its direction remains direct on touch. */ export let moveLook = (cam, i, yaw, dt)=>cam.orbiting && !i.faceMove ? yaw - Math.PI - i.turn * dt : cam.yaw;
|
|
78
|
+
/** Which way the camera looks, in whole degrees clockwise from north (-z).
|
|
79
|
+
*
|
|
80
|
+
* ```ts
|
|
81
|
+
* import { assertEquals } from '@std/assert'
|
|
82
|
+
* assertEquals(bearing(0), 0) // from the south, looking north
|
|
83
|
+
* assertEquals(bearing(-Math.PI / 2), 90) // from the west, looking east
|
|
84
|
+
* assertEquals(bearing(Math.PI / 2 + 4 * Math.PI), 270)
|
|
85
|
+
* ```
|
|
86
|
+
*/ export let bearing = (yaw)=>(Math.round(-yaw * 180 / Math.PI) % 360 + 360) % 360;
|
|
87
|
+
/** Orbit around target, shortening the arm immediately when blocked and
|
|
88
|
+
* easing it back out. The caller supplies collision and the minimum pitch. */ export let aim = (cam, camera, target, blocked, dt, lift = 0)=>{
|
|
89
|
+
cam.lift += (lift - cam.lift) * (1 - Math.exp(-dt * 3));
|
|
90
|
+
let pitch = Math.max(cam.pitch, cam.lift);
|
|
91
|
+
let cp = Math.cos(pitch);
|
|
92
|
+
let dir = new THREE.Vector3(Math.sin(cam.yaw) * cp, Math.sin(pitch), Math.cos(cam.yaw) * cp);
|
|
93
|
+
let clear = cam.dist;
|
|
94
|
+
for(let d = CLOSEST; d <= cam.dist; d += 0.4){
|
|
95
|
+
let p = target.clone().addScaledVector(dir, d);
|
|
96
|
+
if (blocked(p)) {
|
|
97
|
+
clear = Math.max(CLOSEST, d - 0.6);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
cam.reach = clear < cam.reach ? clear : cam.reach + (clear - cam.reach) * (1 - Math.exp(-dt * 2.5));
|
|
102
|
+
camera.position.copy(target).addScaledVector(dir, cam.reach);
|
|
103
|
+
if (cam.shake > 0.002) {
|
|
104
|
+
camera.position.x += (Math.random() - 0.5) * cam.shake;
|
|
105
|
+
camera.position.y += (Math.random() - 0.5) * cam.shake;
|
|
106
|
+
cam.shake *= Math.exp(-dt * 12);
|
|
107
|
+
}
|
|
108
|
+
camera.lookAt(target);
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=cam.js.map
|
package/cam.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cam.js","sources":["./cam.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,8EAA8E;AAC9E,+EAA+E;AAC/E,8CAA8C;AAC9C,2EAA2E;AAC3E,oEAAoE;AACpE,yEAAyE;AACzE,6EAA6E;AAC7E,aAAa;AACb,wCAAwC;AACxC,YAAY,mBAA+B;AAS3C,IAAI,QAAQ,CAAC,GAAW,IAAY,KAAe,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI;AAsB7E;YACY,GACZ,OAAO,IAAI,UAAU,IAAG;AAExB;;8CAE8C,GAC9C,OAAO,IAAI,OAAO,IAAG;AAErB;8CAC8C,GAC9C,OAAO,IAAI,QAAQ,CAAC,QAAiC;EACnD,IAAI,OAAO,IAAI,IAAI,QAAQ,OAAO,GAAG,IAAI,IAAI,GAAG,EAAE;EAClD,OAAO,IAAI,GAAG;EACd,OAAO,GAAG,GAAG,IAAI,GAAG;EACpB,OAAO,sBAAsB;AAC/B,EAAC;AAED,iDAAiD;AACjD,IAAI,OAAO;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BC,GACD,OAAO,IAAI,QAAQ,CACjB,KACA,GACA,KACA;EAEA,IAAI,CAAC,IAAI,GA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