ecs/test/test.lua

61 lines
1.2 KiB
Lua

local ecs = require "ecs"
local test = require "ecs_test"
manager = get_manager()
ent = manager:create_entity()
ent:add_component("Position", test.Position.new(1.9, 9.7))
ent:add_component("Velocity", test.Velocity.new(0.2, 0.3))
random = {
a = 10,
b = 11,
c = function(s)
print("Hello " .. s .. "!")
end
}
ent:add_component("Random", ecs.LuaWrapper.new(random))
print(ent:has_components("Position", "Velocity"))
pos = ent:get_component("Position")
print("x: " .. pos.x)
print("y: " .. pos.y)
vel = ent:get_component("Velocity")
print("v_x: " .. vel.x)
print("v_y: " .. vel.y)
print("View test")
view = manager:view("Position", "Velocity")
view:for_each(function(ent)
pos = ent:get_component("Position")
vel = ent:get_component("Velocity")
pos.x = pos.x + vel.x
pos.y = pos.y + vel.y
print(ent)
print("x: " .. pos.x)
print("y: " .. pos.y)
print("v_x: " .. vel.x)
print("v_y: " .. vel.y)
end)
-- @todo Implement this
-- for uuid,entity in pairs(view) do
-- print "TEST"
-- end
manager:view("Random"):for_each(function(ent)
wrapped = ent:get_component("Random").object
print(wrapped.a)
wrapped.a = 11
print(wrapped.a)
print(random.a)
random.a = 20
print(wrapped.a)
print(random.a)
random.c("you")
end)