diff --git a/lib/World.luau b/lib/World.luau index 4182cb0..197b34f 100644 --- a/lib/World.luau +++ b/lib/World.luau @@ -679,7 +679,7 @@ function QueryResult.new(compatibleArchetypes: { Archetype }, queryLength: numbe local entityId: number --[=[ @within QueryResult - + @method next Returns the next set of values from the query result. Once all results have been returned, the QueryResult is exhausted and is no longer useful. @@ -777,11 +777,11 @@ function QueryResult.new(compatibleArchetypes: { Archetype }, queryLength: numbe --[=[ @within QueryResult + @method without Returns an iterator that will skip any entities that also have the given components. The filtering is done at the archetype level, and so it is faster than manually skipping entities. - @param self QueryResult @param ... Component -- The component types to filter against. @return () -> (id, ...ComponentInstance) -- Iterator of entity ID followed by the requested component values @@ -844,6 +844,7 @@ function QueryResult.new(compatibleArchetypes: { Archetype }, queryLength: numbe --[=[ @within QueryResult + @method snapshot Creates a "snapshot" of this query, draining this QueryResult and returning a list containing all of its results. @@ -884,8 +885,23 @@ function QueryResult.new(compatibleArchetypes: { Archetype }, queryLength: numbe return entities end + --[=[ + @class View + + Provides random access to the results of a query. + + Calling the View is equivalent to iterating a query. + + ```lua + for id, player, health, poison in world:query(Player, Health, Poison):view() do + -- Do something + end + ``` + ]=] + --[=[ @within QueryResult + @method view Creates a View of the query and does all of the iterator tasks at once at an amortized cost. This is used for many repeated random access to an entity. If you only need to iterate, just use a query. @@ -899,7 +915,7 @@ function QueryResult.new(compatibleArchetypes: { Archetype }, queryLength: numbe for _ in world:query(Damage):view() do end -- You can still iterate views if you want! ``` - @return View See [View](/api/View) docs. + @return View ]=] local function view() local entities = {} @@ -914,10 +930,10 @@ function QueryResult.new(compatibleArchetypes: { Archetype }, queryLength: numbe --[=[ @within View + @method get Retrieve the query results to corresponding `entity` - @param _ View - @param entityId number - the entity ID + @param entityId number -- the entity ID @return ...ComponentInstance ]=] local function get(_, entityId: EntityId) @@ -931,10 +947,10 @@ function QueryResult.new(compatibleArchetypes: { Archetype }, queryLength: numbe --[=[ @within View + @method contains Equivalent to `world:contains()` - @param _ View - @param entityId number - the entity ID + @param entityId number -- the entity ID @return boolean ]=] local function contains(_, entityId: EntityId) @@ -972,20 +988,6 @@ function QueryResult.new(compatibleArchetypes: { Archetype }, queryLength: numbe }) end ---[=[ - @class View - - Provides random access to the results of a query. - - Calling the View is equivalent to iterating a query. - - ```lua - for id, player, health, poison in world:query(Player, Health, Poison):view() do - -- Do something - end - ``` -]=] - --[=[ Performs a query against the entities in this World. Returns a [QueryResult](/api/QueryResult), which iterates over the results of the query. @@ -1263,7 +1265,7 @@ end @param id number -- The entity ID @param ... Component -- The components to remove ]=] -function World.remove(self: World, id, ...: Component) +function World:remove(id, ...: Component) local entityRecord = self.allEntities[id] if entityRecord == nil then error(ERROR_NO_ENTITY, 2)