From 45e5ec97643bdec964602c3b72e5a6e47435d072 Mon Sep 17 00:00:00 2001 From: Quinn Date: Fri, 18 Apr 2025 21:38:09 +0200 Subject: [PATCH] begin adding options added the basic framework of how options are loaded. --- src/game/opts.c | 21 +++++++++++++++++++++ src/game/opts.h | 5 +++++ src/game/paths.c | 7 +++++-- src/game/paths.h | 1 + 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/game/opts.c create mode 100644 src/game/opts.h diff --git a/src/game/opts.c b/src/game/opts.c new file mode 100644 index 0000000..5a7c651 --- /dev/null +++ b/src/game/opts.c @@ -0,0 +1,21 @@ +#include "../error.h" +#include "../util/compat.h" +#include "paths.h" + +/* attempts to load the options, + returns 1 upon failure */ +int load_opts(void) { + if (!path_opts) return 1; + if (!faccess(path_opts, FA_W | FA_R)) { + error("attempted to load opts file, but the given path wasn't writable"); + return 1; + } + + // TODO: load opts from the file + // the options shall be loaded as key-value-pairs + // lines starting with # are seen as comments + // the keys are stored on the left size, and the values on the right. + // if a field couldn't be parsed the program is not allowed to fail. I'd say we fix the field for the user. + + return 0; +} diff --git a/src/game/opts.h b/src/game/opts.h new file mode 100644 index 0000000..87657e0 --- /dev/null +++ b/src/game/opts.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +int load_opts(void); diff --git a/src/game/paths.c b/src/game/paths.c index 237446a..51e41be 100644 --- a/src/game/paths.c +++ b/src/game/paths.c @@ -6,6 +6,7 @@ #include "../util/compat.h" char const* restrict path_dat = NULL; +char const* restrict path_opts = NULL; char const* restrict path_font = NULL; char const* restrict path_music = NULL; char const* restrict path_place_sfx = NULL; @@ -52,14 +53,16 @@ int paths_init(void) { if (!len) return 1; // these are explicitly static, as string literals just work like that - path_font = init_path("pixeldroid_botic-regular.ttf", len + 28); + path_opts = init_path("opts", len + 4); // TODO: shouldn't opts be stored at .config/? + path_font = init_path("pixeldroid_botic-regular.ttf", len + 28); // TODO: these three paths should not be stored like opts path_music = init_path("korobeiniki.wav", len + 15); path_place_sfx = init_path("place.wav", len + 9); - return -(!path_font || !path_music || !path_place_sfx); + return -(!path_opts || !path_font || !path_music || !path_place_sfx); } void paths_free(void) { free((void*)path_dat), path_dat = NULL; + free((void*)path_opts), path_opts = NULL; free((void*)path_music), path_music = NULL; free((void*)path_place_sfx), path_place_sfx = NULL; } diff --git a/src/game/paths.h b/src/game/paths.h index 10bc66a..7f4c0f3 100644 --- a/src/game/paths.h +++ b/src/game/paths.h @@ -1,6 +1,7 @@ #pragma once extern char const* restrict path_dat; +extern char const* restrict path_opts; extern char const* restrict path_font; extern char const* restrict path_music; extern char const* restrict path_place_sfx;