mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 14:05:45 +01:00
begin adding options
added the basic framework of how options are loaded.
This commit is contained in:
21
src/game/opts.c
Normal file
21
src/game/opts.c
Normal file
@@ -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;
|
||||
}
|
||||
5
src/game/opts.h
Normal file
5
src/game/opts.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
int load_opts(void);
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user