Compare commits

..

5 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
4 changed files with 38 additions and 41 deletions

View file

@ -2,15 +2,20 @@ local jecs = require("@jecs")
type Observer = {
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 & {
added: <T>(PatchedWorld, jecs.Id<T>, (jecs.Entity, jecs.Id, T) -> ()) -> () -> (),
removed: <T>(PatchedWorld, jecs.Id<T>, (jecs.Entity, jecs.Id) -> ()) -> () -> (),
changed: <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>, (e: jecs.Entity, id: jecs.Id) -> ()) -> () -> (),
changed: <T>(PatchedWorld, jecs.Id<T>, (e: jecs.Entity, id: jecs.Id, value: T) -> ()) -> () -> (),
observer: (PatchedWorld, Observer) -> (),
monitor: (PatchedWorld, Observer) -> (),
monitor: (PatchedWorld, Monitor) -> (),
}
local function observers_new(world, description)
@ -45,7 +50,6 @@ local function observers_new(world, description)
end
end
local function join(world, component)
local sparse_array = {}
local dense_array = {}
@ -163,17 +167,17 @@ local function observers_add(world: jecs.World): PatchedWorld
listener(entity, id, value)
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]
if idr then
local idr_hook_existing = idr.hooks.on_add
if idr_hook_existing then
table.insert(listeners, idr_hook_existing)
idr.hooks.on_add = on_add
end
idr.hooks.on_add = on_add :: any
else
end
world:set(component, jecs.OnAdd, on_add)
end
end
table.insert(listeners, fn)
return function()
local n = #listeners
@ -197,17 +201,16 @@ local function observers_add(world: jecs.World): PatchedWorld
listener(entity, id, value)
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]
if idr then
local idr_hook_existing = idr.hooks.on_change
if idr_hook_existing then
table.insert(listeners, idr_hook_existing)
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
table.insert(listeners, fn)
return function()
local n = #listeners
@ -231,17 +234,17 @@ local function observers_add(world: jecs.World): PatchedWorld
listener(entity, id, value)
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]
if idr then
local idr_hook_existing = idr.hooks.on_remove
if idr_hook_existing then
table.insert(listeners, idr_hook_existing)
idr.hooks.on_remove = on_remove
end
idr.hooks.on_remove = on_remove :: any
else
end
world:set(component, jecs.OnRemove, on_remove)
end
end
table.insert(listeners, fn)
return function()
local n = #listeners

View file

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

View file

@ -89,6 +89,7 @@ print(`${world.get(Position, jecs.Name)} is a Component: ${world.has(Position, j
### 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.
::: code-group
```luau [luau]
world:range(1000, 5000) -- Defines the lower and upper bounds of the entity range respectively
@ -98,14 +99,13 @@ print(e)
-- 1000
```
```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)
// Output:
// 1000
```
```
:::
### 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)
- [Hibitset - DOCS.RS](https://docs.rs/hibitset/0.6.3/hibitset/)
------------------
## 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)
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
#### [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
### Helpers