mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 11:26:18 -04:00
0ae0938965
During level extraction, the last 4 characters of the level name are always removed, because it is assumed that '-vis' is there. But it isn't always there. This is especially true in post-TPL games. This causes multiple problems: - There can be levels in the extraction that will miss their last 4 characters from their name, which is sad, and may make it harder to identify them. - If there are '-vis'-less levels whose names are identical apart from the last 4 characters, the extractor will only get the last one (it probably extracts all but overwrites everything but the last one). For example 'ctyasha' and 'ctykora'. This issue affects the glb extraction and the entities json extraction. I personally think that just keeping the -vis in the name would be the best solution, but I guess there was a reason why it was decided that it should be removed from the name. So to adapt to this, my implementation will still remove '-vis' from the name, but only if it is actually in the name - otherwise it won't remove anything. I hope my changes didn't break anything. Extraction seemed to run fine after my changes, and I was able to see both ctyasha and ctykora json files. And didn't see any '-vis', so it is still properly removed. --------- Co-authored-by: Tyler Wilding <xtvaser@gmail.com>
141 lines
4.7 KiB
C++
141 lines
4.7 KiB
C++
#include "settings.h"
|
|
|
|
#include "common/log/log.h"
|
|
#include "common/util/json_util.h"
|
|
|
|
#include "game/runtime.h"
|
|
|
|
namespace game_settings {
|
|
|
|
void to_json(json& j, const DebugSettings& obj) {
|
|
json_serialize(version);
|
|
json_serialize(show_imgui);
|
|
json_serialize(imgui_font_size);
|
|
json_serialize(monospaced_font);
|
|
json_serialize(alternate_style);
|
|
json_serialize(ignore_hide_imgui);
|
|
json_serialize(text_filters);
|
|
json_serialize(text_check_range);
|
|
json_serialize(text_max_range);
|
|
json_serialize(hide_imgui_key);
|
|
}
|
|
|
|
void from_json(const json& j, DebugSettings& obj) {
|
|
json_deserialize_if_exists(version);
|
|
json_deserialize_if_exists(show_imgui);
|
|
json_deserialize_if_exists(imgui_font_size);
|
|
json_deserialize_if_exists(monospaced_font);
|
|
json_deserialize_if_exists(alternate_style);
|
|
json_deserialize_if_exists(ignore_hide_imgui);
|
|
json_deserialize_if_exists(text_filters);
|
|
json_deserialize_if_exists(text_check_range);
|
|
json_deserialize_if_exists(text_max_range);
|
|
json_deserialize_if_exists(hide_imgui_key);
|
|
}
|
|
|
|
DebugSettings::DebugSettings() {
|
|
try {
|
|
std::string file_path =
|
|
(file_util::get_user_misc_dir(g_game_version) / "debug-settings.json").string();
|
|
if (!file_util::file_exists(file_path)) {
|
|
return;
|
|
}
|
|
lg::info("Loading debug settings at {}", file_path);
|
|
auto raw = file_util::read_text_file(file_path);
|
|
from_json(parse_commented_json(raw, "debug-settings.json"), *this);
|
|
} catch (std::exception& e) {
|
|
// do nothing
|
|
lg::error("Error encountered when attempting to load debug settings {}", e.what());
|
|
// TODO - make sure a bad debug-settings.json is fine, check others below as well
|
|
}
|
|
}
|
|
|
|
void DebugSettings::save_settings() {
|
|
json data = *this;
|
|
auto debug_settings_filename =
|
|
file_util::get_user_misc_dir(g_game_version) / "debug-settings.json";
|
|
file_util::create_dir_if_needed_for_file(debug_settings_filename);
|
|
file_util::write_text_file(debug_settings_filename, data.dump(2));
|
|
}
|
|
|
|
void to_json(json& j, const DisplaySettings& obj) {
|
|
json_serialize(version);
|
|
json_serialize(display_id);
|
|
json_serialize(window_xpos);
|
|
json_serialize(window_ypos);
|
|
}
|
|
void from_json(const json& j, DisplaySettings& obj) {
|
|
json_deserialize_if_exists(version);
|
|
json_deserialize_if_exists(display_id);
|
|
json_deserialize_if_exists(window_xpos);
|
|
json_deserialize_if_exists(window_ypos);
|
|
}
|
|
|
|
DisplaySettings::DisplaySettings() {
|
|
try {
|
|
std::string file_path =
|
|
(file_util::get_user_settings_dir(g_game_version) / "display-settings.json").string();
|
|
if (!file_util::file_exists(file_path)) {
|
|
return;
|
|
}
|
|
lg::info("Loading display settings at {}", file_path);
|
|
auto raw = file_util::read_text_file(file_path);
|
|
from_json(parse_commented_json(raw, "display-settings.json"), *this);
|
|
} catch (std::exception& e) {
|
|
// do nothing
|
|
lg::error("Error encountered when attempting to load display settings {}", e.what());
|
|
}
|
|
}
|
|
|
|
void DisplaySettings::save_settings() {
|
|
json data = *this;
|
|
auto file_path = file_util::get_user_settings_dir(g_game_version) / "display-settings.json";
|
|
file_util::create_dir_if_needed_for_file(file_path);
|
|
file_util::write_text_file(file_path, data.dump(2));
|
|
}
|
|
|
|
void to_json(json& j, const InputSettings& obj) {
|
|
json_serialize(version);
|
|
json_serialize(last_selected_controller_guid);
|
|
json_serialize(controller_port_mapping);
|
|
json_serialize(controller_binds);
|
|
json_serialize(keyboard_binds);
|
|
json_serialize(mouse_binds);
|
|
json_serialize(keyboard_enabled);
|
|
}
|
|
|
|
void from_json(const json& j, InputSettings& obj) {
|
|
json_deserialize_if_exists(version);
|
|
json_deserialize_if_exists(last_selected_controller_guid);
|
|
json_deserialize_if_exists(controller_port_mapping);
|
|
json_deserialize_if_exists(controller_binds);
|
|
json_deserialize_if_exists(keyboard_binds);
|
|
json_deserialize_if_exists(mouse_binds);
|
|
json_deserialize_if_exists(keyboard_enabled);
|
|
}
|
|
|
|
InputSettings::InputSettings() {
|
|
try {
|
|
keyboard_binds = DEFAULT_KEYBOARD_BINDS;
|
|
mouse_binds = DEFAULT_MOUSE_BINDS;
|
|
std::string file_path =
|
|
(file_util::get_user_settings_dir(g_game_version) / "input-settings.json").string();
|
|
if (!file_util::file_exists(file_path)) {
|
|
return;
|
|
}
|
|
lg::info("Loading input settings at {}", file_path);
|
|
auto raw = file_util::read_text_file(file_path);
|
|
from_json(parse_commented_json(raw, "input-settings.json"), *this);
|
|
} catch (std::exception& e) {
|
|
// do nothing
|
|
lg::error("Error encountered when attempting to load input settings {}", e.what());
|
|
}
|
|
}
|
|
void InputSettings::save_settings() {
|
|
json data = *this;
|
|
auto file_path = file_util::get_user_settings_dir(g_game_version) / "input-settings.json";
|
|
file_util::create_dir_if_needed_for_file(file_path);
|
|
file_util::write_text_file(file_path, data.dump(2));
|
|
}
|
|
} // namespace game_settings
|