From e5355d0013f09e7a5cc18b2506e849464a636404 Mon Sep 17 00:00:00 2001 From: Almamu Date: Thu, 14 Aug 2025 01:55:39 +0200 Subject: [PATCH] fix: small mistakes in parsing (fbos not taken into account, values not validated, failed to parse properties not ignored) --- .../Core/Projects/CProperty.cpp | 8 +++++--- .../Data/Parsers/EffectParser.cpp | 20 +++++++++++++++++++ .../Data/Parsers/EffectParser.h | 1 + .../Data/Parsers/MaterialParser.cpp | 2 +- .../Data/Parsers/ProjectParser.cpp | 5 +++++ 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/WallpaperEngine/Core/Projects/CProperty.cpp b/src/WallpaperEngine/Core/Projects/CProperty.cpp index bffbcea..ccfb1ef 100644 --- a/src/WallpaperEngine/Core/Projects/CProperty.cpp +++ b/src/WallpaperEngine/Core/Projects/CProperty.cpp @@ -24,9 +24,11 @@ std::shared_ptr CProperty::fromJSON (const json& data, const std::str if (*type == "text") return CPropertyText::fromJSON (data, name); - // show the error and ignore this property - sLog.error ("Unexpected type for property: ", *type); - sLog.error (data); + if (*type != "group") { + // show the error and ignore this property + sLog.error ("Unexpected type for property: ", *type); + sLog.error (data); + } return nullptr; } diff --git a/src/WallpaperEngine/Data/Parsers/EffectParser.cpp b/src/WallpaperEngine/Data/Parsers/EffectParser.cpp index 93ddda5..d2e63b3 100644 --- a/src/WallpaperEngine/Data/Parsers/EffectParser.cpp +++ b/src/WallpaperEngine/Data/Parsers/EffectParser.cpp @@ -16,6 +16,7 @@ EffectUniquePtr EffectParser::load (Project& project, const std::string& filenam EffectUniquePtr EffectParser::parse (const JSON& it, Project& project) { const auto dependencies = it.optional ("dependencies"); + const auto fbos = it.optional ("fbos"); return std::make_unique (Effect { .name = it.optional ("name", ""), @@ -24,6 +25,7 @@ EffectUniquePtr EffectParser::parse (const JSON& it, Project& project) { .preview = it.optional ("preview", ""), .dependencies = dependencies.has_value () ? parseDependencies (*dependencies) : std::vector {}, .passes = parseEffectPasses (it.require ("passes", "Effect file must have passes"), project), + .fbos = fbos.has_value () ? parseFBOs (*fbos) : std::vector {}, }); } @@ -91,5 +93,23 @@ std::map EffectParser::parseBinds (const JSON& it) { ); } + return result; +} + +std::vector EffectParser::parseFBOs (const JSON& it) { + std::vector result = {}; + + if (!it.is_array ()) { + return result; + } + + for (const auto& cur : it) { + result.push_back(std::make_unique(FBO { + .name = cur.require ("name", "FBO must have a name"), + .format = cur.optional ("format", "rgba8888"), + .scale = cur.optional ("scale", 1.0f), + })); + } + return result; } \ No newline at end of file diff --git a/src/WallpaperEngine/Data/Parsers/EffectParser.h b/src/WallpaperEngine/Data/Parsers/EffectParser.h index 5897aca..0a64c31 100644 --- a/src/WallpaperEngine/Data/Parsers/EffectParser.h +++ b/src/WallpaperEngine/Data/Parsers/EffectParser.h @@ -16,5 +16,6 @@ class EffectParser { static std::vector parseDependencies (const JSON& it); static std::vector parseEffectPasses (const JSON& it, Project& project); static std::map parseBinds (const JSON& it); + static std::vector parseFBOs (const JSON& it); }; } // namespace WallpaperEngine::Data::Parsers diff --git a/src/WallpaperEngine/Data/Parsers/MaterialParser.cpp b/src/WallpaperEngine/Data/Parsers/MaterialParser.cpp index 4804bdb..edc2d3f 100644 --- a/src/WallpaperEngine/Data/Parsers/MaterialParser.cpp +++ b/src/WallpaperEngine/Data/Parsers/MaterialParser.cpp @@ -60,7 +60,7 @@ std::map MaterialParser::parseTextures (const JSON& it) { int index = 0; for (const auto& cur : it) { - if (!it.is_null ()) { + if (!cur.is_null ()) { result.emplace (index, cur); } diff --git a/src/WallpaperEngine/Data/Parsers/ProjectParser.cpp b/src/WallpaperEngine/Data/Parsers/ProjectParser.cpp index cc74d4a..b2dffe4 100644 --- a/src/WallpaperEngine/Data/Parsers/ProjectParser.cpp +++ b/src/WallpaperEngine/Data/Parsers/ProjectParser.cpp @@ -63,6 +63,11 @@ Properties ProjectParser::parseProperties (const std::optional & data) { for (const auto& cur : properties.value ().items ()) { const auto& property = Property::fromJSON (cur.value (), cur.key ()); + // ignore properties that failed, these are generally groups + if (property == nullptr) { + continue; + } + result.emplace (property->getName (), property); }