[skotty] More flexible property parsing

Older Json versions don't tag properties wih an "a" animation marker,
but appear to instead rely on a try-and-see-what-sticks approach.

TBR=
Change-Id: I8a3a7e43576c590aa5ac168891574ceb4811ad49
Reviewed-on: https://skia-review.googlesource.com/91861
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Florin Malita 2018-01-08 10:15:12 -05:00 committed by Skia Commit-Bot
parent 7c2192b336
commit 95448a90c1

View File

@ -60,25 +60,33 @@ bool AttachProperty(const Json::Value& jprop, AttachContext* ctx, const sk_sp<No
if (!jprop.isObject())
return false;
if (!ParseBool(jprop["a"], false)) {
// Static property.
const auto& jpropA = jprop["a"];
const auto& jpropK = jprop["k"];
// Older Json versions don't have an "a" animation marker.
// For those, we attempt to parse both ways.
if (jpropA.isNull() || !ParseBool(jpropA, "false")) {
ValueT val;
if (!ValueT::Parse(jprop["k"], &val)) {
return LogFail(jprop, "Could not parse static property");
if (ValueT::Parse(jpropK, &val)) {
// Static property.
apply(node, val.template as<AttrT>());
return true;
}
if (!jpropA.isNull()) {
return LogFail(jprop, "Could not parse (explicit) static property");
}
}
apply(node, val.template as<AttrT>());
} else {
// Keyframe property.
using AnimatorT = Animator<ValueT, AttrT, NodeT>;
auto animator = AnimatorT::Make(jprop["k"], node, std::move(apply));
auto animator = AnimatorT::Make(jpropK, node, std::move(apply));
if (!animator) {
return LogFail(jprop, "Could not instantiate keyframe animator");
return LogFail(jprop, "Could not parse keyframed property");
}
ctx->fAnimators.push_back(std::move(animator));
}
return true;
}