lantern-engine 0.0.0-stage → 0.4.0
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 +101 -0
- package/LICENSE +21 -0
- package/README.md +113 -2
- package/dist/assets/takeCleanerWorker-DTcI_Jqr.js +31 -0
- package/dist/assets/takeCleanerWorker-DTcI_Jqr.js.map +1 -0
- package/dist/constants-CjYVdFid.js +252 -0
- package/dist/constants-CjYVdFid.js.map +1 -0
- package/dist/lantern-engine.js +3473 -0
- package/dist/lantern-engine.js.map +1 -0
- package/dist/pixel.js +1404 -0
- package/dist/pixel.js.map +1 -0
- package/dist/types/anim/Animator.d.ts +50 -0
- package/dist/types/anim/Animator.d.ts.map +1 -0
- package/dist/types/anim/animationSystem.d.ts +13 -0
- package/dist/types/anim/animationSystem.d.ts.map +1 -0
- package/dist/types/assets/AssetLoader.d.ts +85 -0
- package/dist/types/assets/AssetLoader.d.ts.map +1 -0
- package/dist/types/audio/MusicPlayer.d.ts +57 -0
- package/dist/types/audio/MusicPlayer.d.ts.map +1 -0
- package/dist/types/audio/SoundEngine.d.ts +42 -0
- package/dist/types/audio/SoundEngine.d.ts.map +1 -0
- package/dist/types/audio/cleanTake.d.ts +3 -0
- package/dist/types/audio/cleanTake.d.ts.map +1 -0
- package/dist/types/audio/sampleBank.d.ts +27 -0
- package/dist/types/audio/sampleBank.d.ts.map +1 -0
- package/dist/types/audio/soundTable.d.ts +14 -0
- package/dist/types/audio/soundTable.d.ts.map +1 -0
- package/dist/types/audio/synth.d.ts +34 -0
- package/dist/types/audio/synth.d.ts.map +1 -0
- package/dist/types/audio/takeCleanerWorker.d.ts +2 -0
- package/dist/types/audio/takeCleanerWorker.d.ts.map +1 -0
- package/dist/types/core/BitmapLabel.d.ts +26 -0
- package/dist/types/core/BitmapLabel.d.ts.map +1 -0
- package/dist/types/core/Camera.d.ts +90 -0
- package/dist/types/core/Camera.d.ts.map +1 -0
- package/dist/types/core/Clock.d.ts +11 -0
- package/dist/types/core/Clock.d.ts.map +1 -0
- package/dist/types/core/Graphics.d.ts +37 -0
- package/dist/types/core/Graphics.d.ts.map +1 -0
- package/dist/types/core/Group.d.ts +15 -0
- package/dist/types/core/Group.d.ts.map +1 -0
- package/dist/types/core/Image.d.ts +25 -0
- package/dist/types/core/Image.d.ts.map +1 -0
- package/dist/types/core/ObjectFactory.d.ts +34 -0
- package/dist/types/core/ObjectFactory.d.ts.map +1 -0
- package/dist/types/core/Pointer.d.ts +27 -0
- package/dist/types/core/Pointer.d.ts.map +1 -0
- package/dist/types/core/Rectangle.d.ts +26 -0
- package/dist/types/core/Rectangle.d.ts.map +1 -0
- package/dist/types/core/Stage.d.ts +58 -0
- package/dist/types/core/Stage.d.ts.map +1 -0
- package/dist/types/core/Text.d.ts +22 -0
- package/dist/types/core/Text.d.ts.map +1 -0
- package/dist/types/core/TextureRegistry.d.ts +51 -0
- package/dist/types/core/TextureRegistry.d.ts.map +1 -0
- package/dist/types/core/Tweener.d.ts +53 -0
- package/dist/types/core/Tweener.d.ts.map +1 -0
- package/dist/types/core/atlas.d.ts +16 -0
- package/dist/types/core/atlas.d.ts.map +1 -0
- package/dist/types/core/atlasPlan.d.ts +34 -0
- package/dist/types/core/atlasPlan.d.ts.map +1 -0
- package/dist/types/core/eases.d.ts +3 -0
- package/dist/types/core/eases.d.ts.map +1 -0
- package/dist/types/core/gameObject.d.ts +42 -0
- package/dist/types/core/gameObject.d.ts.map +1 -0
- package/dist/types/core/pixiPatches.d.ts +9 -0
- package/dist/types/core/pixiPatches.d.ts.map +1 -0
- package/dist/types/core/types.d.ts +4 -0
- package/dist/types/core/types.d.ts.map +1 -0
- package/dist/types/ecs/SparseSet.d.ts +25 -0
- package/dist/types/ecs/SparseSet.d.ts.map +1 -0
- package/dist/types/ecs/World.d.ts +133 -0
- package/dist/types/ecs/World.d.ts.map +1 -0
- package/dist/types/ecs/fields.d.ts +34 -0
- package/dist/types/ecs/fields.d.ts.map +1 -0
- package/dist/types/engine/Engine.d.ts +80 -0
- package/dist/types/engine/Engine.d.ts.map +1 -0
- package/dist/types/engine/FixedLoop.d.ts +32 -0
- package/dist/types/engine/FixedLoop.d.ts.map +1 -0
- package/dist/types/engine/Scene.d.ts +37 -0
- package/dist/types/engine/Scene.d.ts.map +1 -0
- package/dist/types/engine/SceneManager.d.ts +31 -0
- package/dist/types/engine/SceneManager.d.ts.map +1 -0
- package/dist/types/events/EventBus.d.ts +20 -0
- package/dist/types/events/EventBus.d.ts.map +1 -0
- package/dist/types/fx/hitStop.d.ts +20 -0
- package/dist/types/fx/hitStop.d.ts.map +1 -0
- package/dist/types/fx/viewCull.d.ts +14 -0
- package/dist/types/fx/viewCull.d.ts.map +1 -0
- package/dist/types/index.d.ts +68 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/input/Actions.d.ts +75 -0
- package/dist/types/input/Actions.d.ts.map +1 -0
- package/dist/types/input/Keyboard.d.ts +25 -0
- package/dist/types/input/Keyboard.d.ts.map +1 -0
- package/dist/types/input/aimAxis.d.ts +9 -0
- package/dist/types/input/aimAxis.d.ts.map +1 -0
- package/dist/types/input/longPress.d.ts +21 -0
- package/dist/types/input/longPress.d.ts.map +1 -0
- package/dist/types/input/stickAxis.d.ts +26 -0
- package/dist/types/input/stickAxis.d.ts.map +1 -0
- package/dist/types/input/touchDetect.d.ts +18 -0
- package/dist/types/input/touchDetect.d.ts.map +1 -0
- package/dist/types/light/LightLayer.d.ts +65 -0
- package/dist/types/light/LightLayer.d.ts.map +1 -0
- package/dist/types/net/Connection.d.ts +66 -0
- package/dist/types/net/Connection.d.ts.map +1 -0
- package/dist/types/net/InterpolationBuffer.d.ts +36 -0
- package/dist/types/net/InterpolationBuffer.d.ts.map +1 -0
- package/dist/types/net/PredictedMover.d.ts +43 -0
- package/dist/types/net/PredictedMover.d.ts.map +1 -0
- package/dist/types/net/Room.d.ts +69 -0
- package/dist/types/net/Room.d.ts.map +1 -0
- package/dist/types/net/RoomHost.d.ts +74 -0
- package/dist/types/net/RoomHost.d.ts.map +1 -0
- package/dist/types/net/cadence.d.ts +22 -0
- package/dist/types/net/cadence.d.ts.map +1 -0
- package/dist/types/net/constants.d.ts +24 -0
- package/dist/types/net/constants.d.ts.map +1 -0
- package/dist/types/net/movement.d.ts +50 -0
- package/dist/types/net/movement.d.ts.map +1 -0
- package/dist/types/net/protocol.d.ts +59 -0
- package/dist/types/net/protocol.d.ts.map +1 -0
- package/dist/types/net/serverClock.d.ts +14 -0
- package/dist/types/net/serverClock.d.ts.map +1 -0
- package/dist/types/net/snapshotCodec.d.ts +55 -0
- package/dist/types/net/snapshotCodec.d.ts.map +1 -0
- package/dist/types/pixel/Darkness.d.ts +78 -0
- package/dist/types/pixel/Darkness.d.ts.map +1 -0
- package/dist/types/pixel/Evaporation.d.ts +30 -0
- package/dist/types/pixel/Evaporation.d.ts.map +1 -0
- package/dist/types/pixel/PixelLayer.d.ts +85 -0
- package/dist/types/pixel/PixelLayer.d.ts.map +1 -0
- package/dist/types/pixel/index.d.ts +22 -0
- package/dist/types/pixel/index.d.ts.map +1 -0
- package/dist/types/pixel/lights.d.ts +34 -0
- package/dist/types/pixel/lights.d.ts.map +1 -0
- package/dist/types/pixel/palette.d.ts +54 -0
- package/dist/types/pixel/palette.d.ts.map +1 -0
- package/dist/types/pixel/pixel.d.ts +80 -0
- package/dist/types/pixel/pixel.d.ts.map +1 -0
- package/dist/types/pixel/pixelPaint.d.ts +43 -0
- package/dist/types/pixel/pixelPaint.d.ts.map +1 -0
- package/dist/types/pixel/pixelTone.d.ts +49 -0
- package/dist/types/pixel/pixelTone.d.ts.map +1 -0
- package/dist/types/pixel/propKit.d.ts +26 -0
- package/dist/types/pixel/propKit.d.ts.map +1 -0
- package/dist/types/pixel/ramp.d.ts +31 -0
- package/dist/types/pixel/ramp.d.ts.map +1 -0
- package/dist/types/pixel/selout.d.ts +3 -0
- package/dist/types/pixel/selout.d.ts.map +1 -0
- package/dist/types/pixel/spritePixels.d.ts +29 -0
- package/dist/types/pixel/spritePixels.d.ts.map +1 -0
- package/dist/types/platform/touch.d.ts +5 -0
- package/dist/types/platform/touch.d.ts.map +1 -0
- package/dist/types/rig/PosePlayer.d.ts +64 -0
- package/dist/types/rig/PosePlayer.d.ts.map +1 -0
- package/dist/types/rig/RigView.d.ts +68 -0
- package/dist/types/rig/RigView.d.ts.map +1 -0
- package/dist/types/rig/Skeleton.d.ts +14 -0
- package/dist/types/rig/Skeleton.d.ts.map +1 -0
- package/dist/types/rig/humanoid.d.ts +4 -0
- package/dist/types/rig/humanoid.d.ts.map +1 -0
- package/dist/types/rig/humanoidPoses.d.ts +117 -0
- package/dist/types/rig/humanoidPoses.d.ts.map +1 -0
- package/dist/types/rig/poseMath.d.ts +14 -0
- package/dist/types/rig/poseMath.d.ts.map +1 -0
- package/dist/types/rig/rigTypes.d.ts +82 -0
- package/dist/types/rig/rigTypes.d.ts.map +1 -0
- package/dist/types/settings.d.ts +25 -0
- package/dist/types/settings.d.ts.map +1 -0
- package/dist/types/tilemap/TilemapView.d.ts +42 -0
- package/dist/types/tilemap/TilemapView.d.ts.map +1 -0
- package/dist/types/tilemap/collision.d.ts +16 -0
- package/dist/types/tilemap/collision.d.ts.map +1 -0
- package/dist/types/tilemap/tiled.d.ts +104 -0
- package/dist/types/tilemap/tiled.d.ts.map +1 -0
- package/package.json +82 -4
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Container } from 'pixi.js';
|
|
2
|
+
import { World } from '../ecs/World.js';
|
|
3
|
+
import type { Engine } from './Engine.js';
|
|
4
|
+
/**
|
|
5
|
+
* One screen of the game: a title, a level, a pause menu. A scene owns a `World` of entities and systems and a
|
|
6
|
+
* `root` container in the engine's world layer; both are cleared when it leaves, so nothing it made outlives it.
|
|
7
|
+
*
|
|
8
|
+
* Override the hooks you need. `fixedUpdate` runs once per simulation step, `update` once per rendered frame, both
|
|
9
|
+
* after the world's own systems of that phase.
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class Scene {
|
|
12
|
+
readonly world: World;
|
|
13
|
+
/** Everything the scene draws in the world goes under this (the camera moves it). */
|
|
14
|
+
readonly root: Container<import("pixi.js").ContainerChild>;
|
|
15
|
+
/** Everything the scene draws on the screen (HUD) goes under this. */
|
|
16
|
+
readonly hud: Container<import("pixi.js").ContainerChild>;
|
|
17
|
+
private bound;
|
|
18
|
+
/** The engine running this scene; only valid between `enter` and `exit`. */
|
|
19
|
+
get engine(): Engine;
|
|
20
|
+
/** Called once when the scene becomes active. May be async: the scene starts updating when it resolves. */
|
|
21
|
+
onEnter(): void | Promise<void>;
|
|
22
|
+
/** Called when the scene is removed. The world and containers are cleared after it returns. */
|
|
23
|
+
onExit(): void;
|
|
24
|
+
/** Called when another scene is pushed over this one. */
|
|
25
|
+
onPause(): void;
|
|
26
|
+
/** Called when the scene over this one is popped. */
|
|
27
|
+
onResume(): void;
|
|
28
|
+
/** Once per simulation step, `dt` in seconds. */
|
|
29
|
+
fixedUpdate(_dt: number): void;
|
|
30
|
+
/** Once per rendered frame, `dt` in seconds; `alpha` is the share of a step since the last one (0–1). */
|
|
31
|
+
update(_dt: number, _alpha: number): void;
|
|
32
|
+
/** @internal Engine-side wiring; games call `engine.scenes`. */
|
|
33
|
+
attach(engine: Engine): void;
|
|
34
|
+
/** @internal Clears what the scene made but keeps its containers, so the same scene may be entered again. */
|
|
35
|
+
detach(): void;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=Scene.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Scene.d.ts","sourceRoot":"","sources":["../../../src/engine/Scene.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC;;;;;;GAMG;AACH,8BAAsB,KAAK;IACzB,QAAQ,CAAC,KAAK,QAAe;IAC7B,qFAAqF;IACrF,QAAQ,CAAC,IAAI,8CAA6C;IAC1D,sEAAsE;IACtE,QAAQ,CAAC,GAAG,8CAAmB;IAC/B,OAAO,CAAC,KAAK,CAAuB;IAEpC,4EAA4E;IAC5E,IAAI,MAAM,IAAI,MAAM,CAGnB;IAED,2GAA2G;IAC3G,OAAO,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC/B,+FAA+F;IAC/F,MAAM,IAAI,IAAI;IACd,yDAAyD;IACzD,OAAO,IAAI,IAAI;IACf,qDAAqD;IACrD,QAAQ,IAAI,IAAI;IAChB,iDAAiD;IACjD,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAC9B,yGAAyG;IACzG,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAEzC,gEAAgE;IAChE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAM5B,6GAA6G;IAC7G,MAAM,IAAI,IAAI;CAQf"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Engine } from './Engine.js';
|
|
2
|
+
import type { Scene } from './Scene.js';
|
|
3
|
+
/**
|
|
4
|
+
* A stack of scenes. Only the top one updates; the ones under it are paused but still drawn (a pause menu over the
|
|
5
|
+
* level). Changes are queued and applied one at a time, so a scene that replaces itself from inside its own update,
|
|
6
|
+
* or an async `onEnter` still loading, never leaves two scenes half entered.
|
|
7
|
+
*/
|
|
8
|
+
export declare class SceneManager {
|
|
9
|
+
private readonly engine;
|
|
10
|
+
private readonly stack;
|
|
11
|
+
private queue;
|
|
12
|
+
/** True while an async `onEnter` is running: nothing updates until it is done. */
|
|
13
|
+
private entering;
|
|
14
|
+
constructor(engine: Engine);
|
|
15
|
+
/** The scene that updates, if any. */
|
|
16
|
+
get current(): Scene | undefined;
|
|
17
|
+
/** Every scene on the stack, bottom first. */
|
|
18
|
+
get all(): readonly Scene[];
|
|
19
|
+
/** Removes every scene and enters `scene`. */
|
|
20
|
+
replace(scene: Scene): Promise<void>;
|
|
21
|
+
/** Pauses the current scene and enters `scene` over it. */
|
|
22
|
+
push(scene: Scene): Promise<void>;
|
|
23
|
+
/** Leaves the current scene and resumes the one under it. */
|
|
24
|
+
pop(): Promise<void>;
|
|
25
|
+
/** Leaves every scene (the engine is shutting down). */
|
|
26
|
+
clear(): Promise<void>;
|
|
27
|
+
private enter;
|
|
28
|
+
private exitTop;
|
|
29
|
+
private enqueue;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=SceneManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SceneManager.d.ts","sourceRoot":"","sources":["../../../src/engine/SceneManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC;;;;GAIG;AACH,qBAAa,YAAY;IAMX,OAAO,CAAC,QAAQ,CAAC,MAAM;IALnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IACrC,OAAO,CAAC,KAAK,CAAoC;IACjD,kFAAkF;IAClF,OAAO,CAAC,QAAQ,CAAS;gBAEI,MAAM,EAAE,MAAM;IAE3C,sCAAsC;IACtC,IAAI,OAAO,IAAI,KAAK,GAAG,SAAS,CAE/B;IAED,8CAA8C;IAC9C,IAAI,GAAG,IAAI,SAAS,KAAK,EAAE,CAE1B;IAED,8CAA8C;IAC9C,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAOpC,2DAA2D;IAC3D,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjC,6DAA6D;IAC7D,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAQpB,wDAAwD;IACxD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAMR,KAAK;IAanB,OAAO,CAAC,OAAO;IAUf,OAAO,CAAC,OAAO;CAMhB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed observer: listeners subscribe per event name and run in subscription order.
|
|
3
|
+
* `Events` maps each event name to its payload, e.g. `EventBus<{ enemyKilled: { id: number } }>`.
|
|
4
|
+
*
|
|
5
|
+
* A listener that throws does not stop the ones after it; the error is handed to `onError` (the console by default).
|
|
6
|
+
*/
|
|
7
|
+
export declare class EventBus<Events extends object> {
|
|
8
|
+
private readonly onError;
|
|
9
|
+
private readonly listeners;
|
|
10
|
+
constructor(onError?: (type: keyof Events, err: unknown) => void);
|
|
11
|
+
/** Subscribes to `type`; returns the unsubscribe function. */
|
|
12
|
+
on<K extends keyof Events>(type: K, fn: (payload: Events[K]) => void): () => void;
|
|
13
|
+
/** Subscribes for the next `type` only. */
|
|
14
|
+
once<K extends keyof Events>(type: K, fn: (payload: Events[K]) => void): () => void;
|
|
15
|
+
off<K extends keyof Events>(type: K, fn: (payload: Events[K]) => void): void;
|
|
16
|
+
emit<K extends keyof Events>(type: K, payload: Events[K]): void;
|
|
17
|
+
listenerCount(type: keyof Events): number;
|
|
18
|
+
clear(): void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=EventBus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventBus.d.ts","sourceRoot":"","sources":["../../../src/events/EventBus.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,QAAQ,CAAC,MAAM,SAAS,MAAM;IAG7B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAyD;gBAEtD,OAAO,GAAE,CAAC,IAAI,EAAE,MAAM,MAAM,EAAE,GAAG,EAAE,OAAO,KAAK,IAAoF;IAEhK,8DAA8D;IAC9D,EAAE,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI;IAKjF,2CAA2C;IAC3C,IAAI,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI;IAQnF,GAAG,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI;IAQ5E,IAAI,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI;IAW/D,aAAa,CAAC,IAAI,EAAE,MAAM,MAAM,GAAG,MAAM;IAIzC,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** The freeze-frame of a blow (ms): 40 for a scratch, up to 140 for one that took a third of the body; a crit +40. */
|
|
2
|
+
export declare function hitStopMs(share: number, crit: boolean): number;
|
|
3
|
+
/** How far the body struck recoils away from the blow (whole world px): a heavy body barely, a crit a pixel further. */
|
|
4
|
+
export declare function recoilPx(heavy: boolean, share: number, crit: boolean): number;
|
|
5
|
+
/** How long a recoil takes to settle back (ms). */
|
|
6
|
+
export declare const RECOIL_MS = 120;
|
|
7
|
+
/** The recoil left at `t` (0 the blow, 1 settled): out at once, eased back, whole pixels only. */
|
|
8
|
+
export declare function recoilAt(px: number, t: number): number;
|
|
9
|
+
/** The least time between two white flashes on a heavy body (ms). */
|
|
10
|
+
export declare const HEAVY_FLASH_GAP_MS = 400;
|
|
11
|
+
/**
|
|
12
|
+
* How long the body struck flashes white (ms), 0 for none: 70, a crit of one's own 140 (the impact frame), nothing with
|
|
13
|
+
* `reduce` (a "reduce flashes" setting). A heavy body (a boss, anything drawn large) flashes only for the local
|
|
14
|
+
* player's own crit, 60 ms, `HEAVY_FLASH_GAP_MS` apart: a sheet covering most of the screen turning white on every
|
|
15
|
+
* blow, beat and tick is a strobe. Sparks, numbers and the recoil still mark every blow.
|
|
16
|
+
*/
|
|
17
|
+
export declare function hurtFlashMs(heavy: boolean, impact: boolean, reduce: boolean): number;
|
|
18
|
+
/** The gap a body keeps between two flashes (ms). */
|
|
19
|
+
export declare function hurtFlashGapMs(heavy: boolean): number;
|
|
20
|
+
//# sourceMappingURL=hitStop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hitStop.d.ts","sourceRoot":"","sources":["../../../src/fx/hitStop.ts"],"names":[],"mappings":"AAMA,sHAAsH;AACtH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAG9D;AAED,wHAAwH;AACxH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAG7E;AAED,mDAAmD;AACnD,eAAO,MAAM,SAAS,MAAM,CAAC;AAE7B,kGAAkG;AAClG,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAGtD;AAED,qEAAqE;AACrE,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAIpF;AAED,qDAAqD;AACrD,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAErD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** What `inView` reads off the main camera (Camera's own fields; a fake stage may lack them). */
|
|
2
|
+
export interface CameraLike {
|
|
3
|
+
zoom: number;
|
|
4
|
+
scrollX?: number;
|
|
5
|
+
scrollY?: number;
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Whether the world point (x, y) lies within `margin` world pixels of the screen. Effects use it to skip painting what
|
|
11
|
+
* nobody can see. A camera that has no size yet (a tool's fake stage, before the first resize) counts everything in.
|
|
12
|
+
*/
|
|
13
|
+
export declare function inView(cam: CameraLike, x: number, y: number, margin: number): boolean;
|
|
14
|
+
//# sourceMappingURL=viewCull.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viewCull.d.ts","sourceRoot":"","sources":["../../../src/fx/viewCull.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAOrF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lantern Engine: the core's public API, for 2D games in any art style. Pixel-art tools are `lantern-engine/pixel`.
|
|
3
|
+
* Anything not exported here or there is internal and may change in any release.
|
|
4
|
+
*/
|
|
5
|
+
export { Engine, type EngineOptions, type EngineEvents } from './engine/Engine.js';
|
|
6
|
+
export { Scene } from './engine/Scene.js';
|
|
7
|
+
export { SceneManager } from './engine/SceneManager.js';
|
|
8
|
+
export { FixedLoop, type FixedLoopOptions } from './engine/FixedLoop.js';
|
|
9
|
+
export { World, defineComponent, defineFields, entityIndex, system, type Entity, type ComponentType, type System, type SystemContext, type SystemPhase, type ComponentValues, } from './ecs/World.js';
|
|
10
|
+
export type { FieldKind, FieldSpec, FieldsType, FieldValues, Columns, ArrayOf } from './ecs/fields.js';
|
|
11
|
+
export { EventBus } from './events/EventBus.js';
|
|
12
|
+
export { engineSettings, type EngineSettings, type SettingsListener } from './settings.js';
|
|
13
|
+
export { Stage } from './core/Stage.js';
|
|
14
|
+
export { Camera, type ViewRect, type TrackOptions } from './core/Camera.js';
|
|
15
|
+
export { Clock } from './core/Clock.js';
|
|
16
|
+
export { Tweener, Tween, type TweenConfig, type TweenTarget } from './core/Tweener.js';
|
|
17
|
+
export { easeByName, type EaseFn } from './core/eases.js';
|
|
18
|
+
export { ObjectFactory } from './core/ObjectFactory.js';
|
|
19
|
+
export { Graphics, type Vec2 } from './core/Graphics.js';
|
|
20
|
+
export { Image } from './core/Image.js';
|
|
21
|
+
export { Group } from './core/Group.js';
|
|
22
|
+
export { Rectangle } from './core/Rectangle.js';
|
|
23
|
+
export { Text, type TextStyle } from './core/Text.js';
|
|
24
|
+
export { BitmapLabel, installLabelFont, addLabelGlyphs } from './core/BitmapLabel.js';
|
|
25
|
+
export { Pointer } from './core/Pointer.js';
|
|
26
|
+
export { TextureRegistry, CanvasTexture } from './core/TextureRegistry.js';
|
|
27
|
+
export { AtlasBuilder } from './core/atlas.js';
|
|
28
|
+
export { planAtlas, atlasPageLimit, type AtlasSize, type AtlasPlan, type AtlasPage } from './core/atlasPlan.js';
|
|
29
|
+
export type { WorldObject } from './core/types.js';
|
|
30
|
+
export { AssetLoader, resolveUrl, type AssetLoaderOptions, type TilemapAssetOptions, type LoadProgress, type TextureSink } from './assets/AssetLoader.js';
|
|
31
|
+
export { Animator, type AnimationClip, type AnimationClips } from './anim/Animator.js';
|
|
32
|
+
export { animationSystem, SpriteComponent, AnimationComponent } from './anim/animationSystem.js';
|
|
33
|
+
export { parseTiled, tileAt, tileRect, gidOf, layerByName, objectsOf, FLIP_H, FLIP_V, FLIP_D, type TileMap, type TileLayer, type ObjectLayer, type MapLayer, type MapObject, type Tileset, type Properties, type TiledPropertyValue, } from './tilemap/tiled.js';
|
|
34
|
+
export { collisionFromTiled, type TiledCollisionOptions } from './tilemap/collision.js';
|
|
35
|
+
export { TilemapView, type TilemapViewOptions } from './tilemap/TilemapView.js';
|
|
36
|
+
export { Skeleton } from './rig/Skeleton.js';
|
|
37
|
+
export { HUMANOID_RIG } from './rig/humanoid.js';
|
|
38
|
+
export { blendPose, overlay, upperOver } from './rig/poseMath.js';
|
|
39
|
+
export type { RigDef, RigPose, Limb, Face, Joints, Point as RigPoint } from './rig/rigTypes.js';
|
|
40
|
+
export { HUMANOID_POSES, HUMANOID_CLIPS, type HumanoidClip } from './rig/humanoidPoses.js';
|
|
41
|
+
export { PosePlayer, type PoseClip } from './rig/PosePlayer.js';
|
|
42
|
+
export { RigView, RIG_PARTS, type RigPart, type PartSkin, type RigSkin, type RigViewOptions } from './rig/RigView.js';
|
|
43
|
+
export { LightLayer, type Light, type LightLayerOptions } from './light/LightLayer.js';
|
|
44
|
+
export { hitStopMs, recoilPx, recoilAt, RECOIL_MS, hurtFlashMs, hurtFlashGapMs, HEAVY_FLASH_GAP_MS } from './fx/hitStop.js';
|
|
45
|
+
export { inView, type CameraLike } from './fx/viewCull.js';
|
|
46
|
+
export { sound, SoundEngine, type SoundOptions } from './audio/SoundEngine.js';
|
|
47
|
+
export { music, MusicPlayer, type PlayOptions as MusicOptions } from './audio/MusicPlayer.js';
|
|
48
|
+
export { registerSounds, type SoundTable } from './audio/soundTable.js';
|
|
49
|
+
export { registerTakes, hasTakes } from './audio/sampleBank.js';
|
|
50
|
+
export { renderRecipe, SYNTH_RATE, type SynthRecipe, type SynthLayer } from './audio/synth.js';
|
|
51
|
+
export { Keyboard } from './input/Keyboard.js';
|
|
52
|
+
export { Actions, PAD_BUTTONS, type Bindings, type ActionsOptions, type PadState } from './input/Actions.js';
|
|
53
|
+
export { aimAxis } from './input/aimAxis.js';
|
|
54
|
+
export { stickVector, stickActive, stickToAxis, STICK_DEAD_ZONE, type StickVector } from './input/stickAxis.js';
|
|
55
|
+
export { LongPress } from './input/longPress.js';
|
|
56
|
+
export { isTouchUi, setNativeShell } from './platform/touch.js';
|
|
57
|
+
export { TILE_SIZE, INPUT_STEP_RATE, INPUT_STEP_DT, INPUT_FLAG_DASH, BODY_HALF_WIDTH, BODY_HALF_HEIGHT, type InputStep, type MovementParams, type EntityUpdate, } from './net/constants.js';
|
|
58
|
+
export { createCollisionGrid, createMover, stepMover, moveX, moveY, bodyCollides, isSolidTile, blocksShot, DIAGONAL, type CollisionGrid, type CollisionGridOptions, type MoverState, } from './net/movement.js';
|
|
59
|
+
export { encodeSnapshotFrame, decodeSnapshotFrame, encodeUpdates, decodeUpdates, quantizeUpdates, UPDATE_RECORD_BYTES, type SnapshotLike, } from './net/snapshotCodec.js';
|
|
60
|
+
export { CADENCE, cadenceEarly, cadenceNext } from './net/cadence.js';
|
|
61
|
+
export { serverNow, serverOffset, noteServerTime, resetServerClock } from './net/serverClock.js';
|
|
62
|
+
export { PredictedMover } from './net/PredictedMover.js';
|
|
63
|
+
export { InterpolationBuffer, type InterpolatedState } from './net/InterpolationBuffer.js';
|
|
64
|
+
export { Room, type RoomPlayer, type RoomOptions } from './net/Room.js';
|
|
65
|
+
export { RoomHost, type HostSocket, type RoomHostOptions } from './net/RoomHost.js';
|
|
66
|
+
export { Connection, type ConnectionEvents, type ConnectionOptions } from './net/Connection.js';
|
|
67
|
+
export { moverToWire, moverFromWire, type ClientMessage, type ServerMessage, type Snapshot, type SpawnInfo, type MoverWire } from './net/protocol.js';
|
|
68
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EA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F,OAAO,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC7F,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Keyboard } from './Keyboard.js';
|
|
2
|
+
/**
|
|
3
|
+
* Named actions bound to any input: keys, gamepad buttons and sticks, and virtual buttons a touch UI presses. Game
|
|
4
|
+
* code asks for `'jump'`, never for `Space`, so players can rebind and every device works the same.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* const input = new Actions(keyboard, {
|
|
8
|
+
* left: ['KeyA', 'ArrowLeft', 'pad:left', 'pad:lx-'],
|
|
9
|
+
* right: ['KeyD', 'ArrowRight', 'pad:right', 'pad:lx+'],
|
|
10
|
+
* jump: ['Space', 'pad:a'],
|
|
11
|
+
* });
|
|
12
|
+
* // in a fixed system:
|
|
13
|
+
* input.poll();
|
|
14
|
+
* if (input.pressed('jump')) …
|
|
15
|
+
* const [x, y] = input.vector('left', 'right', 'up', 'down');
|
|
16
|
+
* input.endStep();
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Bindings: a `KeyboardEvent.code` (`KeyW`, `Space`, `ArrowUp`), `pad:<button>` (standard mapping names below),
|
|
20
|
+
* `pad:<axis>+` / `pad:<axis>-` for a stick half (`lx`, `ly`, `rx`, `ry`), or `touch:<name>` for a virtual button
|
|
21
|
+
* (`press`/`release`).
|
|
22
|
+
*/
|
|
23
|
+
export type Bindings<A extends string> = Record<A, readonly string[]>;
|
|
24
|
+
/** Button names of the browser's standard gamepad mapping, in index order. */
|
|
25
|
+
export declare const PAD_BUTTONS: readonly ["a", "b", "x", "y", "lb", "rb", "lt", "rt", "select", "start", "ls", "rs", "up", "down", "left", "right", "home"];
|
|
26
|
+
/** What the actions read from a gamepad; `navigator.getGamepads()` entries satisfy it. */
|
|
27
|
+
export interface PadState {
|
|
28
|
+
readonly buttons: readonly {
|
|
29
|
+
readonly pressed: boolean;
|
|
30
|
+
readonly value: number;
|
|
31
|
+
}[];
|
|
32
|
+
readonly axes: readonly number[];
|
|
33
|
+
}
|
|
34
|
+
export interface ActionsOptions {
|
|
35
|
+
/** Stick values under this count as 0 (default 0.25). */
|
|
36
|
+
deadZone?: number;
|
|
37
|
+
/** Where gamepads come from (default `navigator.getGamepads`); tests pass their own. */
|
|
38
|
+
gamepads?: () => readonly (PadState | null)[];
|
|
39
|
+
}
|
|
40
|
+
export declare class Actions<A extends string> {
|
|
41
|
+
private readonly keyboard;
|
|
42
|
+
private bindings;
|
|
43
|
+
private readonly virtual;
|
|
44
|
+
private readonly virtualDown;
|
|
45
|
+
/** Analog value of each action this step (0–1), and last step's, for edges. */
|
|
46
|
+
private now;
|
|
47
|
+
private before;
|
|
48
|
+
private readonly deadZone;
|
|
49
|
+
private readonly gamepads;
|
|
50
|
+
constructor(keyboard: Keyboard | null, bindings: Bindings<A>, options?: ActionsOptions);
|
|
51
|
+
/** Replaces one action's bindings (a player's rebinding). */
|
|
52
|
+
bind(action: A, inputs: readonly string[]): void;
|
|
53
|
+
bindingsOf(action: A): readonly string[];
|
|
54
|
+
/** A touch UI's virtual button went down: `touch:<name>` bindings read it. */
|
|
55
|
+
press(name: string): void;
|
|
56
|
+
release(name: string): void;
|
|
57
|
+
/** Reads every device once; call at the start of each simulation step. */
|
|
58
|
+
poll(): void;
|
|
59
|
+
/** Held this step. */
|
|
60
|
+
down(action: A): boolean;
|
|
61
|
+
/** How far it is held (0–1): 1 for a key, the trigger or stick amount for analog input. */
|
|
62
|
+
value(action: A): number;
|
|
63
|
+
/** Went down this step. */
|
|
64
|
+
pressed(action: A): boolean;
|
|
65
|
+
/** Came up this step. */
|
|
66
|
+
released(action: A): boolean;
|
|
67
|
+
/** `value(positive) - value(negative)`, in −1…1. */
|
|
68
|
+
axis(negative: A, positive: A): number;
|
|
69
|
+
/** A 2D direction from four actions, never longer than 1 (a diagonal is not faster). */
|
|
70
|
+
vector(left: A, right: A, up: A, down: A): [number, number];
|
|
71
|
+
/** Ends the step: the keyboard forgets its edges; virtual taps shorter than a step have now been seen. */
|
|
72
|
+
endStep(): void;
|
|
73
|
+
private read;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=Actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Actions.d.ts","sourceRoot":"","sources":["../../../src/input/Actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI,MAAM,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;AAEtE,8EAA8E;AAC9E,eAAO,MAAM,WAAW,6HAA8H,CAAC;AAGvJ,0FAA0F;AAC1F,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,OAAO,EAAE,SAAS;QAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACnF,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC;AAED,MAAM,WAAW,cAAc;IAC7B,yDAAyD;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wFAAwF;IACxF,QAAQ,CAAC,EAAE,MAAM,SAAS,CAAC,QAAQ,GAAG,I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AC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAO3D,0GAA0G;IAC1G,OAAO,IAAI,IAAI;IAKf,OAAO,CAAC,IAAI;CA6Bb"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which keys are held, by `KeyboardEvent.code` (the physical key, so WASD stays WASD on any layout). `pressed` and
|
|
3
|
+
* `released` report edges since the last `endStep`; call that once per simulation step so a tap shorter than a frame
|
|
4
|
+
* is still seen by exactly one step.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Keyboard {
|
|
7
|
+
private readonly held;
|
|
8
|
+
private readonly down;
|
|
9
|
+
private readonly up;
|
|
10
|
+
private readonly cleanup;
|
|
11
|
+
constructor(target?: Window | HTMLElement);
|
|
12
|
+
isDown(code: string): boolean;
|
|
13
|
+
/** Any of these keys is held. */
|
|
14
|
+
anyDown(...codes: string[]): boolean;
|
|
15
|
+
/** Went down since the last `endStep`. */
|
|
16
|
+
pressed(code: string): boolean;
|
|
17
|
+
/** Came up since the last `endStep`. */
|
|
18
|
+
released(code: string): boolean;
|
|
19
|
+
/** -1, 0 or 1 from two sets of keys: `axis(['KeyA', 'ArrowLeft'], ['KeyD', 'ArrowRight'])`. */
|
|
20
|
+
axis(negative: string[], positive: string[]): number;
|
|
21
|
+
/** Forgets this step's edges; held keys stay held. */
|
|
22
|
+
endStep(): void;
|
|
23
|
+
destroy(): void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=Keyboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Keyboard.d.ts","sourceRoot":"","sources":["../../../src/input/Keyboard.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAqB;IAC1C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAqB;IAC1C,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAqB;IACxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;gBAElC,MAAM,GAAE,MAAM,GAAG,WAAoB;IA2BjD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI7B,iCAAiC;IACjC,OAAO,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO;IAIpC,0CAA0C;IAC1C,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI9B,wCAAwC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI/B,+FAA+F;IAC/F,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM;IAIpD,sDAAsD;IACtD,OAAO,IAAI,IAAI;IAKf,OAAO,IAAI,IAAI;CAKhB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An aim turned into the eight-way axis the keyboard makes (each part -1, 0 or 1; `stepMover` scales a diagonal),
|
|
3
|
+
* so a step sent along it is one a key could have sent. A part counts once the aim leans past 22.5° towards it.
|
|
4
|
+
*/
|
|
5
|
+
export declare function aimAxis(aim: number): {
|
|
6
|
+
dx: number;
|
|
7
|
+
dy: number;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=aimAxis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aimAxis.d.ts","sourceRoot":"","sources":["../../../src/input/aimAxis.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAK/D"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A long press, as pure timing so it can be tested: a finger that stays down `ms` without moving more than `slop`
|
|
3
|
+
* CSS px fires once, where it went down. A second finger, a move past the slop or a lift before the time is up is
|
|
4
|
+
* not a long press — a tap stays a tap. The caller owns the clock (`fire(now)` from a timer or a frame).
|
|
5
|
+
*/
|
|
6
|
+
export declare class LongPress {
|
|
7
|
+
readonly ms: number;
|
|
8
|
+
readonly slop: number;
|
|
9
|
+
private finger;
|
|
10
|
+
private done;
|
|
11
|
+
constructor(ms?: number, slop?: number);
|
|
12
|
+
down(id: number, x: number, y: number, now: number): void;
|
|
13
|
+
move(id: number, x: number, y: number): void;
|
|
14
|
+
up(id: number): void;
|
|
15
|
+
/** Where the press is, the first time this is asked at or after `ms`; null otherwise. */
|
|
16
|
+
fire(now: number): {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
} | null;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=longPress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"longPress.d.ts","sourceRoot":"","sources":["../../../src/input/longPress.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,SAAS;IAKlB,QAAQ,CAAC,EAAE;IACX,QAAQ,CAAC,IAAI;IALf,OAAO,CAAC,MAAM,CAAiE;IAC/E,OAAO,CAAC,IAAI,CAAS;gBAGV,EAAE,SAAM,EACR,IAAI,SAAK;IAGpB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI;IAWzD,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI;IAK5C,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAKpB,yFAAyF;IACzF,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;CAMnD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The virtual joystick's arithmetic, kept pure so it can be tested. The stick hands the game the **same** axis
|
|
3
|
+
* the keyboard does — `stepMover` clamps every step to -1/0/1 on each axis (movement is eight-way, and the server
|
|
4
|
+
* reads it the same way), so an analog stick would only be rounded there anyway. The rounding happens here instead,
|
|
5
|
+
* by eight 45° sectors, so a thumb held a little off the horizontal walks straight rather than flickering between
|
|
6
|
+
* east and north-east.
|
|
7
|
+
*/
|
|
8
|
+
/** Below this share of the stick's radius the thumb is resting: no movement, and the aim falls back (touchAim.ts). */
|
|
9
|
+
export declare const STICK_DEAD_ZONE = 0.28;
|
|
10
|
+
export interface StickVector {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
}
|
|
14
|
+
/** The thumb's offset from where the stick was planted, as a vector of length at most 1 (radius = full tilt). */
|
|
15
|
+
export declare function stickVector(dx: number, dy: number, radius: number): StickVector;
|
|
16
|
+
/** True when the stick is tilted past the dead zone. */
|
|
17
|
+
export declare function stickActive(v: StickVector, deadZone?: number): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The keyboard-shaped axis for a stick vector: each of dx, dy is -1, 0 or 1 (screen y grows downward, as the
|
|
20
|
+
* keyboard's "down" does), nothing inside the dead zone, and the nearest of the eight directions otherwise.
|
|
21
|
+
*/
|
|
22
|
+
export declare function stickToAxis(v: StickVector, deadZone?: number): {
|
|
23
|
+
dx: number;
|
|
24
|
+
dy: number;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=stickAxis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stickAxis.d.ts","sourceRoot":"","sources":["../../../src/input/stickAxis.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,sHAAsH;AACtH,eAAO,MAAM,eAAe,OAAO,CAAC;AAEpC,MAAM,WAAW,WAAW;IAC1B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,iHAAiH;AACjH,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAM/E;AAED,wDAAwD;AACxD,wBAAgB,WAAW,CAAC,CAAC,EAAE,WAAW,EAAE,QAAQ,SAAkB,GAAG,OAAO,CAE/E;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,WAAW,EAAE,QAAQ,SAAkB,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAMlG"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** What decides whether the touch controls are shown; read off the browser by `touchDevice.ts`. */
|
|
2
|
+
export interface TouchEnv {
|
|
3
|
+
/** Running inside the native shell (Capacitor iOS). */
|
|
4
|
+
native: boolean;
|
|
5
|
+
/** `(pointer: coarse)` matches: the **primary** pointer is a finger. */
|
|
6
|
+
coarse: boolean;
|
|
7
|
+
/** `navigator.maxTouchPoints`. */
|
|
8
|
+
touchPoints: number;
|
|
9
|
+
/** `?touch=1|0` in the URL or `localStorage['engine.touch']`, for trying the controls on a desktop browser. */
|
|
10
|
+
override: string | null;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Touch controls only where a finger is the main way in: the native app always, a browser whose primary pointer
|
|
14
|
+
* is coarse and that reports touch points (a phone or tablet), never a desktop — a laptop with a touch screen
|
|
15
|
+
* still has a fine primary pointer and keeps its mouse and keyboard.
|
|
16
|
+
*/
|
|
17
|
+
export declare function detectTouch(env: TouchEnv): boolean;
|
|
18
|
+
//# sourceMappingURL=touchDetect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"touchDetect.d.ts","sourceRoot":"","sources":["../../../src/input/touchDetect.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,MAAM,WAAW,QAAQ;IACvB,uDAAuD;IACvD,MAAM,EAAE,OAAO,CAAC;IAChB,wEAAwE;IACxE,MAAM,EAAE,OAAO,CAAC;IAChB,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,+GAA+G;IAC/G,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAKlD"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Stage } from '../core/Stage.js';
|
|
2
|
+
/** A light in the world. Change its fields any time (follow a body by writing `x`/`y` each frame). */
|
|
3
|
+
export interface Light {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
/** World px. */
|
|
7
|
+
radius: number;
|
|
8
|
+
/** The colour it casts on what it lights (default warm white). */
|
|
9
|
+
color?: number;
|
|
10
|
+
/** 0–1: how much of the dark it takes away, and how strong its colour (default 1). */
|
|
11
|
+
intensity?: number;
|
|
12
|
+
/** Radius wobble, 0–1 (a torch ≈ 0.08). */
|
|
13
|
+
flicker?: number;
|
|
14
|
+
/** A light off is kept but not drawn. */
|
|
15
|
+
on?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface LightLayerOptions {
|
|
18
|
+
/** Colour of the dark (default deep blue). */
|
|
19
|
+
ambient?: number;
|
|
20
|
+
/** 0 no dark at all, 1 black where nothing is lit (default 0.85). */
|
|
21
|
+
darkness?: number;
|
|
22
|
+
/** How strongly lights tint what they light, 0–1 (default 0.35). */
|
|
23
|
+
tint?: number;
|
|
24
|
+
/** A light's height over its width: the ground is seen at a slant (default 1, round; a 3/4 view ≈ 0.85). */
|
|
25
|
+
squash?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Smooth darkness with lights cut out of it, for art that is not pixel art (the pixel module has its own dithered
|
|
29
|
+
* `Darkness`). The dark is a screen-sized texture: each light erases a soft hole in it, and lays its colour over what
|
|
30
|
+
* shows through. It sits on the screen layer, over the world and under the HUD you add after it.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* const night = new LightLayer(stage, { darkness: 0.9 });
|
|
34
|
+
* const torch = night.add({ x: 100, y: 80, radius: 90, color: 0xffb060, flicker: 0.08 });
|
|
35
|
+
* // each frame: torch.x = hero.x; night.update(now);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare class LightLayer {
|
|
39
|
+
private readonly stage;
|
|
40
|
+
private readonly lights;
|
|
41
|
+
private readonly scratch;
|
|
42
|
+
private readonly sheet;
|
|
43
|
+
private readonly holes;
|
|
44
|
+
private readonly washes;
|
|
45
|
+
private readonly view;
|
|
46
|
+
private rt;
|
|
47
|
+
private readonly pool;
|
|
48
|
+
private ambient;
|
|
49
|
+
private darkness;
|
|
50
|
+
private readonly tint;
|
|
51
|
+
private readonly squash;
|
|
52
|
+
private readonly unsubscribe;
|
|
53
|
+
constructor(stage: Stage, options?: LightLayerOptions);
|
|
54
|
+
add(light: Light): Light;
|
|
55
|
+
remove(light: Light): void;
|
|
56
|
+
clear(): void;
|
|
57
|
+
/** Changes the dark: its colour and how dark (a day/night cycle eases these). */
|
|
58
|
+
setAmbient(color: number, darkness: number): void;
|
|
59
|
+
/** Redraws the dark with this frame's lights. Call once a frame, after the camera moved. */
|
|
60
|
+
update(now?: number): void;
|
|
61
|
+
destroy(): void;
|
|
62
|
+
private sprites;
|
|
63
|
+
private fit;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=LightLayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LightLayer.d.ts","sourceRoot":"","sources":["../../../src/light/LightLayer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAE3C,sGAAsG;AACtG,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,gBAAgB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,KAAK,GAAG,IAAI;IAI1B,KAAK,IAAI,IAAI;IAIb,iFAAiF;IACjF,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAKjD,4FAA4F;IAC5F,MAAM,CAAC,GAAG,SAAoB,GAAG,IAAI;IAqCrC,OAAO,IAAI,IAAI;IASf,OAAO,CAAC,OAAO;IAgBf,OAAO,CAAC,GAAG;CAOZ"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { EventBus } from '../events/EventBus.js';
|
|
2
|
+
import type { InputStep } from './constants.js';
|
|
3
|
+
import type { ClientMessage, ServerMessage, Snapshot } from './protocol.js';
|
|
4
|
+
export interface ConnectionEvents {
|
|
5
|
+
open: undefined;
|
|
6
|
+
/** The socket closed; `willRetry` when it will reconnect by itself. */
|
|
7
|
+
close: {
|
|
8
|
+
code: number;
|
|
9
|
+
reason: string;
|
|
10
|
+
willRetry: boolean;
|
|
11
|
+
};
|
|
12
|
+
welcome: Extract<ServerMessage, {
|
|
13
|
+
t: 'welcome';
|
|
14
|
+
}>;
|
|
15
|
+
snapshot: Snapshot;
|
|
16
|
+
/** Any message the engine does not handle: the game's own. */
|
|
17
|
+
message: {
|
|
18
|
+
t: string;
|
|
19
|
+
[k: string]: unknown;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface ConnectionOptions {
|
|
23
|
+
/** Reconnect after the socket drops (default true), waiting longer each time up to `maxBackoffMs`. */
|
|
24
|
+
reconnect?: boolean;
|
|
25
|
+
maxBackoffMs?: number;
|
|
26
|
+
/** Ping interval for the server clock and the round-trip time (default 1000 ms). */
|
|
27
|
+
pingMs?: number;
|
|
28
|
+
/** Sent on every (re)connect as `hello.data`. */
|
|
29
|
+
hello?: () => unknown;
|
|
30
|
+
/** The WebSocket class (default the global one; Node 22+ and browsers have it). */
|
|
31
|
+
WebSocket?: typeof WebSocket;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The client side of the engine's netcode over a WebSocket: hello on open, input steps batched and sent once a frame
|
|
35
|
+
* (`queueInput` then `flush`), snapshots decoded (binary or JSON) onto `events`, pings that keep the server clock
|
|
36
|
+
* (`serverNow`) and `rtt` up to date, and reconnection with backoff.
|
|
37
|
+
*/
|
|
38
|
+
export declare class Connection {
|
|
39
|
+
readonly url: string;
|
|
40
|
+
private readonly options;
|
|
41
|
+
readonly events: EventBus<ConnectionEvents>;
|
|
42
|
+
/** The last measured round trip, ms. */
|
|
43
|
+
rtt: number;
|
|
44
|
+
private socket;
|
|
45
|
+
private batch;
|
|
46
|
+
private closedByUs;
|
|
47
|
+
private attempt;
|
|
48
|
+
private pingTimer;
|
|
49
|
+
private retryTimer;
|
|
50
|
+
constructor(url: string, options?: ConnectionOptions);
|
|
51
|
+
get open(): boolean;
|
|
52
|
+
connect(): this;
|
|
53
|
+
/** Sends a message now (dropped while closed: input is resent by the prediction's own state, not by the socket). */
|
|
54
|
+
send(msg: ClientMessage | {
|
|
55
|
+
t: string;
|
|
56
|
+
[k: string]: unknown;
|
|
57
|
+
}): void;
|
|
58
|
+
/** Adds one input step to this frame's batch; `flush` sends it. Steps must come in sequence order. */
|
|
59
|
+
queueInput(seq: number, step: InputStep): void;
|
|
60
|
+
/** Sends this frame's input steps as one message. Call once a frame. */
|
|
61
|
+
flush(): void;
|
|
62
|
+
close(): void;
|
|
63
|
+
private ping;
|
|
64
|
+
private receive;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=Connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Connection.d.ts","sourceRoot":"","sources":["../../../src/net/Connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAG7C,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE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AAC,GAAG,EAAE,aAAa,GAAG;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,GAAG,IAAI;IAIpE,sGAAsG;IACtG,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,IAAI;IAK9C,wEAAwE;IACxE,KAAK,IAAI,IAAI;IAMb,KAAK,IAAI,IAAI;IAQb,OAAO,CAAC,IAAI;IAIZ,OAAO,CAAC,OAAO;CAyBhB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { EntityUpdate } from './constants.js';
|
|
2
|
+
export interface InterpolatedState {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
aim: number;
|
|
6
|
+
/** Discrete fields come from the older of the two samples until the newer one is reached. */
|
|
7
|
+
anim: number;
|
|
8
|
+
hp: number;
|
|
9
|
+
flags: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Smooth motion for bodies the server moves (other players, monsters): snapshots arrive 10–30 times a second and
|
|
13
|
+
* jittered, so each body is drawn a little in the past (`delayMs`) between the two snapshots around that moment.
|
|
14
|
+
* Past the newest snapshot it extrapolates for at most `maxExtrapolateMs`, then holds.
|
|
15
|
+
*
|
|
16
|
+
* Times are server times (`Snapshot.time`); render at `serverNow()`.
|
|
17
|
+
*/
|
|
18
|
+
export declare class InterpolationBuffer {
|
|
19
|
+
/** How far in the past bodies are drawn (default 100 ms: two snapshots at 20 Hz, so one may be late). */
|
|
20
|
+
readonly delayMs: number;
|
|
21
|
+
private readonly maxExtrapolateMs;
|
|
22
|
+
private readonly keep;
|
|
23
|
+
private readonly samples;
|
|
24
|
+
constructor(
|
|
25
|
+
/** How far in the past bodies are drawn (default 100 ms: two snapshots at 20 Hz, so one may be late). */
|
|
26
|
+
delayMs?: number, maxExtrapolateMs?: number, keep?: number);
|
|
27
|
+
/** Records every body of a snapshot taken at `time`. */
|
|
28
|
+
push(time: number, updates: readonly EntityUpdate[]): void;
|
|
29
|
+
/** Forgets a body (it left view). */
|
|
30
|
+
remove(id: number): void;
|
|
31
|
+
has(id: number): boolean;
|
|
32
|
+
ids(): IterableIterator<number>;
|
|
33
|
+
/** Where body `id` should be drawn at server time `now`, or null if nothing is known of it. */
|
|
34
|
+
sample(id: number, now: number): InterpolatedState | null;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=InterpolationBuffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InterpolationBuffer.d.ts","sourceRoot":"","sources":["../../../src/net/InterpolationBuffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAahD,MAAM,WAAW,iBAAiB;IAChC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,GAAG,EAAE,MAAM,CAAC;IACZ,6FAA6F;IAC7F,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,qBAAa,mBAAmB;IAI5B,yGAAyG;IACzG,QAAQ,CAAC,OAAO;IAChB,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,IAAI;IANvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA+B;;IAGrD,yGAAyG;IAChG,OAAO,SAAM,EACL,gBAAgB,SAAM,EACtB,IAAI,SAAK;IAG5B,wDAAwD;IACxD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,IAAI;IAe1D,qCAAqC;IACrC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAIxB,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAIxB,GAAG,IAAI,gBAAgB,CAAC,MAAM,CAAC;IAI/B,+FAA+F;IAC/F,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI;CAqB1D"}
|