Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
libtrx: pull Config_Read and Config_Write
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Sep 26, 2024
1 parent 310fe4d commit b587e40
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 32 deletions.
36 changes: 8 additions & 28 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,25 @@

#include "config_map.h"

#include <libtrx/config/config_file.h>
#include <libtrx/filesystem.h>
#include <libtrx/game/ui/events.h>
#include <libtrx/config/file.h>

CONFIG g_Config = { 0 };

#define DIR_CONFIG "cfg"
static const char *m_ConfigPath = "cfg/TR2X.json5";

static const char *m_ConfigPath = DIR_CONFIG "/TR2X.json5";

static void M_Load(JSON_OBJECT *root_obj);
static void M_Dump(JSON_OBJECT *root_obj);

static void M_Load(JSON_OBJECT *root_obj)
const char *Config_GetPath(void)
{
ConfigFile_LoadOptions(root_obj, g_ConfigOptionMap);
return m_ConfigPath;
}

static void M_Dump(JSON_OBJECT *root_obj)
void Config_LoadFromJSON(JSON_OBJECT *root_obj)
{
ConfigFile_DumpOptions(root_obj, g_ConfigOptionMap);
}

bool Config_Read(void)
{
return ConfigFile_Read(m_ConfigPath, &M_Load);
ConfigFile_LoadOptions(root_obj, g_ConfigOptionMap);
}

bool Config_Write(void)
void Config_DumpToJSON(JSON_OBJECT *root_obj)
{
const EVENT event = {
.name = "change",
.sender = NULL,
.data = NULL,
};
UI_Events_Fire(&event);

File_CreateDirectory(DIR_CONFIG);
return ConfigFile_Write(m_ConfigPath, &M_Dump);
ConfigFile_DumpOptions(root_obj, g_ConfigOptionMap);
}

void Config_Sanitize(void)
Expand Down
3 changes: 2 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <libtrx/config/config_option.h>
#include <libtrx/config/common.h>
#include <libtrx/config/option.h>

#include <stdbool.h>

Expand Down
2 changes: 1 addition & 1 deletion src/config_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "config.h"

// import order guard
#include <libtrx/config/config_map.h>
#include <libtrx/config/map.h>
// import order guard

#include "global/enum_str.h"
Expand Down
2 changes: 1 addition & 1 deletion src/config_map.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

#include <libtrx/config/config_option.h>
#include <libtrx/config/option.h>

extern const CONFIG_OPTION g_ConfigOptionMap[];

0 comments on commit b587e40

Please sign in to comment.