From 451daefa056a07e971bfd88c5d7f9119fbc37c53 Mon Sep 17 00:00:00 2001 From: WerWolv98 Date: Fri, 17 Aug 2018 11:06:44 +0200 Subject: [PATCH] Added support for config file redirection --- include/gui_editor.hpp | 2 +- source/gui_editor.cpp | 33 ++++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/include/gui_editor.hpp b/include/gui_editor.hpp index 1b46188f..af0f3205 100644 --- a/include/gui_editor.hpp +++ b/include/gui_editor.hpp @@ -26,7 +26,7 @@ class GuiEditor : public Gui { WidgetItems m_widgets; json m_offsetFile; void createWidgets(); - s8 loadConfigFile(json &j); + s8 loadConfigFile(json &j, std::string filepath); void updateSaveFileList(std::vector saveFilePath, std::string files); }; diff --git a/source/gui_editor.cpp b/source/gui_editor.cpp index b161d2ad..19b0741e 100644 --- a/source/gui_editor.cpp +++ b/source/gui_editor.cpp @@ -80,7 +80,12 @@ GuiEditor::GuiEditor() : Gui() { Widget::g_selectedWidgetIndex = 0; Widget::g_selectedCategory = ""; - configFileResult = loadConfigFile(m_offsetFile); + + std::stringstream path; + path << CONFIG_ROOT << std::setfill('0') << std::setw(sizeof(u64) * 2) << std::uppercase << std::hex << Title::g_currTitle->getTitleID() << ".json"; + + configFileResult = loadConfigFile(m_offsetFile, path.str()); + bool foundVersion = false; @@ -178,11 +183,8 @@ void GuiEditor::draw() { Gui::endDraw(); } -s8 GuiEditor::loadConfigFile(json &j) { - std::stringstream path; - path << CONFIG_ROOT << std::setfill('0') << std::setw(sizeof(u64) * 2) << std::uppercase << std::hex << Title::g_currTitle->getTitleID() << ".json"; - - std::ifstream file(path.str().c_str()); +s8 GuiEditor::loadConfigFile(json &j, std::string filepath) { + std::ifstream file(filepath.c_str()); m_widgets.clear(); @@ -196,6 +198,12 @@ s8 GuiEditor::loadConfigFile(json &j) { return 2; } + if (j.find("useInstead") != j.end()) { + std::stringstream path; + path << CONFIG_ROOT << j["useInstead"].get(); + loadConfigFile(j, path.str()); + } + return 0; } @@ -221,7 +229,10 @@ void GuiEditor::createWidgets() { optionalArg(itemWidget, "preEquation", "value"), optionalArg(itemWidget, "postEquation", "value"), optionalArg(itemWidget, "postEquationInverse", "value"), - itemWidget["minValue"], itemWidget["maxValue"], optionalArg(itemWidget, "stepSize", 0)) }); + itemWidget["minValue"], + itemWidget["maxValue"], + optionalArg(itemWidget, "stepSize", 0)) + }); } else if (itemWidget["type"] == "bool") { if (itemWidget["onValue"] == nullptr || itemWidget["offValue"] == nullptr) continue; @@ -233,7 +244,9 @@ void GuiEditor::createWidgets() { optionalArg(itemWidget, "preEquation", "value"), optionalArg(itemWidget, "postEquation", "value"), optionalArg(itemWidget, "postEquationInverse", "value"), - itemWidget["onValue"].get(), itemWidget["offValue"].get()) }); + itemWidget["onValue"].get(), + itemWidget["offValue"].get()) + }); } else if(itemWidget["onValue"].is_string() && itemWidget["offValue"].is_string()) m_widgets[item["category"]].push_back({ item["name"], @@ -248,7 +261,9 @@ void GuiEditor::createWidgets() { optionalArg(itemWidget, "preEquation", "value"), optionalArg(itemWidget, "postEquation", "value"), optionalArg(itemWidget, "postEquationInverse", "value"), - itemWidget["listItemNames"], itemWidget["listItemValues"].get>()) }); + itemWidget["listItemNames"], + itemWidget["listItemValues"].get>()) + }); } else if (itemWidget["listItemValues"][0].is_string()) m_widgets[item["category"]].push_back({ item["name"], new WidgetList(&luaParser, itemWidget["listItemNames"], itemWidget["listItemValues"].get>()) });