From 7f92d7b6885dc3f0e5fdf067872420784a9b6cd2 Mon Sep 17 00:00:00 2001 From: thinknathan Date: Sat, 21 Sep 2024 09:39:32 -0700 Subject: [PATCH] feat: add tiny-ecs type definitions --- packages/defold-tiny-ecs/library.json | 4 + packages/defold-tiny-ecs/tinyecs-1.3.3.d.ts | 2 + packages/defold-tiny-ecs/tinyecs.tiny.d.ts | 82 +++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 packages/defold-tiny-ecs/library.json create mode 100644 packages/defold-tiny-ecs/tinyecs-1.3.3.d.ts create mode 100644 packages/defold-tiny-ecs/tinyecs.tiny.d.ts diff --git a/packages/defold-tiny-ecs/library.json b/packages/defold-tiny-ecs/library.json new file mode 100644 index 0000000..3628952 --- /dev/null +++ b/packages/defold-tiny-ecs/library.json @@ -0,0 +1,4 @@ +{ + "name": "tinyecs", + "url": "https://github.com/ivanquirino/defold-tiny-ecs" +} diff --git a/packages/defold-tiny-ecs/tinyecs-1.3.3.d.ts b/packages/defold-tiny-ecs/tinyecs-1.3.3.d.ts new file mode 100644 index 0000000..4470608 --- /dev/null +++ b/packages/defold-tiny-ecs/tinyecs-1.3.3.d.ts @@ -0,0 +1,2 @@ +/// +/// diff --git a/packages/defold-tiny-ecs/tinyecs.tiny.d.ts b/packages/defold-tiny-ecs/tinyecs.tiny.d.ts new file mode 100644 index 0000000..8906698 --- /dev/null +++ b/packages/defold-tiny-ecs/tinyecs.tiny.d.ts @@ -0,0 +1,82 @@ +/** @noSelfInFile **/ + +/** + * @see {@link https://github.com/ivanquirino/defold-tiny-ecs|Github Source} + * @noResolution + */ +declare module 'tinyecs.tiny' { + type Entity = any; + + export function requireAll(...args: any[]): (entity: Entity) => boolean; + export function requireAny(...args: any[]): (entity: Entity) => boolean; + export function rejectAll(...args: any[]): (entity: Entity) => boolean; + export function rejectAny(...args: any[]): (entity: Entity) => boolean; + export function filter(pattern: string): (entity: Entity) => boolean; + export function system(table: System): System; + export function processingSystem(table: System): System; + export function sortedSystem(table: System): System; + export function sortedProcessingSystem(table: System): System; + export function world(...args: any[]): World; + export function addEntity(world: World, entity: Entity): Entity; + export function addSystem(world: World, system: System): System; + export function add(world: World, ...args: any[]): any; + export function removeEntity(world: World, entity: Entity): Entity; + export function removeSystem(world: World, system: System): System; + export function remove(world: World, ...args: any[]): any; + export function refresh(world: World): void; + export function update(world: World, dt: number, filter?: () => void): void; + export function clearEntities(world: World): void; + export function clearSystems(world: World): void; + export function getEntityCount(world: World): number; + export function getSystemCount(world: World): number; + export function setSystemIndex(world: World): void; + + interface System { + id: string | number | undefined; + active: boolean; + filter?: (this: System, entity: Entity) => void; + world: World; + entities: Entity[]; + /** Entity index in entities table */ + indices: LuaTable; + nocache: boolean; + index: number; + modified: boolean; + interval?: number; + onAdd?: (this: System, entity: Entity) => void; + onRemove?: (this: System, entity: Entity) => void; + onModify?: (dt: number) => void; + onAddToWorld?: (this: System, world: World) => void; + onRemoveFromWorld?: (this: System, world: World) => void; + preWrap?: (dt: number) => void; + postWrap?: () => void; + update?: (dt: number) => void; + preProcess?: (dt: number) => void; + process?: (entity: Entity, dt: number) => void; + postProcess?: (dt: number) => void; + compare?: (e1: Entity, e2: Entity) => void; + } + + interface World { + entities: Entity[]; + systems: System[]; + add: (this: World, ...args: any[]) => any; + addEntity: (this: World, entity: Entity) => Entity; + addSystem: (this: World, system: System) => System; + remove: (this: World) => void; + removeEntity: (this: World, entity: Entity) => Entity; + removeSystem: (this: World, system: System) => System; + refresh: (this: World) => void; + update: (this: World, dt: number, filter?: () => void) => void; + clearEntities: (this: World) => void; + clearSystems: (this: World) => void; + getEntityCount: (this: World) => number; + getSystemCount: (this: World) => number; + setSystemIndex: (this: World) => void; + entitiesToChange: Entity[]; + entitiesToRemove: Entity[]; + systemsToChange: System[]; + systemsToAdd: System[]; + systemsToRemove: System[]; + } +}