Pārlūkot izejas kodu

chore: fix condition checking and value propagation for string values (mainly affects combos, fixes #440)

Almamu 7 mēneši atpakaļ
vecāks
revīzija
894d12329a

+ 6 - 0
src/WallpaperEngine/Data/Model/DynamicValue.cpp

@@ -273,6 +273,12 @@ void DynamicValue::update (const std::string& newValue) {
     this->m_bool = false;
     this->m_string = newValue;
     this->m_type = UnderlyingType::String;
+
+    if (this->m_condition.has_value ()) {
+        this->m_bool = this->m_condition.value ().condition == newValue;
+    }
+
+    this->propagate ();
 }
 
 void DynamicValue::update (const DynamicValue& other) {

+ 6 - 1
src/WallpaperEngine/Data/Model/Property.h

@@ -152,8 +152,13 @@ class PropertyCombo final : public Property, ComboData {
 
     using Property::update;
     void update(const std::string& value) override {
+        if (this->values.contains (value) == false) {
+            sLog.error ("Combo value not found in combo options: ", value);
+            return;
+        }
+
         // search for the value in the combo options or default to the textual value
-        this->DynamicValue::update (this->values.contains (value) ? this->values.at (value) : value);
+        this->DynamicValue::update (value);
     }
 
     [[nodiscard]] std::string dump () const override {

+ 2 - 2
src/WallpaperEngine/Data/Parsers/PropertyParser.cpp

@@ -60,8 +60,8 @@ PropertySharedPtr PropertyParser::parseCombo (const JSON& it, const std::string&
         const auto value = cur.require ("value", "Combo option must have a value");
 
         optionsMap.emplace (
-            cur.require ("label", "Combo option must have a label"),
-            value.is_number () ? std::to_string (value.get <int> ()) : value.get <std::string> ()
+            value.is_number () ? std::to_string (value.get <int> ()) : value.get <std::string> (),
+            cur.require ("label", "Combo option must have a label")
         );
     }