Add some script modules

This commit is contained in:
2026-06-02 12:55:32 -05:00
parent 0f8b629e20
commit 82c300b077
12 changed files with 1189 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/**
* Interactable component. Fires a callback when the player activates it.
*
* Assign a JS function to `onInteract` to handle the event from script.
* Call `trigger()` to fire the callback imperatively from C or JS.
*/
interface Interactable extends Component {
/** Called when the player interacts with this entity. Set to null to clear. */
onInteract: (() => void) | null;
/** Fires the registered callback immediately (no-op if none is set). */
trigger(): void;
toString(): string;
}
interface InteractableConstructor {
new(): never;
}
declare var Interactable: InteractableConstructor;
+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
*/
/** Overworld character component (player or NPC). */
interface Overworld extends Component {
/**
* Entity type — `Overworld.PLAYER` or `Overworld.NPC`.
*/
type: number;
/**
* Facing direction — one of the `Overworld.FACING_*` constants.
*/
facing: number;
/** Component ID of the linked Renderable, or INVALID if none. */
readonly renderComponentId: number;
/** Component ID of the linked Physics body, or INVALID if none. */
readonly physicsComponentId: number;
toString(): string;
}
interface OverworldConstructor {
readonly PLAYER: number;
readonly NPC: number;
readonly FACING_DOWN: number;
readonly FACING_UP: number;
readonly FACING_LEFT: number;
readonly FACING_RIGHT: number;
readonly FACING_SOUTH: number;
readonly FACING_NORTH: number;
readonly FACING_WEST: number;
readonly FACING_EAST: number;
new(): never;
}
declare var Overworld: OverworldConstructor;
+35
View File
@@ -0,0 +1,35 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/**
* Overworld follow-camera component.
* Smoothly tracks a target entity's Position each frame.
*/
interface OverworldCamera extends Component {
/** Entity ID to follow. */
targetEntity: number;
/** Position component ID on the target entity. */
targetPositionComponent: number;
/** World-space offset added to the target's position before placing the camera. */
targetOffset: Vec3;
/** Eye-space offset applied on top of targetOffset. */
eyeOffset: Vec3;
/** Orthographic scale factor (larger = wider view). */
scale: number;
/**
* Convenience setter — equivalent to assigning `targetEntity` and
* `targetPositionComponent` individually.
*/
setTarget(targetEntityId: number, targetPositionComponentId: number): void;
toString(): string;
}
interface OverworldCameraConstructor {
new(): never;
}
declare var OverworldCamera: OverworldCameraConstructor;
+38
View File
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/**
* Overworld AABB trigger. Fires callbacks as the player enters, stays inside,
* exits, or remains outside the defined bounding box each frame.
*/
interface OverworldTrigger extends Component {
/** Minimum corner of the trigger AABB. */
min: Vec3;
/** Maximum corner of the trigger AABB. */
max: Vec3;
/** `true` while the player is inside the trigger bounds. */
readonly playerInside: boolean;
/** Fired once when the player first enters the bounds. */
onEnter: (() => void) | null;
/** Fired once when the player leaves the bounds. */
onExit: (() => void) | null;
/** Fired every frame while the player remains inside the bounds. */
onStay: (() => void) | null;
/** Fired every frame while the player remains outside the bounds. */
onOutside: (() => void) | null;
/** Convenience setter for both corners at once. */
setBounds(min: Vec3, max: Vec3): void;
toString(): string;
}
interface OverworldTriggerConstructor {
new(): never;
}
declare var OverworldTrigger: OverworldTriggerConstructor;
+21
View File
@@ -0,0 +1,21 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/** Player movement component. Controls walk and run speeds. */
interface Player extends Component {
/** Walk speed in world units per second. */
speed: number;
/** Run speed in world units per second. */
runSpeed: number;
toString(): string;
}
interface PlayerConstructor {
new(): never;
}
declare var Player: PlayerConstructor;
+5
View File
@@ -36,7 +36,12 @@
// entity / components
/// <reference path="./entity/component.d.ts" />
/// <reference path="./entity/component/camera.d.ts" />
/// <reference path="./entity/component/interactable.d.ts" />
/// <reference path="./entity/component/overworld.d.ts" />
/// <reference path="./entity/component/overworldcamera.d.ts" />
/// <reference path="./entity/component/overworldtrigger.d.ts" />
/// <reference path="./entity/component/physics.d.ts" />
/// <reference path="./entity/component/player.d.ts" />
/// <reference path="./entity/component/position.d.ts" />
/// <reference path="./entity/component/renderable.d.ts" />
/// <reference path="./entity/component/trigger.d.ts" />