Load config test

This commit is contained in:
Dusk 2023-09-27 21:08:04 +02:00
parent e72ab56197
commit be50d94f78
2 changed files with 32 additions and 0 deletions

28
src/Config/config.zig Normal file
View File

@ -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()});
}
}

View File

@ -5,10 +5,14 @@ const shouldClose = @import("raylib.zig").windowShouldClose;
const Renderer = @import("Renderer.zig"); const Renderer = @import("Renderer.zig");
const Game = @import("Game.zig"); const Game = @import("Game.zig");
const MainMenu = @import("MainMenu.zig"); const MainMenu = @import("MainMenu.zig");
const config = @import("Config/config.zig");
const State = @import("flow.zig").State; const State = @import("flow.zig").State;
pub fn main() !void { pub fn main() !void {
config.getConfig("test");
var renderer = try Renderer.init(); var renderer = try Renderer.init();
defer renderer.deinit(); defer renderer.deinit();