Fix and rename lookupType

main
copygirl 9 months ago
parent ffddcdf9b9
commit e728e47136
  1. 13
      src/world.zig

@ -101,10 +101,11 @@ pub fn World(comptime ctx: anytype) type {
return Entity.fromRaw(self, current); return Entity.fromRaw(self, current);
} }
/// Returns the component `Entity` registered for the specified /// Returns the component `Entity` registered for the specified type
/// type `T`, or an error if an association has not been made. /// `T`, or an error if an association has not been made, or the
pub fn lookupByType(self: *Self, comptime T: type) !Entity { /// entity is not alive.
return lookupAlive(self, Context.lookup(T).*); pub fn lookupType(self: *Self, comptime T: type) !Entity {
return lookupAlive(self, Context.lookup(T));
} }
/// Creates or modifies an `Entity` in this `World`. /// Creates or modifies an `Entity` in this `World`.
@ -157,7 +158,7 @@ pub fn World(comptime ctx: anytype) type {
/// Returns `error.ComponentMissing` if the component is missing. /// Returns `error.ComponentMissing` if the component is missing.
/// Both of these may occur from not calling `singleton()` first. /// Both of these may occur from not calling `singleton()` first.
pub fn get(self: *Self, comptime T: type) !T { pub fn get(self: *Self, comptime T: type) !T {
const e = try self.lookupByType(T); const e = try self.lookupType(T);
return e.get(T) orelse error.ComponentMissing; return e.get(T) orelse error.ComponentMissing;
} }
@ -166,7 +167,7 @@ pub fn World(comptime ctx: anytype) type {
/// Returns `error.IsNotAlive` if the entity is missing. /// Returns `error.IsNotAlive` if the entity is missing.
/// This may occur from not calling `singleton()` first. /// This may occur from not calling `singleton()` first.
pub fn set(self: *Self, comptime T: type, value: T) !void { pub fn set(self: *Self, comptime T: type, value: T) !void {
const e = try self.lookupByType(T); const e = try self.lookupType(T);
e.set(T, value); e.set(T, value);
} }

Loading…
Cancel
Save