LUS Cleanup: Removes GameSettings class. Moves code to Imgui. (#1036)

* LUS Cleanup: Removes GameSettings class. Moves code to Imgui.

* Fixes more strdup problems and finalized removal of GameSetting.

* Reverts changes to Directory.h

* Update Directory.h

* Fixes PR.

* Update Directory.h

* Update rando_main.cpp
This commit is contained in:
Kenix3 2022-08-05 01:03:11 -04:00 committed by GitHub
commit 93d0d7443a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 188 additions and 246 deletions

View file

@ -1,11 +1,6 @@
#include "CosmeticsEditor.h"
#include "../../util.h"
#include "../libultraship/ImGuiImpl.h"
#include "GameSettings.h"
#include <array>
#include <bit>
#include <map>
#include <string>
#include <Cvar.h>
#include <PR/ultra64/types.h>

View file

@ -14,7 +14,6 @@
#define Path _Path
#define PATH_HACK
#include <Utils/StringHelper.h>
#include <Utils/File.h>
#include "Window.h"
#include "Lib/ImGui/imgui_internal.h"
@ -426,7 +425,7 @@ static bool SetCVarHandler(const std::vector<std::string>& args) {
else
CVar_SetS32(args[1].c_str(), std::stoi(args[2]));
DebugConsole_SaveCVars();
CVar_Save();
//INFO("[SOH] Updated player position to [ %.2f, %.2f, %.2f ]", pos.x, pos.y, pos.z);
return CMD_SUCCESS;
@ -507,123 +506,5 @@ void DebugConsole_Init(void) {
Ship::ArgumentType::NUMBER,
}
} });
DebugConsole_LoadCVars();
}
template <typename Numeric> bool is_number(const std::string& s) {
Numeric n;
return ((std::istringstream(s) >> n >> std::ws).eof());
}
void DebugConsole_LoadLegacyCVars() {
auto cvarsConfig = Ship::GlobalCtx2::GetPathRelativeToAppDirectory("cvars.cfg");
if (File::Exists(cvarsConfig)) {
const auto lines = File::ReadAllLines(cvarsConfig);
for (const std::string& line : lines) {
std::vector<std::string> cfg = StringHelper::Split(line, " = ");
if (line.empty()) continue;
if (cfg.size() < 2) continue;
if (cfg[1].find("\"") == std::string::npos && (cfg[1].find("#") != std::string::npos))
{
std::string value(cfg[1]);
value.erase(std::remove_if(value.begin(), value.end(), [](char c) { return c == '#'; }), value.end());
auto splitTest = StringHelper::Split(value, "\r")[0];
uint32_t val = std::stoul(splitTest, nullptr, 16);
Color_RGBA8 clr;
clr.r = val >> 24;
clr.g = val >> 16;
clr.b = val >> 8;
clr.a = val & 0xFF;
CVar_SetRGBA(cfg[0].c_str(), clr);
}
if (cfg[1].find("\"") != std::string::npos) {
std::string value(cfg[1]);
value.erase(std::remove(value.begin(), value.end(), '\"'), value.end());
CVar_SetString(cfg[0].c_str(), ImStrdup(value.c_str()));
}
if (is_number<float>(cfg[1])) {
CVar_SetFloat(cfg[0].c_str(), std::stof(cfg[1]));
}
if (is_number<int>(cfg[1])) {
CVar_SetS32(cfg[0].c_str(), std::stoi(cfg[1]));
}
}
fs::remove(cvarsConfig);
}
}
void DebugConsole_LoadCVars() {
std::shared_ptr<Mercury> pConf = Ship::GlobalCtx2::GetInstance()->GetConfig();
pConf->reload();
for (const auto& item : pConf->rjson["CVars"].items()) {
auto value = item.value();
switch (value.type()) {
case nlohmann::detail::value_t::array:
break;
case nlohmann::detail::value_t::object:
if (value["Type"].get<std::string>() == mercuryRGBAObjectType) {
Color_RGBA8 clr;
clr.r = value["R"].get<uint8_t>();
clr.g = value["G"].get<uint8_t>();
clr.b = value["B"].get<uint8_t>();
clr.a = value["A"].get<uint8_t>();
}
break;
case nlohmann::detail::value_t::string:
CVar_SetString(item.key().c_str(), value.get<std::string>().c_str());
break;
case nlohmann::detail::value_t::boolean:
CVar_SetS32(item.key().c_str(), value.get<bool>());
break;
case nlohmann::detail::value_t::number_unsigned:
case nlohmann::detail::value_t::number_integer:
CVar_SetS32(item.key().c_str(), value.get<int>());
break;
case nlohmann::detail::value_t::number_float:
CVar_SetFloat(item.key().c_str(), value.get<float>());
break;
default: ;
}
if (item.key() == "gOpenMenuBar") {
int bp = 0;
}
}
DebugConsole_LoadLegacyCVars();
}
void DebugConsole_SaveCVars()
{
std::shared_ptr<Mercury> pConf = Ship::GlobalCtx2::GetInstance()->GetConfig();
for (const auto &cvar : cvars) {
const std::string key = StringHelper::Sprintf("CVars.%s", cvar.first.c_str());
if (cvar.second->type == CVarType::String && cvar.second->value.valueStr != nullptr)
pConf->setString(key, std::string(cvar.second->value.valueStr));
else if (cvar.second->type == CVarType::S32)
pConf->setInt(key, cvar.second->value.valueS32);
else if (cvar.second->type == CVarType::Float)
pConf->setFloat(key, cvar.second->value.valueFloat);
else if (cvar.second->type == CVarType::RGBA)
{
auto keyStr = key.c_str();
Color_RGBA8 clr = cvar.second->value.valueRGBA;
pConf->setUInt(StringHelper::Sprintf("%s.R", keyStr), clr.r);
pConf->setUInt(StringHelper::Sprintf("%s.G", keyStr), clr.r);
pConf->setUInt(StringHelper::Sprintf("%s.B", keyStr), clr.r);
pConf->setUInt(StringHelper::Sprintf("%s.A", keyStr), clr.r);
pConf->setString(StringHelper::Sprintf("%s.Type", keyStr), mercuryRGBAObjectType);
}
}
pConf->save();
CVar_Load();
}

View file

@ -1,5 +1,3 @@
#pragma once
void DebugConsole_Init(void);
void DebugConsole_LoadCVars();
void DebugConsole_SaveCVars();

View file

@ -6,7 +6,6 @@
#include "rando_main.hpp"
// #include <soh/Enhancements/randomizer.h>
#include <Cvar.h>
#include <GameSettings.h>
#define NOGDI
#define WIN32_LEAN_AND_MEAN
#include <GlobalCtx2.h>
@ -25,7 +24,7 @@ void RandoMain::GenerateRando(std::unordered_map<RandomizerSettingKey, u8> cvarS
std::string fileName = Ship::GlobalCtx2::GetPathRelativeToAppDirectory(GenerateRandomizer(cvarSettings).c_str());
CVar_SetString("gSpoilerLog", fileName.c_str());
Game::SaveSettings();
Game::LoadSettings();
CVar_Save();
CVar_Load();
CVar_SetS32("gNewSeedGenerated", 1);
}

View file

@ -8,7 +8,6 @@
#include <Cvar.h>
#include <textures/icon_item_static/icon_item_static.h>
#include <textures/icon_item_24_static/icon_item_24_static.h>
#include <GameSettings.h>
#include "../libultraship/ImGuiImpl.h"
#include <thread>
#include "3drando/rando_main.hpp"
@ -3192,7 +3191,7 @@ std::thread randoThread;
void GenerateRandomizerImgui() {
CVar_SetS32("gRandoGenerating", 1);
Game::SaveSettings();
CVar_Save();
std::unordered_map<RandomizerSettingKey, u8> cvarSettings;
cvarSettings[RSK_FOREST] = CVar_GetS32("gRandomizeForest", 1);
@ -3258,9 +3257,8 @@ void GenerateRandomizerImgui() {
RandoMain::GenerateRando(cvarSettings);
CVar_SetS32("gRandoGenerating", 0);
Game::SaveSettings();
Game::LoadSettings();
CVar_Save();
CVar_Load();
generated = 1;
}