Use different enable strategy

This commit is contained in:
Christian Semmler 2025-07-09 17:12:15 -07:00
parent 7a0b0cb5ef
commit 93d97cf73f
4 changed files with 15 additions and 10 deletions

View File

@ -5,12 +5,9 @@
#include <functional>
#include <optional>
#include <string>
#include <vector>
namespace Extensions
{
extern std::vector<std::string> enabledExtensions;
constexpr const char* availableExtensions[] = {"extensions:texture loader"};
LEGO1_EXPORT void Enable(const char* p_key);
@ -21,7 +18,7 @@ struct Extension {
static auto Call(Function&& function, Args&&... args) -> std::optional<std::invoke_result_t<Function, Args...>>
{
#ifdef EXTENSIONS
if (std::find(enabledExtensions.begin(), enabledExtensions.end(), T::key) != enabledExtensions.end()) {
if (T::enabled) {
return std::invoke(std::forward<Function>(function), std::forward<Args>(args)...);
}
#endif

View File

@ -7,9 +7,8 @@ namespace Extensions
{
class TextureLoader {
public:
static constexpr const char* key = "extensions:texture loader";
static bool PatchTexture(LegoTextureInfo* p_textureInfo);
static bool enabled;
private:
static constexpr const char* texturePath = "/textures/";

View File

@ -1,12 +1,19 @@
#include "extensions/extensions.h"
#include "extensions/textureloader.h"
#include <SDL3/SDL_log.h>
std::vector<std::string> Extensions::enabledExtensions;
void Extensions::Enable(const char* p_key)
{
enabledExtensions.emplace_back(p_key);
for (const char* key : availableExtensions) {
if (!SDL_strcasecmp(p_key, key)) {
if (!SDL_strcasecmp(p_key, "extensions:texture loader")) {
TextureLoader::enabled = true;
}
SDL_Log("Enabled extension: %s", p_key);
SDL_Log("Enabled extension: %s", p_key);
break;
}
}
}

View File

@ -2,6 +2,8 @@
using namespace Extensions;
bool TextureLoader::enabled = false;
bool TextureLoader::PatchTexture(LegoTextureInfo* p_textureInfo)
{
SDL_Surface* surface = FindTexture(p_textureInfo->m_name);