mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
fix: small mistakes in parsing (fbos not taken into account, values not validated, failed to parse properties not ignored)
This commit is contained in:
parent
2569960681
commit
e5355d0013
@ -24,9 +24,11 @@ std::shared_ptr<CProperty> 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;
|
||||
}
|
||||
|
@ -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> (Effect {
|
||||
.name = it.optional <std::string> ("name", ""),
|
||||
@ -24,6 +25,7 @@ EffectUniquePtr EffectParser::parse (const JSON& it, Project& project) {
|
||||
.preview = it.optional <std::string> ("preview", ""),
|
||||
.dependencies = dependencies.has_value () ? parseDependencies (*dependencies) : std::vector <std::string> {},
|
||||
.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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
@ -16,5 +16,6 @@ class EffectParser {
|
||||
static std::vector <std::string> parseDependencies (const JSON& it);
|
||||
static std::vector <EffectPassUniquePtr> parseEffectPasses (const JSON& it, Project& project);
|
||||
static std::map <int, std::string> parseBinds (const JSON& it);
|
||||
static std::vector <FBOUniquePtr> parseFBOs (const JSON& it);
|
||||
};
|
||||
} // namespace WallpaperEngine::Data::Parsers
|
||||
|
@ -60,7 +60,7 @@ std::map <int, std::string> 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);
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,11 @@ Properties ProjectParser::parseProperties (const std::optional <JSON>& 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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user