2021-01-03 23:19:56 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-01-11 19:31:40 +00:00
|
|
|
#include <any>
|
2021-01-03 23:19:56 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <vector>
|
2021-01-11 20:11:03 +00:00
|
|
|
#include <map>
|
2021-01-03 23:19:56 +00:00
|
|
|
|
|
|
|
#include <helpers/event.hpp>
|
2021-01-11 19:31:40 +00:00
|
|
|
#include <helpers/content_registry.hpp>
|
|
|
|
|
2021-01-03 23:19:56 +00:00
|
|
|
#include <imgui.h>
|
2021-01-11 19:31:40 +00:00
|
|
|
#include <nlohmann/json.hpp>
|
2021-01-03 23:19:56 +00:00
|
|
|
|
|
|
|
namespace hex { class SharedData; }
|
|
|
|
|
|
|
|
namespace hex::plugin::internal {
|
|
|
|
void initializePlugin(SharedData &sharedData);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
|
|
|
namespace prv { class Provider; }
|
|
|
|
|
|
|
|
class SharedData {
|
|
|
|
SharedData() = default;
|
|
|
|
public:
|
|
|
|
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;
|
|
|
|
|
2021-01-11 19:31:40 +00:00
|
|
|
template<typename T>
|
|
|
|
T& getVariable(std::string variableName) {
|
|
|
|
return std::any_cast<T&>((*this->sharedVariables)[variableName]);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void setVariable(std::string variableName, T value) {
|
|
|
|
(*this->sharedVariables)[variableName] = value;
|
|
|
|
}
|
|
|
|
|
2021-01-03 23:19:56 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
void initializeData() {
|
|
|
|
static std::vector<EventHandler> eventHandlersStorage;
|
|
|
|
static std::vector<std::function<void()>> deferredCallsStorage;
|
|
|
|
static prv::Provider *currentProviderStorage;
|
2021-01-11 19:31:40 +00:00
|
|
|
static std::map<std::string, std::vector<ContentRegistry::Settings::Entry>> settingsEntriesStorage;
|
|
|
|
static std::map<std::string, std::any> sharedVariablesStorage;
|
2021-01-03 23:19:56 +00:00
|
|
|
static ImVec2 windowPosStorage, windowSizeStorage;
|
2021-01-11 19:31:40 +00:00
|
|
|
static nlohmann::json settingsJsonStorage;
|
2021-01-11 20:11:03 +00:00
|
|
|
static std::map<std::string, Events> customEventsStorage;
|
|
|
|
static u32 customEventsLastIdStorage = u32(Events::Events_BuiltinEnd) + 1;
|
2021-01-11 22:02:55 +00:00
|
|
|
static std::vector<ContentRegistry::CommandPaletteCommands::Entry> commandPaletteCommandsStorage;
|
2021-01-11 22:54:12 +00:00
|
|
|
static std::map<std::string, ContentRegistry::PatternLanguageFunctions::Function> patternLanguageFunctionsStorage;
|
2021-01-11 22:02:55 +00:00
|
|
|
|
|
|
|
this->imguiContext = ImGui::GetCurrentContext();
|
|
|
|
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;
|
2021-01-11 22:54:12 +00:00
|
|
|
this->patternLanguageFunctions = &patternLanguageFunctionsStorage;
|
2021-01-03 23:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void initializeData(const SharedData &other) {
|
2021-01-11 22:02:55 +00:00
|
|
|
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;
|
2021-01-11 22:54:12 +00:00
|
|
|
this->patternLanguageFunctions = other.patternLanguageFunctions;
|
2021-01-03 23:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
ImGuiContext *imguiContext;
|
|
|
|
std::vector<EventHandler> *eventHandlers;
|
|
|
|
std::vector<std::function<void()>> *deferredCalls;
|
|
|
|
prv::Provider **currentProvider;
|
2021-01-11 19:31:40 +00:00
|
|
|
std::map<std::string, std::vector<ContentRegistry::Settings::Entry>> *settingsEntries;
|
|
|
|
nlohmann::json *settingsJson;
|
2021-01-11 20:11:03 +00:00
|
|
|
std::map<std::string, Events> *customEvents;
|
|
|
|
u32 *customEventsLastId;
|
2021-01-11 22:02:55 +00:00
|
|
|
std::vector<ContentRegistry::CommandPaletteCommands::Entry> *commandPaletteCommands;
|
2021-01-11 22:54:12 +00:00
|
|
|
std::map<std::string, ContentRegistry::PatternLanguageFunctions::Function> *patternLanguageFunctions;
|
2021-01-03 23:19:56 +00:00
|
|
|
|
|
|
|
ImVec2 *windowPos;
|
|
|
|
ImVec2 *windowSize;
|
2021-01-11 19:31:40 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::map<std::string, std::any> *sharedVariables;
|
2021-01-03 23:19:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|