Compare commits

...

6 commits

Author SHA1 Message Date
Clown
c2b4398a4f
Merge 96bed9bd7e into bb03e88d3d 2025-05-20 20:34:27 -05:00
Ukendio
bb03e88d3d Fix contrived bug with observer
Some checks failed
analysis / Run Luau Analyze (push) Has been cancelled
deploy-docs / build (push) Has been cancelled
publish-npm / publish (push) Has been cancelled
unit-testing / Run Luau Tests (push) Has been cancelled
deploy-docs / Deploy (push) Has been cancelled
2025-05-20 00:33:16 +02:00
Ukendio
5dba6e7bac Fix typescript example
Some checks are pending
analysis / Run Luau Analyze (push) Waiting to run
deploy-docs / build (push) Waiting to run
deploy-docs / Deploy (push) Blocked by required conditions
publish-npm / publish (push) Waiting to run
unit-testing / Run Luau Tests (push) Waiting to run
2025-05-18 23:05:26 +02:00
Ukendio
0541f80b5d Fix hyperlinks 2025-05-18 23:02:16 +02:00
Ukendio
fd685537ea Fix docs issues 2025-05-18 22:59:07 +02:00
YetAnotherClown
96bed9bd7e Empty Commit 2025-02-25 11:28:04 -05:00
4 changed files with 38 additions and 41 deletions

View file

@ -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,16 +167,16 @@ local function observers_add(world: jecs.World): PatchedWorld
listener(entity, id, value) listener(entity, id, value)
end end
end end
local idr = world.component_index[component] local existing_hook = world:get(component, jecs.OnAdd)
if idr then if existing_hook then
local idr_hook_existing = idr.hooks.on_add table.insert(listeners, existing_hook)
if idr_hook_existing then local idr = world.component_index[component]
table.insert(listeners, idr_hook_existing) if idr then
idr.hooks.on_add = on_add
end end
idr.hooks.on_add = on_add :: any
else
world:set(component, jecs.OnAdd, on_add)
end end
world:set(component, jecs.OnAdd, on_add)
end end
table.insert(listeners, fn) table.insert(listeners, fn)
return function() return function()
@ -197,16 +201,15 @@ local function observers_add(world: jecs.World): PatchedWorld
listener(entity, id, value) listener(entity, id, value)
end end
end end
local idr = world.component_index[component] local existing_hook = world:get(component, jecs.OnChange)
if idr then if existing_hook then
local idr_hook_existing = idr.hooks.on_change table.insert(listeners, existing_hook)
if idr_hook_existing then local idr = world.component_index[component]
table.insert(listeners, idr_hook_existing) if idr then
idr.hooks.on_change = on_change
end end
idr.hooks.on_change = on_change :: any
else
world:set(component, jecs.OnChange, on_change)
end end
world:set(component, jecs.OnChange, on_change)
end end
table.insert(listeners, fn) table.insert(listeners, fn)
return function() return function()
@ -231,16 +234,16 @@ local function observers_add(world: jecs.World): PatchedWorld
listener(entity, id, value) listener(entity, id, value)
end end
end end
local idr = world.component_index[component] local existing_hook = world:get(component, jecs.OnRemove)
if idr then if existing_hook then
local idr_hook_existing = idr.hooks.on_remove table.insert(listeners, existing_hook)
if idr_hook_existing then local idr = world.component_index[component]
table.insert(listeners, idr_hook_existing) if idr then
idr.hooks.on_remove = on_remove
end end
idr.hooks.on_remove = on_remove :: any
else
world:set(component, jecs.OnRemove, on_remove)
end end
world:set(component, jecs.OnRemove, on_remove)
end end
table.insert(listeners, fn) table.insert(listeners, fn)
return function() return function()

View file

@ -25,10 +25,6 @@ export default defineConfig({
}, },
], ],
"/learn/": [ "/learn/": [
{
text: "Overview",
items: [{ text: "Overview", link: "/learn/overview" }],
},
{ {
text: "API Reference", text: "API Reference",
items: [ items: [

View file

@ -89,6 +89,7 @@ print(`${world.get(Position, jecs.Name)} is a Component: ${world.has(Position, j
### Entity ranges ### Entity ranges
Jecs reserves entity ids under a threshold (HI_COMPONENT_ID, default is 256) for components. That means that regular entities will start after this number. This number can be further specified via the `range` member function. Jecs reserves entity ids under a threshold (HI_COMPONENT_ID, default is 256) for components. That means that regular entities will start after this number. This number can be further specified via the `range` member function.
::: code-group
```luau [luau] ```luau [luau]
world:range(1000, 5000) -- Defines the lower and upper bounds of the entity range respectively world:range(1000, 5000) -- Defines the lower and upper bounds of the entity range respectively
@ -98,14 +99,13 @@ print(e)
-- 1000 -- 1000
``` ```
```typescript [typescript] ```typescript [typescript]
world.range(1000, 5000) -- Defines the lower and upper bounds of the entity range respectively world.range(1000, 5000) // Defines the lower and upper bounds of the entity range respectively
local e = world.entity() const e = world.entity()
print(e) print(e)
// Output: // Output:
// 1000 // 1000
``` ```
```
::: :::
### Hooks ### Hooks

View file

@ -32,8 +32,6 @@
- [Awesome Entity Component System (link collection related to ECS) - Jeongseok Lee](https://github.com/jslee02/awesome-entity-component-system) - [Awesome Entity Component System (link collection related to ECS) - Jeongseok Lee](https://github.com/jslee02/awesome-entity-component-system)
- [Hibitset - DOCS.RS](https://docs.rs/hibitset/0.6.3/hibitset/) - [Hibitset - DOCS.RS](https://docs.rs/hibitset/0.6.3/hibitset/)
------------------
## Addons ## Addons
A collection of third-party jecs addons made by the community. If you would like to share what you're working on, [submit a pull request](/learn/contributing/pull-requests#addons)! A collection of third-party jecs addons made by the community. If you would like to share what you're working on, [submit a pull request](/learn/contributing/pull-requests#addons)!
@ -43,10 +41,10 @@ A collection of third-party jecs addons made by the community. If you would like
#### [jabby](https://github.com/alicesaidhi/jabby) #### [jabby](https://github.com/alicesaidhi/jabby)
A jecs debugger with a string-based query language and entity editing capabilities. A jecs debugger with a string-based query language and entity editing capabilities.
#### [jecs_entity_visualiser](https://github.com/Ukendio/jecs/blob/main/addons/entity_visualiser.luau) #### [jecs_entity_visualiser](https://github.com/Ukendio/jecs/blob/main/tools/entity_visualiser.luau)
A simple entity and component visualiser in the output A simple entity and component visualiser in the output
#### [jecs_lifetime_tracker](https://github.com/Ukendio/jecs/blob/main/addons/lifetime_tracker.luau) #### [jecs_lifetime_tracker](https://github.com/Ukendio/jecs/blob/main/tools/lifetime_tracker.luau)
A tool for inspecting entity lifetimes A tool for inspecting entity lifetimes
### Helpers ### Helpers