diff --git a/CHANGELOG.md b/CHANGELOG.md index 80ae17c..49598e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,12 @@ The format is based on [Keep a Changelog][kac], and this project adheres to - `[luau]`: - Exported Query - Improved types for the hooks `OnAdd`, `OnSet`, `OnRemove` + - Expose `world:contains()` in `World` type and expose `query:drain()` in `Query` type + - Allow functions to accept any ID including pairs in type parameters + - Applies to `world:add()`, `world:set()`, `world:remove()`, `world:get()`, `world:has()` and `world:query()` + - New exported type `Id = Entity | Pair` + - Make `world:contains()` return a `boolean` instead of an entity which may or may not exist + - Fix `world:has()` to explicitly take in an entity (new: `(self: World, entity: Entity, ...id) -> boolean`, old: `(self: World, ...Id) -> boolean`) ## [0.2.2] - 2024-07-07 diff --git a/src/init.luau b/src/init.luau index bbb3393..d2dc583 100644 --- a/src/init.luau +++ b/src/init.luau @@ -921,9 +921,8 @@ function world_delete(world: World, entity: i53) entityIndex.sparse[entity] = nil end -local function world_contains(world: World, entity) - - return world.entityIndex.sparse[entity] +local function world_contains(world: World, entity): boolean + return world.entityIndex.sparse[entity] ~= nil end type CompatibleArchetype = { archetype: Archetype, indices: { number } } @@ -1494,6 +1493,7 @@ type Query = typeof(setmetatable({}, { })) & { iter: Iter, next: Item, + drain: (self: Query) -> Query, with: (self: Query, ...i53) -> Query, without: (self: Query, ...i53) -> Query, replace: (self: Query, (T...) -> (U...)) -> (), @@ -1537,10 +1537,13 @@ export type World = { & ((self: World, id: Entity, Id, Id, Id) -> (A?, B?, C?)) & (self: World, id: Entity, Id, Id, Id, Id) -> (A?, B?, C?, D?), - has: (self: World, ...Id) -> boolean, + has: (self: World, entity: Entity, ...Id) -> boolean, parent: (self: World, entity: Entity) -> Entity, + --- Checks if the world contains the given entity + contains: (self: World, entity: Entity) -> boolean, + --- Searches the world for entities that match a given query query: ((self: World, Id) -> Query) & ((self: World, Id, Id) -> Query)