Fix typedefs

This commit is contained in:
2026-06-06 19:06:52 -05:00
parent 9edb2aa0c1
commit 47a6f396fa
5 changed files with 51 additions and 68 deletions
+24
View File
@@ -0,0 +1,24 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/**
* Returns a Promise that resolves on the next engine frame.
*
* @example
* await frame();
* Console.print('one frame later');
*/
declare function frame(): Promise<void>;
/**
* Returns a Promise that resolves after `ms` milliseconds of engine time.
*
* @example
* await timeout(500);
* Console.print('half a second later');
*/
declare function timeout(ms: number): Promise<void>;
+2 -25
View File
@@ -5,20 +5,12 @@
* https://opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
/** Fields shared by every renderable type. */ /** A Renderable component. Returned by `entity.add(Component.RENDERABLE)`. */
interface Renderable extends Component { interface Renderable extends Component {
/** Current render type — one of the `Renderable.*` type constants. */ /** Current render type — one of the `Renderable.*` type constants. */
type: number; type: number;
/** Render priority. 0 = auto. Higher = drawn later. */ /** Render priority. 0 = auto. Higher = drawn later. */
priority: number; 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 * Unlit material color. Reading returns a fresh `Color` copy; assigning
* a `Color` instance writes through to the C material. * a `Color` instance writes through to the C material.
@@ -28,22 +20,12 @@ interface RenderableMaterial extends Renderable {
* r.color = new Color(255, 128, 0); * r.color = new Color(255, 128, 0);
*/ */
color: Color; color: Color;
}
/**
* Renderable in `SPRITEBATCH` mode.
*
* Set `texture` to activate spritebatch rendering (also switches `type`
* to `Renderable.SPRITEBATCH` automatically).
*/
interface RenderableSpritebatch extends Renderable {
/** /**
* The bound texture. Assigning a `Texture` switches the renderable to * The bound texture. Assigning a `Texture` switches the renderable to
* `SPRITEBATCH` mode and pins the object against GC. Reading returns the * `SPRITEBATCH` mode and pins the object against GC. Reading returns the
* same `Texture` instance that was assigned, or `undefined` if none. * same `Texture` instance that was assigned, or `undefined` if none.
*/ */
texture: Texture | undefined; texture: Texture | undefined;
/** /**
* Sprite list. Reading returns a JS array of 10-element sub-arrays * Sprite list. Reading returns a JS array of 10-element sub-arrays
* `[x1,y1,z1, x2,y2,z2, u1,v1, u2,v2]` — one per sprite. * `[x1,y1,z1, x2,y2,z2, u1,v1, u2,v2]` — one per sprite.
@@ -57,14 +39,9 @@ interface RenderableSpritebatch extends Renderable {
* r.sprites = []; // clear * r.sprites = []; // clear
*/ */
sprites: number[][]; sprites: number[][];
toString(): string;
} }
/**
* Renderable in `CUSTOM` mode.
* Draw logic is provided by a C callback set via `entityRenderableSetDraw`.
*/
interface RenderableCustom extends Renderable {}
interface RenderableConstructor { interface RenderableConstructor {
readonly SHADER_MATERIAL: number; readonly SHADER_MATERIAL: number;
readonly SPRITEBATCH: number; readonly SPRITEBATCH: number;
+1
View File
@@ -33,6 +33,7 @@
// engine systems // engine systems
/// <reference path="./console/console.d.ts" /> /// <reference path="./console/console.d.ts" />
/// <reference path="./engine/engine.d.ts" /> /// <reference path="./engine/engine.d.ts" />
/// <reference path="./engine/globals.d.ts" />
/// <reference path="./input/input.d.ts" /> /// <reference path="./input/input.d.ts" />
/// <reference path="./scene/scene.d.ts" /> /// <reference path="./scene/scene.d.ts" />
/// <reference path="./system/system.d.ts" /> /// <reference path="./system/system.d.ts" />
+7 -29
View File
@@ -6,10 +6,7 @@
*/ */
/** /**
* CommonJS-style module loader. Accepts a single path or an array of paths. * CommonJS-style module loader.
*
* - Single string → returns that module's `exports`.
* - Array of strings → returns an array of `exports` in the same order.
* *
* Modules are cached after their first load. Subsequent calls with the same * Modules are cached after their first load. Subsequent calls with the same
* resolved path return the cached exports without re-executing the file. * resolved path return the cached exports without re-executing the file.
@@ -20,41 +17,22 @@
* *
* @example * @example
* const NPC = require('./entities/NPC'); * const NPC = require('./entities/NPC');
* const [NPC, Item] = require(['./entities/NPC', './entities/Item']);
*/ */
declare function require(path: string): any; declare function require(path: string): any;
declare function require(paths: string[]): any[];
/** /**
* Asynchronous module loader. Accepts a single path or an array of paths. * Asynchronous module loader. Loads the module at `path` in the background
* The asset file(s) are read in the background; once all are loaded and * and returns a Promise that resolves to the module's `exports`.
* evaluated, `callback` is invoked.
* *
* - Single string → `callback(exports)` — first argument is the module's * If the module is already cached it resolves immediately. On load failure
* `exports`, or `null` on load failure. * the Promise is rejected.
* - Array of strings → `callback(exportsArray)` — first argument is an array
* of `exports` values in the same order; failed entries are `null`.
* *
* Cached modules resolve synchronously (callback fires on the same call).
* Path rules are identical to `require`. * Path rules are identical to `require`.
* *
* @example * @example
* requireAsync('./entities/NPC', function(NPC) { * const NPC = await requireAsync('./entities/NPC');
* if(NPC) NPC.init();
* });
*
* requireAsync(['./entities/NPC', './entities/Item'], function(mods) {
* const [NPC, Item] = mods;
* });
*/ */
declare function requireAsync( declare function requireAsync(path: string): Promise<any>;
path: string,
callback: (exports: any) => void
): void;
declare function requireAsync(
paths: string[],
callback: (exports: any[]) => void
): void;
/** /**
* The module object for the currently executing script. * The module object for the currently executing script.
+17 -14
View File
@@ -12,18 +12,14 @@
* @example * @example
* // assets/scenes/game.js * // assets/scenes/game.js
* var scene = {}; * var scene = {};
* var batch = AssetBatch([{ path: 'tex/bg.png', type: Asset.TYPE_TEXTURE }]);
* *
* scene.load = function() { return batch; };
* scene.init = function() { Console.print('scene started'); }; * scene.init = function() { Console.print('scene started'); };
* scene.update = function() { /* per-frame logic *\/ }; * scene.update = function() { /* per-frame logic *\/ };
* scene.dispose = function() { batch.unlock(); }; * scene.dispose = function() { };
* *
* module.exports = scene; * module.exports = scene;
*/ */
interface SceneObject { interface SceneObject {
/** Return an AssetBatch to preload before init is called. Optional. */
load?(): AssetBatch | undefined;
/** Called when this scene becomes active. Optional. */ /** Called when this scene becomes active. Optional. */
init?(): void; init?(): void;
/** Called every frame while this scene is active. Optional. */ /** Called every frame while this scene is active. Optional. */
@@ -34,20 +30,27 @@ interface SceneObject {
/** Scene management. */ /** Scene management. */
interface SceneNamespace { interface SceneNamespace {
/** `true` while a JS script scene is running. */ /** The currently active scene object, or `null` if none. */
readonly active: boolean; current: SceneObject | null;
/** /**
* Loads the JS module at `path`, waits for any `AssetBatch` returned by * Replaces the active scene. Calls `dispose()` on the previous scene (if
* `scene.load()`, then activates the scene (calling `scene.init()`). * any), then calls `init()` on the new one. Pass `null` to clear.
* The previous scene's `dispose()` is called just before `init()`.
*
* Returns immediately — the transition is asynchronous.
* *
* @example * @example
* Scene.set('assets/scenes/game.js'); * const myScene = require('./scenes/game');
* Scene.set(myScene);
*/ */
set(path: string): void; set(newScene: SceneObject | null): void;
/** Called each frame by the engine — drives `current.update()`. */
update(): void;
/** Called each frame by the engine for dynamic/physics updates. */
dynamicUpdate(): void;
/** Disposes the current scene and sets `current` to `null`. */
dispose(): void;
} }
declare var Scene: SceneNamespace; declare var Scene: SceneNamespace;