Changes to pass File class tests.

1. A scalar value is also emitted if the display name is not different
from the file name, and the value is single-quoted to match masterlist
style.
2. Condition and display YAML keys are only created if data exists for
those keys, to match the emitter behaviour.
This commit is contained in:
Oliver Hamlet
2015-07-12 18:36:53 +01:00
parent 4aa59f05cc
commit 2eedbba841
2 changed files with 15 additions and 7 deletions
+2 -2
View File
@@ -56,8 +56,8 @@ namespace loot {
namespace YAML {
Emitter& operator << (Emitter& out, const loot::File& rhs) {
if (!rhs.IsConditional() && rhs.DisplayName().empty())
out << rhs.Name();
if (!rhs.IsConditional() && (rhs.DisplayName().empty() || rhs.DisplayName() == rhs.Name()))
out << YAML::SingleQuoted << rhs.Name();
else {
out << BeginMap
<< Key << "name" << Value << YAML::SingleQuoted << rhs.Name();
+13 -5
View File
@@ -53,28 +53,36 @@ namespace YAML {
struct convert < loot::File > {
static Node encode(const loot::File& rhs) {
Node node;
node["condition"] = rhs.Condition();
node["name"] = rhs.Name();
node["display"] = rhs.DisplayName();
if (rhs.IsConditional())
node["condition"] = rhs.Condition();
if (rhs.DisplayName() != rhs.Name())
node["display"] = rhs.DisplayName();
return node;
}
static bool decode(const Node& node, loot::File& rhs) {
if (!node.IsMap() && !node.IsScalar())
return false;
if (node.IsMap()) {
if (!node["name"])
return false;
std::string condition, name, display;
std::string name = node["name"].as<std::string>();
std::string condition, display;
if (node["condition"])
condition = node["condition"].as<std::string>();
if (node["name"])
name = node["name"].as<std::string>();
if (node["display"])
display = node["display"].as<std::string>();
rhs = loot::File(name, display, condition);
}
else
rhs = loot::File(node.as<std::string>());
return true;
}
};