Skip to content

Commit

Permalink
Fix world docs
Browse files Browse the repository at this point in the history
  • Loading branch information
memorycode committed Oct 23, 2024
1 parent ad1714a commit 570622b
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions lib/World.luau
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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 = {}
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 570622b

Please sign in to comment.