Skip to content

Commit

Permalink
use query include argument in readme example
Browse files Browse the repository at this point in the history
  • Loading branch information
Avokadoen committed Jan 5, 2025
1 parent f657a10 commit c0d43e4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion examples/readme/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub fn main() anyerror!void {
pub const Weapon = struct {};
pub const Position = struct {};
pub const Velocity = struct {};
pub const HeartOrgan = struct {};
};

// Given a set of components, we can store them in a storage defined by the component set.
Expand All @@ -26,6 +27,7 @@ pub fn main() anyerror!void {
Component.Weapon,
Component.Position,
Component.Velocity,
Component.HeartOrgan,
});

// Initialize our storage
Expand All @@ -36,7 +38,16 @@ pub fn main() anyerror!void {
const Queries = struct {
pub const Living = Storage.Query(
// Any result item will be of this type
struct { health: *Component.Health, pos: Component.Position },
struct {
health: *Component.Health,
pos: Component.Position,
},
// include types:
.{
// Any query result must have the following components, but they wont be included in the result struct
Component.HeartOrgan,
},
// exclude types:
.{
// Exclude any entity with the following component
Component.DeadTag,
Expand All @@ -48,6 +59,7 @@ pub fn main() anyerror!void {
const my_living_entity = try storage.createEntity(.{
Component.Health{ .value = 42 },
Component.Position{},
Component.HeartOrgan{},
});

// You can unset components (remove)
Expand Down

0 comments on commit c0d43e4

Please sign in to comment.