mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-04 03:09:18 +00:00
Monitors and observers need to able to accept pair terms
Some checks failed
Some checks failed
This commit is contained in:
parent
4230a0a797
commit
4153a7cdfe
4 changed files with 27 additions and 6 deletions
|
@ -69,6 +69,9 @@ local function observers_new<T...>(
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, term in terms do
|
for _, term in terms do
|
||||||
|
if jecs.IS_PAIR(term) then
|
||||||
|
term = jecs.ECS_PAIR_FIRST(term)
|
||||||
|
end
|
||||||
world:added(term, emplaced)
|
world:added(term, emplaced)
|
||||||
world:changed(term, emplaced)
|
world:changed(term, emplaced)
|
||||||
end
|
end
|
||||||
|
@ -151,7 +154,7 @@ local function monitors_new<T...>(
|
||||||
i += 1
|
i += 1
|
||||||
entities[i] = entity
|
entities[i] = entity
|
||||||
if callback ~= nil then
|
if callback ~= nil then
|
||||||
callback(entity, id, value)
|
callback(entity, jecs.OnAdd)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -164,6 +167,9 @@ local function monitors_new<T...>(
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, term in terms do
|
for _, term in terms do
|
||||||
|
if jecs.IS_PAIR(term) then
|
||||||
|
term = jecs.ECS_PAIR_FIRST(term)
|
||||||
|
end
|
||||||
world:added(term, emplaced)
|
world:added(term, emplaced)
|
||||||
world:removed(term, removed)
|
world:removed(term, removed)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||||
local jecs = require(ReplicatedStorage.ecs)
|
local jecs = require(ReplicatedStorage.ecs)
|
||||||
local schedule = require(ReplicatedStorage.schedule)
|
local schedule = require(ReplicatedStorage.schedule)
|
||||||
local observers_add = require(ReplicatedStorage.observers_add)
|
|
||||||
|
|
||||||
local SYSTEM = schedule.SYSTEM
|
local SYSTEM = schedule.SYSTEM
|
||||||
local RUN = schedule.RUN
|
local RUN = schedule.RUN
|
||||||
require(ReplicatedStorage.components)
|
require(ReplicatedStorage.components)
|
||||||
local world = observers_add(jecs.world())
|
local world = jecs.world()
|
||||||
|
|
||||||
local systems = ReplicatedStorage.systems
|
local systems = ReplicatedStorage.systems
|
||||||
SYSTEM(world, systems.receive_replication)
|
SYSTEM(world, systems.receive_replication)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
local jecs = require(game:GetService("ReplicatedStorage").ecs)
|
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 Entity = jecs.Entity
|
||||||
export type Id<T> = jecs.Id<T>
|
export type Id<T> = jecs.Id<T>
|
||||||
export type Snapshot = {
|
export type Snapshot = {
|
||||||
|
|
|
@ -2,11 +2,28 @@ local jecs = require("@jecs")
|
||||||
local testkit = require("@testkit")
|
local testkit = require("@testkit")
|
||||||
local test = testkit.test()
|
local test = testkit.test()
|
||||||
local CASE, TEST, FINISH, CHECK = test.CASE, test.TEST, test.FINISH, test.CHECK
|
local CASE, TEST, FINISH, CHECK = test.CASE, test.TEST, test.FINISH, test.CHECK
|
||||||
|
local FOCUS = test.FOCUS
|
||||||
local ob = require("@addons/ob")
|
local ob = require("@addons/ob")
|
||||||
|
|
||||||
TEST("addons/observers", function()
|
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"
|
do CASE "Ensure ordering between signals and observers"
|
||||||
local A = world:component()
|
local A = world:component()
|
||||||
local B = world:component()
|
local B = world:component()
|
||||||
|
|
Loading…
Reference in a new issue