mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2025-12-15 04:15:28 +07:00
batch_xxx as query methods
This commit is contained in:
@@ -81,6 +81,12 @@ entity:detach -> (entity)
|
||||
query:include -> entity... -> query
|
||||
query:exclude -> entity... -> query
|
||||
query:execute -> (() -> (chunk?))
|
||||
query:batch_destroy -> (integer)
|
||||
query:batch_apply -> (any -> any) -> entity -> (integer)
|
||||
query:batch_assign -> entity -> any -> (integer)
|
||||
query:batch_insert -> entity -> any -> (integer)
|
||||
query:batch_remove -> entity... -> (integer)
|
||||
query:batch_detach -> (integer)
|
||||
```
|
||||
|
||||
### Instance `chunk`
|
||||
|
||||
@@ -425,35 +425,35 @@ do
|
||||
|
||||
do
|
||||
local q = evo.registry.query(f2)
|
||||
assert(2 == evo.registry.batch_assign(q, f1, 42))
|
||||
assert(2 == q:batch_assign(f1, 42))
|
||||
assert(e1:get(f1) == 10 and e2:get(f1) == 15 and e3:get(f1) == 42 and e4:get(f1) == 42)
|
||||
assert(e3:get(f2) == 40 and e4:get(f2) == 45)
|
||||
end
|
||||
|
||||
do
|
||||
local q = evo.registry.query(f1)
|
||||
assert(4 == evo.registry.batch_assign(q, f1, 21))
|
||||
assert(4 == q:batch_assign(f1, 21))
|
||||
assert(e1:get(f1) == 21 and e2:get(f1) == 21 and e3:get(f1) == 21 and e4:get(f1) == 21)
|
||||
assert(e3:get(f2) == 40 and e4:get(f2) == 45)
|
||||
end
|
||||
|
||||
do
|
||||
local q = evo.registry.query(f1, f2)
|
||||
assert(2 == evo.registry.batch_assign(q, f1, nil))
|
||||
assert(2 == q:batch_assign(f1, nil))
|
||||
assert(e1:get(f1) == 21 and e2:get(f1) == 21 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_assign(q, f2, 42))
|
||||
assert(2 == q:batch_assign(f2, 42))
|
||||
assert(e1:get(f1) == 21 and e2:get(f1) == 21 and e3:get(f1) == true and e4:get(f1) == true)
|
||||
assert(e3:get(f2) == 42 and e4:get(f2) == 42)
|
||||
end
|
||||
|
||||
do
|
||||
local q = evo.registry.query(f1):exclude(f2)
|
||||
assert(2 == evo.registry.batch_assign(q, f1, 84))
|
||||
assert(2 == q:batch_assign(f1, 84))
|
||||
assert(e1:get(f1) == 84 and e2:get(f1) == 84 and e3:get(f1) == true and e4:get(f1) == true)
|
||||
assert(e3:get(f2) == 42 and e4:get(f2) == 42)
|
||||
end
|
||||
@@ -472,35 +472,35 @@ do
|
||||
|
||||
do
|
||||
local q = evo.registry.query(f2)
|
||||
assert(2 == evo.registry.batch_apply(q, mul2, f1))
|
||||
assert(2 == q:batch_apply(mul2, f1))
|
||||
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, mul2, f1))
|
||||
assert(4 == q:batch_apply(mul2, f1))
|
||||
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, null, f1))
|
||||
assert(2 == q:batch_apply(null, f1))
|
||||
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, mul2, f2))
|
||||
assert(2 == q:batch_apply(mul2, f2))
|
||||
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, mul2, f1))
|
||||
assert(2 == q:batch_apply(mul2, f1))
|
||||
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
|
||||
@@ -517,7 +517,7 @@ do
|
||||
|
||||
local q = evo.registry.query(f1)
|
||||
|
||||
assert(2 == evo.registry.batch_insert(q, f2, 42))
|
||||
assert(2 == q:batch_insert(f2, 42))
|
||||
assert(e1:get(f1) == 10 and e2:get(f1) == 15 and e3:get(f1) == 20 and e4:get(f1) == 25)
|
||||
assert(e1:get(f2) == 42 and e2:get(f2) == 42 and e3:get(f2) == 40 and e4:get(f2) == 45)
|
||||
end
|
||||
@@ -540,7 +540,7 @@ do
|
||||
do
|
||||
local q = evo.registry.query(f2)
|
||||
|
||||
assert(2 == evo.registry.batch_remove(q, f1, f4))
|
||||
assert(2 == q:batch_remove(f1, f4))
|
||||
assert(e1.__chunk == evo.registry.chunk(f1))
|
||||
assert(e2.__chunk == evo.registry.chunk(f1))
|
||||
assert(e3.__chunk == evo.registry.chunk(f2))
|
||||
@@ -549,7 +549,7 @@ do
|
||||
assert(e1:get(f1) == 10 and e2:get(f1) == 15)
|
||||
assert(e3:get(f2) == 40 and e4:get(f2) == 45 and e4:get(f3) == 55)
|
||||
|
||||
assert(2 == evo.registry.batch_remove(q, f2))
|
||||
assert(2 == q:batch_remove(f2))
|
||||
assert(e1.__chunk == evo.registry.chunk(f1))
|
||||
assert(e2.__chunk == evo.registry.chunk(f1))
|
||||
assert(e3.__chunk == nil)
|
||||
@@ -562,8 +562,8 @@ do
|
||||
|
||||
do
|
||||
local q = evo.registry.query(f3)
|
||||
assert(0 == evo.registry.batch_remove(q, f1))
|
||||
assert(2 == evo.registry.batch_remove(q, f3))
|
||||
assert(0 == q:batch_remove(f1))
|
||||
assert(2 == q:batch_remove(f3))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -580,7 +580,7 @@ do
|
||||
|
||||
do
|
||||
local q = evo.registry.query(f2):exclude(f3)
|
||||
assert(1 == evo.registry.batch_detach(q))
|
||||
assert(1 == q:batch_detach())
|
||||
assert(e1.__chunk == evo.registry.chunk(f1))
|
||||
assert(e2.__chunk == evo.registry.chunk(f1))
|
||||
assert(e3.__chunk == nil)
|
||||
@@ -594,7 +594,7 @@ do
|
||||
|
||||
do
|
||||
local q = evo.registry.query(f1)
|
||||
assert(3 == evo.registry.batch_detach(q))
|
||||
assert(3 == q:batch_detach())
|
||||
assert(e1.__chunk == nil)
|
||||
assert(e2.__chunk == nil)
|
||||
assert(e3.__chunk == nil)
|
||||
@@ -617,7 +617,7 @@ do
|
||||
|
||||
do
|
||||
local q = evo.registry.query(f2):exclude(f3)
|
||||
assert(1 == evo.registry.batch_destroy(q))
|
||||
assert(1 == q:batch_destroy())
|
||||
assert(e1.__chunk == evo.registry.chunk(f1))
|
||||
assert(e2.__chunk == evo.registry.chunk(f1))
|
||||
assert(e3.__chunk == nil)
|
||||
@@ -631,7 +631,7 @@ do
|
||||
|
||||
do
|
||||
local q = evo.registry.query(f1)
|
||||
assert(3 == evo.registry.batch_destroy(q))
|
||||
assert(3 == q:batch_destroy())
|
||||
assert(e1.__chunk == nil)
|
||||
assert(e2.__chunk == nil)
|
||||
assert(e3.__chunk == nil)
|
||||
|
||||
@@ -1159,6 +1159,12 @@ end
|
||||
evolved_query_mt.include = registry.include
|
||||
evolved_query_mt.exclude = registry.exclude
|
||||
evolved_query_mt.execute = registry.execute
|
||||
evolved_query_mt.batch_destroy = registry.batch_destroy
|
||||
evolved_query_mt.batch_apply = registry.batch_apply
|
||||
evolved_query_mt.batch_assign = registry.batch_assign
|
||||
evolved_query_mt.batch_insert = registry.batch_insert
|
||||
evolved_query_mt.batch_remove = registry.batch_remove
|
||||
evolved_query_mt.batch_detach = registry.batch_detach
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user