This commit is contained in:
Ukendio 2024-07-07 04:48:12 +02:00
parent 2aecdc6fe1
commit 63e14504f4
2 changed files with 25 additions and 6 deletions

View file

@ -674,7 +674,7 @@ export type Query = typeof(EmptyQuery)
type CompatibleArchetype = { archetype: Archetype, indices: { number } }
local function replaceColumns(row, columns, ...)
local function replaceMult(row, columns, ...)
for i, column in columns do
column[row] = select(i, ...)
end
@ -800,10 +800,9 @@ local function preparedQuery(compatibleArchetypes: { Archetype },
return queryNext
end
local function replace(fn)
for _, compatibleArchetype in compatibleArchetypes do
local archetype = compatibleArchetype.archetype
local tr = compatibleArchetype.indices
local function replace(_, fn)
for i, archetype in compatibleArchetypes do
local tr = indices[i]
local columns = archetype.columns
for row in archetype.entities do
@ -835,7 +834,7 @@ local function preparedQuery(compatibleArchetypes: { Archetype },
for i = 1, queryLength do
queryOutput[i] = columns[tr[i]][row]
end
replaceColumns(row, columns, fn(unpack(queryOutput)))
replaceMult(row, columns, fn(unpack(queryOutput)))
end
end
end

View file

@ -451,6 +451,26 @@ TEST("world", function()
CHECK(count == 2)
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)
FINISH()