mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-26 01:50:01 +00:00
Add test
This commit is contained in:
parent
2aecdc6fe1
commit
63e14504f4
2 changed files with 25 additions and 6 deletions
|
@ -674,7 +674,7 @@ export type Query = typeof(EmptyQuery)
|
||||||
|
|
||||||
type CompatibleArchetype = { archetype: Archetype, indices: { number } }
|
type CompatibleArchetype = { archetype: Archetype, indices: { number } }
|
||||||
|
|
||||||
local function replaceColumns(row, columns, ...)
|
local function replaceMult(row, columns, ...)
|
||||||
for i, column in columns do
|
for i, column in columns do
|
||||||
column[row] = select(i, ...)
|
column[row] = select(i, ...)
|
||||||
end
|
end
|
||||||
|
@ -800,10 +800,9 @@ local function preparedQuery(compatibleArchetypes: { Archetype },
|
||||||
return queryNext
|
return queryNext
|
||||||
end
|
end
|
||||||
|
|
||||||
local function replace(fn)
|
local function replace(_, fn)
|
||||||
for _, compatibleArchetype in compatibleArchetypes do
|
for i, archetype in compatibleArchetypes do
|
||||||
local archetype = compatibleArchetype.archetype
|
local tr = indices[i]
|
||||||
local tr = compatibleArchetype.indices
|
|
||||||
local columns = archetype.columns
|
local columns = archetype.columns
|
||||||
|
|
||||||
for row in archetype.entities do
|
for row in archetype.entities do
|
||||||
|
@ -835,7 +834,7 @@ local function preparedQuery(compatibleArchetypes: { Archetype },
|
||||||
for i = 1, queryLength do
|
for i = 1, queryLength do
|
||||||
queryOutput[i] = columns[tr[i]][row]
|
queryOutput[i] = columns[tr[i]][row]
|
||||||
end
|
end
|
||||||
replaceColumns(row, columns, fn(unpack(queryOutput)))
|
replaceMult(row, columns, fn(unpack(queryOutput)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -451,6 +451,26 @@ TEST("world", function()
|
||||||
|
|
||||||
CHECK(count == 2)
|
CHECK(count == 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do CASE "should replace component data"
|
||||||
|
local world = jecs.World.new()
|
||||||
|
local A = world:component()
|
||||||
|
local B = world:component()
|
||||||
|
local C = world:component()
|
||||||
|
|
||||||
|
local e = world:entity()
|
||||||
|
world:set(e, A, 1)
|
||||||
|
world:set(e, B, true)
|
||||||
|
world:set(e, C, "hello ")
|
||||||
|
|
||||||
|
world:query(A, B, C):replace(function(a, b, c)
|
||||||
|
return a * 2, not b, c.."world"
|
||||||
|
end)
|
||||||
|
|
||||||
|
CHECK(world:get(e, A) == 2)
|
||||||
|
CHECK(world:get(e, B) == false)
|
||||||
|
CHECK(world:get(e, C) == "hello world")
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
FINISH()
|
FINISH()
|
||||||
|
|
Loading…
Reference in a new issue