diff --git a/source/client/core/ClientApplication.cpp b/source/client/core/ClientApplication.cpp index b762902f5..cb3b4e8d0 100644 --- a/source/client/core/ClientApplication.cpp +++ b/source/client/core/ClientApplication.cpp @@ -35,7 +35,6 @@ #include "Config.hpp" #include "EngineConfig.hpp" #include "Font.hpp" -#include "GameConfig.hpp" #include "TextureAtlas.hpp" #include "TextureLoader.hpp" #include "Vertex.hpp" @@ -101,7 +100,7 @@ void ClientApplication::init() { Config::defaultUsername = m_argumentParser.getArgument("username").parameter; if (m_argumentParser.getArgument("texture-pack").isFound) - GameConfig::texturePack = m_argumentParser.getArgument("texture-pack").parameter; + Config::texturePack = m_argumentParser.getArgument("texture-pack").parameter; m_keyboardHandler.loadKeysFromFile("config/keys.lua"); gk::GamePad::init(m_keyboardHandler); diff --git a/source/client/core/Config.cpp b/source/client/core/Config.cpp index 1a893c170..b354f1d2a 100644 --- a/source/client/core/Config.cpp +++ b/source/client/core/Config.cpp @@ -68,6 +68,7 @@ u8 Config::mouseSensitivity = 8; // Other std::string Config::defaultUsername = ""; std::string Config::defaultServerAddress = "localhost:4242"; +std::string Config::texturePack = ""; void Config::loadConfigFromFile(const char *filename) { if (!fs::exists("config") && !fs::create_directory("config")) { @@ -107,6 +108,7 @@ void Config::loadConfigFromFile(const char *filename) { defaultUsername = lua["defaultUsername"].get_or(defaultUsername); defaultServerAddress = lua["defaultServerAddress"].get_or(defaultServerAddress); + texturePack = lua["texturePack"].get_or(texturePack); gkInfo() << "Config file loaded successfully"; } @@ -144,5 +146,6 @@ void Config::saveConfigToFile(const char *filename) { file << std::endl; file << "defaultUsername = \"" << defaultUsername << "\"" << std::endl; file << "defaultServerAddress = \"" << defaultServerAddress << "\"" << std::endl; + file << "texturePack = \"" << texturePack << "\"" << std::endl; } diff --git a/source/client/core/Config.hpp b/source/client/core/Config.hpp index 3ce6aa17b..9f57388e7 100644 --- a/source/client/core/Config.hpp +++ b/source/client/core/Config.hpp @@ -63,6 +63,7 @@ namespace Config { // Other extern std::string defaultUsername; extern std::string defaultServerAddress; + extern std::string texturePack; void loadConfigFromFile(const char *filename); void saveConfigToFile(const char *filename); diff --git a/source/client/core/GameConfig.cpp b/source/client/core/GameConfig.cpp index d49a16835..31da58730 100644 --- a/source/client/core/GameConfig.cpp +++ b/source/client/core/GameConfig.cpp @@ -28,7 +28,6 @@ // Pre-game configuration std::string GameConfig::worldName = ""; -std::string GameConfig::texturePack = ""; // Screen effects u16 GameConfig::currentScreenEffect = 0; diff --git a/source/client/core/GameConfig.hpp b/source/client/core/GameConfig.hpp index bb3797e3a..ace7b21e2 100644 --- a/source/client/core/GameConfig.hpp +++ b/source/client/core/GameConfig.hpp @@ -35,7 +35,6 @@ namespace GameConfig { // Pre-game configuration extern std::string worldName; - extern std::string texturePack; // Screen effects extern u16 currentScreenEffect; diff --git a/source/client/gui/ItemWidget.cpp b/source/client/gui/ItemWidget.cpp index 2ec5f76f3..db76447be 100644 --- a/source/client/gui/ItemWidget.cpp +++ b/source/client/gui/ItemWidget.cpp @@ -26,6 +26,7 @@ */ #include +#include "Config.hpp" #include "ItemWidget.hpp" #include "Registry.hpp" #include "TextureAtlas.hpp" @@ -57,12 +58,9 @@ void ItemWidget::update() { m_text.setPosition(16 - 4 - 6 * floor(log10(stack().amount())), 16 - 6, 0); } -#include "GameConfig.hpp" - void ItemWidget::updateImage(const BlockState *blockState) { - static std::string oldTexturePack{""}; - if (m_image.width() == 0 || oldTexturePack != GameConfig::texturePack) { - oldTexturePack = GameConfig::texturePack; + if (m_image.width() == 0 || m_oldTexturePack != Config::texturePack) { + m_oldTexturePack = Config::texturePack; m_image.load(m_textureAtlas.texture()); m_image.setPosition(1, 1, 0); diff --git a/source/client/gui/ItemWidget.hpp b/source/client/gui/ItemWidget.hpp index 16b0cc087..94e1e3995 100644 --- a/source/client/gui/ItemWidget.hpp +++ b/source/client/gui/ItemWidget.hpp @@ -71,6 +71,8 @@ class ItemWidget : public Widget { bool m_isImage = false; bool m_hasChanged = false; + + std::string m_oldTexturePack{""}; }; #endif // ITEMWIDGET_HPP_ diff --git a/source/client/states/ServerLoadingState.cpp b/source/client/states/ServerLoadingState.cpp index 02417f654..9a481555d 100644 --- a/source/client/states/ServerLoadingState.cpp +++ b/source/client/states/ServerLoadingState.cpp @@ -32,7 +32,6 @@ #include "Config.hpp" #include "ConnectionErrorState.hpp" -#include "GameConfig.hpp" #include "GameState.hpp" #include "Events.hpp" #include "ServerLoadingState.hpp" @@ -96,7 +95,7 @@ void ServerLoadingState::update() { } else if (!m_game.textureAtlas().isReady()) { try { - m_game.textureAtlas().loadFromRegistry(GameConfig::texturePack); + m_game.textureAtlas().loadFromRegistry(Config::texturePack); } catch (gk::Exception &e) { m_game.client().disconnect(); diff --git a/source/client/states/TexturePackSelectionState.cpp b/source/client/states/TexturePackSelectionState.cpp index eed6ae455..31e1e97f0 100644 --- a/source/client/states/TexturePackSelectionState.cpp +++ b/source/client/states/TexturePackSelectionState.cpp @@ -30,7 +30,6 @@ #include #include "Config.hpp" -#include "GameConfig.hpp" #include "TextureAtlas.hpp" #include "TexturePackSelectionState.hpp" #include "World.hpp" @@ -55,12 +54,12 @@ TexturePackSelectionState::TexturePackSelectionState(gk::ApplicationState *paren const ScrollableListElement *element = m_texturePackList.selectedElement(); if (element) { std::string texturePack = (element->id()) ? element->line1() : ""; - if (GameConfig::texturePack != texturePack) { - GameConfig::texturePack = texturePack; + if (Config::texturePack != texturePack) { + Config::texturePack = texturePack; auto &atlas = gk::ResourceHandler::getInstance().get("atlas-blocks"); atlas.clear(); - atlas.loadFromRegistry(GameConfig::texturePack); + atlas.loadFromRegistry(Config::texturePack); World::isReloadRequested = true; } @@ -122,7 +121,7 @@ void TexturePackSelectionState::updateWidgetPosition() { } void TexturePackSelectionState::loadTexturePackList() { - m_texturePackList.addElement("No Texture Pack", "Use default mod textures", "", GameConfig::texturePack.empty()); + m_texturePackList.addElement("No Texture Pack", "Use default mod textures", "", Config::texturePack.empty()); if (fs::is_directory("texturepacks")) { std::vector dirs; @@ -151,7 +150,7 @@ void TexturePackSelectionState::loadTexturePackList() { textures += "GUI"; } - bool isSelected = GameConfig::texturePack == dirname; + bool isSelected = Config::texturePack == dirname; m_texturePackList.addElement(dirname, textures, "", isSelected); } }