Compare commits
2 commits
8d9ac83b46
...
34f8310980
Author | SHA1 | Date | |
---|---|---|---|
![]() |
34f8310980 | ||
22bcaa2f05 |
7 changed files with 43 additions and 40 deletions
|
@ -2,15 +2,20 @@ local jecs = require("@jecs")
|
||||||
|
|
||||||
type Observer = {
|
type Observer = {
|
||||||
callback: (jecs.Entity) -> (),
|
callback: (jecs.Entity) -> (),
|
||||||
query: jecs.Query<...jecs.Id>,
|
query: jecs.Query<...any>,
|
||||||
|
}
|
||||||
|
|
||||||
|
type Monitor = {
|
||||||
|
callback: (jecs.Entity, jecs.Entity) -> (),
|
||||||
|
queyr: jecs.Query<any>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PatchedWorld = jecs.World & {
|
export type PatchedWorld = jecs.World & {
|
||||||
added: <T>(PatchedWorld, jecs.Id<T>, (jecs.Entity, jecs.Id, T) -> ()) -> () -> (),
|
added: <T>(PatchedWorld, jecs.Id<T>, (e: jecs.Entity, id: jecs.Id, value: T) -> ()) -> () -> (),
|
||||||
removed: <T>(PatchedWorld, jecs.Id<T>, (jecs.Entity, jecs.Id) -> ()) -> () -> (),
|
removed: <T>(PatchedWorld, jecs.Id<T>, (e: jecs.Entity, id: jecs.Id) -> ()) -> () -> (),
|
||||||
changed: <T>(PatchedWorld, jecs.Id<T>, (jecs.Entity, jecs.Id, T) -> ()) -> () -> (),
|
changed: <T>(PatchedWorld, jecs.Id<T>, (e: jecs.Entity, id: jecs.Id, value: T) -> ()) -> () -> (),
|
||||||
observer: (PatchedWorld, Observer) -> (),
|
observer: (PatchedWorld, Observer) -> (),
|
||||||
monitor: (PatchedWorld, Observer) -> (),
|
monitor: (PatchedWorld, Monitor) -> (),
|
||||||
}
|
}
|
||||||
|
|
||||||
local function observers_new(world, description)
|
local function observers_new(world, description)
|
||||||
|
@ -45,7 +50,6 @@ local function observers_new(world, description)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function join(world, component)
|
local function join(world, component)
|
||||||
local sparse_array = {}
|
local sparse_array = {}
|
||||||
local dense_array = {}
|
local dense_array = {}
|
||||||
|
@ -163,17 +167,17 @@ local function observers_add(world: jecs.World): PatchedWorld
|
||||||
listener(entity, id, value)
|
listener(entity, id, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local existing_hook = world:get(component, jecs.OnAdd)
|
||||||
|
if existing_hook then
|
||||||
|
table.insert(listeners, existing_hook)
|
||||||
local idr = world.component_index[component]
|
local idr = world.component_index[component]
|
||||||
if idr then
|
if idr then
|
||||||
local idr_hook_existing = idr.hooks.on_add
|
idr.hooks.on_add = on_add
|
||||||
if idr_hook_existing then
|
|
||||||
table.insert(listeners, idr_hook_existing)
|
|
||||||
end
|
end
|
||||||
idr.hooks.on_add = on_add :: any
|
end
|
||||||
else
|
|
||||||
world:set(component, jecs.OnAdd, on_add)
|
world:set(component, jecs.OnAdd, on_add)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
table.insert(listeners, fn)
|
table.insert(listeners, fn)
|
||||||
return function()
|
return function()
|
||||||
local n = #listeners
|
local n = #listeners
|
||||||
|
@ -197,17 +201,16 @@ local function observers_add(world: jecs.World): PatchedWorld
|
||||||
listener(entity, id, value)
|
listener(entity, id, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local existing_hook = world:get(component, jecs.OnChange)
|
||||||
|
if existing_hook then
|
||||||
|
table.insert(listeners, existing_hook)
|
||||||
local idr = world.component_index[component]
|
local idr = world.component_index[component]
|
||||||
if idr then
|
if idr then
|
||||||
local idr_hook_existing = idr.hooks.on_change
|
idr.hooks.on_change = on_change
|
||||||
if idr_hook_existing then
|
end
|
||||||
table.insert(listeners, idr_hook_existing)
|
|
||||||
end
|
end
|
||||||
idr.hooks.on_change = on_change :: any
|
|
||||||
else
|
|
||||||
world:set(component, jecs.OnChange, on_change)
|
world:set(component, jecs.OnChange, on_change)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
table.insert(listeners, fn)
|
table.insert(listeners, fn)
|
||||||
return function()
|
return function()
|
||||||
local n = #listeners
|
local n = #listeners
|
||||||
|
@ -231,17 +234,17 @@ local function observers_add(world: jecs.World): PatchedWorld
|
||||||
listener(entity, id, value)
|
listener(entity, id, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local existing_hook = world:get(component, jecs.OnRemove)
|
||||||
|
if existing_hook then
|
||||||
|
table.insert(listeners, existing_hook)
|
||||||
local idr = world.component_index[component]
|
local idr = world.component_index[component]
|
||||||
if idr then
|
if idr then
|
||||||
local idr_hook_existing = idr.hooks.on_remove
|
idr.hooks.on_remove = on_remove
|
||||||
if idr_hook_existing then
|
|
||||||
table.insert(listeners, idr_hook_existing)
|
|
||||||
end
|
end
|
||||||
idr.hooks.on_remove = on_remove :: any
|
end
|
||||||
else
|
|
||||||
world:set(component, jecs.OnRemove, on_remove)
|
world:set(component, jecs.OnRemove, on_remove)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
table.insert(listeners, fn)
|
table.insert(listeners, fn)
|
||||||
return function()
|
return function()
|
||||||
local n = #listeners
|
local n = #listeners
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
modified = ["README.md", "jecs.luau"]
|
modified = ["addons/observers.luau"]
|
||||||
version = "0.6.0-nightly.20250519T001113Z"
|
version = "0.6.0-nightly.20250520T001101Z"
|
||||||
|
|
|
@ -3,7 +3,7 @@ includes = ["init.luau", "pesde.toml", "README.md", "CHANGELOG.md", "LICENSE", "
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
name = "marked/jecs_nightly"
|
name = "marked/jecs_nightly"
|
||||||
repository = "https://git.devmarked.win/marked/jecs-nightly"
|
repository = "https://git.devmarked.win/marked/jecs-nightly"
|
||||||
version = "0.6.0-nightly.20250519T001113Z"
|
version = "0.6.0-nightly.20250520T001101Z"
|
||||||
|
|
||||||
[indices]
|
[indices]
|
||||||
default = "https://github.com/pesde-pkg/index"
|
default = "https://github.com/pesde-pkg/index"
|
||||||
|
|
|
@ -3,7 +3,7 @@ includes = ["init.luau", "pesde.toml", "README.md", "CHANGELOG.md", "LICENSE", "
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
name = "marked/jecs_nightly"
|
name = "marked/jecs_nightly"
|
||||||
repository = "https://git.devmarked.win/marked/jecs-nightly"
|
repository = "https://git.devmarked.win/marked/jecs-nightly"
|
||||||
version = "0.6.0-nightly.20250519T001113Z"
|
version = "0.6.0-nightly.20250520T001101Z"
|
||||||
|
|
||||||
[indices]
|
[indices]
|
||||||
default = "https://github.com/pesde-pkg/index"
|
default = "https://github.com/pesde-pkg/index"
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
passed = true
|
passed = true
|
||||||
timestamp = "20250519T001115Z"
|
timestamp = "20250521T001102Z"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[38;1m7.3[0m [33;1mus[0m [38;1m 3[0m [33;1mkB[0m[38;1m│[0m [38;1mdelete children of entity[0m
|
[38;1m7.2[0m [33;1mus[0m [38;1m 3[0m [33;1mkB[0m[38;1m│[0m [38;1mdelete children of entity[0m
|
||||||
[38;1m9.2[0m [33;1mus[0m [38;1m 1[0m [33;1mkB[0m[38;1m│[0m [38;1mremove friends of entity[0m
|
[38;1m9.1[0m [33;1mus[0m [38;1m 1[0m [33;1mkB[0m[38;1m│[0m [38;1mremove friends of entity[0m
|
||||||
[38;1m348[0m [32;1mns[0m [38;1m 10[0m [32;1m B[0m[38;1m│[0m [38;1msimple deletion of entity[0m
|
[38;1m347[0m [32;1mns[0m [38;1m 10[0m [32;1m B[0m[38;1m│[0m [38;1msimple deletion of entity[0m
|
||||||
[37;1mrepro[0m
|
[37;1mrepro[0m
|
||||||
[38;5;208mNONE[0m[38;1m│[0m [38;1m[0m
|
[38;5;208mNONE[0m[38;1m│[0m [38;1m[0m
|
||||||
|
|
||||||
|
@ -121,5 +121,5 @@
|
||||||
[32;1mPASS[0m[38;1m│[0m [38;1m#2[0m
|
[32;1mPASS[0m[38;1m│[0m [38;1m#2[0m
|
||||||
[32;1mPASS[0m[38;1m│[0m [38;1m#3[0m
|
[32;1mPASS[0m[38;1m│[0m [38;1m#3[0m
|
||||||
|
|
||||||
[38;1m74/74 test cases passed in 33.314 ms.[0m
|
[38;1m74/74 test cases passed in 32.770 ms.[0m
|
||||||
[32;1m0 fails[0m
|
[32;1m0 fails[0m
|
||||||
|
|
|
@ -5,4 +5,4 @@ license = "MIT"
|
||||||
name = "mark-marks/jecs-nightly"
|
name = "mark-marks/jecs-nightly"
|
||||||
realm = "shared"
|
realm = "shared"
|
||||||
registry = "https://github.com/UpliftGames/wally-index"
|
registry = "https://github.com/UpliftGames/wally-index"
|
||||||
version = "0.6.0-nightly.20250519T001113Z"
|
version = "0.6.0-nightly.20250520T001101Z"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue