diff --git a/ISLE/isleapp.cpp b/ISLE/isleapp.cpp index fb511569..a78a9f71 100644 --- a/ISLE/isleapp.cpp +++ b/ISLE/isleapp.cpp @@ -1128,13 +1128,19 @@ bool IsleApp::LoadConfig() strcpy(m_savePath, savePath); #ifdef EXTENSIONS - std::vector keys; - keys.resize(iniparser_getsecnkeys(dict, "extensions")); - iniparser_getseckeys(dict, "extensions", keys.data()); - - for (const char* key : keys) { + for (const char* key : Extensions::availableExtensions) { if (iniparser_getboolean(dict, key, 0)) { - Extensions::Enable(key); + std::vector extensionKeys; + const char* section = SDL_strchr(key, ':') + 1; + extensionKeys.resize(iniparser_getsecnkeys(dict, section)); + iniparser_getseckeys(dict, section, extensionKeys.data()); + + std::map extensionDict; + for (const char* key : extensionKeys) { + extensionDict[key] = iniparser_getstring(dict, key, NULL); + } + + Extensions::Enable(key, std::move(extensionDict)); } } #endif diff --git a/extensions/include/extensions/extensions.h b/extensions/include/extensions/extensions.h index 215bf80a..6c6f4f99 100644 --- a/extensions/include/extensions/extensions.h +++ b/extensions/include/extensions/extensions.h @@ -3,6 +3,7 @@ #include "lego1_export.h" #include +#include #include #include @@ -10,7 +11,7 @@ namespace Extensions { constexpr const char* availableExtensions[] = {"extensions:texture loader"}; -LEGO1_EXPORT void Enable(const char* p_key); +LEGO1_EXPORT void Enable(const char* p_key, std::map p_options); template struct Extension { diff --git a/extensions/include/extensions/textureloader.h b/extensions/include/extensions/textureloader.h index 649c6112..c476c7ff 100644 --- a/extensions/include/extensions/textureloader.h +++ b/extensions/include/extensions/textureloader.h @@ -3,16 +3,24 @@ #include "extensions/extensions.h" #include "legotextureinfo.h" +#include +#include + namespace Extensions { class TextureLoader { public: + static void Initialize(); static bool PatchTexture(LegoTextureInfo* p_textureInfo); + + static std::map options; static bool enabled; -private: - static constexpr const char* texturePath = "/textures/"; + static constexpr std::array, 1> defaults = { + {{"texture loader:texture path", "/textures/"}} + }; +private: static SDL_Surface* FindTexture(const char* p_name); }; diff --git a/extensions/src/extensions.cpp b/extensions/src/extensions.cpp index e1d0c389..779c0547 100644 --- a/extensions/src/extensions.cpp +++ b/extensions/src/extensions.cpp @@ -4,12 +4,14 @@ #include -void Extensions::Enable(const char* p_key) +void Extensions::Enable(const char* p_key, std::map p_options) { for (const char* key : availableExtensions) { if (!SDL_strcasecmp(p_key, key)) { if (!SDL_strcasecmp(p_key, "extensions:texture loader")) { + TextureLoader::options = std::move(p_options); TextureLoader::enabled = true; + TextureLoader::Initialize(); } SDL_Log("Enabled extension: %s", p_key); diff --git a/extensions/src/textureloader.cpp b/extensions/src/textureloader.cpp index dd96105e..07b53253 100644 --- a/extensions/src/textureloader.cpp +++ b/extensions/src/textureloader.cpp @@ -2,8 +2,18 @@ using namespace Extensions; +std::map TextureLoader::options; bool TextureLoader::enabled = false; +void TextureLoader::Initialize() +{ + for (const auto& option : defaults) { + if (!options.count(option.first.data())) { + options[option.first.data()] = option.second; + } + } +} + bool TextureLoader::PatchTexture(LegoTextureInfo* p_textureInfo) { SDL_Surface* surface = FindTexture(p_textureInfo->m_name); @@ -88,6 +98,7 @@ bool TextureLoader::PatchTexture(LegoTextureInfo* p_textureInfo) SDL_Surface* TextureLoader::FindTexture(const char* p_name) { SDL_Surface* surface; + const char* texturePath = options["texture loader:texture path"].c_str(); MxString path = MxString(MxOmni::GetHD()) + texturePath + p_name + ".bmp"; path.MapPathToFilesystem();