This commit is contained in:
Ukendio 2024-08-30 01:19:03 +02:00
commit 012c4accf1
2 changed files with 13 additions and 4 deletions

View file

@ -12,6 +12,12 @@ The format is based on [Keep a Changelog][kac], and this project adheres to
- `[luau]`: - `[luau]`:
- Exported Query - Exported Query
- Improved types for the hooks `OnAdd`, `OnSet`, `OnRemove` - 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<T = nil> = Entity<T> | 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 ## [0.2.2] - 2024-07-07

View file

@ -921,9 +921,8 @@ function world_delete(world: World, entity: i53)
entityIndex.sparse[entity] = nil entityIndex.sparse[entity] = nil
end end
local function world_contains(world: World, entity) local function world_contains(world: World, entity): boolean
return world.entityIndex.sparse[entity] ~= nil
return world.entityIndex.sparse[entity]
end end
type CompatibleArchetype = { archetype: Archetype, indices: { number } } type CompatibleArchetype = { archetype: Archetype, indices: { number } }
@ -1494,6 +1493,7 @@ type Query<T...> = typeof(setmetatable({}, {
})) & { })) & {
iter: Iter<T...>, iter: Iter<T...>,
next: Item<T...>, next: Item<T...>,
drain: (self: Query<T...>) -> Query<T...>,
with: (self: Query<T...>, ...i53) -> Query<T...>, with: (self: Query<T...>, ...i53) -> Query<T...>,
without: (self: Query<T...>, ...i53) -> Query<T...>, without: (self: Query<T...>, ...i53) -> Query<T...>,
replace: (self: Query<T...>, <U...>(T...) -> (U...)) -> (), replace: (self: Query<T...>, <U...>(T...) -> (U...)) -> (),
@ -1537,10 +1537,13 @@ export type World = {
& (<A, B, C>(self: World, id: Entity, Id<A>, Id<B>, Id<C>) -> (A?, B?, C?)) & (<A, B, C>(self: World, id: Entity, Id<A>, Id<B>, Id<C>) -> (A?, B?, C?))
& <A, B, C, D>(self: World, id: Entity, Id<A>, Id<B>, Id<C>, Id<D>) -> (A?, B?, C?, D?), & <A, B, C, D>(self: World, id: Entity, Id<A>, Id<B>, Id<C>, Id<D>) -> (A?, B?, C?, D?),
has: (self: World, ...Id) -> boolean, has: (self: World, entity: Entity, ...Id) -> boolean,
parent: (self: World, entity: Entity) -> Entity, 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 --- Searches the world for entities that match a given query
query: (<A>(self: World, Id<A>) -> Query<A>) query: (<A>(self: World, Id<A>) -> Query<A>)
& (<A, B>(self: World, Id<A>, Id<B>) -> Query<A, B>) & (<A, B>(self: World, Id<A>, Id<B>) -> Query<A, B>)