mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2026-09-27 11:07:08 +07:00
registry.batch_apply impl
This commit is contained in:
@@ -415,6 +415,53 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local f1, f2 = evo.registry.entity(), evo.registry.entity()
|
||||
|
||||
local function mul2(v) return v * 2 end
|
||||
local function null(_) end
|
||||
|
||||
local e1 = evo.registry.entity():set(f1, 10)
|
||||
local e2 = evo.registry.entity():set(f1, 15)
|
||||
local e3 = evo.registry.entity():set(f1, 20):set(f2, 40)
|
||||
local e4 = evo.registry.entity():set(f1, 25):set(f2, 45)
|
||||
|
||||
do
|
||||
local q = evo.registry.query(f2)
|
||||
assert(2 == evo.registry.batch_apply(q, f1, mul2))
|
||||
assert(e1:get(f1) == 10 and e2:get(f1) == 15 and e3:get(f1) == 40 and e4:get(f1) == 50)
|
||||
assert(e3:get(f2) == 40 and e4:get(f2) == 45)
|
||||
end
|
||||
|
||||
do
|
||||
local q = evo.registry.query(f1)
|
||||
assert(4 == evo.registry.batch_apply(q, f1, mul2))
|
||||
assert(e1:get(f1) == 20 and e2:get(f1) == 30 and e3:get(f1) == 80 and e4:get(f1) == 100)
|
||||
assert(e3:get(f2) == 40 and e4:get(f2) == 45)
|
||||
end
|
||||
|
||||
do
|
||||
local q = evo.registry.query(f1, f2)
|
||||
assert(2 == evo.registry.batch_apply(q, f1, null))
|
||||
assert(e1:get(f1) == 20 and e2:get(f1) == 30 and e3:get(f1) == true and e4:get(f1) == true)
|
||||
assert(e3:get(f2) == 40 and e4:get(f2) == 45)
|
||||
end
|
||||
|
||||
do
|
||||
local q = evo.registry.query(f1)
|
||||
assert(2 == evo.registry.batch_apply(q, f2, mul2))
|
||||
assert(e1:get(f1) == 20 and e2:get(f1) == 30 and e3:get(f1) == true and e4:get(f1) == true)
|
||||
assert(e3:get(f2) == 80 and e4:get(f2) == 90)
|
||||
end
|
||||
|
||||
do
|
||||
local q = evo.registry.query(f1):exclude(f2)
|
||||
assert(2 == evo.registry.batch_apply(q, f1, mul2))
|
||||
assert(e1:get(f1) == 40 and e2:get(f1) == 60 and e3:get(f1) == true and e4:get(f1) == true)
|
||||
assert(e3:get(f2) == 80 and e4:get(f2) == 90)
|
||||
end
|
||||
end
|
||||
|
||||
for _ = 1, 100 do
|
||||
local insert_fragments = {} ---@type evolved.entity[]
|
||||
local insert_fragment_count = math.random(0, 10)
|
||||
|
||||
Reference in New Issue
Block a user