2024-04-23 15:10:49 +00:00
|
|
|
local ecs = require(script.Parent).World.new()
|
|
|
|
|
|
|
|
local A, B, C, D = ecs:entity(), ecs:entity(), ecs:entity(), ecs:entity()
|
|
|
|
local E, F, G, H = ecs:entity(), ecs:entity(), ecs:entity(), ecs:entity()
|
|
|
|
print("A", A)
|
|
|
|
print("B", B)
|
|
|
|
print("C", C)
|
|
|
|
print("D", D)
|
|
|
|
print("E", E)
|
|
|
|
print("F", F)
|
|
|
|
print("G", G)
|
|
|
|
print("H", H)
|
|
|
|
|
|
|
|
for i = 1, 256 do
|
|
|
|
local entity = ecs:entity()
|
2024-04-24 15:32:07 +00:00
|
|
|
ecs:set(entity, A, true)
|
|
|
|
ecs:set(entity, B, true)
|
|
|
|
ecs:set(entity, C, true)
|
|
|
|
ecs:set(entity, D, true)
|
2024-04-23 15:10:49 +00:00
|
|
|
|
|
|
|
--[[
|
2024-04-24 15:32:07 +00:00
|
|
|
ecs:set(entity, E, true)
|
|
|
|
ecs:set(entity, F, true)
|
|
|
|
ecs:set(entity, G, true)
|
|
|
|
ecs:set(entity, H, true)
|
2024-04-23 15:10:49 +00:00
|
|
|
print("end")
|
|
|
|
]]
|
|
|
|
end
|
|
|
|
|
|
|
|
return function()
|
|
|
|
describe("World", function()
|
|
|
|
it("should add component", function()
|
|
|
|
local id = ecs:entity()
|
2024-04-24 15:32:07 +00:00
|
|
|
ecs:set(id, A, true)
|
|
|
|
ecs:set(id, B, 1)
|
2024-04-23 15:10:49 +00:00
|
|
|
|
|
|
|
local id1 = ecs:entity()
|
2024-04-24 15:32:07 +00:00
|
|
|
ecs:set(id1, A, "hello")
|
2024-04-23 15:10:49 +00:00
|
|
|
expect(ecs:get(id, A)).to.equal(true)
|
|
|
|
expect(ecs:get(id, B)).to.equal(1)
|
|
|
|
expect(ecs:get(id1, A)).to.equal("hello")
|
|
|
|
end)
|
|
|
|
it("should remove component", function()
|
|
|
|
local id = ecs:entity()
|
2024-04-24 15:32:07 +00:00
|
|
|
ecs:set(id, A, true)
|
|
|
|
ecs:set(id, B, 1000)
|
2024-04-23 15:10:49 +00:00
|
|
|
ecs:remove(id, A, false)
|
|
|
|
|
|
|
|
expect(ecs:get(id, A)).to.equal(nil)
|
|
|
|
end)
|
|
|
|
it("should override component data", function()
|
|
|
|
|
|
|
|
local id = ecs:entity()
|
2024-04-24 15:32:07 +00:00
|
|
|
ecs:set(id, A, true)
|
2024-04-23 15:10:49 +00:00
|
|
|
expect(ecs:get(id, A)).to.equal(true)
|
|
|
|
|
2024-04-24 15:32:07 +00:00
|
|
|
ecs:set(id, A, false)
|
2024-04-23 15:10:49 +00:00
|
|
|
expect(ecs:get(id, A)).to.equal(false)
|
|
|
|
|
|
|
|
end)
|
|
|
|
it("query", function()
|
|
|
|
local added = 0
|
|
|
|
for e, a, b, c, d in ecs:query(A, B, C, D) do
|
|
|
|
added += 1
|
|
|
|
end
|
|
|
|
expect(added).to.equal(256)
|
|
|
|
end)
|
|
|
|
|
|
|
|
end)
|
|
|
|
end
|