From 64a816dbe194c05e089729ac1fdc15061afdd903 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 16 Nov 2026 22:51:49 -0300 Subject: anim: talks: gates that let time run on, pause, beside, loop, clear, slides and the Deck A talk is a live scene re-run from the top every frame, a function of its time and of the gates opened so far. Frame.gate(open) waits while time runs on and records the value it opened with; pause() is the presenter's click. beside and loop are the sub-animations, slide() the second navigation level, clear() the end of a slide. anim.Deck is the playhead and the gate log as plain data for any sketch's State: update() takes an Ask (next, back, next_slide, back_slide, to, end) and runs the talk with the app mutable, shot() runs it read-only for drawing. A click during a step finishes it; back cuts to the picture held before the last click; an edit that moves the last opened gate moves t with it; exported, every gate holds Deck.hold. Live takes a namespace or a tuple of them (sources) and exposes frame. Builder.pause, Instant.clock and Frame.clock are gone: t runs through gates. A test-anim step runs the module's tests and the player's scenes. --- build.zig | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'build.zig') diff --git a/build.zig b/build.zig index 1933d92..9c6085c 100644 --- a/build.zig +++ b/build.zig @@ -164,13 +164,17 @@ pub fn build(b: *Build) void { for ([_]*Build.Module{ b.createModule(.{ .root_source_file = b.path("src/vector/root.zig"), .target = target, .optimize = optimize, .imports = vector_imports }), b.createModule(.{ .root_source_file = b.path("src/scope/root.zig"), .target = target, .optimize = optimize, .imports = scope_imports }), - b.createModule(.{ .root_source_file = b.path("src/anim/root.zig"), .target = target, .optimize = optimize, .imports = anim_imports }), b.createModule(.{ .root_source_file = b.path("src/glsl.zig"), .target = target, .optimize = optimize }), b.createModule(.{ .root_source_file = b.path("src/abi.zig"), .target = target, .optimize = optimize }), b.createModule(.{ .root_source_file = b.path("src/sketch/root.zig"), .target = target, .optimize = optimize, .imports = sketch_imports }), b.createModule(.{ .root_source_file = b.path("src/math/root.zig"), .target = target, .optimize = optimize }), b.createModule(.{ .root_source_file = b.path("src/host/root.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "abi", .module = abi }, .{ .name = "c", .module = c }, .{ .name = "gpu", .module = gpu }, .{ .name = "tracy", .module = tracy }, .{ .name = "cloud9", .module = cloud9 } } }), }) |module| test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = module })).step); + // The anim module alone: its unit tests, and below the player's scenes. + const test_anim = b.step("test-anim", "Test the anim module: its unit tests and the player on its test scenes"); + const anim_tests = b.addRunArtifact(b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("src/anim/root.zig"), .target = target, .optimize = optimize, .imports = anim_imports }) })); + test_anim.dependOn(&anim_tests.step); + test_step.dependOn(&anim_tests.step); // The noise tests again on wasm32 as the web builds it, under Node's // WASI: the golden bits must come out the same in the browser as @@ -234,13 +238,16 @@ pub fn build(b: *Build) void { // custom object between vector objects, and a compiled one, which is // also exported, at half size. const live = sb.addScene(.{ .root_source_file = b.path("test/scene_live.zig") }); - test_step.dependOn(&live.app.addScript(live.app.addExecutable(), b.path("test/scene_live.script"), .{}).step); + const live_script = live.app.addScript(live.app.addExecutable(), b.path("test/scene_live.script"), .{}); + test_step.dependOn(&live_script.step); + test_anim.dependOn(&live_script.step); const compiled = sb.addScene(.{ .root_source_file = b.path("test/scene_compiled.zig") }); const compiled_exe = compiled.app.addExecutable(); const compiled_script = compiled.app.addScript(compiled_exe, b.path("test/scene_compiled.script"), .{}); compiled_script.addArg("--define"); compiled_script.addPrefixedDirectoryArg("frames=", compiled.app.addExport(compiled_exe, .{ .fps = 30, .size = .{ 640, 360 }, .frames = 200 }).frames); test_step.dependOn(&compiled_script.step); + test_anim.dependOn(&compiled_script.step); // Both vector renderers against resvg, through the host (tools/svgdiff.py). const svgview = sb.app(.{ .name = "svgview", .root_source_file = b.path("test/svgview.zig"), .imports = &.{.{ .name = "vector", .module = sb.modules.vector }} }); -- cgit v1.3 From 6b07c3b2ee86592a28a713b4c6c40007c28eb6b8 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 16 Nov 2026 22:59:59 -0300 Subject: examples: a talk that runs its own Deck, and its script examples/talk.zig keeps an anim.Deck in its State beside its own data, turns clicks and keys into asks and paints with an anim.Painter: two slides, a mass that bobs (loop) while the deck waits, a damping slider laid out and hit-tested in the talk (it takes its clicks), a choice gate that branches on it, and slide 1 cleared beside slide 2's writing. test/talk.script (zig build test-talk) steps it, finishes a step on a click, goes back, jumps slides, drags the slider without advancing, reloads mid-wait with the first step retimed (same step, t a second later) and checks two exports with 2 s holds frame by frame. The vecanim live scene's words follow the new pause. --- build.zig | 22 ++++++ examples/talk.zig | 160 ++++++++++++++++++++++++++++++++++++++ examples/vecanim/scenes/live.zig | 7 +- examples/vecanim/test/live.script | 5 +- test/talk.script | 104 +++++++++++++++++++++++++ 5 files changed, 293 insertions(+), 5 deletions(-) create mode 100644 examples/talk.zig create mode 100644 test/talk.script (limited to 'build.zig') diff --git a/build.zig b/build.zig index 9c6085c..3739bcf 100644 --- a/build.zig +++ b/build.zig @@ -249,6 +249,28 @@ pub fn build(b: *Build) void { test_step.dependOn(&compiled_script.step); test_anim.dependOn(&compiled_script.step); + // The talk example: a Deck in a sketch's own State, stepped, sent back, + // jumped by slides, clicked on its slider, reloaded mid-wait with its + // first step retimed, and exported twice, with the same frames. + const talk_imports: []const Build.Module.Import = &.{ .{ .name = "anim", .module = sb.modules.anim }, .{ .name = "sketch", .module = sketch } }; + const talk = sb.app(.{ .name = "talk", .root_source_file = b.path("examples/talk.zig"), .imports = &.{ + .{ .name = "anim", .module = sb.modules.anim }, + .{ .name = "typst", .module = sb.addTypst(b.createModule(.{ .root_source_file = b.path("examples/talk.zig"), .imports = talk_imports })) }, + } }); + const talk_check = talk.addReloadCheck(.{ .script = b.path("test/talk.script"), .edits = &.{.{ + .file = "examples/talk.zig", + .old = "s.play(.{ title.write(), law.write() }, .{});", + .new = "s.play(.{ title.write(), law.write() }, .{ .seconds = 3 });", + }} }); + const talk_exe = talk.addExecutable(); + for ([_][]const u8{ "a", "b" }, [_]u64{ 400, 401 }) |define, frames| { + talk_check.run.addArg("--define"); + talk_check.run.addPrefixedDirectoryArg(b.fmt("{s}=", .{define}), talk.addExport(talk_exe, .{ .fps = 30, .frames = frames, .size = .{ 640, 360 } }).frames); + } + const test_talk = b.step("test-talk", "Play the talk example: steps, back, slides, its slider, a reload mid-wait and its export"); + test_talk.dependOn(&talk_check.run.step); + test_step.dependOn(&talk_check.run.step); + // Both vector renderers against resvg, through the host (tools/svgdiff.py). const svgview = sb.app(.{ .name = "svgview", .root_source_file = b.path("test/svgview.zig"), .imports = &.{.{ .name = "vector", .module = sb.modules.vector }} }); const diff = b.addSystemCommand(&.{ "python3", "tools/svgdiff.py" }); diff --git a/examples/talk.zig b/examples/talk.zig new file mode 100644 index 0000000..f2a2d9c --- /dev/null +++ b/examples/talk.zig @@ -0,0 +1,160 @@ +//! A talk in a sketch of its own: the sketch keeps an `anim.Deck` in its +//! State beside its own data, decides which keys and clicks step the talk, +//! and paints with an `anim.Painter`. The talk is a function run from the +//! top every frame; it may change the app in `update` (`anim.mutable`), +//! so the slider below is laid out, drawn and hit-tested in one place. +//! +//! click, space, right, page down next step left, page up back +//! ] / [ next / previous slide +const std = @import("std"); +const sk = @import("sketch"); +const anim = @import("anim"); +/// This file's Typst, compiled at build time (`sb.addTypst`). +const svgs = @import("typst"); + +pub const name = "talk"; +pub const width = anim.width; +pub const height = anim.height; + +pub const typst_preamble = + \\#set page(width: auto, height: auto, margin: 3pt, fill: none) + \\#set text(fill: rgb("#ece6e2"), size: 28pt) +; +pub const typst = struct { + pub const title = "#text(size: 40pt, weight: \"bold\")[Damping]"; + pub const law = "$ x'' + 2 zeta x' + x = 0 $"; + pub const hint = "#text(size: 18pt, fill: rgb(\"#58c4dd\"))[drag $zeta$, then go on]"; + pub const rings = "#text(size: 24pt)[$zeta < 1$: it rings]"; + pub const creeps = "#text(size: 24pt)[$zeta >= 1$: it creeps back]"; + pub const end = "#text(size: 32pt)[$zeta = 1$: home fastest, no overshoot]"; +}; +/// What the build compiles. +pub const scene = struct { + pub const typst_sources = anim.sources(.{typst}); +}; + +const App = struct { + zeta: f32 = 0.2, + /// The slider is held. + dragging: bool = false, +}; + +pub const State = struct { + deck: anim.Deck = .{ .hold = 2 }, + app: App = .{}, +}; + +pub const Session = struct { + painter: anim.Painter = .{}, +}; + +pub fn update(s: *State, in: *const sk.Input) void { + var ask: anim.Ask = .{}; + for (in.events) |e| switch (e.kind) { + // Every click is the presenter's, unless the talk takes it. + .mouse_up => ask.next = true, + .key_down => switch (@as(sk.Key, @fromBackingInt(@intCast(@as(u8, @truncate(e.code)))))) { + .space, .right, .page_down => ask.next = true, + .left, .page_up => ask.back = true, + .right_bracket => ask.next_slide = true, + .left_bracket => ask.back_slide = true, + else => {}, + }, + else => {}, + }; + s.deck.update(in, ask, talk, .{&s.app}); +} + +pub fn draw(s: *const State, ss: *Session, f: *sk.Frame) void { + const mouse = anim.Deck.pointer(f.in, f.in.mouse_x, f.in.mouse_y); + const shot = s.deck.shot(f.scratch, f.in, mouse, talk, .{&s.app}) catch |err| return f.host.print("talk: {t}", .{err}); + ss.painter.paint(f, shot, svgs, .{}) catch |err| f.host.print("paint: {t}", .{err}); + if (f.in.exporting and s.deck.t >= shot.duration) f.quit(); +} + +/// Run in `update` with `app: *App`, and drawn with `app: *const App`. +fn talk(s: *anim.Frame, app: anytype) void { + // Slide 1: the law, and a mass on a spring that bobs while we talk. + s.slide(); + const title = s.typst(typst.title, .{ .y = -270 }); + const law = s.typst(typst.law, .{ .y = -180 }); + const mass = s.rect(.{ .w = 60, .h = 60, .fill = anim.blue }); + s.play(.{ title.write(), law.write() }, .{}); + s.play(.{mass.fadeIn()}, .{ .seconds = 0.5 }); + s.loop(bob, .{mass}); + s.pause(); + + // The slider, laid out before the gate it waits at: a click on it is + // its own, not the presenter's. + const plot = s.custom(s.new(Plot{ .zeta = app.zeta }), .{}); + const hint = s.typst(typst.hint, .{ .y = 290 }); + s.play(.{ mass.fadeOut(), plot.fadeIn(), hint.fadeIn() }, .{ .seconds = 0.6 }); + if (anim.mutable(app)) |a| if (s.pose(plot).visible) drag(s, a); + // A choice: the regime the slider is in when the presenter goes on. + const regime = s.gate(if (s.next) @intFromBool(app.zeta >= 1) else null) orelse return; + const verdict = s.typst(if (regime == 0) typst.rings else typst.creeps, .{ .y = 290 }); + s.play(.{ hint.fadeOut(), verdict.write() }, .{ .seconds = 1 }); + s.pause(); + + // Slide 2, written while slide 1 goes. + s.beside(anim.Frame.clear, .{.{ .seconds = 0.8 }}); + s.slide(); + s.play(.{s.typst(typst.end, .{}).write()}, .{}); +} + +/// Down and up again, in a second. +fn bob(s: *anim.Frame, mass: anim.Obj) void { + s.play(.{mass.move(.{ .y = 80 })}, .{ .seconds = 0.5 }); + s.play(.{mass.move(.{ .y = 0 })}, .{ .seconds = 0.5 }); +} + +/// The slider's track, in scene units: zeta from 0 to 2 along it. +const track: sk.Rect = .{ .x = -300, .y = 200, .w = 600, .h = 40 }; + +/// The slider follows a press on it to where it is let go, and takes that +/// click: it is not the presenter's next. +fn drag(s: *anim.Frame, app: *App) void { + for (s.events) |e| { + if (e.kind != .mouse_down and e.kind != .mouse_move and e.kind != .mouse_up) continue; + if (e.kind == .mouse_down) app.dragging = track.contains(e.x, e.y); + if (!app.dragging) continue; + app.zeta = std.math.clamp((e.x - track.x) / track.w * 2, 0, 2); + if (e.kind == .mouse_up) { + app.dragging = false; + s.next = false; + } + } +} + +/// The motion zeta makes, x(t) from x = 1 at rest, over the slider: a +/// custom object at the scene's origin, so its units are scene units. +const Plot = struct { + zeta: f32, + + pub fn draw(p: *const Plot, f: *sk.Frame, at: anim.Placed) void { + var points: [121]sk.math.Vec = undefined; + for (&points, 0..) |*q, i| { + const t: f32 = @as(f32, @floatFromInt(i)) / 10; + q.* = .{ -300 + 50 * t, 60 - 120 * response(p.zeta, t) }; + } + sk.draw.line(f, .{ -300, 60 }, .{ 300, 60 }, at.pen(.{ .stroke = .hex(0x8c8c8c), .width = 1 })); + sk.draw.polyline(f, &points, at.pen(.{ .stroke = .hex(anim.yellow), .width = 3 })); + sk.draw.rect(f, .{ .x = track.x, .y = track.y + 18, .w = track.w, .h = 4 }, at.pen(.{ .fill = .hex(0x8c8c8c) })); + sk.draw.circle(f, .{ track.x + p.zeta / 2 * track.w, track.y + 20 }, 14, at.pen(.{ .fill = .hex(anim.blue) })); + var label: [16]u8 = undefined; + at.text(f, track.x + p.zeta / 2 * track.w - 30, track.y - 22, 1.5, std.fmt.bufPrint(&label, "{d:.2}", .{p.zeta}) catch "", .white); + } +}; + +/// x(t) of x'' + 2 zeta x' + x = 0 from x = 1, x' = 0. +fn response(zeta: f32, t: f32) f32 { + if (zeta < 1) { + const w = @sqrt(1 - zeta * zeta); + return @exp(-zeta * t) * (@cos(w * t) + zeta / w * @sin(w * t)); + } + if (zeta == 1) return @exp(-t) * (1 + t); + const r = @sqrt(zeta * zeta - 1); + const a = -zeta + r; + const b = -zeta - r; + return (b * @exp(a * t) - a * @exp(b * t)) / (b - a); +} diff --git a/examples/vecanim/scenes/live.zig b/examples/vecanim/scenes/live.zig index 4af7998..9b94d17 100644 --- a/examples/vecanim/scenes/live.zig +++ b/examples/vecanim/scenes/live.zig @@ -1,6 +1,7 @@ //! A live scene, presented like slides: `frame` runs every frame, so the -//! code after the plays can follow the mouse, the clock or any data, and -//! `pause` holds until a click. Everything it needs is in this file. +//! code after the plays can follow the mouse, the time or any data, and +//! what comes after a `pause` waits for a click while time runs on. +//! Everything it needs is in this file. const anim = @import("anim"); pub const typst_preamble = @@ -28,7 +29,7 @@ fn frame(s: *anim.Frame) void { s.play(.{ title.fadeOut(), hint.fadeOut() }, .{ .seconds = 0.6 }); // A wave of dots: its height is a value the timeline animates, its - // phase the wall clock, which runs on through pauses. + // phase the scene's time, which runs on while a pause waits. const wave = s.typst(typst.wave, .{ .y = -220, .scale = 1.2 }); const note = s.typst(typst.note, .{ .y = 230 }); const height = s.value(0); diff --git a/examples/vecanim/test/live.script b/examples/vecanim/test/live.script index a3ddcdc..d955b6f 100644 --- a/examples/vecanim/test/live.script +++ b/examples/vecanim/test/live.script @@ -1,5 +1,6 @@ -# Plays the live scene headless: it holds at each pause until a click, the -# dots follow the pointer, and the guides draw over everything. +# Plays the live scene headless: it waits at each pause for a click, the +# wave running on, the dots follow the pointer, and the guides draw over +# everything. frames 150 expect t 2 screenshot .zig-cache/e2e/live-title.png diff --git a/test/talk.script b/test/talk.script new file mode 100644 index 0000000..e123d59 --- /dev/null +++ b/test/talk.script @@ -0,0 +1,104 @@ +# The talk example (examples/talk.zig): a Deck in the sketch's own State, +# stepped by the clicks and keys the sketch turns into asks. +frames 90 +expect deck.waiting false +expect deck.slide 1 +# Slide 2 lies after the choice, which has not been made. +expect deck.slides 1 +# A click during the first step finishes it: held at the first pause. +click 100 100 +expect deck.t 2.5 ~0.0001 +expect deck.waiting true +expect deck.log.len 0 +# The mass bobs while the deck waits. +screenshot .zig-cache/talk/bob-a.png +frames 14 +screenshot .zig-cache/talk/bob-b.png +expect-different-screenshot .zig-cache/talk/bob-a.png .zig-cache/talk/bob-b.png +# The next click opens the pause where it lands: the slider comes in, and +# the deck waits at the choice. +click 100 100 +expect deck.log.len 1 +expect deck.log.buffer[0].wait 0.2833 ~0.001 +await deck.waiting true +frames 5 +# Reloaded mid-wait, the first step retimed from 2 s to 3: the same step, +# as far into it, a second later. +console set deck.playing false +expect deck.t 3.4833 ~0.001 +load {v2} +expect deck.t 4.4833 ~0.001 +expect deck.waiting true +expect deck.log.len 1 +expect deck.log.buffer[0].wait 0.2833 ~0.001 +console set deck.playing true +# A click on the slider is the slider's: zeta goes there, the deck stays. +click 790 580 +expect app.zeta 1.5 ~0.01 +expect deck.log.len 1 +expect deck.waiting true +# So is a drag along it, let go and all. +down 640 580 +move 400 580 +up 400 580 +expect app.zeta 0.2 ~0.01 +expect app.dragging false +expect deck.log.len 1 +expect deck.waiting true +# Going on chooses by the slider: under 1, it rings; slide 2 is laid. +key space +expect deck.log.len 2 +expect deck.log.buffer[1].value 0 +expect deck.slides 2 +frames 90 +screenshot .zig-cache/talk/rings.png +# Back: held at the choice again; over 1, it creeps. +key page_up +expect deck.log.len 1 +expect deck.waiting true +click 840 580 +expect app.zeta 1.667 ~0.01 +key space +expect deck.log.len 2 +expect deck.log.buffer[1].value 1 +frames 90 +screenshot .zig-cache/talk/creeps.png +expect-different-screenshot .zig-cache/talk/rings.png .zig-cache/talk/creeps.png +# Slide 2 at rest: it holds no pause, so its end. +key right_bracket +expect deck.slide 2 +expect deck.log.len 3 +expect deck.waiting false +# Back a slide: slide 1 at rest, held at its first pause (3 s of writing +# in this build, then the mass). +key left_bracket +expect deck.slide 1 +expect deck.log.len 0 +expect deck.t 3.5 ~0.0001 +expect deck.waiting true +# Recorded, clicks, the slider and keys replay to the same State: the deck +# opens gates in update, from events and State alone. +console record 0 +click 100 100 +frames 40 +click 790 580 +key space +frames 30 +key page_up +key right_bracket +frames 10 +console save 2 +console play 0 +frames 120 +expect-snapshot 2 +console stop +# Exported ({a}, {b}: 30 fps, half size), each gate holds 2 s: the mass +# bobs through the first hold (to 4.5 s), nothing moves at the choice +# (5.1 to 7.1 s), and the verdict writes after it. Twice, the same frames. +expect-different-screenshot {a}/000080.png {a}/000090.png +expect-different-screenshot {a}/000130.png {a}/000170.png +expect-same-screenshot {a}/000170.png {a}/000200.png +expect-different-screenshot {a}/000200.png {a}/000230.png +expect-same-screenshot {a}/000080.png {b}/000080.png +expect-same-screenshot {a}/000230.png {b}/000230.png +expect-same-screenshot {a}/000350.png {b}/000350.png -- cgit v1.3 From bc6fe168278957ad15cf87826c8410e7358e0849 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 16 Nov 2026 23:07:39 -0300 Subject: anim: Event.key, and the talk example runs in a window An Event says its key (abi.Event.key), which the player and the talk example each spelled out by hand; `zig build talk` shows examples/talk.zig in a window on the generic host, its state under .zig-cache, and `zig build talk-lib --watch` beside it reloads every edit in place. Co-Authored-By: Claude Fable 5.2 --- build.zig | 5 +++++ examples/talk.zig | 2 +- src/abi.zig | 5 +++++ src/anim/player.zig | 6 +----- 4 files changed, 12 insertions(+), 6 deletions(-) (limited to 'build.zig') diff --git a/build.zig b/build.zig index 3739bcf..cb47d8a 100644 --- a/build.zig +++ b/build.zig @@ -267,6 +267,11 @@ pub fn build(b: *Build) void { talk_check.run.addArg("--define"); talk_check.run.addPrefixedDirectoryArg(b.fmt("{s}=", .{define}), talk.addExport(talk_exe, .{ .fps = 30, .frames = frames, .size = .{ 640, 360 } }).frames); } + // `zig build talk` shows it in a window; `zig build talk-lib --watch` + // beside it reloads every edit in place. + const talk_lib = talk.addLibrary(); + b.step("talk", "Run the talk example in a window (reload edits with `zig build talk-lib --watch`)").dependOn(&talk.addRun(talk_lib, .{ .state = ".zig-cache/talk.state" }).step); + b.step("talk-lib", "Build and install the talk example's hot-reloadable library").dependOn(&b.addInstallArtifact(talk_lib, .{}).step); const test_talk = b.step("test-talk", "Play the talk example: steps, back, slides, its slider, a reload mid-wait and its export"); test_talk.dependOn(&talk_check.run.step); test_step.dependOn(&talk_check.run.step); diff --git a/examples/talk.zig b/examples/talk.zig index f2a2d9c..2ad3d70 100644 --- a/examples/talk.zig +++ b/examples/talk.zig @@ -53,7 +53,7 @@ pub fn update(s: *State, in: *const sk.Input) void { for (in.events) |e| switch (e.kind) { // Every click is the presenter's, unless the talk takes it. .mouse_up => ask.next = true, - .key_down => switch (@as(sk.Key, @fromBackingInt(@intCast(@as(u8, @truncate(e.code)))))) { + .key_down => switch (e.key()) { .space, .right, .page_down => ask.next = true, .left, .page_up => ask.back = true, .right_bracket => ask.next_slide = true, diff --git a/src/abi.zig b/src/abi.zig index 7177f14..af106af 100644 --- a/src/abi.zig +++ b/src/abi.zig @@ -114,6 +114,11 @@ pub const Event = extern struct { /// `flags` bit for a held key's auto-repeat. pub const repeat: u8 = 1; + /// The key of a `key_down` or `key_up`. + pub fn key(e: Event) Key { + return @fromBackingInt(@intCast(@as(u8, @truncate(e.code)))); + } + /// For mouse and wheel events: the modifier keys held as it happened, /// as `Key.Mod` bits. Read this rather than `Input.held`, which is the /// state after the frame's events, and misses modifiers that come with diff --git a/src/anim/player.zig b/src/anim/player.zig index 3b0662d..b329714 100644 --- a/src/anim/player.zig +++ b/src/anim/player.zig @@ -71,7 +71,7 @@ pub fn update(s: *State, in: *const sk.Input) void { var ask: anim.Ask = .{}; var mark: enum { none, previous, next } = .none; for (in.events) |e| switch (e.kind) { - .key_down => if (e.flags & sk.Event.repeat == 0 or key(e) == .left or key(e) == .right or key(e) == .comma or key(e) == .period) switch (key(e)) { + .key_down => if (e.flags & sk.Event.repeat == 0 or e.key() == .left or e.key() == .right or e.key() == .comma or e.key() == .period) switch (e.key()) { .space => if (talking) { ask.next = true; } else { @@ -126,10 +126,6 @@ pub fn update(s: *State, in: *const sk.Input) void { d.update(in, ask, talk, .{}); } -fn key(e: sk.Event) sk.Key { - return @fromBackingInt(@intCast(@as(u8, @truncate(e.code)))); -} - /// The scene at the deck's `t`: a live one through the deck, with its gates. fn shotNow(s: *const State, arena: std.mem.Allocator, in: *const sk.Input, mouse: [2]f32) !anim.Shot { if (@hasDecl(scene, "frame")) return s.deck.shot(arena, in, mouse, scene.frame, .{}); -- cgit v1.3