const std = @import("std"); const Action = @import("../actions.zig").Action; const IOInterface = @import("io_interface.zig").IOInterface; pub const ActionStack = struct { stream: std.ArrayList(Action), pub fn init(allocator: std.mem.Allocator) ActionStack { return ActionStack{ .stream = std.ArrayList(Action).init(allocator), }; } pub fn deinit(self: *ActionStack) void { self.stream.deinit(); } pub fn scheduleAction(self: *ActionStack, action: Action) !void { try self.stream.append(action); } pub fn next(self: *ActionStack) ?Action { return self.stream.popOrNull(); } }; pub const IO = struct { allocator: std.mem.Allocator, as: ActionStack, out_as: ActionStack, pub fn displayMessage(self: *IO, str: []const u8) anyerror!void { _ = self; std.log.info("{s}\n", .{str}); } pub fn waitForTick(self: *IO) anyerror!Action { const a = self.as.next() orelse return error.NoAvailableAction; try self.out_as.scheduleAction(a); return a; } pub fn init(allocator: std.mem.Allocator, as: ActionStack) !IOInterface { var io = try allocator.create(IO); io.allocator = allocator; io.as = as; io.out_as = ActionStack.init(allocator); return IOInterface.init(io); } pub fn deinit(self: *IO) void { self.out_as.deinit(); self.allocator.destroy(self); } };