From be50d94f78013d5920dbc93866dfc8119ee0f8a6 Mon Sep 17 00:00:00 2001 From: dusk Date: Wed, 27 Sep 2023 21:08:04 +0200 Subject: [PATCH] Load config test --- src/Config/config.zig | 28 ++++++++++++++++++++++++++++ src/main.zig | 4 ++++ 2 files changed, 32 insertions(+) create mode 100644 src/Config/config.zig diff --git a/src/Config/config.zig b/src/Config/config.zig new file mode 100644 index 0000000..7ed5ccc --- /dev/null +++ b/src/Config/config.zig @@ -0,0 +1,28 @@ +const std = @import("std"); +const fs = std.fs; +const io = std.io; + +pub fn getConfig(path: []const u8) void { + var file = fs.cwd().createFile(path, .{.read = true, .truncate = false}) catch |err| { + // TODO: Tirar error cap a dalt + std.debug.print("Error opening config file '{s}': {any}", .{ path, err }); + return; + }; + defer file.close(); + + var buf: [256]u8 = undefined; + + var fbs = io.fixedBufferStream(&buf); + + var reader = file.reader(); + + while (true) { + reader.streamUntilDelimiter(fbs.writer(), '\n', buf.len) catch |err| { + std.debug.print("{any}\n", .{err}); + break; + }; + defer fbs.reset(); + + std.debug.print("{s}\n", .{fbs.getWritten()}); + } +} diff --git a/src/main.zig b/src/main.zig index ae7520f..ceea022 100644 --- a/src/main.zig +++ b/src/main.zig @@ -5,10 +5,14 @@ const shouldClose = @import("raylib.zig").windowShouldClose; const Renderer = @import("Renderer.zig"); const Game = @import("Game.zig"); const MainMenu = @import("MainMenu.zig"); +const config = @import("Config/config.zig"); const State = @import("flow.zig").State; pub fn main() !void { + + config.getConfig("test"); + var renderer = try Renderer.init(); defer renderer.deinit();