49 lines
1.0 KiB
Lua
49 lines
1.0 KiB
Lua
local ecs = require "ecs"
|
|
local LuaComponent = require "ecs.LuaComponent"
|
|
|
|
function init()
|
|
print("Registering components")
|
|
|
|
-- Swapped compared to test.lua
|
|
TestThing = LuaComponent.create("TestThing", {
|
|
test = "string"
|
|
})
|
|
LuaData = LuaComponent.create("LuaData", {
|
|
speed = "number",
|
|
something = "string",
|
|
alive = "boolean"
|
|
})
|
|
end
|
|
|
|
function run()
|
|
print("Running!")
|
|
|
|
manager = get_manager()
|
|
|
|
manager:view(TestThing):for_each(function(ent)
|
|
data = ent:get_component(TestThing)
|
|
print("test: " .. data.test)
|
|
end)
|
|
|
|
|
|
manager:view(LuaData):for_each(function(ent)
|
|
-- @todo It would be nice if this could somehow be passed in as function arg
|
|
data = ent:get_component(LuaData)
|
|
print("speed: " .. data.speed)
|
|
print("something: " .. data.something)
|
|
-- @todo You cannot concatenate bool to string
|
|
print("alive: ")
|
|
print(data.alive)
|
|
end)
|
|
|
|
-- @todo Allow this
|
|
-- for i, v in pairs(manager:view("TestThing")) do
|
|
-- print(i, v)
|
|
-- end
|
|
|
|
print("Exists: ")
|
|
print(manager:has_entity("70bca3cf-33dd-40dc-8b0f-2e19aa0b4a17"))
|
|
|
|
print("Done running!")
|
|
end
|