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
+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;