#include "UserSettingParser.h" #include "WallpaperEngine/Data/Model/UserSetting.h" #include "WallpaperEngine/Data/Model/Property.h" using namespace WallpaperEngine::Data::Parsers; using namespace WallpaperEngine::Data::Builders; UserSettingUniquePtr UserSettingParser::parse (const json& data, const Properties& properties) { auto value = std::make_unique (); PropertySharedPtr property; std::optional condition; auto valueIt = data; std::string content = data.dump (); if (data.is_object ()) { const auto user = data.optional ("user"); const auto script = data.optional ("script"); valueIt = data.require ("value", "User setting must have a value"); // TODO: PARSE SCRIPT VALUES if (script.has_value () && !script->is_null ()) { sLog.error ("Found user setting with script value: ", script.value ().dump ()); } if (user.has_value () && !user->is_null ()) { std::string source; if (const auto& it = *user; it.is_string ()) { source = it; } else { condition = ConditionInfo { .name = it.require ("name", "Name for conditional setting must be present"), .condition = it.require ("condition", "Condition for conditional setting must be present"), }; source = condition.value ().name; } if (const auto propertyIt = properties.find (source); propertyIt != properties.end ()) { property = propertyIt->second; } } } // actual value parsing if (valueIt.is_string ()) { std::string str = valueIt; int size = VectorBuilder::preparseSize (str); //TODO: VALIDATE THIS IS RIGHT? if (size == 2) { value->update (static_cast (valueIt)); } else if (size == 3) { value->update (static_cast (valueIt)); } else { value->update (static_cast (valueIt)); } } else if (valueIt.is_number_integer ()) { value->update (valueIt.get ()); } else if (valueIt.is_number_float ()) { value->update (valueIt.get ()); } else if (valueIt.is_boolean ()) { value->update (valueIt.get ()); } else if (valueIt.is_null () && property != nullptr) { // null values are directly connected to the property value->connect (property.get()); } else { sLog.exception ("Unsupported user setting type ", valueIt.type_name ()); } return std::make_unique (UserSetting { .value = std::move (value), .property = property, .condition = condition, }); }