From bdcd98a9899ed977b5c53203e57c6f7a7d4aec97 Mon Sep 17 00:00:00 2001 From: menduz Date: Mon, 3 Jul 2023 14:38:43 -0300 Subject: [PATCH] fix: signals for addOrReplace --- zig-ecs/src/ecs/registry.zig | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/zig-ecs/src/ecs/registry.zig b/zig-ecs/src/ecs/registry.zig index 17711d3..1cc554d 100644 --- a/zig-ecs/src/ecs/registry.zig +++ b/zig-ecs/src/ecs/registry.zig @@ -316,6 +316,7 @@ pub const Registry = struct { const store = self.assure(@TypeOf(value)); if (store.tryGet(entity)) |found| { found.* = value; + store.update.publish(entity); } else { store.add(entity, value); } @@ -369,9 +370,10 @@ pub const Registry = struct { /// Returns a reference to the given component for an entity creating it if necessary pub fn getOrAdd(self: *Registry, comptime T: type, entity: Entity) *T { - if (self.has(T, entity)) return self.get(T, entity); - self.add(T, entity, std.mem.zeros(T)); - return self.get(T, type); + if (!self.has(T, entity)) { + self.addTyped(T, entity, .{}); + } + return self.get(T, entity); } pub fn tryGet(self: *Registry, comptime T: type, entity: Entity) ?*T {