- [NEW] configuration file working.

- [NEW] zoom(), fullscreen(), cursor(), getconf(), setconf().
- [CHG] now zoom and fullscreen are controlled by the game, not by mini.
- [FIX] quit() now actually quits.
- [NEW] btnp() without parameters returns key pressed.
- [NEW] zoom, fullscreen and cursor are saved to config automatically.
This commit is contained in:
2023-01-18 17:41:57 +01:00
parent 4c0cf979d3
commit e53befb700
8 changed files with 207 additions and 18 deletions

View File

@@ -50,7 +50,7 @@ char *resource_folder = NULL;
DATA_File *data_file = NULL;
int file_source = SOURCE_FILE;
char scratch[255];
std::string config_folder = NULL;
std::string config_folder;
std::vector<keyvalue_t> config;
void file_setresourcefilename(const char *str) {
@@ -139,7 +139,7 @@ char *file_getfilebuffer(const char *resourcename, int& filesize) {
}
// Crea la carpeta del sistema donde guardar datos
void createSystemFolder(const char *foldername)
void file_setconfigfolder(const char *foldername)
{
#ifdef _WIN32
config_folder = std::string(getenv("APPDATA")) + "/" + foldername;
@@ -191,14 +191,18 @@ void file_loadconfigvalues() {
config.clear();
std::string config_file = config_folder + "/config.txt";
FILE *f = fopen(config_file.c_str(), "r");
if (f) {
while (!feof(f)) {
char key[100], value[100];
fscanf(f, "%s = %S", key, value);
config.push_back({key, value});
}
fclose(f);
}
if (!f) return;
char line[1024];
while (fgets(line, sizeof(line), f)) {
char *value = strchr(line, '=');
if (value) {
*value='\0'; value++;
value[strlen(value)-1] = '\0';
config.push_back({line, value});
}
}
fclose(f);
}
void file_saveconfigvalues() {
@@ -206,7 +210,7 @@ void file_saveconfigvalues() {
FILE *f = fopen(config_file.c_str(), "w");
if (f) {
for (auto pair : config) {
fprintf(f, "%s = %s\n", pair.key.c_str(), pair.value.c_str());
fprintf(f, "%s=%s\n", pair.key.c_str(), pair.value.c_str());
}
fclose(f);
}
@@ -225,7 +229,7 @@ const char* file_getconfigvalue(const char *key) {
void file_setconfigvalue(const char* key, const char* value) {
if (config.empty()) file_loadconfigvalues();
for (auto pair : config) {
for (auto &pair : config) {
if (pair.key == std::string(key)) {
pair.value = value;
file_saveconfigvalues();