diff --git a/package.json b/package.json index 21c2cc4..871da8e 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@rbxts/jecs", - "version": "0.9.0-rc.6", + "version": "0.9.0-rc.7", "description": "Stupidly fast Entity Component System", "main": "jecs.luau", "repository": { diff --git a/wally.toml b/wally.toml index e099f5f..12df0ed 100755 --- a/wally.toml +++ b/wally.toml @@ -1,6 +1,6 @@ [package] name = "ukendio/jecs" -version = "0.9.0-rc.6" +version = "0.9.0-rc.7" registry = "https://github.com/UpliftGames/wally-index" realm = "shared" license = "MIT" diff --git a/werewitch.luau b/werewitch.luau new file mode 100755 index 0000000..7c8d4dd --- /dev/null +++ b/werewitch.luau @@ -0,0 +1,66 @@ +local jecs = require("@jecs") + +local world = jecs.world() +local pair = jecs.pair + +local IsA = world:entity() + +local traits = { + IsA = IsA +} + +world:set(IsA, jecs.OnAdd, function(component, id) + local second = jecs.pair_second(world, id) + assert(second ~= component, "circular") + + local is_tag = jecs.is_tag(world, second) + world:added(component, function(entity, _, value) + if is_tag then + world:add(entity, second) + else + world:set(entity, second, value) + end + end) + + world:removed(component, function(entity) + world:remove(entity, second) + end) + + if not is_tag then + world:changed(component, function(entity, _, value) + world:set(entity, second, value) + end) + end + + local r = jecs.record(world, second) :: jecs.Record + local archetype = r.archetype + if not archetype then + return + end + local types = archetype.types + + for _, id in types do + if jecs.is_tag(world, id) then + world:add(component, id) + else + local metadata = world:get(second, id) + if not world:has(component, id) then + world:set(component, id, metadata) + end + end + end + + -- jecs.bulk_insert(world, component, ids, values) +end) + +local Witch = world:entity() +local Werewolf = world:entity() + +local WereWitch = world:entity() +world:add(WereWitch, pair(IsA, Witch)) +world:add(WereWitch, pair(IsA, Werewolf)) + +local e = world:entity() +world:add(e, WereWitch) +print(world:has(e, pair(IsA, Witch))) -- false +print(world:has(e, Witch)) -- true