fix: signals for addOrReplace

master
menduz 1 year ago
parent 13852c2e08
commit bdcd98a989

@ -316,6 +316,7 @@ pub const Registry = struct {
const store = self.assure(@TypeOf(value)); const store = self.assure(@TypeOf(value));
if (store.tryGet(entity)) |found| { if (store.tryGet(entity)) |found| {
found.* = value; found.* = value;
store.update.publish(entity);
} else { } else {
store.add(entity, value); 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 /// 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 { pub fn getOrAdd(self: *Registry, comptime T: type, entity: Entity) *T {
if (self.has(T, entity)) return self.get(T, entity); if (!self.has(T, entity)) {
self.add(T, entity, std.mem.zeros(T)); self.addTyped(T, entity, .{});
return self.get(T, type); }
return self.get(T, entity);
} }
pub fn tryGet(self: *Registry, comptime T: type, entity: Entity) ?*T { pub fn tryGet(self: *Registry, comptime T: type, entity: Entity) ?*T {

Loading…
Cancel
Save