Test sprite from script

This commit is contained in:
2026-06-02 09:32:07 -05:00
parent 57766a9104
commit a25871a849
38 changed files with 1913 additions and 377 deletions
+72
View File
@@ -0,0 +1,72 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/** Asset archive queries and cache management. */
interface AssetNamespace {
// Loader type constants
readonly TYPE_MESH: number;
readonly TYPE_TEXTURE: number;
readonly TYPE_TILESET: number;
readonly TYPE_LOCALE: number;
readonly TYPE_JSON: number;
readonly TYPE_SCRIPT: number;
// Mesh axis input constants (pass as `input` to lock with TYPE_MESH)
readonly MESH_AXIS_Y_UP: number;
readonly MESH_AXIS_Z_UP: number;
readonly MESH_AXIS_X_UP: number;
readonly MESH_AXIS_Y_DOWN: number;
readonly MESH_AXIS_Z_DOWN: number;
readonly MESH_AXIS_X_DOWN: number;
/**
* Returns `true` if the given path exists in the asset archive (`dusk.dsk`).
*
* @param path - Archive-relative path, e.g. `"init.js"` or `"ui/hud.png"`.
*/
exists(path: string): boolean;
/**
* Locks an entry in the asset cache and returns an `AssetEntry`.
* The entry begins loading in the background. Call `entry.requireLoaded()`
* to block until it is ready.
*
* The lock is released when the `AssetEntry` is GC'd or `entry.unlock()`
* is called explicitly.
*
* @param path - Archive-relative path.
* @param type - Loader type constant (`Asset.TYPE_*`).
* @param input - Optional loader-specific input constant.
* `TYPE_TEXTURE` → `Texture.FORMAT_*`
* `TYPE_MESH` → `Asset.MESH_AXIS_*`
*
* @example
* const entry = Asset.lock('data/map.json');
* entry.requireLoaded();
*/
lock(path: string, type: number, input?: number): AssetEntry;
/**
* Blocks until the given entry is fully loaded.
* Returns the entry for chaining.
* @throws If the load fails.
*
* @example
* const entry = Asset.requireLoaded(Asset.lock('map.json', Asset.TYPE_JSON));
*/
requireLoaded(entry: AssetEntry): AssetEntry;
/**
* Releases the lock on an asset by path.
* Prefer calling `entry.unlock()` on the `AssetEntry` object directly.
*
* @param path - The path originally passed to `lock`.
*/
unlock(path: string): void;
}
declare var Asset: AssetNamespace;
+54
View File
@@ -0,0 +1,54 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/**
* A live reference to an entry in the asset cache.
* Holds a lock that keeps the entry alive; the lock is released automatically
* when the object is garbage collected, or immediately via `unlock()`.
*/
interface AssetEntry {
/** Archive-relative path used as the cache key. */
readonly name: string;
/** Current loading state — compare against `AssetEntry.*` state constants. */
readonly state: number;
/** Loader type — one of the `AssetEntry.TYPE_*` constants. */
readonly type: number;
/** `true` when the entry has fully loaded (`state === AssetEntry.LOADED`). */
readonly isLoaded: boolean;
/**
* Returns a `Texture` for this entry when it is a loaded texture asset.
* The `Texture` holds its own asset lock — independent of this `AssetEntry`.
* Returns `undefined` if the entry is not of type `Asset.TYPE_TEXTURE` or
* is not yet loaded.
*/
readonly texture: Texture | undefined;
/**
* Blocks until the entry reaches `LOADED` (or `ERROR`).
* Returns `this` for chaining.
* @throws If the load fails.
*/
requireLoaded(): this;
/**
* Releases the lock immediately.
* After this call the object is invalid — do not use it again.
*/
unlock(): void;
toString(): string;
}
interface AssetEntryConstructor {
// Loading state constants
readonly NOT_STARTED: number;
readonly PENDING: number;
readonly LOADING: number;
readonly LOADED: number;
readonly ERROR: number;
new(): never;
}
declare var AssetEntry: AssetEntryConstructor;
+1 -8
View File
@@ -5,16 +5,12 @@
* https://opensource.org/licenses/MIT
*/
/**
* Interface for the in-game developer console.
*/
/** Interface for the in-game developer console. */
interface ConsoleNamespace {
/**
* Prints one or more values to the in-game console, separated by tabs.
* Each argument is coerced to a string before printing.
*
* @param args - Values to print.
*
* @example
* Console.print("x =", player.x, "y =", player.y);
*/
@@ -23,9 +19,6 @@ interface ConsoleNamespace {
/**
* Whether the in-game console overlay is currently visible.
* Set to `true` to show the console, `false` to hide it.
*
* @example
* Console.visible = true;
*/
visible: boolean;
}
+41
View File
@@ -0,0 +1,41 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/** An RGBA color with channels in the range 0255. */
declare class Color {
/** @param r Red 0255 (default 0) */
/** @param g Green 0255 (default 0) */
/** @param b Blue 0255 (default 0) */
/** @param a Alpha 0255 (default 255) */
constructor(r?: number, g?: number, b?: number, a?: number);
r: number;
g: number;
b: number;
a: number;
toString(): string;
// Named color constants
static readonly WHITE: Color;
static readonly BLACK: Color;
static readonly RED: Color;
static readonly GREEN: Color;
static readonly BLUE: Color;
static readonly YELLOW: Color;
static readonly CYAN: Color;
static readonly MAGENTA: Color;
static readonly TRANSPARENT: Color;
static readonly GRAY: Color;
static readonly LIGHT_GRAY: Color;
static readonly DARK_GRAY: Color;
static readonly ORANGE: Color;
static readonly PURPLE: Color;
static readonly PINK: Color;
static readonly TEAL: Color;
static readonly CORNFLOWER_BLUE: Color;
}
+19
View File
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/** Read-only information about the current display surface. */
interface ScreenNamespace {
/** Current render-target width in pixels. */
readonly width: number;
/** Current render-target height in pixels. */
readonly height: number;
/** Aspect ratio: `width / height`. */
readonly aspect: number;
}
/** Current display / render-target dimensions. */
declare var Screen: ScreenNamespace;
+28
View File
@@ -0,0 +1,28 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/**
* A loaded texture asset. Holds a lock on the underlying asset entry —
* the lock is released automatically when the object is garbage collected.
*/
interface Texture {
/** Pixel width of the texture. */
readonly width: number;
/** Pixel height of the texture. */
readonly height: number;
toString(): string;
}
interface TextureConstructor {
/** RGBA 32-bit format (4 channels × 8 bits). */
readonly FORMAT_RGBA: number;
/** Paletted format. */
readonly FORMAT_PALETTE: number;
new(): never;
}
declare var Texture: TextureConstructor;
+4 -13
View File
@@ -5,26 +5,17 @@
* https://opensource.org/licenses/MIT
*/
/**
* Controls over the engine main loop.
*/
/** Controls over the engine main loop. */
interface EngineNamespace {
/**
* Whether the engine main loop is still running (read-only).
* Whether the engine main loop is still running.
* Becomes `false` after `Engine.exit()` is called.
*
* @example
* while (Engine.running) { ... }
*/
readonly running: boolean;
/**
* Requests an orderly shutdown of the engine.
* Sets the internal running flag to `false`; the main loop exits at the end
* of the current tick.
*
* @example
* Engine.exit();
* Requests an orderly shutdown. Sets `running` to `false`; the main loop
* exits at the end of the current tick.
*/
exit(): void;
}
-129
View File
@@ -1,129 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
// ---------------------------------------------------------------------------
// Component (generic base returned by entity.add() for untyped components)
// ---------------------------------------------------------------------------
/** Base component returned by entity.add() for component types without a specific module. */
interface Component {
/** Entity ID this component belongs to. */
readonly entity: number;
/** Component slot ID. */
readonly id: number;
toString(): string;
}
interface ComponentConstructor {
/** Sentinel value for an invalid component ID. */
readonly INVALID: number;
// Component type constants (generated from componentlist.h)
readonly POSITION: number;
readonly CAMERA: number;
readonly RENDERABLE: number;
readonly PHYSICS: number;
readonly TRIGGER: number;
readonly OVERWORLD: number;
readonly PLAYER: number;
readonly INTERACTABLE: number;
readonly OVERWORLD_CAMERA: number;
readonly OVERWORLD_TRIGGER: number;
new(): never;
}
declare var Component: ComponentConstructor;
// ---------------------------------------------------------------------------
// Position
// ---------------------------------------------------------------------------
/** Position/rotation/scale transform component with optional parent hierarchy. */
interface Position extends Component {
/**
* Local-space position. Assigning a Vec3 writes to the C transform and
* marks the world transform dirty. Reading returns a fresh Vec3 copy.
*/
localPosition: Vec3;
/** World-space position (accounts for all parent transforms). */
worldPosition: Vec3;
/** Local-space euler rotation in radians (XYZ). */
localRotation: Vec3;
/** World-space euler rotation in radians. */
worldRotation: Vec3;
/** Local-space scale. */
localScale: Vec3;
/** World-space scale. */
worldScale: Vec3;
/**
* Orients the transform to look at a world-space target point.
* Uses the current local position as the eye. Optionally specify an up
* vector (defaults to Y-up).
*/
lookAt(target: Vec3, up?: Vec3): void;
/**
* Sets this component's parent in the transform hierarchy.
* Pass `null` or `undefined` to detach.
*/
setParent(parent: Position | null | undefined): void;
toString(): string;
}
interface PositionConstructor {
new(): never;
}
declare var Position: PositionConstructor;
// ---------------------------------------------------------------------------
// Camera
// ---------------------------------------------------------------------------
/** Camera projection component. */
interface Camera extends Component {
/** Field of view in radians (perspective projections only). */
fov: number;
/** Near clip plane distance. */
nearClip: number;
/** Far clip plane distance. */
farClip: number;
/** Projection type — one of the Camera.PERSPECTIVE / Camera.ORTHOGRAPHIC constants. */
projType: number;
toString(): string;
}
interface CameraConstructor {
readonly PERSPECTIVE: number;
readonly PERSPECTIVE_FLIPPED: number;
readonly ORTHOGRAPHIC: number;
new(): never;
}
declare var Camera: CameraConstructor;
// ---------------------------------------------------------------------------
// Entity
// ---------------------------------------------------------------------------
interface Entity {
/** Add a component of the given type and return a typed instance. */
add(type: CameraConstructor["PERSPECTIVE"] | number): Component;
toString(): string;
}
interface EntityConstructor {
/** Sentinel value for an invalid entity ID. */
readonly INVALID: number;
/** Creates a new entity and returns it. Returns Entity.INVALID slot if the pool is full. */
create(): Entity;
/** Disposes the entity and all its components. */
dispose(entity: Entity): void;
new(): never;
}
declare var Entity: EntityConstructor;
+39
View File
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/**
* Base type for all components. `entity.add()` returns a subtype when the
* component type has a dedicated module; cast with `as Position` etc. when
* you need the specific API.
*/
interface Component {
/** Entity ID this component belongs to. */
readonly entity: number;
/** Component slot index. */
readonly id: number;
toString(): string;
}
interface ComponentConstructor {
/** Sentinel for an invalid component ID. */
readonly INVALID: number;
readonly POSITION: number;
readonly CAMERA: number;
readonly RENDERABLE: number;
readonly PHYSICS: number;
readonly TRIGGER: number;
readonly OVERWORLD: number;
readonly PLAYER: number;
readonly INTERACTABLE: number;
readonly OVERWORLD_CAMERA: number;
readonly OVERWORLD_TRIGGER: number;
new(): never;
}
declare var Component: ComponentConstructor;
+28
View File
@@ -0,0 +1,28 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/** Camera projection component. Only one camera is active at a time. */
interface Camera extends Component {
/** Field of view in radians (perspective only). */
fov: number;
/** Near clip plane distance. */
nearClip: number;
/** Far clip plane distance. */
farClip: number;
/** One of `Camera.PERSPECTIVE`, `Camera.PERSPECTIVE_FLIPPED`, or `Camera.ORTHOGRAPHIC`. */
projType: number;
toString(): string;
}
interface CameraConstructor {
readonly PERSPECTIVE: number;
readonly PERSPECTIVE_FLIPPED: number;
readonly ORTHOGRAPHIC: number;
new(): never;
}
declare var Camera: CameraConstructor;
+39
View File
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/** Physics body component. */
interface Physics extends Component {
/** Body simulation type — `Physics.STATIC`, `DYNAMIC`, or `KINEMATIC`. */
bodyType: number;
/**
* Collision shape type — one of the `Physics.SHAPE_*` constants.
* Changing the type preserves existing velocity and ground state.
*/
shape: number;
/** Current linear velocity (Vec3). */
velocity: Vec3;
/** Gravity multiplier. 0 = no gravity, 1 = full, negative = inverted. */
gravityScale: number;
/** `true` if the body rested on a surface during the last simulation step. */
readonly onGround: boolean;
/** Applies an instantaneous velocity change. No-op on STATIC bodies. */
applyImpulse(impulse: Vec3): void;
toString(): string;
}
interface PhysicsConstructor {
readonly STATIC: number;
readonly DYNAMIC: number;
readonly KINEMATIC: number;
readonly SHAPE_CUBE: number;
readonly SHAPE_SPHERE: number;
readonly SHAPE_CAPSULE: number;
readonly SHAPE_PLANE: number;
new(): never;
}
declare var Physics: PhysicsConstructor;
+41
View File
@@ -0,0 +1,41 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/** Transform component — local/world PRS with an optional parent hierarchy. */
interface Position extends Component {
/**
* Local-space position. Reading returns a Vec3 copy; assigning a Vec3
* writes through to the C transform and marks descendants dirty.
*/
localPosition: Vec3;
/** World-space position (full parent-chain applied). */
worldPosition: Vec3;
/** Local euler rotation in radians (XYZ order). */
localRotation: Vec3;
/** World euler rotation in radians. */
worldRotation: Vec3;
/** Local scale. */
localScale: Vec3;
/** World scale (extracted from parent-chain matrix). */
worldScale: Vec3;
/**
* Orients the transform so it faces `target`. Uses the current local
* position as the eye. `up` defaults to world Y-up.
*/
lookAt(target: Vec3, up?: Vec3): void;
/**
* Attaches this transform to a parent. Pass `null` / `undefined` to detach.
*/
setParent(parent: Position | null | undefined): void;
toString(): string;
}
interface PositionConstructor {
new(): never;
}
declare var Position: PositionConstructor;
+71
View File
@@ -0,0 +1,71 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/** Fields shared by every renderable type. */
interface Renderable extends Component {
/** Current render type — one of the `Renderable.*` type constants. */
type: number;
/** Render priority. 0 = auto. Higher = drawn later. */
priority: number;
toString(): string;
}
/**
* Renderable in `SHADER_MATERIAL` mode (default after `entity.add`).
* Renders a mesh with the unlit shader.
*/
interface RenderableMaterial extends Renderable {
/**
* Unlit material color. Reading returns a fresh `Color` copy; assigning
* a `Color` instance writes through to the C material.
*
* @example
* r.color = Color.RED;
* r.color = new Color(255, 128, 0);
*/
color: Color;
}
/**
* Renderable in `SPRITEBATCH` mode.
* Activated by calling `setTexture`.
*/
interface RenderableSpritebatch extends Renderable {
/**
* Assigns a texture and switches to `SPRITEBATCH` mode.
* The Texture object is pinned (GC-safe) for the component's lifetime.
*/
setTexture(texture: Texture): void;
/**
* Adds a sprite quad to the spritebatch.
*
* 3D form (10 args): `addSprite(x1,y1,z1, x2,y2,z2, u1,v1, u2,v2)`
* 2D form (8 args): `addSprite(x1,y1, x2,y2, u1,v1, u2,v2)` — z defaults to 0
*/
addSprite(
x1: number, y1: number, z1OrX2: number,
x2OrY2: number, y2OrZ2?: number, z2?: number,
u1?: number, v1?: number, u2?: number, v2?: number
): void;
/** Resets the sprite count to zero. */
clearSprites(): void;
}
/**
* Renderable in `CUSTOM` mode.
* Draw logic is provided by a C callback set via `entityRenderableSetDraw`.
*/
interface RenderableCustom extends Renderable {}
interface RenderableConstructor {
readonly SHADER_MATERIAL: number;
readonly SPRITEBATCH: number;
readonly CUSTOM: number;
new(): never;
}
declare var Renderable: RenderableConstructor;
+25
View File
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/** AABB trigger volume. `contains` tests whether a world point is inside. */
interface Trigger extends Component {
/** Minimum corner of the AABB (Vec3). */
min: Vec3;
/** Maximum corner of the AABB (Vec3). */
max: Vec3;
/** Sets both corners at once. */
setBounds(min: Vec3, max: Vec3): void;
/** Returns `true` if `point` is inside `[min, max]`. */
contains(point: Vec3): boolean;
toString(): string;
}
interface TriggerConstructor {
new(): never;
}
declare var Trigger: TriggerConstructor;
+29
View File
@@ -0,0 +1,29 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
interface Entity {
/**
* Adds a component of the given type and returns it.
* Returns a typed subclass when the component has a dedicated module
* (`Position`, `Camera`, `Renderable`, `Trigger`, `Physics`); otherwise
* returns the base `Component`. Cast with `as Position` etc. when needed.
*/
add(type: number): Component;
toString(): string;
}
interface EntityConstructor {
/** Sentinel for an invalid entity ID. */
readonly INVALID: number;
/** Allocates a new entity from the fixed pool (max 64). */
create(): Entity;
/** Disposes the entity and all of its components. */
dispose(entity: Entity): void;
new(): never;
}
declare var Entity: EntityConstructor;
+27 -8
View File
@@ -14,11 +14,30 @@
* { "compilerOptions": { "typeRoots": ["./types"] } }
*/
/// <reference path="./console.d.ts" />
/// <reference path="./screen.d.ts" />
/// <reference path="./engine.d.ts" />
/// <reference path="./input.d.ts" />
/// <reference path="./system.d.ts" />
/// <reference path="./vec3.d.ts" />
/// <reference path="./entity.d.ts" />
/// <reference path="./scene.d.ts" />
// math
/// <reference path="./math/vec3.d.ts" />
// display
/// <reference path="./display/color.d.ts" />
/// <reference path="./display/screen.d.ts" />
/// <reference path="./display/texture.d.ts" />
// asset
/// <reference path="./asset/assetentry.d.ts" />
/// <reference path="./asset/asset.d.ts" />
// engine systems
/// <reference path="./console/console.d.ts" />
/// <reference path="./engine/engine.d.ts" />
/// <reference path="./input/input.d.ts" />
/// <reference path="./scene/scene.d.ts" />
/// <reference path="./system/system.d.ts" />
// entity / components
/// <reference path="./entity/component.d.ts" />
/// <reference path="./entity/component/camera.d.ts" />
/// <reference path="./entity/component/physics.d.ts" />
/// <reference path="./entity/component/position.d.ts" />
/// <reference path="./entity/component/renderable.d.ts" />
/// <reference path="./entity/component/trigger.d.ts" />
/// <reference path="./entity/entity.d.ts" />
-115
View File
@@ -1,115 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/**
* Opaque type alias for input action identifiers.
* Use the `INPUT_ACTION_*` constants rather than raw numbers.
*/
type InputAction = number;
/**
* Polling-based input queries and button rebinding.
*/
interface InputNamespace {
/**
* Returns `true` while the given action is held down this frame.
*
* @param action - An `INPUT_ACTION_*` constant.
*
* @example
* if (Input.isDown(INPUT_ACTION_UP)) { player.moveUp(); }
*/
isDown(action: InputAction): boolean;
/**
* Returns `true` if the given action was held down in the previous frame.
*
* @param action - An `INPUT_ACTION_*` constant.
*/
wasDown(action: InputAction): boolean;
/**
* Returns `true` on the first frame the action transitions from up → down.
*
* @param action - An `INPUT_ACTION_*` constant.
*
* @example
* if (Input.pressed(INPUT_ACTION_ACCEPT)) { confirmSelection(); }
*/
pressed(action: InputAction): boolean;
/**
* Returns `true` on the first frame the action transitions from down → up.
*
* @param action - An `INPUT_ACTION_*` constant.
*/
released(action: InputAction): boolean;
/**
* Returns the continuous (analog) value of an action in the range `0.01.0`.
* Digital buttons return either `0` or `1`.
*
* @param action - An `INPUT_ACTION_*` constant.
*
* @example
* const speed = Input.getValue(INPUT_ACTION_UP) * MAX_SPEED;
*/
getValue(action: InputAction): number;
/**
* Returns a signed axis value in the range `-1.01.0`, derived from two
* opposing actions: `getValue(pos) - getValue(neg)`.
*
* @param neg - Action mapped to the negative direction.
* @param pos - Action mapped to the positive direction.
*
* @example
* const moveX = Input.axis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT);
*/
axis(neg: InputAction, pos: InputAction): number;
/**
* Rebinds a physical button (by name) to a logical input action at runtime.
* Throws if `buttonName` is unknown or `action` is out of range.
*
* @param buttonName - Platform-specific button identifier string (e.g. `"A"`, `"START"`).
* @param action - Target `INPUT_ACTION_*` constant.
*
* @example
* Input.bind("A", INPUT_ACTION_ACCEPT);
*/
bind(buttonName: string, action: InputAction): void;
}
/** Polling-based input system. */
declare var Input: InputNamespace;
// ---------------------------------------------------------------------------
// Input action constants.
// Injected as plain global variables by the engine at startup.
// ---------------------------------------------------------------------------
/** Move / navigate upward. */
declare var INPUT_ACTION_UP: InputAction;
/** Move / navigate downward. */
declare var INPUT_ACTION_DOWN: InputAction;
/** Move / navigate left. */
declare var INPUT_ACTION_LEFT: InputAction;
/** Move / navigate right. */
declare var INPUT_ACTION_RIGHT: InputAction;
/** Confirm / accept the current selection. */
declare var INPUT_ACTION_ACCEPT: InputAction;
/** Cancel / go back. */
declare var INPUT_ACTION_CANCEL: InputAction;
/** Emergency quit (e.g. hold-to-exit on embedded platforms). */
declare var INPUT_ACTION_RAGEQUIT: InputAction;
/** Toggle the developer console overlay. */
declare var INPUT_ACTION_CONSOLE: InputAction;
/** Pointer / cursor horizontal position (analog). */
declare var INPUT_ACTION_POINTERX: InputAction;
/** Pointer / cursor vertical position (analog). */
declare var INPUT_ACTION_POINTERY: InputAction;
+50
View File
@@ -0,0 +1,50 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/** Opaque type alias for input action identifiers. */
type InputAction = number;
/** Polling-based input queries and button rebinding. */
interface InputNamespace {
/** Returns `true` while the given action is held down this frame. */
isDown(action: InputAction): boolean;
/** Returns `true` if the given action was held down last frame. */
wasDown(action: InputAction): boolean;
/** Returns `true` on the first frame the action transitions up → down. */
pressed(action: InputAction): boolean;
/** Returns `true` on the first frame the action transitions down → up. */
released(action: InputAction): boolean;
/** Continuous (analog) value in `0.01.0`. Digital buttons return 0 or 1. */
getValue(action: InputAction): number;
/**
* Signed axis value `-1.01.0`: `getValue(pos) - getValue(neg)`.
* @param neg - Action mapped to the negative direction.
* @param pos - Action mapped to the positive direction.
*/
axis(neg: InputAction, pos: InputAction): number;
/**
* Rebinds a physical button to a logical action at runtime.
* @param buttonName - Platform-specific button name, e.g. `"A"`, `"START"`.
* @param action - Target `INPUT_ACTION_*` constant.
*/
bind(buttonName: string, action: InputAction): void;
}
/** Polling-based input system. */
declare var Input: InputNamespace;
// Input action constants — injected as globals by the engine at startup.
declare var INPUT_ACTION_UP: InputAction;
declare var INPUT_ACTION_DOWN: InputAction;
declare var INPUT_ACTION_LEFT: InputAction;
declare var INPUT_ACTION_RIGHT: InputAction;
declare var INPUT_ACTION_ACCEPT: InputAction;
declare var INPUT_ACTION_CANCEL: InputAction;
declare var INPUT_ACTION_RAGEQUIT: InputAction;
declare var INPUT_ACTION_CONSOLE: InputAction;
declare var INPUT_ACTION_POINTERX: InputAction;
declare var INPUT_ACTION_POINTERY: InputAction;
View File
+1 -4
View File
@@ -7,21 +7,18 @@
/** Scene management — request scene transitions and query the active scene. */
interface SceneNamespace {
/** The type constant of the currently active scene, or 0 if none. */
/** Type constant of the currently active scene, or 0 if none. */
readonly current: number;
/**
* Requests a scene transition. The change takes effect at the start of the
* next safe update tick (current scene is disposed, new scene is initialized).
*
* @param type - A `Scene.*` scene type constant.
*
* @example
* Scene.set(Scene.OVERWORLD);
*/
set(type: number): void;
// Scene type constants (generated from scenelist.h)
readonly INITIAL: number;
readonly TEST: number;
readonly OVERWORLD: number;
-28
View File
@@ -1,28 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/**
* Read-only information about the current display surface.
*/
interface ScreenNamespace {
/** Current render-target width in pixels (read-only). */
readonly width: number;
/** Current render-target height in pixels (read-only). */
readonly height: number;
/**
* Aspect ratio of the current render target: `width / height` (read-only).
*
* @example
* if (Screen.aspect > 1) { /* landscape *\/ }
*/
readonly aspect: number;
}
/** Current display / render-target dimensions. */
declare var Screen: ScreenNamespace;
+2 -13
View File
@@ -5,12 +5,10 @@
* https://opensource.org/licenses/MIT
*/
/**
* Runtime platform detection and system-level information.
*/
/** Runtime platform detection. */
interface SystemNamespace {
/**
* Numeric identifier for the platform the engine is running on (read-only).
* Numeric identifier for the current platform.
* Compare against the `System.PLATFORM_*` constants.
*
* @example
@@ -18,19 +16,10 @@ interface SystemNamespace {
*/
readonly platform: number;
/** Linux desktop. */
readonly PLATFORM_LINUX: number;
/** Knulli handheld (Linux-based). */
readonly PLATFORM_KNULLI: number;
/** Sony PlayStation Portable. */
readonly PLATFORM_PSP: number;
/** Nintendo GameCube. */
readonly PLATFORM_GAMECUBE: number;
/** Nintendo Wii. */
readonly PLATFORM_WII: number;
}