mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-04 11:19:17 +00:00
Compare commits
2 commits
499afc20cd
...
4153a7cdfe
Author | SHA1 | Date | |
---|---|---|---|
|
4153a7cdfe | ||
|
4230a0a797 |
7 changed files with 95 additions and 8 deletions
|
@ -69,6 +69,9 @@ local function observers_new<T...>(
|
|||
end
|
||||
|
||||
for _, term in terms do
|
||||
if jecs.IS_PAIR(term) then
|
||||
term = jecs.ECS_PAIR_FIRST(term)
|
||||
end
|
||||
world:added(term, emplaced)
|
||||
world:changed(term, emplaced)
|
||||
end
|
||||
|
@ -151,7 +154,7 @@ local function monitors_new<T...>(
|
|||
i += 1
|
||||
entities[i] = entity
|
||||
if callback ~= nil then
|
||||
callback(entity, id, value)
|
||||
callback(entity, jecs.OnAdd)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -164,6 +167,9 @@ local function monitors_new<T...>(
|
|||
end
|
||||
|
||||
for _, term in terms do
|
||||
if jecs.IS_PAIR(term) then
|
||||
term = jecs.ECS_PAIR_FIRST(term)
|
||||
end
|
||||
world:added(term, emplaced)
|
||||
world:removed(term, removed)
|
||||
end
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local jecs = require(ReplicatedStorage.ecs)
|
||||
local schedule = require(ReplicatedStorage.schedule)
|
||||
local observers_add = require(ReplicatedStorage.observers_add)
|
||||
|
||||
local SYSTEM = schedule.SYSTEM
|
||||
local RUN = schedule.RUN
|
||||
require(ReplicatedStorage.components)
|
||||
local world = observers_add(jecs.world())
|
||||
local world = jecs.world()
|
||||
|
||||
local systems = ReplicatedStorage.systems
|
||||
SYSTEM(world, systems.receive_replication)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
local jecs = require(game:GetService("ReplicatedStorage").ecs)
|
||||
local observers_add = require("../ReplicatedStorage/observers_add")
|
||||
|
||||
export type World = typeof(observers_add(jecs.world()))
|
||||
export type World = typeof(jecs.world())
|
||||
export type Entity = jecs.Entity
|
||||
export type Id<T> = jecs.Id<T>
|
||||
export type Snapshot = {
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -2,11 +2,28 @@ local jecs = require("@jecs")
|
|||
local testkit = require("@testkit")
|
||||
local test = testkit.test()
|
||||
local CASE, TEST, FINISH, CHECK = test.CASE, test.TEST, test.FINISH, test.CHECK
|
||||
local FOCUS = test.FOCUS
|
||||
local ob = require("@addons/ob")
|
||||
|
||||
TEST("addons/observers", function()
|
||||
local world = jecs.world()
|
||||
|
||||
local world = jecs.world()
|
||||
do CASE "monitors should accept pairs"
|
||||
local A = world:component()
|
||||
local B = world:component()
|
||||
|
||||
local c = 1
|
||||
ob.monitor(world:query(jecs.pair(A, B)), function (_, event)
|
||||
c += 1
|
||||
end)
|
||||
|
||||
local child = world:entity()
|
||||
world:add(child, jecs.pair(A, B))
|
||||
CHECK(c == 2)
|
||||
|
||||
world:remove(child, jecs.pair(A, B))
|
||||
CHECK(c == 3)
|
||||
end
|
||||
do CASE "Ensure ordering between signals and observers"
|
||||
local A = world:component()
|
||||
local B = world:component()
|
||||
|
|
|
@ -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"
|
||||
|
|
66
werewitch.luau
Executable file
66
werewitch.luau
Executable file
|
@ -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
|
Loading…
Reference in a new issue