feat: runtime content processing, supporting glue

This commit is contained in:
Brett Broadhurst 2026-03-30 16:47:05 -06:00
parent d325cdf965
commit f5eac49729
Failed to generate hash of commit
12 changed files with 387 additions and 286 deletions

View file

@ -108,28 +108,29 @@ fn mainArgs(
return if (!compile_only) run(gpa, &story);
}
fn run(gpa: std.mem.Allocator, story: *Story) !void {
fn run(_: std.mem.Allocator, story: *Story) !void {
const stdin = std.fs.File.stdin();
var stdin_reader = stdin.reader(&stdin_buffer);
const stdout = std.fs.File.stdin();
var stdout_writer = stdout.writer(&stdout_buffer);
const reader = &stdin_reader.interface;
const writer = &stdout_writer.interface;
while (!story.is_exited and story.can_advance) {
while (story.can_advance) {
const content_text = try story.advance(gpa);
defer gpa.free(content_text);
std.debug.print("{s}\n", .{content_text});
while (try story.advance()) |content| {
try writer.print("{s}\n", .{content});
try writer.flush();
}
if (story.current_choices.items.len > 0) {
for (story.current_choices.items, 0..) |*choice, index| {
const choice_text = try choice.text.toOwnedSlice(gpa);
defer gpa.free(choice_text);
std.debug.print("[{d}]: {s}\n", .{ index + 1, choice_text });
for (story.current_choices.items, 0..) |choice, index| {
try writer.print("[{d}]: {s}\n", .{ index + 1, choice.content });
}
std.debug.print("> ", .{});
try writer.writeAll("> ");
try writer.flush();
const input_line = try stdin_reader.interface.takeDelimiter('\n');
if (input_line) |bytes| {
const choice_index = try std.fmt.parseUnsigned(usize, bytes, 10);
try story.selectChoiceIndex(if (choice_index == 0) 0 else choice_index - 1);
if (try reader.takeDelimiter('\n')) |bytes| {
const index = try std.fmt.parseUnsigned(usize, bytes, 10);
try story.selectChoiceIndex(if (index > 0) index - 1 else index);
}
}
}