mirror of
https://github.com/isledecomp/isle-portable.git
synced 2025-09-22 03:22:35 -04:00
Allow extensions to define options (#590)
* Allow extensions to define their own options * Fixes * Remove logging
This commit is contained in:
parent
42bac60ec5
commit
232ef07b51
@ -1128,13 +1128,19 @@ bool IsleApp::LoadConfig()
|
|||||||
strcpy(m_savePath, savePath);
|
strcpy(m_savePath, savePath);
|
||||||
|
|
||||||
#ifdef EXTENSIONS
|
#ifdef EXTENSIONS
|
||||||
std::vector<const char*> keys;
|
for (const char* key : Extensions::availableExtensions) {
|
||||||
keys.resize(iniparser_getsecnkeys(dict, "extensions"));
|
|
||||||
iniparser_getseckeys(dict, "extensions", keys.data());
|
|
||||||
|
|
||||||
for (const char* key : keys) {
|
|
||||||
if (iniparser_getboolean(dict, key, 0)) {
|
if (iniparser_getboolean(dict, key, 0)) {
|
||||||
Extensions::Enable(key);
|
std::vector<const char*> extensionKeys;
|
||||||
|
const char* section = SDL_strchr(key, ':') + 1;
|
||||||
|
extensionKeys.resize(iniparser_getsecnkeys(dict, section));
|
||||||
|
iniparser_getseckeys(dict, section, extensionKeys.data());
|
||||||
|
|
||||||
|
std::map<std::string, std::string> extensionDict;
|
||||||
|
for (const char* key : extensionKeys) {
|
||||||
|
extensionDict[key] = iniparser_getstring(dict, key, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
Extensions::Enable(key, std::move(extensionDict));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "lego1_export.h"
|
#include "lego1_export.h"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -10,7 +11,7 @@ namespace Extensions
|
|||||||
{
|
{
|
||||||
constexpr const char* availableExtensions[] = {"extensions:texture loader"};
|
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<std::string, std::string> p_options);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct Extension {
|
struct Extension {
|
||||||
|
@ -3,16 +3,24 @@
|
|||||||
#include "extensions/extensions.h"
|
#include "extensions/extensions.h"
|
||||||
#include "legotextureinfo.h"
|
#include "legotextureinfo.h"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace Extensions
|
namespace Extensions
|
||||||
{
|
{
|
||||||
class TextureLoader {
|
class TextureLoader {
|
||||||
public:
|
public:
|
||||||
|
static void Initialize();
|
||||||
static bool PatchTexture(LegoTextureInfo* p_textureInfo);
|
static bool PatchTexture(LegoTextureInfo* p_textureInfo);
|
||||||
|
|
||||||
|
static std::map<std::string, std::string> options;
|
||||||
static bool enabled;
|
static bool enabled;
|
||||||
|
|
||||||
private:
|
static constexpr std::array<std::pair<std::string_view, std::string_view>, 1> defaults = {
|
||||||
static constexpr const char* texturePath = "/textures/";
|
{{"texture loader:texture path", "/textures/"}}
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
static SDL_Surface* FindTexture(const char* p_name);
|
static SDL_Surface* FindTexture(const char* p_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,12 +4,14 @@
|
|||||||
|
|
||||||
#include <SDL3/SDL_log.h>
|
#include <SDL3/SDL_log.h>
|
||||||
|
|
||||||
void Extensions::Enable(const char* p_key)
|
void Extensions::Enable(const char* p_key, std::map<std::string, std::string> p_options)
|
||||||
{
|
{
|
||||||
for (const char* key : availableExtensions) {
|
for (const char* key : availableExtensions) {
|
||||||
if (!SDL_strcasecmp(p_key, key)) {
|
if (!SDL_strcasecmp(p_key, key)) {
|
||||||
if (!SDL_strcasecmp(p_key, "extensions:texture loader")) {
|
if (!SDL_strcasecmp(p_key, "extensions:texture loader")) {
|
||||||
|
TextureLoader::options = std::move(p_options);
|
||||||
TextureLoader::enabled = true;
|
TextureLoader::enabled = true;
|
||||||
|
TextureLoader::Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Log("Enabled extension: %s", p_key);
|
SDL_Log("Enabled extension: %s", p_key);
|
||||||
|
@ -2,8 +2,18 @@
|
|||||||
|
|
||||||
using namespace Extensions;
|
using namespace Extensions;
|
||||||
|
|
||||||
|
std::map<std::string, std::string> TextureLoader::options;
|
||||||
bool TextureLoader::enabled = false;
|
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)
|
bool TextureLoader::PatchTexture(LegoTextureInfo* p_textureInfo)
|
||||||
{
|
{
|
||||||
SDL_Surface* surface = FindTexture(p_textureInfo->m_name);
|
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* TextureLoader::FindTexture(const char* p_name)
|
||||||
{
|
{
|
||||||
SDL_Surface* surface;
|
SDL_Surface* surface;
|
||||||
|
const char* texturePath = options["texture loader:texture path"].c_str();
|
||||||
MxString path = MxString(MxOmni::GetHD()) + texturePath + p_name + ".bmp";
|
MxString path = MxString(MxOmni::GetHD()) + texturePath + p_name + ".bmp";
|
||||||
|
|
||||||
path.MapPathToFilesystem();
|
path.MapPathToFilesystem();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user