mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
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:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user