fix: small mistakes in parsing (fbos not taken into account, values not validated, failed to parse properties not ignored)

This commit is contained in:
Almamu 2025-08-14 01:55:39 +02:00
parent 2569960681
commit e5355d0013
5 changed files with 32 additions and 4 deletions

View File

@ -24,9 +24,11 @@ std::shared_ptr<CProperty> CProperty::fromJSON (const json& data, const std::str
if (*type == "text") if (*type == "text")
return CPropertyText::fromJSON (data, name); return CPropertyText::fromJSON (data, name);
// show the error and ignore this property if (*type != "group") {
sLog.error ("Unexpected type for property: ", *type); // show the error and ignore this property
sLog.error (data); sLog.error ("Unexpected type for property: ", *type);
sLog.error (data);
}
return nullptr; return nullptr;
} }

View File

@ -16,6 +16,7 @@ EffectUniquePtr EffectParser::load (Project& project, const std::string& filenam
EffectUniquePtr EffectParser::parse (const JSON& it, Project& project) { EffectUniquePtr EffectParser::parse (const JSON& it, Project& project) {
const auto dependencies = it.optional ("dependencies"); const auto dependencies = it.optional ("dependencies");
const auto fbos = it.optional ("fbos");
return std::make_unique <Effect> (Effect { return std::make_unique <Effect> (Effect {
.name = it.optional <std::string> ("name", ""), .name = it.optional <std::string> ("name", ""),
@ -24,6 +25,7 @@ EffectUniquePtr EffectParser::parse (const JSON& it, Project& project) {
.preview = it.optional <std::string> ("preview", ""), .preview = it.optional <std::string> ("preview", ""),
.dependencies = dependencies.has_value () ? parseDependencies (*dependencies) : std::vector <std::string> {}, .dependencies = dependencies.has_value () ? parseDependencies (*dependencies) : std::vector <std::string> {},
.passes = parseEffectPasses (it.require ("passes", "Effect file must have passes"), project), .passes = parseEffectPasses (it.require ("passes", "Effect file must have passes"), project),
.fbos = fbos.has_value () ? parseFBOs (*fbos) : std::vector <FBOUniquePtr> {},
}); });
} }
@ -93,3 +95,21 @@ std::map <int, std::string> EffectParser::parseBinds (const JSON& it) {
return result; return result;
} }
std::vector <FBOUniquePtr> EffectParser::parseFBOs (const JSON& it) {
std::vector <FBOUniquePtr> result = {};
if (!it.is_array ()) {
return result;
}
for (const auto& cur : it) {
result.push_back(std::make_unique<FBO>(FBO {
.name = cur.require <std::string> ("name", "FBO must have a name"),
.format = cur.optional <std::string> ("format", "rgba8888"),
.scale = cur.optional ("scale", 1.0f),
}));
}
return result;
}

View File

@ -16,5 +16,6 @@ class EffectParser {
static std::vector <std::string> parseDependencies (const JSON& it); static std::vector <std::string> parseDependencies (const JSON& it);
static std::vector <EffectPassUniquePtr> parseEffectPasses (const JSON& it, Project& project); static std::vector <EffectPassUniquePtr> parseEffectPasses (const JSON& it, Project& project);
static std::map <int, std::string> parseBinds (const JSON& it); static std::map <int, std::string> parseBinds (const JSON& it);
static std::vector <FBOUniquePtr> parseFBOs (const JSON& it);
}; };
} // namespace WallpaperEngine::Data::Parsers } // namespace WallpaperEngine::Data::Parsers

View File

@ -60,7 +60,7 @@ std::map <int, std::string> MaterialParser::parseTextures (const JSON& it) {
int index = 0; int index = 0;
for (const auto& cur : it) { for (const auto& cur : it) {
if (!it.is_null ()) { if (!cur.is_null ()) {
result.emplace (index, cur); result.emplace (index, cur);
} }

View File

@ -63,6 +63,11 @@ Properties ProjectParser::parseProperties (const std::optional <JSON>& data) {
for (const auto& cur : properties.value ().items ()) { for (const auto& cur : properties.value ().items ()) {
const auto& property = Property::fromJSON (cur.value (), cur.key ()); 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); result.emplace (property->getName (), property);
} }