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