diff --git a/source/client/StarClientApplication.cpp b/source/client/StarClientApplication.cpp index 71bec5d..7d8d321 100644 --- a/source/client/StarClientApplication.cpp +++ b/source/client/StarClientApplication.cpp @@ -434,6 +434,8 @@ void ClientApplication::getAudioData(int16_t* sampleData, size_t frameCount) { } } +auto postProcessGroupsRoot = "postProcessGroups"; + void ClientApplication::renderReload() { auto assets = m_root->assets(); auto renderer = Application::renderer(); @@ -464,18 +466,55 @@ void ClientApplication::renderReload() { loadEffectConfig("world"); + // define post process groups and set them to be enabled/disabled based on config + + auto config = m_root->configuration(); + if (!config->get(postProcessGroupsRoot).isType(Json::Type::Object)) + config->set(postProcessGroupsRoot, JsonObject()); + auto groupsConfig = config->get(postProcessGroupsRoot); + + m_postProcessGroups.clear(); + auto postProcessGroups = assets->json("/client.config:postProcessGroups").toObject(); + for (auto& pair : postProcessGroups) { + auto name = pair.first; + auto groupConfig = groupsConfig.opt(name); + auto def = pair.second.getBool("enabledDefault",true); + if (!groupConfig) + config->setPath(strf("{}.{}", postProcessGroupsRoot, name),JsonObject()); + m_postProcessGroups.add(name,PostProcessGroup{ groupConfig ? groupConfig.value().getBool("enabled", def) : def }); + } + + // define post process layers and optionally assign them to groups m_postProcessLayers.clear(); auto postProcessLayers = assets->json("/client.config:postProcessLayers").toArray(); for (auto& layer : postProcessLayers) { auto effects = jsonToStringList(layer.getArray("effects")); for (auto& effect : effects) loadEffectConfig(effect); - m_postProcessLayers.append(PostProcessLayer{ std::move(effects), (unsigned)layer.getUInt("passes", 1) }); + PostProcessGroup* group = nullptr; + auto gname = layer.optString("group"); + if (gname) { + group = &m_postProcessGroups.get(gname.value()); + } + m_postProcessLayers.append(PostProcessLayer{ std::move(effects), (unsigned)layer.getUInt("passes", 1), group }); } loadEffectConfig("interface"); } +void ClientApplication::setPostProcessGroupEnabled(String group, bool enabled, Maybe save) { + m_postProcessGroups.get(group).enabled = enabled; + if (save && save.value()) + m_root->configuration()->setPath(strf("{}.{}.enabled", postProcessGroupsRoot, group),enabled); +} +bool ClientApplication::postProcessGroupEnabled(String group) { + return m_postProcessGroups.get(group).enabled; +} + +Json ClientApplication::postProcessGroups() { + return m_root->assets()->json("/client.config:postProcessGroups"); +} + void ClientApplication::changeState(MainAppState newState) { MainAppState oldState = m_state; m_state = newState;