const std = @import("std"); const rl = @cImport(@cInclude("raylib.h")); const root = @import("root.zig"); const Animation = @import("Animation.zig"); pub var camera: rl.Camera2D = undefined; pub var grid: []root.MyRect = undefined; pub const Grid = struct { buffer: std.MultiArrayList(root.Hex), cursor: usize, size: usize, const GridError = error{ OutOfBounds, }; //TODO think about what size really means pub fn init( allocator: std.mem.Allocator, size: usize, ) !Grid { var buffer: std.MultiArrayList(root.Hex) = .{}; try buffer.ensureTotalCapacity(allocator, size * size); return .{ .buffer = buffer, .cursor = 0, .size = size, }; } // should only be used when standing up the buffer, afterwards should use q, r indexing pub fn initPush(self: *Grid, hex: root.Hex) GridError!void { if (self.cursor >= self.size * 2) { return GridError.OutOfBounds; } self.buffer.insertAssumeCapacity(self.cursor, hex); } pub fn set(self: *Grid, hex: root.Hex) GridError!void { const idx = hex.qr[1] * self.size + hex.qr[0]; if (idx >= self.size * 2) { return GridError.OutOfBounds; } self.buffer.set(idx, hex); } }; pub var hex_grid: Grid = undefined; pub var hovered_coords: root.HexCoord = root.HexCoord{ .q = 0, .r = 0 }; pub var hovered_handle: ?usize = null; pub const Dude = struct { world_coords: rl.Vector2, hex_coords: root.HexCoord, target_coords: root.HexCoord, animation: Animation, }; pub var main_dude: Dude = undefined; var Gpa = std.heap.GeneralPurposeAllocator(.{}){}; pub var gpa: std.mem.Allocator = Gpa.allocator();