Added hasComponent | Forgor about it
This commit is contained in:
parent
7b8b2833a9
commit
3dec2867e5
3 changed files with 29 additions and 1 deletions
|
|
@ -41,3 +41,5 @@ pub const Player = struct {
|
||||||
try writer.print("\"{s}\"", .{self.name});
|
try writer.print("\"{s}\"", .{self.name});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const Dead = struct { value: bool = false };
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ pub fn test_ecs(
|
||||||
ctx: App.scheduler.Context,
|
ctx: App.scheduler.Context,
|
||||||
) !void {
|
) !void {
|
||||||
// --- SPAWN ENTITY ---
|
// --- SPAWN ENTITY ---
|
||||||
try ctx.app.world.spawn(.{
|
const player = try ctx.app.world.spawnEntity(.{
|
||||||
component.Player{ .name = "abux" },
|
component.Player{ .name = "abux" },
|
||||||
component.Material{},
|
component.Material{},
|
||||||
component.Transform{},
|
component.Transform{},
|
||||||
|
|
@ -204,4 +204,20 @@ pub fn test_ecs(
|
||||||
);
|
);
|
||||||
std.debug.print("\x1b[0m", .{});
|
std.debug.print("\x1b[0m", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ctx.app.world.getComponent(component.Dead, player)) |_| {
|
||||||
|
std.debug.print("------------------>\n", .{});
|
||||||
|
}
|
||||||
|
|
||||||
|
// try ctx.app.world.addComponents(player, .{component.Dead{}});
|
||||||
|
try ctx.app.world.addComponents(player, .{
|
||||||
|
component.Dead{},
|
||||||
|
});
|
||||||
|
|
||||||
|
const cmps = try ctx.app.world.getComponents(struct {
|
||||||
|
mat: *component.Material,
|
||||||
|
dead: ?*component.Dead,
|
||||||
|
}, player);
|
||||||
|
|
||||||
|
if (cmps.dead) |_| {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -225,6 +225,16 @@ pub fn getComponents(
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ----------------------------------------------------
|
||||||
|
/// ----------------------------------------------------
|
||||||
|
pub fn hasComponent(
|
||||||
|
self: *Self,
|
||||||
|
comptime T: type,
|
||||||
|
entity: u64,
|
||||||
|
) bool {
|
||||||
|
return self.getComponent(T, entity) != null;
|
||||||
|
}
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
pub fn despawn(
|
pub fn despawn(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue