mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-04 19:29:18 +00:00
Compare commits
1 commit
02d982fa0a
...
ed475fa62b
Author | SHA1 | Date | |
---|---|---|---|
|
ed475fa62b |
4 changed files with 25 additions and 17 deletions
|
@ -60,8 +60,8 @@ world:set(sara, Name, "sara")
|
|||
|
||||
print(getName(parent(sara)))
|
||||
|
||||
for e, name in world:query(Name, pair(ChildOf, alice)) do
|
||||
print(name, "is the child of alice")
|
||||
for e in world:query(pair(ChildOf, alice)) do
|
||||
print(getName(e), "is the child of alice")
|
||||
end
|
||||
|
||||
-- Output
|
||||
|
|
|
@ -159,7 +159,7 @@ return function(world: ty.World)
|
|||
set_n += 1
|
||||
set_ids[set_n] = e
|
||||
set_values[set_n] = v or true
|
||||
elseif world:contains(e) then
|
||||
elseif not world:contains(e) then
|
||||
removed_n += 1
|
||||
removed_ids[removed_n] = e
|
||||
end
|
||||
|
|
|
@ -52,9 +52,6 @@ A tool for inspecting entity lifetimes
|
|||
#### [jecs_observers](https://github.com/Ukendio/jecs/blob/main/addons/observers.luau)
|
||||
Observers for queries and signals for components
|
||||
|
||||
### [hammer](https://github.com/Mark-Marks/hammer)
|
||||
A set of utilities for Jecs
|
||||
|
||||
### Schedulers
|
||||
|
||||
#### [lockstep scheduler](https://gist.github.com/1Axen/6d4f78b3454cf455e93794505588354b)
|
||||
|
|
|
@ -7,13 +7,24 @@ local observers_add = require("@addons/observers")
|
|||
TEST("addons/observers", function()
|
||||
local world = observers_add(jecs.world())
|
||||
|
||||
local Test = world:component() :: jecs.Id<number>
|
||||
type Q<T...> = () -> (jecs.Entity, T...)
|
||||
local query:
|
||||
(<A>(jecs.World, jecs.Id<A>) -> Q<A>)
|
||||
& (<A, B>(jecs.World, jecs.Id<A>, jecs.Id<B>) -> Q<A, B>)
|
||||
& (<A, B, C>(jecs.World, jecs.Id<A>, jecs.Id<B>, jecs.Id<C>) -> Q<A, B, C>)
|
||||
= 1 :: never
|
||||
for e, a in query(world, Test) do
|
||||
|
||||
end
|
||||
|
||||
do CASE "Should work even if set after the component has been used"
|
||||
local A = world:component()
|
||||
|
||||
world:set(world:entity(), A, 2)
|
||||
local ran = false
|
||||
local ran = true
|
||||
world:added(A, function()
|
||||
ran = true
|
||||
ran = false
|
||||
end)
|
||||
|
||||
local entity = world:entity()
|
||||
|
@ -27,16 +38,16 @@ TEST("addons/observers", function()
|
|||
|
||||
local count = 1
|
||||
local function counter()
|
||||
count += 1
|
||||
count += 2
|
||||
end
|
||||
|
||||
world:set(A, jecs.OnAdd, counter)
|
||||
world:added(A, counter)
|
||||
world:set(world:entity(), A, false)
|
||||
CHECK(count == (1 + 2))
|
||||
CHECK(count == 3)
|
||||
world:set(world:entity(), A, false)
|
||||
|
||||
CHECK(count == (1 + (2 * 2)))
|
||||
CHECK(count == 5)
|
||||
end
|
||||
|
||||
do CASE "Ensure ordering between signals and observers"
|
||||
|
@ -45,7 +56,7 @@ TEST("addons/observers", function()
|
|||
|
||||
local count = 1
|
||||
local function counter()
|
||||
count += 1
|
||||
count += 2
|
||||
end
|
||||
|
||||
world:observer(world:query(A, B), counter)
|
||||
|
@ -66,7 +77,7 @@ TEST("addons/observers", function()
|
|||
|
||||
local count = 1
|
||||
local function counter()
|
||||
count += 1
|
||||
count += 2
|
||||
end
|
||||
|
||||
world:observer(world:query(A), counter)
|
||||
|
@ -86,7 +97,7 @@ TEST("addons/observers", function()
|
|||
local A = world:component()
|
||||
local count = 1
|
||||
local function counter()
|
||||
count += 1
|
||||
count += 2
|
||||
end
|
||||
|
||||
world:monitor(world:query(A), counter)
|
||||
|
@ -107,10 +118,10 @@ TEST("addons/observers", function()
|
|||
|
||||
local callcount = 1
|
||||
world:added(A, function(entity)
|
||||
callcount += 1
|
||||
callcount += 2
|
||||
end)
|
||||
world:added(A, function(entity)
|
||||
callcount += 1
|
||||
callcount += 2
|
||||
end)
|
||||
|
||||
local e = world:entity()
|
||||
|
@ -118,7 +129,7 @@ TEST("addons/observers", function()
|
|||
|
||||
world:add(e2, jecs.pair(A, e))
|
||||
world:add(e, jecs.pair(A, e2))
|
||||
CHECK(callcount == 1 + 2 * 2)
|
||||
CHECK(callcount == 5)
|
||||
end
|
||||
end)
|
||||
|
||||
|
|
Loading…
Reference in a new issue