Fixed string cvar load and added fipps font

This commit is contained in:
KiritoDev 2022-05-11 12:18:37 -05:00
commit 44f15c34eb
2 changed files with 21 additions and 2 deletions

View file

@ -84,8 +84,17 @@ ImVec2 Ship::GameOverlay::CalculateTextSize(const char* text, const char* text_e
void Ship::GameOverlay::Init() { void Ship::GameOverlay::Init() {
this->LoadFont("Press Start 2P", "assets/ship_of_harkinian/fonts/PressStart2P-Regular.ttf", 12.0f); this->LoadFont("Press Start 2P", "assets/ship_of_harkinian/fonts/PressStart2P-Regular.ttf", 12.0f);
this->LoadFont("Fipps", "assets/ship_of_harkinian/fonts/Fipps-Regular.otf", 32.0f);
const std::string DefaultFont = this->Fonts.begin()->first;
if(!this->Fonts.empty()) { if(!this->Fonts.empty()) {
this->CurrentFont = CVar_GetString("gOverlayFont", ImStrdup(this->Fonts.begin()->first.c_str())); const std::string font = CVar_GetString("gOverlayFont", ImStrdup(DefaultFont.c_str()));
for (auto& [name, _] : this->Fonts) {
if (font.starts_with(name)) {
this->CurrentFont = name;
break;
}
this->CurrentFont = DefaultFont;
}
} }
SohImGui::console->Commands["overlay"] = { OverlayCommand, "Draw an overlay using a cvar value" }; SohImGui::console->Commands["overlay"] = { OverlayCommand, "Draw an overlay using a cvar value" };
} }

View file

@ -421,6 +421,14 @@ template <typename Numeric> bool is_number(const std::string& s) {
return ((std::istringstream(s) >> n >> std::ws).eof()); return ((std::istringstream(s) >> n >> std::ws).eof());
} }
char* Strdup(const char* src) {
const unsigned len = strlen(src) + 1;
char* newstr = static_cast<char*>(malloc(len));
if (newstr)
memcpy(newstr, src, len);
return newstr;
}
void DebugConsole_LoadCVars() void DebugConsole_LoadCVars()
{ {
if (File::Exists("cvars.cfg")) { if (File::Exists("cvars.cfg")) {
@ -431,7 +439,9 @@ void DebugConsole_LoadCVars()
if (line.empty()) continue; if (line.empty()) continue;
if (cfg.size() < 2) continue; if (cfg.size() < 2) continue;
if (cfg[1].find("\"") != std::string::npos) { if (cfg[1].find("\"") != std::string::npos) {
CVar_SetString(cfg[0].c_str(), const_cast<char*>(cfg[1].c_str())); std::string value(cfg[1]);
value.erase(std::ranges::remove(value, '\"').begin(), value.end());
CVar_SetString(cfg[0].c_str(), Strdup(value.c_str()));
} }
if (is_number<float>(cfg[1])) { if (is_number<float>(cfg[1])) {
CVar_SetFloat(cfg[0].c_str(), std::stof(cfg[1])); CVar_SetFloat(cfg[0].c_str(), std::stof(cfg[1]));