Improve Lua ECS #30
|
@ -104,9 +104,10 @@ function on_update()
|
||||||
end
|
end
|
||||||
|
|
||||||
local pos_view = View.new(Transform)
|
local pos_view = View.new(Transform)
|
||||||
local vone = world:view_one(cube_entity, pos_view)
|
local vone = world:view_one(cube_entity --[[@as Entity]], pos_view)
|
||||||
local r = vone()
|
local r = vone() -- short hand for 'vone:get()'
|
||||||
if r ~= nil then
|
if r then
|
||||||
|
---@type Transform
|
||||||
local pos = r[1]
|
local pos = r[1]
|
||||||
print("Found cube entity at '" .. tostring(pos) .. "'")
|
print("Found cube entity at '" .. tostring(pos) .. "'")
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,14 +38,15 @@ function Not(val)
|
||||||
return NotQuery.new(val)
|
return NotQuery.new(val)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Create a `OrQuery` filter that will allow results if any of the queries return something.
|
---Create a `AnyQuery` filter that will allow results if any of the queries return something.
|
||||||
|
---
|
||||||
---The queries are evaluated in the order they were provided.
|
---The queries are evaluated in the order they were provided.
|
||||||
---
|
---
|
||||||
---@see OrQuery
|
---@see AnyQuery
|
||||||
---@param ... Query
|
---@param ... Query
|
||||||
---@return OrQuery
|
---@return AnyQuery
|
||||||
function Or(...)
|
function Any(...)
|
||||||
return OrQuery.new(...)
|
return AnyQuery.new(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Create a `TickOfQuery` for retrieving the tick of the resource or component on the entity.
|
---Create a `TickOfQuery` for retrieving the tick of the resource or component on the entity.
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---An ECS filter that will return if any of the provided queries return.
|
||||||
|
---
|
||||||
|
---The queries are evaluated in the order they were provided. When a query or filter returns a value,
|
||||||
|
---that value will be returned.
|
||||||
|
---
|
||||||
|
---Use the utility function `Any(...)` to create a new query since its faster to
|
||||||
|
---write than this.
|
||||||
|
---
|
||||||
|
---@see Any
|
||||||
|
---@class AnyQuery: userdata
|
||||||
|
AnyQuery = {}
|
||||||
|
|
||||||
|
---Create a new AnyQuery.
|
||||||
|
---
|
||||||
|
---Use the utility function `Any(...)` to create a new query since its faster to
|
||||||
|
---write than this.
|
||||||
|
---
|
||||||
|
---@see Any
|
||||||
|
---@param ... Query The query to invert.
|
||||||
|
function AnyQuery:new(...) end
|
||||||
|
|
||||||
|
---An internal function used by the engine to retrieve the query result.
|
||||||
|
function AnyQuery:__lyra_internal_ecs_query_result(world, entity) end
|
|
@ -0,0 +1,22 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---An ECS filter that allows the query if the entity has the Component.
|
||||||
|
---
|
||||||
|
---Use the utility function `Has(...)` to create a new query since its faster to
|
||||||
|
---write than this.
|
||||||
|
---
|
||||||
|
---@see Has
|
||||||
|
---@class HasQuery: userdata
|
||||||
|
HasQuery = {}
|
||||||
|
|
||||||
|
---Create a new HasQuery.
|
||||||
|
---
|
||||||
|
---Use the utility function `Has(...)` to create a new query since its faster to
|
||||||
|
---write than this.
|
||||||
|
---
|
||||||
|
---@see Has
|
||||||
|
---@param val table|userdata The component to look for on the entity.
|
||||||
|
function HasQuery:new(val) end
|
||||||
|
|
||||||
|
---An internal function used by the engine to retrieve the query result.
|
||||||
|
function HasQuery:__lyra_internal_ecs_query_result(world, entity) end
|
|
@ -1,3 +1,9 @@
|
||||||
require "view"
|
require "view"
|
||||||
|
require "view_one"
|
||||||
require "changed"
|
require "changed"
|
||||||
require "res"
|
require "res"
|
||||||
|
require "has"
|
||||||
|
require "any"
|
||||||
|
require "not"
|
||||||
|
require "optional"
|
||||||
|
require "tick_of"
|
|
@ -0,0 +1,22 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---An ECS filter that inverts the provided filter/query result.
|
||||||
|
---
|
||||||
|
---Use the utility function `Not(...)` to create a new query since its faster to
|
||||||
|
---write than this.
|
||||||
|
---
|
||||||
|
---@see Not
|
||||||
|
---@class NotQuery: userdata
|
||||||
|
NotQuery = {}
|
||||||
|
|
||||||
|
---Create a new NotQuery.
|
||||||
|
---
|
||||||
|
---Use the utility function `Not(...)` to create a new query since its faster to
|
||||||
|
---write than this.
|
||||||
|
---
|
||||||
|
---@see Not
|
||||||
|
---@param val Query The query to invert.
|
||||||
|
function NotQuery:new(val) end
|
||||||
|
|
||||||
|
---An internal function used by the engine to retrieve the query result.
|
||||||
|
function NotQuery:__lyra_internal_ecs_query_result(world, entity) end
|
|
@ -0,0 +1,26 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---An ECS query that ignores filters and queries that dont return anything.
|
||||||
|
---
|
||||||
|
---If the provided query returns nothing, this query will provide a `nil` value.
|
||||||
|
---The results of filters are essentially ignored, since it doesn't matter the result, this query
|
||||||
|
---will return. If the provided query has a result, this query will also return it.
|
||||||
|
---
|
||||||
|
---Use the utility function `Optional(...)` to create a new query since its faster to
|
||||||
|
---write than this.
|
||||||
|
---
|
||||||
|
---@see Optional
|
||||||
|
---@class OptionalQuery: userdata
|
||||||
|
OptionalQuery = {}
|
||||||
|
|
||||||
|
---Create a new OptionalQuery.
|
||||||
|
---
|
||||||
|
---Use the utility function `Optional(...)` to create a new query since its faster to
|
||||||
|
---write than this.
|
||||||
|
---
|
||||||
|
---@see Optional
|
||||||
|
---@param val Query The query to invert.
|
||||||
|
function OptionalQuery:new(val) end
|
||||||
|
|
||||||
|
---An internal function used by the engine to retrieve the query result.
|
||||||
|
function OptionalQuery:__lyra_internal_ecs_query_result(world, entity) end
|
|
@ -0,0 +1,22 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---An ECS query that returns the tick of the resource or component provided.
|
||||||
|
---
|
||||||
|
---Use the utility function `TickOf(...)` to create a new query since its faster to
|
||||||
|
---write than this.
|
||||||
|
---
|
||||||
|
---@see TickOf
|
||||||
|
---@class TickOfQuery: userdata
|
||||||
|
TickOfQuery = {}
|
||||||
|
|
||||||
|
---Create a new TickOfQuery.
|
||||||
|
---
|
||||||
|
---Use the utility function `TickOf(...)` to create a new query since its faster to
|
||||||
|
---write than this.
|
||||||
|
---
|
||||||
|
---@see TickOf
|
||||||
|
---@param val table|userdata The component or resource to retrieve the tick of.
|
||||||
|
function TickOfQuery:new(val) end
|
||||||
|
|
||||||
|
---An internal function used by the engine to retrieve the query result.
|
||||||
|
function TickOfQuery:__lyra_internal_ecs_query_result(world, entity) end
|
|
@ -0,0 +1,19 @@
|
||||||
|
---@meta
|
||||||
|
|
||||||
|
---Results of a View over a single entity.
|
||||||
|
---@class ViewOneResult: userdata
|
||||||
|
ViewOneResult = {}
|
||||||
|
|
||||||
|
---Returns the results of the view over a single entity.
|
||||||
|
---
|
||||||
|
---@see ViewOneResult.__call
|
||||||
|
---@generic T...
|
||||||
|
---@return T...
|
||||||
|
function ViewOneResult:get() end
|
||||||
|
|
||||||
|
---Returns the results of the view over a single entity.
|
||||||
|
---
|
||||||
|
---@see ViewOneResult.get
|
||||||
|
---@generic T...
|
||||||
|
---@return T...
|
||||||
|
function ViewOneResult:__call() end
|
|
@ -95,6 +95,15 @@ function World:read_event(event) end
|
||||||
---@return ViewResult
|
---@return ViewResult
|
||||||
function World:view_query(view) end
|
function World:view_query(view) end
|
||||||
|
|
||||||
|
---View a single entity in the world.
|
||||||
|
---
|
||||||
|
---The view can contain queries and filters, but they will only be evaluated for a single entity.
|
||||||
|
---
|
||||||
|
---@param en Entity
|
||||||
|
---@param view View
|
||||||
|
---@return ViewOneResult
|
||||||
|
function World:view_one(en, view) end
|
||||||
|
|
||||||
--World global
|
--World global
|
||||||
---@type World
|
---@type World
|
||||||
world = nil
|
world = nil
|
|
@ -45,11 +45,12 @@ impl ScriptApiProvider for LyraEcsApiProvider {
|
||||||
globals.set("ActionHandler", ctx.create_proxy::<LuaActionHandler>()?)?;
|
globals.set("ActionHandler", ctx.create_proxy::<LuaActionHandler>()?)?;
|
||||||
globals.set("Window", ctx.create_proxy::<LuaWindow>()?)?;
|
globals.set("Window", ctx.create_proxy::<LuaWindow>()?)?;
|
||||||
globals.set("View", ctx.create_proxy::<View>()?)?;
|
globals.set("View", ctx.create_proxy::<View>()?)?;
|
||||||
|
|
||||||
globals.set("ResQuery", ctx.create_proxy::<LuaResQuery>()?)?;
|
globals.set("ResQuery", ctx.create_proxy::<LuaResQuery>()?)?;
|
||||||
globals.set("ChangedQuery", ctx.create_proxy::<LuaChangedQuery>()?)?;
|
globals.set("ChangedQuery", ctx.create_proxy::<LuaChangedQuery>()?)?;
|
||||||
globals.set("HasQuery", ctx.create_proxy::<LuaHasQuery>()?)?;
|
globals.set("HasQuery", ctx.create_proxy::<LuaHasQuery>()?)?;
|
||||||
globals.set("NotQuery", ctx.create_proxy::<LuaNotQuery>()?)?;
|
globals.set("NotQuery", ctx.create_proxy::<LuaNotQuery>()?)?;
|
||||||
globals.set("OrQuery", ctx.create_proxy::<LuaOrQuery>()?)?;
|
globals.set("AnyQuery", ctx.create_proxy::<LuaOrQuery>()?)?;
|
||||||
globals.set("TickOfQuery", ctx.create_proxy::<LuaTickOfQuery>()?)?;
|
globals.set("TickOfQuery", ctx.create_proxy::<LuaTickOfQuery>()?)?;
|
||||||
globals.set("OptionalQuery", ctx.create_proxy::<LuaOptionalQuery>()?)?;
|
globals.set("OptionalQuery", ctx.create_proxy::<LuaOptionalQuery>()?)?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue