#Knoedel-ECS. Bevy's api in Zig.

1 messages · Page 1 of 1 (latest)

cursive junco
cursive junco
#

Added some new features:

1.) Required Components

Components that are added together with the parent, if they are missing.

pub const Node = struct {
    pub const Required = .{ pre.GlobalTransform{}, Computed{}, pre.RenderLayer.ui, pre.NoInherit{} };
    // ...
}

Leading to clean ui trees and much better readable entity spawning.

_ = try cmd.spawn(.{
    ui.Node{ .align_x = .center, .align_y = .center },
    kn.StateScoped(pre.GameState){ .state = pre.GameState.Menu },
    kn.StateScoped(MenuState){ .state = MenuState.main },
    .{
        ui.Node{ .width = .{ .pixel = 520 }, .height = .{ .pixel = 600 }, .align_x = .center, .padding = .allPx(20), .display = .col, .gap = .{ .pixel = 20 } },
        ui.Background{ .rect = pre.SP.UI_PANEL },
        .{
            ui.Node{ .width = .grow, .align_x = .center, .padding = .yPx(50) },
            ui.Text.new("Put Title Here", .{}, 64),
        },
        .{
            ui.Node{ .width = .grow, .padding = .allPx(32) },
            ui.Background{ .rect = pre.SP.UI_PANEL },
            ui.Button{},
            ui.On{ .press = Switch(.selection), .hover = hover_sound },
            ui.Text.new("Play", .{}, 32),
        },
    },
});

2.) Instant calling Systems

Run any system function right now. Great, when you need precise order of execution in sync. Example in render

  try app.runInstant(&SpritePipeline.render_sys);

3.) Command queue

Any command function can now create new commands that get consumed in the same run iteration.

fn hover_sound(_: *anyopaque, world: *kn.App) !void {
    const cmd = world.getCommands();
    const assets = try world.getResource(pre.Assets);
    _ = try cmd.spawn(.{
        pre.Sound{
            .stream = try assets.load("./res/tool_3.ogg"),
            .ty = .Sfx,
            .volume = 0.2,
        },
    });
}