summaryrefslogtreecommitdiff
path: root/examples/vecanim/build.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-16 21:28:20 -0300
committerGabriel Schneider <[email protected]>2026-11-16 21:28:20 -0300
commit6933f99ddb2d7103515d26838496309a807bba26 (patch)
tree991c2fe7d4a57957222876e190fa4d16a0fb889c /examples/vecanim/build.zig
parent82fca5c9f29124f37f6dcd08e73e6999ce44a69d (diff)
downloadsketchbook-6933f99ddb2d7103515d26838496309a807bba26.tar.gz
sketchbook-6933f99ddb2d7103515d26838496309a807bba26.zip
Move standalone sketches into sketchbook examples
Diffstat (limited to 'examples/vecanim/build.zig')
-rw-r--r--examples/vecanim/build.zig31
1 files changed, 31 insertions, 0 deletions
diff --git a/examples/vecanim/build.zig b/examples/vecanim/build.zig
new file mode 100644
index 0000000..b7e5623
--- /dev/null
+++ b/examples/vecanim/build.zig
@@ -0,0 +1,31 @@
+const std = @import("std");
+const sketchbook = @import("sketchbook");
+
+pub fn build(b: *std.Build) void {
+ const target = b.standardTargetOptions(.{});
+ const optimize = b.standardOptimizeOption(.{});
+ const sb = sketchbook.init(b, .{ .target = target, .optimize = optimize });
+
+ // A scene is one file, played by sketchbook's `anim` player. `-Dscene`
+ // picks the one `run`, `lib`, `web` and `export` use; `test` plays each
+ // of these through its script.
+ const scenes = [_]struct { []const u8, []const u8 }{
+ .{ "scenes/intro.zig", "test/intro.script" },
+ .{ "scenes/live.zig", "test/live.script" },
+ };
+ const selected = b.option([]const u8, "scene", "The scene to play (default scenes/intro.zig)") orelse scenes[0][0];
+ const player = addPlayer(sb, selected);
+ const steps = player.app.addSteps(.{ .web = .{} });
+ for (scenes) |entry| {
+ const same = std.mem.eql(u8, entry[0], selected);
+ const each = if (same) player else addPlayer(sb, entry[0]);
+ const exe = if (same) steps.exe else each.app.addExecutable();
+ steps.e2e.dependOn(&each.app.addScript(exe, b.path(entry[1]), .{}).step);
+ }
+}
+
+/// The player built around one scene file, named after it (`vecanim-intro`),
+/// so that players of different scenes keep their own state and library.
+fn addPlayer(sb: sketchbook.Sketchbook, path: []const u8) sketchbook.Sketchbook.Scene {
+ return sb.addScene(.{ .name = sb.b.fmt("vecanim-{s}", .{std.fs.path.stem(path)}), .root_source_file = sb.b.path(path) });
+}