Browse Source

Add module whitelist to settings and Module Browser.

tags/v2.0.0
Andrew Belt 5 years ago
parent
commit
14d9a8ea82
3 changed files with 51 additions and 7 deletions
  1. +2
    -0
      include/settings.hpp
  2. +21
    -6
      src/app/ModuleBrowser.cpp
  3. +28
    -1
      src/settings.cpp

+ 2
- 0
include/settings.hpp View File

@@ -38,6 +38,8 @@ extern float autosavePeriod;
extern bool skipLoadOnLaunch;
extern std::string patchPath;
extern std::vector<NVGcolor> cableColors;
// pluginSlug -> moduleSlugs
extern std::map<std::string, std::vector<std::string>> moduleWhitelist;

json_t* toJson();
void fromJson(json_t* rootJ);


+ 21
- 6
src/app/ModuleBrowser.cpp View File

@@ -428,16 +428,31 @@ struct ModuleBrowser : widget::OpaqueWidget {
modelContainer->spacing = math::Vec(10, 10);
modelMargin->addChild(modelContainer);

// Add ModelBoxes for each Model
resetModelContainer();

clear();
}

void resetModelContainer() {
modelContainer->clearChildren();
// Iterate plugins
for (plugin::Plugin* plugin : plugin::plugins) {
// Get module slugs from module whitelist
const auto& pluginIt = settings::moduleWhitelist.find(plugin->slug);
// Iterate models in plugin
for (plugin::Model* model : plugin->models) {
ModelBox* moduleBox = new ModelBox;
moduleBox->setModel(model);
modelContainer->addChild(moduleBox);
// Don't show module if plugin whitelist exists but the module is not in it.
if (pluginIt != settings::moduleWhitelist.end()) {
auto moduleIt = std::find(pluginIt->second.begin(), pluginIt->second.end(), model->slug);
if (moduleIt == pluginIt->second.end())
continue;
}
// Create ModelBox
ModelBox* modelBox = new ModelBox;
modelBox->setModel(model);
modelContainer->addChild(modelBox);
}
}

clear();
}

void step() override {


+ 28
- 1
src/settings.cpp View File

@@ -43,6 +43,7 @@ std::vector<NVGcolor> cableColors = {
nvgRGB(0xc9, 0x18, 0x47), // red
nvgRGB(0x09, 0x86, 0xad), // blue
};
std::map<std::string, std::vector<std::string>> moduleWhitelist = {};


json_t* toJson() {
@@ -93,6 +94,16 @@ json_t* toJson() {
}
json_object_set_new(rootJ, "cableColors", cableColorsJ);

json_t* moduleWhitelistJ = json_object();
for (const auto& pair : moduleWhitelist) {
json_t* moduleSlugsJ = json_array();
for (const std::string& moduleSlug : pair.second) {
json_array_append_new(moduleSlugsJ, json_string(moduleSlug.c_str()));
}
json_object_set_new(moduleWhitelistJ, pair.first.c_str(), moduleSlugsJ);
}
json_object_set_new(rootJ, "moduleWhitelist", moduleWhitelistJ);

return rootJ;
}

@@ -171,9 +182,9 @@ void fromJson(json_t* rootJ) {
if (patchPathJ)
patchPath = json_string_value(patchPathJ);

cableColors.clear();
json_t* cableColorsJ = json_object_get(rootJ, "cableColors");
if (cableColorsJ) {
cableColors.clear();
size_t i;
json_t* cableColorJ;
json_array_foreach(cableColorsJ, i, cableColorJ) {
@@ -181,6 +192,22 @@ void fromJson(json_t* rootJ) {
cableColors.push_back(color::fromHexString(colorStr));
}
}

moduleWhitelist.clear();
json_t* moduleWhitelistJ = json_object_get(rootJ, "moduleWhitelist");
if (moduleWhitelistJ) {
const char* pluginSlug;
json_t* moduleSlugsJ;
json_object_foreach(moduleWhitelistJ, pluginSlug, moduleSlugsJ) {
auto& moduleSlugs = moduleWhitelist[pluginSlug];
size_t i;
json_t* moduleSlugJ;
json_array_foreach(moduleSlugsJ, i, moduleSlugJ) {
std::string moduleSlug = json_string_value(moduleSlugJ);
moduleSlugs.push_back(moduleSlug);
}
}
}
}

void save(const std::string& path) {


Loading…
Cancel
Save