mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 13:37:42 -05:00
Hopefully fixed the whole plugin mess I started
This commit is contained in:
@@ -28,106 +28,39 @@ namespace hex {
|
||||
SharedData(const SharedData&) = delete;
|
||||
SharedData(SharedData&&) = delete;
|
||||
|
||||
static auto& get() {
|
||||
static SharedData instance;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
friend void hex::plugin::internal::initializePlugin(SharedData &sharedData);
|
||||
friend class Window;
|
||||
|
||||
template<typename T>
|
||||
T& getVariable(std::string variableName) {
|
||||
return std::any_cast<T&>((*this->sharedVariables)[variableName]);
|
||||
static T& getVariable(std::string variableName) {
|
||||
return std::any_cast<T&>(SharedData::sharedVariables[variableName]);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void setVariable(std::string variableName, T value) {
|
||||
(*this->sharedVariables)[variableName] = value;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void initializeData() {
|
||||
static int mainArgcStorage;
|
||||
static char **mainArgvStorage;
|
||||
static ImGuiContext *imGuiContextStorage;
|
||||
static std::vector<EventHandler> eventHandlersStorage;
|
||||
static std::vector<std::function<void()>> deferredCallsStorage;
|
||||
static prv::Provider *currentProviderStorage;
|
||||
static std::map<std::string, std::vector<ContentRegistry::Settings::Entry>> settingsEntriesStorage;
|
||||
static std::map<std::string, std::any> sharedVariablesStorage;
|
||||
static ImVec2 windowPosStorage, windowSizeStorage;
|
||||
static nlohmann::json settingsJsonStorage;
|
||||
static std::map<std::string, Events> customEventsStorage;
|
||||
static u32 customEventsLastIdStorage = u32(Events::Events_BuiltinEnd) + 1;
|
||||
static std::vector<ContentRegistry::CommandPaletteCommands::Entry> commandPaletteCommandsStorage;
|
||||
static std::map<std::string, ContentRegistry::PatternLanguageFunctions::Function> patternLanguageFunctionsStorage;
|
||||
static std::vector<View*> viewsStorage;
|
||||
static std::vector<std::function<void()>> toolsStorage;
|
||||
|
||||
this->imguiContext = &imGuiContextStorage;
|
||||
this->eventHandlers = &eventHandlersStorage;
|
||||
this->deferredCalls = &deferredCallsStorage;
|
||||
this->currentProvider = ¤tProviderStorage;
|
||||
this->settingsEntries = &settingsEntriesStorage;
|
||||
this->sharedVariables = &sharedVariablesStorage;
|
||||
this->windowPos = &windowPosStorage;
|
||||
this->windowSize = &windowSizeStorage;
|
||||
this->settingsJson = &settingsJsonStorage;
|
||||
this->customEvents = &customEventsStorage;
|
||||
this->customEventsLastId = &customEventsLastIdStorage;
|
||||
this->commandPaletteCommands = &commandPaletteCommandsStorage;
|
||||
this->patternLanguageFunctions = &patternLanguageFunctionsStorage;
|
||||
this->views = &viewsStorage;
|
||||
this->tools = &toolsStorage;
|
||||
this->mainArgc = &mainArgcStorage;
|
||||
this->mainArgv = &mainArgvStorage;
|
||||
}
|
||||
|
||||
void initializeData(const SharedData &other) {
|
||||
this->imguiContext = other.imguiContext;
|
||||
this->eventHandlers = other.eventHandlers;
|
||||
this->deferredCalls = other.deferredCalls;
|
||||
this->currentProvider = other.currentProvider;
|
||||
this->settingsEntries = other.settingsEntries;
|
||||
this->sharedVariables = other.sharedVariables;
|
||||
this->windowPos = other.windowPos;
|
||||
this->windowSize = other.windowSize;
|
||||
this->settingsJson = other.settingsJson;
|
||||
this->customEvents = other.customEvents;
|
||||
this->customEventsLastId = other.customEventsLastId;
|
||||
this->commandPaletteCommands = other.commandPaletteCommands;
|
||||
this->patternLanguageFunctions = other.patternLanguageFunctions;
|
||||
this->views = other.views;
|
||||
this->tools = other.tools;
|
||||
this->mainArgc = other.mainArgc;
|
||||
this->mainArgv = other.mainArgv;
|
||||
static void setVariable(std::string variableName, T value) {
|
||||
SharedData::sharedVariables[variableName] = value;
|
||||
}
|
||||
|
||||
public:
|
||||
ImGuiContext **imguiContext;
|
||||
std::vector<EventHandler> *eventHandlers;
|
||||
std::vector<std::function<void()>> *deferredCalls;
|
||||
prv::Provider **currentProvider;
|
||||
std::map<std::string, std::vector<ContentRegistry::Settings::Entry>> *settingsEntries;
|
||||
nlohmann::json *settingsJson;
|
||||
std::map<std::string, Events> *customEvents;
|
||||
u32 *customEventsLastId;
|
||||
std::vector<ContentRegistry::CommandPaletteCommands::Entry> *commandPaletteCommands;
|
||||
std::map<std::string, ContentRegistry::PatternLanguageFunctions::Function> *patternLanguageFunctions;
|
||||
std::vector<View*> *views;
|
||||
std::vector<std::function<void()>> *tools;
|
||||
static std::vector<EventHandler> eventHandlers;
|
||||
static std::vector<std::function<void()>> deferredCalls;
|
||||
static prv::Provider *currentProvider;
|
||||
static std::map<std::string, std::vector<ContentRegistry::Settings::Entry>> settingsEntries;
|
||||
static nlohmann::json settingsJson;
|
||||
static std::map<std::string, Events> customEvents;
|
||||
static u32 customEventsLastId;
|
||||
static std::vector<ContentRegistry::CommandPaletteCommands::Entry> commandPaletteCommands;
|
||||
static std::map<std::string, ContentRegistry::PatternLanguageFunctions::Function> patternLanguageFunctions;
|
||||
static std::vector<View*> views;
|
||||
static std::vector<std::function<void()>> tools;
|
||||
|
||||
int *mainArgc;
|
||||
char ***mainArgv;
|
||||
static int mainArgc;
|
||||
static char **mainArgv;
|
||||
|
||||
ImVec2 *windowPos;
|
||||
ImVec2 *windowSize;
|
||||
static ImVec2 windowPos;
|
||||
static ImVec2 windowSize;
|
||||
|
||||
private:
|
||||
std::map<std::string, std::any> *sharedVariables;
|
||||
static std::map<std::string, std::any> sharedVariables;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user