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);
}
/// Returns the component `Entity` registered for the specified
/// type `T`, or an error if an association has not been made.
pub fn lookupByType(self: *Self, comptime T: type) !Entity {
return lookupAlive(self, Context.lookup(T).*);
/// Returns the component `Entity` registered for the specified type
/// `T`, or an error if an association has not been made, or the
/// entity is not alive.
pub fn lookupType(self: *Self, comptime T: type) !Entity {
return lookupAlive(self, Context.lookup(T));
}
/// 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.
/// Both of these may occur from not calling `singleton()` first.
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;
}
@ -166,7 +167,7 @@ pub fn World(comptime ctx: anytype) type {
/// Returns `error.IsNotAlive` if the entity is missing.
/// This may occur from not calling `singleton()` first.
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);
}

Loading…
Cancel
Save