diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-25 21:47:58 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-09-25 21:48:16 -0300 |
| commit | 9c33714591a2147f7e5879e77212ca9886d0c967 (patch) | |
| tree | d250be9d9bc365d7894d49455c0f6376966b58be /test | |
| download | sketchbook-9c33714591a2147f7e5879e77212ca9886d0c967.tar.gz sketchbook-9c33714591a2147f7e5879e77212ca9886d0c967.zip | |
Put the game first: lib/sketchbook, sketches/vecanim
The root is the game. The platform library moves to lib/sketchbook (with
serve_web.py, which serves any sketch's web build, as a tool of it), and
vecanim to sketches/vecanim, still its own package on the same library.
Diffstat (limited to 'test')
| -rw-r--r-- | test/counter_v1.zig | 24 | ||||
| -rw-r--r-- | test/counter_v2.zig | 23 | ||||
| -rw-r--r-- | test/readme.zig | 16 | ||||
| -rw-r--r-- | test/reload.script | 18 |
4 files changed, 81 insertions, 0 deletions
diff --git a/test/counter_v1.zig b/test/counter_v1.zig new file mode 100644 index 0000000..28f7379 --- /dev/null +++ b/test/counter_v1.zig @@ -0,0 +1,24 @@ +//! Reload fixture, first build: counts clicks. +const sk = @import("sketch"); + +pub const name = "counter"; +pub const width = 320; +pub const height = 200; + +pub const State = struct { + clicks: u32 = 0, + label: enum(u8) { cold, warm } = .cold, + retired: f32 = 1, +}; + +pub fn update(state: *State, in: *const sk.Input) void { + for (in.events) |e| if (e.kind == .mouse_up) { + state.clicks += 1; + if (state.clicks >= 2) state.label = .warm; + }; +} + +pub fn draw(state: *const State, f: *sk.Frame) void { + f.clear(0x202830); + f.print(8, 8, 2, 0xffffff, "clicks {d}", .{state.clicks}); +} diff --git a/test/counter_v2.zig b/test/counter_v2.zig new file mode 100644 index 0000000..7771470 --- /dev/null +++ b/test/counter_v2.zig @@ -0,0 +1,23 @@ +//! Reload fixture, second build: a new field, one gone, the rest moved. +const sk = @import("sketch"); + +pub const name = "counter"; +pub const width = 320; +pub const height = 200; + +pub const State = struct { + streak: u16 = 7, + label: enum(u8) { cold, warm, hot } = .cold, + clicks: u32 = 0, +}; + +pub fn update(state: *State, in: *const sk.Input) void { + for (in.events) |e| if (e.kind == .mouse_up) { + state.clicks += 10; + }; +} + +pub fn draw(state: *const State, f: *sk.Frame) void { + f.clear(0x302820); + f.print(8, 8, 2, 0xffffff, "clicks {d} streak {d}", .{ state.clicks, state.streak }); +} diff --git a/test/readme.zig b/test/readme.zig new file mode 100644 index 0000000..70673db --- /dev/null +++ b/test/readme.zig @@ -0,0 +1,16 @@ +//! The example from README.md, compiled by `zig build test`. +const sk = @import("sketch"); + +pub const State = struct { x: f32 = 480, y: f32 = 300, hue: f32 = 0 }; + +pub fn update(s: *State, in: *const sk.Input) void { + if (in.pressed(sk.Key.space)) s.hue += 30; + s.x += (in.mouse_x - s.x) * 0.1; + s.y += (in.mouse_y - s.y) * 0.1; +} + +pub fn draw(s: *const State, f: *sk.Frame) void { + f.clear(0x202020); + f.fill(.{ .x = s.x - 10, .y = s.y - 10, .w = 20, .h = 20 }, 0xff8040); + f.print(8, 8, 2, 0xffffff, "hue {d}", .{s.hue}); +} diff --git a/test/reload.script b/test/reload.script new file mode 100644 index 0000000..863ecc6 --- /dev/null +++ b/test/reload.script @@ -0,0 +1,18 @@ +# The counter sketch reloads with a changed layout and keeps its values. +click 10 10 +click 10 10 +expect clicks 2 +expect label warm +console snapshot 3 +console save +load {v2} +expect clicks 2 +expect label warm +expect streak 7 +click 10 10 +expect clicks 12 +# The snapshot was migrated with the live state. +console load 3 +expect clicks 2 +console set streak 9 +expect streak 9 |
