Merge remote-tracking branch 'refs/remotes/origin/main'

This commit is contained in:
Dusk 2023-10-01 15:30:46 +02:00
commit 174c247e43
3 changed files with 49 additions and 25 deletions

View File

@ -5,7 +5,6 @@ const Self = @This();
const colors = @import("color.zig");
color: colors.Color = .{ 0, 0, 0, 0 },
textureTest: Texture,
const max_objects: usize = 16384;
const quadSize: usize = 9 * 6;
@ -13,17 +12,11 @@ const quadSize: usize = 9 * 6;
pub fn init() !Self {
rl.initWindow(1280, 720, "USG", 120);
var renderer = Self{
.textureTest = Texture.init("res/cell.png"),
};
return renderer;
return Self{};
}
pub fn render(self: *Self) void {
//_ = self;
self.textureTest.drawTo(20, 100, 160, 160, colors.pink);
_ = self;
rl.drawFPS(10, 10);
rl.endDrawing();

View File

@ -1,3 +1,5 @@
const Self = @This();
const rl = @import("raylib.zig");
const std = @import("std");
const config = @import("Config/config.zig");
@ -18,6 +20,12 @@ pub const Input = struct {
}
};
pub fn loadConfig() void {
for (comptime getInputNames()) |name| {
std.debug.print("{s}\n", .{name});
}
}
fn init(comptime name: []const u8, comptime key_code: []const u8) Input {
return Input{
.name = name,
@ -26,20 +34,6 @@ fn init(comptime name: []const u8, comptime key_code: []const u8) Input {
};
}
pub fn loadConfig() void {
var configIterator = config.getConfigIterator("input.ini") catch {
// Error opening config
std.debug.print("Cannot load input.ini configuration file, using default keybindings\n");
return;
};
// while (configIterator.next()) |option| {
// }
configIterator.deinit();
}
pub var menu_right = init("Menu Right", "RIGHT");
pub var menu_left = init("Menu Left", "LEFT");
pub var menu_down = init("Menu Down", "DOWN");
@ -54,3 +48,40 @@ pub var game_drop = init("Drop Piece", "W");
pub var game_swap_piece = init("Swap Piece", "SPACE");
pub var game_rotate_r = init("Rotate Piece Clockwise", "RIGHT");
pub var game_rotate_l = init("Rotate Piece Counterclockwise", "LEFT");
// Get the names of the Input(s) defined in this file with introspection
fn getInputNames() [getInputCount()][]const u8 {
comptime {
const decls = std.meta.declarations(Self);
var ret: [getInputCount()][]const u8 = undefined;
var i: usize = 0;
inline for (decls) |i_decl| {
const field = @field(Self, i_decl.name);
if (@TypeOf(field) == Input) {
ret[i] = i_decl.name;
i += 1;
}
}
return ret;
}
}
// With reflection count the amount of declarations of type "Input"
fn getInputCount() usize {
comptime {
const decls = std.meta.declarations(Self);
var i: usize = 0;
inline for (decls) |i_decl| {
const field = @field(Self, i_decl.name);
if (@TypeOf(field) == Input) i += 1;
}
return i;
}
}

View File

@ -8,10 +8,10 @@ const MainMenu = @import("MainMenu.zig");
const config = @import("Config/config.zig");
const State = @import("flow.zig").State;
const input = @import("input.zig");
pub fn main() !void {
input.loadConfig();
var renderer = try Renderer.init();
defer renderer.deinit();