2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2021-09-03 02:33:15 +02:00
|
|
|
#include <hex/helpers/paths.hpp>
|
2022-01-13 14:33:30 +01:00
|
|
|
#include <hex/helpers/logger.hpp>
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
#include <hex/ui/view.hpp>
|
|
|
|
|
2021-01-11 20:31:40 +01:00
|
|
|
#include <filesystem>
|
|
|
|
#include <fstream>
|
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
2021-01-11 20:31:40 +01:00
|
|
|
namespace hex {
|
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
namespace ContentRegistry::Settings {
|
|
|
|
|
|
|
|
void load() {
|
|
|
|
bool loaded = false;
|
|
|
|
for (const auto &dir : hex::getPath(ImHexPath::Config)) {
|
|
|
|
std::ifstream settingsFile(dir / "settings.json");
|
|
|
|
|
|
|
|
if (settingsFile.good()) {
|
|
|
|
settingsFile >> getSettingsData();
|
|
|
|
loaded = true;
|
|
|
|
break;
|
|
|
|
}
|
2021-03-01 08:56:49 +01:00
|
|
|
}
|
2021-07-31 17:11:10 +02:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
if (!loaded)
|
|
|
|
store();
|
|
|
|
}
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void store() {
|
|
|
|
for (const auto &dir : hex::getPath(ImHexPath::Config)) {
|
|
|
|
std::ofstream settingsFile(dir / "settings.json", std::ios::trunc);
|
2021-03-01 08:56:49 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
if (settingsFile.good()) {
|
|
|
|
settingsFile << getSettingsData();
|
|
|
|
break;
|
|
|
|
}
|
2021-03-01 08:56:49 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, i64 defaultValue, const Callback &callback) {
|
|
|
|
log::info("Registered new integer setting: [{}]: {}", unlocalizedCategory, unlocalizedName);
|
2022-01-13 14:34:27 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
getEntries()[unlocalizedCategory.c_str()].emplace_back(Entry { unlocalizedName.c_str(), callback });
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
auto &json = getSettingsData();
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
if (!json.contains(unlocalizedCategory))
|
|
|
|
json[unlocalizedCategory] = nlohmann::json::object();
|
|
|
|
if (!json[unlocalizedCategory].contains(unlocalizedName) || !json[unlocalizedCategory][unlocalizedName].is_number())
|
|
|
|
json[unlocalizedCategory][unlocalizedName] = int(defaultValue);
|
|
|
|
}
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &defaultValue, const Callback &callback) {
|
|
|
|
log::info("Registered new string setting: [{}]: {}", unlocalizedCategory, unlocalizedName);
|
2022-01-13 14:34:27 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
getEntries()[unlocalizedCategory].emplace_back(Entry { unlocalizedName, callback });
|
2021-02-13 15:15:32 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
auto &json = getSettingsData();
|
2021-02-13 15:15:32 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
if (!json.contains(unlocalizedCategory))
|
|
|
|
json[unlocalizedCategory] = nlohmann::json::object();
|
|
|
|
if (!json[unlocalizedCategory].contains(unlocalizedName) || !json[unlocalizedCategory][unlocalizedName].is_string())
|
|
|
|
json[unlocalizedCategory][unlocalizedName] = std::string(defaultValue);
|
|
|
|
}
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, i64 value) {
|
|
|
|
auto &json = getSettingsData();
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
if (!json.contains(unlocalizedCategory))
|
|
|
|
json[unlocalizedCategory] = nlohmann::json::object();
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
json[unlocalizedCategory][unlocalizedName] = value;
|
|
|
|
}
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &value) {
|
|
|
|
auto &json = getSettingsData();
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
if (!json.contains(unlocalizedCategory))
|
|
|
|
json[unlocalizedCategory] = nlohmann::json::object();
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
json[unlocalizedCategory][unlocalizedName] = value;
|
|
|
|
}
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector<std::string> &value) {
|
|
|
|
auto &json = getSettingsData();
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
if (!json.contains(unlocalizedCategory))
|
|
|
|
json[unlocalizedCategory] = nlohmann::json::object();
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
json[unlocalizedCategory][unlocalizedName] = value;
|
|
|
|
}
|
2021-02-01 19:03:28 +01:00
|
|
|
|
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
i64 read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, i64 defaultValue) {
|
|
|
|
auto &json = getSettingsData();
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
if (!json.contains(unlocalizedCategory))
|
|
|
|
return defaultValue;
|
|
|
|
if (!json[unlocalizedCategory].contains(unlocalizedName))
|
|
|
|
return defaultValue;
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
if (!json[unlocalizedCategory][unlocalizedName].is_number())
|
|
|
|
json[unlocalizedCategory][unlocalizedName] = defaultValue;
|
2021-09-12 13:59:23 +02:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return json[unlocalizedCategory][unlocalizedName].get<i64>();
|
|
|
|
}
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
std::string read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &defaultValue) {
|
|
|
|
auto &json = getSettingsData();
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
if (!json.contains(unlocalizedCategory))
|
|
|
|
return defaultValue;
|
|
|
|
if (!json[unlocalizedCategory].contains(unlocalizedName))
|
|
|
|
return defaultValue;
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
if (!json[unlocalizedCategory][unlocalizedName].is_string())
|
|
|
|
json[unlocalizedCategory][unlocalizedName] = defaultValue;
|
2021-09-12 13:59:23 +02:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return json[unlocalizedCategory][unlocalizedName].get<std::string>();
|
|
|
|
}
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
std::vector<std::string> read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector<std::string> &defaultValue) {
|
|
|
|
auto &json = getSettingsData();
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
if (!json.contains(unlocalizedCategory))
|
|
|
|
return defaultValue;
|
|
|
|
if (!json[unlocalizedCategory].contains(unlocalizedName))
|
|
|
|
return defaultValue;
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
if (!json[unlocalizedCategory][unlocalizedName].is_array())
|
|
|
|
json[unlocalizedCategory][unlocalizedName] = defaultValue;
|
2021-09-12 20:27:56 +02:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
if (!json[unlocalizedCategory][unlocalizedName].array().empty() && !json[unlocalizedCategory][unlocalizedName][0].is_string())
|
|
|
|
json[unlocalizedCategory][unlocalizedName] = defaultValue;
|
2021-09-12 13:59:23 +02:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return json[unlocalizedCategory][unlocalizedName].get<std::vector<std::string>>();
|
|
|
|
}
|
2021-02-01 19:03:28 +01:00
|
|
|
|
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
std::map<std::string, std::vector<Entry>> &getEntries() {
|
|
|
|
static std::map<std::string, std::vector<Entry>> entries;
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return entries;
|
|
|
|
}
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
nlohmann::json getSetting(const std::string &unlocalizedCategory, const std::string &unlocalizedName) {
|
|
|
|
auto &settings = getSettingsData();
|
2021-02-16 23:42:35 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
if (!settings.contains(unlocalizedCategory)) return {};
|
|
|
|
if (!settings[unlocalizedCategory].contains(unlocalizedName)) return {};
|
2021-02-16 23:42:35 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return settings[unlocalizedCategory][unlocalizedName];
|
|
|
|
}
|
2021-02-16 23:42:35 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
nlohmann::json &getSettingsData() {
|
|
|
|
static nlohmann::json settings;
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2021-01-11 20:31:40 +01:00
|
|
|
}
|
|
|
|
|
2021-01-11 21:11:03 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
namespace ContentRegistry::CommandPaletteCommands {
|
2021-01-11 23:02:55 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void add(Type type, const std::string &command, const std::string &unlocalizedDescription, const DisplayCallback &displayCallback, const ExecuteCallback &executeCallback) {
|
|
|
|
log::info("Registered new command palette command: {}", command);
|
2022-01-13 14:34:27 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
getEntries().push_back(ContentRegistry::CommandPaletteCommands::Entry { type, command, unlocalizedDescription, displayCallback, executeCallback });
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Entry> &getEntries() {
|
|
|
|
static std::vector<Entry> commands;
|
2021-01-11 23:02:55 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return commands;
|
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2021-01-11 23:02:55 +01:00
|
|
|
}
|
|
|
|
|
2021-01-11 23:54:12 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
namespace ContentRegistry::PatternLanguage {
|
2021-01-11 23:54:12 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
static std::string getFunctionName(const Namespace &ns, const std::string &name) {
|
|
|
|
std::string functionName;
|
|
|
|
for (auto &scope : ns)
|
|
|
|
functionName += scope + "::";
|
2021-08-27 09:56:20 +02:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
functionName += name;
|
2021-08-27 09:56:20 +02:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return functionName;
|
|
|
|
}
|
2021-08-27 09:56:20 +02:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void addFunction(const Namespace &ns, const std::string &name, u32 parameterCount, const Callback &func) {
|
|
|
|
log::info("Registered new pattern language function: {}", getFunctionName(ns, name));
|
2021-01-11 23:54:12 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
getFunctions()[getFunctionName(ns, name)] = Function { parameterCount, func, false };
|
|
|
|
}
|
2022-01-13 14:34:27 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void addDangerousFunction(const Namespace &ns, const std::string &name, u32 parameterCount, const Callback &func) {
|
|
|
|
log::info("Registered new dangerous pattern language function: {}", getFunctionName(ns, name));
|
2021-12-20 20:40:28 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
getFunctions()[getFunctionName(ns, name)] = Function { parameterCount, func, true };
|
|
|
|
}
|
2022-01-13 14:34:27 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
std::map<std::string, Function> &getFunctions() {
|
|
|
|
static std::map<std::string, Function> functions;
|
2021-12-20 20:40:28 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return functions;
|
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
|
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
static std::vector<impl::ColorPalette> s_colorPalettes;
|
|
|
|
static u32 s_colorIndex;
|
|
|
|
static u32 s_selectedColorPalette;
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
std::vector<impl::ColorPalette> &getPalettes() {
|
|
|
|
return s_colorPalettes;
|
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void addColorPalette(const std::string &unlocalizedName, const std::vector<u32> &colors) {
|
|
|
|
s_colorPalettes.push_back({ unlocalizedName,
|
|
|
|
colors });
|
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void setSelectedPalette(u32 index) {
|
|
|
|
if (index < s_colorPalettes.size())
|
|
|
|
s_selectedColorPalette = index;
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
resetPalette();
|
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
u32 getNextColor() {
|
|
|
|
if (s_colorPalettes.empty())
|
|
|
|
return 0x00;
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
auto &currColors = s_colorPalettes[s_selectedColorPalette].colors;
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
u32 color = currColors[s_colorIndex];
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
s_colorIndex++;
|
|
|
|
s_colorIndex %= currColors.size();
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return color;
|
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void resetPalette() {
|
|
|
|
s_colorIndex = 0;
|
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2021-01-11 23:54:12 +01:00
|
|
|
}
|
|
|
|
|
2021-01-12 16:50:15 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
namespace ContentRegistry::Views {
|
2021-01-12 16:50:15 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void impl::add(View *view) {
|
|
|
|
log::info("Registered new view: {}", view->getUnlocalizedName());
|
2022-01-13 14:34:27 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
getEntries().insert({ view->getUnlocalizedName(), view });
|
|
|
|
}
|
2021-01-12 16:50:15 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
std::map<std::string, View *> &getEntries() {
|
|
|
|
static std::map<std::string, View *> views;
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return views;
|
|
|
|
}
|
2021-01-12 16:50:15 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
View *getViewByName(const std::string &unlocalizedName) {
|
|
|
|
auto &views = getEntries();
|
|
|
|
|
|
|
|
if (views.contains(unlocalizedName))
|
|
|
|
return views[unlocalizedName];
|
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-01-18 00:10:10 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
namespace ContentRegistry::Tools {
|
2021-01-12 16:50:15 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void add(const std::string &unlocalizedName, const impl::Callback &function) {
|
|
|
|
log::info("Registered new tool: {}", unlocalizedName);
|
2021-01-12 16:50:15 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
getEntries().emplace_back(impl::Entry { unlocalizedName, function });
|
|
|
|
}
|
2022-01-13 14:34:27 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
std::vector<impl::Entry> &getEntries() {
|
|
|
|
static std::vector<impl::Entry> entries;
|
2021-01-12 16:50:15 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return entries;
|
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2021-01-12 16:50:15 +01:00
|
|
|
}
|
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
namespace ContentRegistry::DataInspector {
|
2021-01-13 01:24:27 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void add(const std::string &unlocalizedName, size_t requiredSize, impl::GeneratorFunction function) {
|
|
|
|
log::info("Registered new data inspector format: {}", unlocalizedName);
|
2021-01-13 01:24:27 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
getEntries().push_back({ unlocalizedName, requiredSize, std::move(function) });
|
|
|
|
}
|
2022-01-13 14:34:27 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
std::vector<impl::Entry> &getEntries() {
|
|
|
|
static std::vector<impl::Entry> entries;
|
2021-01-13 01:24:27 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return entries;
|
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2021-01-13 01:24:27 +01:00
|
|
|
}
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
namespace ContentRegistry::DataProcessorNode {
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void impl::add(const impl::Entry &entry) {
|
|
|
|
log::info("Registered new data processor node type: [{}]: ", entry.category, entry.name);
|
2022-01-13 14:34:27 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
getEntries().push_back(entry);
|
|
|
|
}
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void addSeparator() {
|
|
|
|
getEntries().push_back({ "", "", [] { return nullptr; } });
|
|
|
|
}
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
std::vector<impl::Entry> &getEntries() {
|
|
|
|
static std::vector<impl::Entry> nodes;
|
|
|
|
|
|
|
|
return nodes;
|
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
2021-02-11 00:35:30 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
namespace ContentRegistry::Language {
|
2021-02-11 00:35:30 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void registerLanguage(const std::string &name, const std::string &languageCode) {
|
|
|
|
log::info("Registered new language: {} ({})", name, languageCode);
|
2022-01-13 14:34:27 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
getLanguages().insert({ languageCode, name });
|
|
|
|
}
|
2021-02-11 00:35:30 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void addLocalizations(const std::string &languageCode, const LanguageDefinition &definition) {
|
|
|
|
log::info("Registered new localization for language {} with {} entries", languageCode, definition.getEntries().size());
|
2022-01-13 14:34:27 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
getLanguageDefinitions()[languageCode].push_back(definition);
|
|
|
|
}
|
2021-02-11 00:35:30 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
std::map<std::string, std::string> &getLanguages() {
|
|
|
|
static std::map<std::string, std::string> languages;
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return languages;
|
|
|
|
}
|
2021-02-11 00:35:30 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
std::map<std::string, std::vector<LanguageDefinition>> &getLanguageDefinitions() {
|
|
|
|
static std::map<std::string, std::vector<LanguageDefinition>> definitions;
|
|
|
|
|
|
|
|
return definitions;
|
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2021-02-11 00:35:30 +01:00
|
|
|
}
|
2021-02-18 12:09:19 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
namespace ContentRegistry::Interface {
|
2021-02-18 12:09:19 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void registerMainMenuItem(const std::string &unlocalizedName, u32 priority) {
|
|
|
|
log::info("Registered new main menu item: {}", unlocalizedName);
|
2022-01-13 14:34:27 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
getMainMenuItems().insert({ priority, { unlocalizedName } });
|
|
|
|
}
|
2022-01-18 00:10:10 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void addMenuItem(const std::string &unlocalizedMainMenuName, u32 priority, const impl::DrawCallback &function) {
|
|
|
|
log::info("Added new menu item to menu {} with priority {}", unlocalizedMainMenuName, priority);
|
2022-01-18 00:10:10 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
getMenuItems().insert({
|
|
|
|
priority, {unlocalizedMainMenuName, function}
|
|
|
|
});
|
|
|
|
}
|
2022-01-23 02:28:38 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void addWelcomeScreenEntry(const impl::DrawCallback &function) {
|
|
|
|
getWelcomeScreenEntries().push_back(function);
|
|
|
|
}
|
2022-01-23 02:28:38 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void addFooterItem(const impl::DrawCallback &function) {
|
|
|
|
getFooterItems().push_back(function);
|
|
|
|
}
|
2021-02-18 12:09:19 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void addToolbarItem(const impl::DrawCallback &function) {
|
|
|
|
getToolbarItems().push_back(function);
|
|
|
|
}
|
2021-02-18 12:09:19 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void addSidebarItem(const std::string &icon, const impl::DrawCallback &function) {
|
|
|
|
getSidebarItems().push_back({ icon, function });
|
|
|
|
}
|
2021-08-21 00:52:11 +02:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void addTitleBarButton(const std::string &icon, const std::string &unlocalizedTooltip, const impl::ClickCallback &function) {
|
|
|
|
getTitleBarButtons().push_back({ icon, unlocalizedTooltip, function });
|
|
|
|
}
|
2022-01-22 22:03:19 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void addLayout(const std::string &unlocalizedName, const impl::LayoutFunction &function) {
|
|
|
|
log::info("Added new layout: {}", unlocalizedName);
|
2021-02-18 12:09:19 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
getLayouts().push_back({ unlocalizedName, function });
|
|
|
|
}
|
2022-01-18 00:10:10 +01:00
|
|
|
|
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
std::multimap<u32, impl::MainMenuItem> &getMainMenuItems() {
|
|
|
|
static std::multimap<u32, impl::MainMenuItem> items;
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return items;
|
|
|
|
}
|
|
|
|
std::multimap<u32, impl::MenuItem> &getMenuItems() {
|
|
|
|
static std::multimap<u32, impl::MenuItem> items;
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return items;
|
|
|
|
}
|
2022-01-18 00:10:10 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
std::vector<impl::DrawCallback> &getWelcomeScreenEntries() {
|
|
|
|
static std::vector<impl::DrawCallback> entries;
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
std::vector<impl::DrawCallback> &getFooterItems() {
|
|
|
|
static std::vector<impl::DrawCallback> items;
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return items;
|
|
|
|
}
|
|
|
|
std::vector<impl::DrawCallback> &getToolbarItems() {
|
|
|
|
static std::vector<impl::DrawCallback> items;
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return items;
|
|
|
|
}
|
|
|
|
std::vector<impl::SidebarItem> &getSidebarItems() {
|
|
|
|
static std::vector<impl::SidebarItem> items;
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return items;
|
|
|
|
}
|
|
|
|
std::vector<impl::TitleBarButton> &getTitleBarButtons() {
|
|
|
|
static std::vector<impl::TitleBarButton> buttons;
|
2021-12-07 22:47:41 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return buttons;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<impl::Layout> &getLayouts() {
|
|
|
|
static std::vector<impl::Layout> layouts;
|
|
|
|
|
|
|
|
return layouts;
|
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-01-18 00:10:10 +01:00
|
|
|
}
|
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
namespace ContentRegistry::Provider {
|
2021-12-07 22:47:41 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void impl::addProviderName(const std::string &unlocalizedName) {
|
|
|
|
log::info("Registered new provider: {}", unlocalizedName);
|
2021-12-07 22:47:41 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
getEntries().push_back(unlocalizedName);
|
|
|
|
}
|
2022-01-13 14:34:27 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
std::vector<std::string> &getEntries() {
|
|
|
|
static std::vector<std::string> providerNames;
|
2021-12-07 22:47:41 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return providerNames;
|
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
}
|
2022-01-13 00:27:31 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
namespace ContentRegistry::DataFormatter {
|
2022-01-13 00:27:31 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void add(const std::string &unlocalizedName, const impl::Callback &callback) {
|
|
|
|
log::info("Registered new data formatter: {}", unlocalizedName);
|
2022-01-13 00:27:31 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
getEntries().push_back({ unlocalizedName, callback });
|
|
|
|
}
|
2022-01-13 14:34:19 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
std::vector<impl::Entry> &getEntries() {
|
|
|
|
static std::vector<impl::Entry> entries;
|
2022-01-13 00:27:31 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return entries;
|
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-01-13 00:27:31 +01:00
|
|
|
}
|
2022-01-13 14:34:19 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
namespace ContentRegistry::FileHandler {
|
2022-01-13 14:34:19 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
void add(const std::vector<std::string> &extensions, const impl::Callback &callback) {
|
|
|
|
for (const auto &extension : extensions)
|
|
|
|
log::info("Registered new data handler for extensions: {}", extension);
|
2022-01-13 14:34:19 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
getEntries().push_back({ extensions, callback });
|
|
|
|
}
|
2022-01-13 14:34:19 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
std::vector<impl::Entry> &getEntries() {
|
|
|
|
static std::vector<impl::Entry> entries;
|
2022-01-13 14:34:19 +01:00
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
return entries;
|
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-01-13 14:34:19 +01:00
|
|
|
}
|
2022-02-02 00:36:09 +01:00
|
|
|
|
2021-01-11 20:31:40 +01:00
|
|
|
}
|