1
0
mirror of synced 2024-11-12 02:00:52 +01:00

Added custom event registry

This commit is contained in:
WerWolv 2021-01-11 21:11:03 +01:00
parent 46388f4707
commit e27993aff2
4 changed files with 54 additions and 20 deletions

View File

@ -33,6 +33,10 @@ namespace hex {
static std::map<std::string, std::vector<Entry>>& getEntries();
static nlohmann::json& getSettingsData();
};
struct Events {
static auto get(std::string_view name);
};
};
}

View File

@ -1,11 +1,13 @@
#pragma once
#include <hex.hpp>
#include <vector>
#include <functional>
namespace hex {
enum class Events {
enum class Events : u32 {
FileLoaded,
DataChanged,
PatternChanged,
@ -21,7 +23,11 @@ namespace hex {
ProjectFileStore,
ProjectFileLoad,
SettingsChanged
SettingsChanged,
/* This is not a real event but a flag to show all events after this one are plugin ones */
Events_BuiltinEnd
};
struct EventHandler {

View File

@ -3,6 +3,7 @@
#include <any>
#include <functional>
#include <vector>
#include <map>
#include <helpers/event.hpp>
#include <helpers/content_registry.hpp>
@ -55,30 +56,36 @@ namespace hex {
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;
this->imguiContext = ImGui::GetCurrentContext();
this->eventHandlers = &eventHandlersStorage;
this->deferredCalls = &deferredCallsStorage;
this->currentProvider = &currentProviderStorage;
this->settingsEntries = &settingsEntriesStorage;
this->sharedVariables = &sharedVariablesStorage;
this->settingsJson = &settingsJsonStorage;
this->imguiContext = ImGui::GetCurrentContext();
this->eventHandlers = &eventHandlersStorage;
this->deferredCalls = &deferredCallsStorage;
this->currentProvider = &currentProviderStorage;
this->settingsEntries = &settingsEntriesStorage;
this->sharedVariables = &sharedVariablesStorage;
this->settingsJson = &settingsJsonStorage;
this->customEvents = &customEventsStorage;
this->customEventsLastId = &customEventsLastIdStorage;
this->windowPos = &windowPosStorage;
this->windowSize = &windowSizeStorage;
this->windowPos = &windowPosStorage;
this->windowSize = &windowSizeStorage;
}
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->settingsJson = other.settingsJson;
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->settingsJson = other.settingsJson;
this->customEvents = other.customEvents;
this->customEventsLastId = other.customEventsLastId;
this->windowPos = other.windowPos;
this->windowSize = other.windowSize;
this->windowPos = other.windowPos;
this->windowSize = other.windowSize;
}
public:
@ -88,6 +95,8 @@ namespace hex {
prv::Provider **currentProvider;
std::map<std::string, std::vector<ContentRegistry::Settings::Entry>> *settingsEntries;
nlohmann::json *settingsJson;
std::map<std::string, Events> *customEvents;
u32 *customEventsLastId;
ImVec2 *windowPos;
ImVec2 *windowSize;

View File

@ -47,4 +47,19 @@ namespace hex {
return *SharedData::get().settingsJson;
}
/* Events */
auto ContentRegistry::Events::get(std::string_view name) {
auto &customEvents = *SharedData::get().customEvents;
auto &lastId = *SharedData::get().customEventsLastId;
if (!customEvents.contains(name.data())) {
customEvents[name.data()] = static_cast<hex::Events>(lastId);
lastId++;
}
return customEvents[name.data()];
}
}