1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

first part of town configuration:

- moved almost all loading to TownHandler
- CBuildings and CStructures are now part of CTown
- merged hall.json into buildings.json

Should not cause any crashes or glitches
This commit is contained in:
Ivan Savenko
2012-09-02 10:33:41 +00:00
parent 3e346e737a
commit 44cc848edc
23 changed files with 816 additions and 786 deletions

View File

@@ -236,6 +236,38 @@ const JsonNode & JsonNode::operator[](std::string child) const
return it->second;
return nullNode;
}
////////////////////////////////////////////////////////////////////////////////
void JsonNode::merge(JsonNode & dest, JsonNode & source)
{
switch (source.getType())
{
break; case DATA_NULL: dest.setType(DATA_NULL);
break; case DATA_BOOL: std::swap(dest.Bool(), source.Bool());
break; case DATA_FLOAT: std::swap(dest.Float(), source.Float());
break; case DATA_STRING: std::swap(dest.String(), source.String());
break; case DATA_VECTOR:
{
//reserve place and *move* data from source to dest
source.Vector().reserve(source.Vector().size() + dest.Vector().size());
std::move(source.Vector().begin(), source.Vector().end(),
std::back_inserter(dest.Vector()));
}
break; case DATA_STRUCT:
{
//recursively merge all entries from struct
BOOST_FOREACH(auto & node, source.Struct())
merge(dest[node.first], node.second);
}
}
}
void JsonNode::mergeCopy(JsonNode & dest, JsonNode source)
{
// uses copy created in stack to safely merge two nodes
merge(dest, source);
}
////////////////////////////////////////////////////////////////////////////////