summaryrefslogtreecommitdiff
path: root/src/host/Host.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-25 21:53:00 -0300
committerGabriel Schneider <[email protected]>2026-09-25 21:54:39 -0300
commit2dfddee8c6fab6eb76cbfe3d95f7c30bfb870702 (patch)
tree32a8bbb55226721834fd5675e7bafc163508dd1e /src/host/Host.zig
parent50f4ee716aeafa13118cbcfa0f5cb37f7d3940a4 (diff)
downloadsketchbook-2dfddee8c6fab6eb76cbfe3d95f7c30bfb870702.tar.gz
sketchbook-2dfddee8c6fab6eb76cbfe3d95f7c30bfb870702.zip
sketchbook: what the game's review needed
- input.started: true on the first update of a run, never after a reload, for a sketch to stop what should not resume from saved state. - A console line that errors fails its script. Sketch commands answer unknown, done or failed (abi.Outcome) instead of a bool that hid errors. - addScript also takes the hot-reloadable library, run through the generic host, so scripts can reload a real build. - Sounds that do not load are .none, not an empty clip. - sk_tag reads an enum field's tag name from the web build, for tests.
Diffstat (limited to 'src/host/Host.zig')
-rw-r--r--src/host/Host.zig19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/host/Host.zig b/src/host/Host.zig
index 81a5dc8..92d1b55 100644
--- a/src/host/Host.zig
+++ b/src/host/Host.zig
@@ -67,6 +67,7 @@ canvas: [2]u32 = .{ 0, 0 },
cursor: abi.Cursor = .arrow,
quit: bool = false,
reloaded: bool = true,
+started: bool = true,
last_now: u64 = 0,
/// Saved after the next frame is drawn (scripts).
screenshot: ?[:0]const u8 = null,
@@ -223,6 +224,8 @@ pub fn update(self: *Host, events: []const abi.Event) void {
if (events.len > 0 and self.timeline.mode != .live and self.timeline.mode != .recording) self.input.now = events[events.len - 1].time;
self.input.events = events;
self.input.mode = self.timeline.mode;
+ self.input.started = self.started;
+ self.started = false;
const ctx = self.context();
self.sketch.update(&ctx, self.live().ptr);
self.input.events = &.{};
@@ -307,7 +310,7 @@ pub fn route(self: *Host, e: abi.Event) !void {
},
.key_down => {
const key = consoleKey(e) orelse return;
- if (self.console.edit(key, self.completions)) |line| self.runLine(line, e.time);
+ if (self.console.edit(key, self.completions)) |line| self.runLine(line, e.time) catch {};
return;
},
.key_up => return,
@@ -319,17 +322,19 @@ pub fn route(self: *Host, e: abi.Event) !void {
try self.pending.append(self.gpa, e);
}
-/// Runs a console line now, replaying whatever a seek asks for.
-pub fn runLine(self: *Host, line: []const u8, now: u64) void {
+/// Runs a console line now, replaying whatever a seek asks for. An error is
+/// printed to the console, and returned for scripts to fail on.
+pub fn runLine(self: *Host, line: []const u8, now: u64) !void {
const replay = self.console.execute(self, line, now) catch |err| {
- self.console.print("{t}. Type help for usage.", .{err});
- return;
+ // The sketch has printed its own error already.
+ if (err != error.CommandFailed) self.console.print("{t}. Type help for usage.", .{err});
+ return err;
};
if (self.timeline.mode == .paused) self.update(replay);
}
-/// Offers a line to the sketch; false if it did not take it.
-pub fn forward(self: *Host, _: *Console, line: []const u8, now: u64) bool {
+/// Offers a line to the sketch.
+pub fn forward(self: *Host, _: *Console, line: []const u8, now: u64) abi.Outcome {
self.input.now = now;
const ctx = self.context();
return self.sketch.command(&ctx, self.live().ptr, self.session.bytes.ptr, &line);