diff --git a/lib/init.lua b/lib/init.lua index 9ef0b10..58f081e 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -845,8 +845,51 @@ function World.__iter(world: World): () -> (number?, unknown?) end end +export type QueryShim = typeof(setmetatable( + {} :: { + --- Excludes the given selection from the query + without: (QueryShim, U...) -> QueryShim + }, + {} :: { + __iter: () -> (number, T...) + } +)) + +export type WorldShim = typeof(setmetatable( + {} :: { + + --- Creates a new entity + entity: (WorldShim) -> T, + --- Creates a new entity located in the first 256 ids. + --- These should be used for static components for fast access. + component: (WorldShim) -> T, + --- Gets the target of an relationship. For example, when a user calls + --- `world:target(id, ChildOf(parent))`, you will obtain the parent entity. + target: (WorldShim, id: unknown, relation: unknown) -> T?, + --- Deletes an entity and all it's related components and relationships. + delete: (WorldShim, id: unknown) -> (), + + --- Adds a component to the entity with no value + add: (WorldShim, id: unknown, component: T) -> (), + --- Assigns a value to a component on the given entity + set: (WorldShim, id: unknown, component: T, data: T) -> (), + --- Removes a component from the given entity + remove: (WorldShim, id: unknown, component: unknown) -> (), + --- Retrieves the value of up to 4 components. These values may be nil. + get: (WorldShim, id: unknown, T...) -> T..., + + --- Searches the world for entities that match a given query + query: (WorldShim, T...) -> Query + + }, + {} :: { + __iter: (world: World) -> () -> (number, {[unknown]: unknown?}) + } + +)) + return table.freeze({ - World = World, + World = World :: {new: () -> WorldShim}, OnAdd = ON_ADD, OnRemove = ON_REMOVE,