Skip to content

Commit

Permalink
feat: add tiny-ecs type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
thinknathan committed Sep 21, 2024
1 parent a3954ff commit 7f92d7b
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/defold-tiny-ecs/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "tinyecs",
"url": "https://github.com/ivanquirino/defold-tiny-ecs"
}
2 changes: 2 additions & 0 deletions packages/defold-tiny-ecs/tinyecs-1.3.3.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <library version="1.3.3" src="https://github.com/ivanquirino/defold-tiny-ecs/archive/refs/tags/1.3-3.zip" />
/// <reference path="tinyecs.tiny.d.ts" />
82 changes: 82 additions & 0 deletions packages/defold-tiny-ecs/tinyecs.tiny.d.ts
Original file line number Diff line number Diff line change
@@ -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<Entity, number>;
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[];
}
}

0 comments on commit 7f92d7b

Please sign in to comment.