DefinitionNode.copy now copies children automatically
This commit is contained in:
parent
c199bef7f2
commit
9b2c60fe16
6 changed files with 31 additions and 27 deletions
|
@ -71,8 +71,6 @@ void AtmosphereDefinition::copy(DefinitionNode* _destination) const
|
||||||
|
|
||||||
AtmosphereDefinition* destination = (AtmosphereDefinition*)_destination;
|
AtmosphereDefinition* destination = (AtmosphereDefinition*)_destination;
|
||||||
|
|
||||||
daytime->copy(destination->daytime);
|
|
||||||
|
|
||||||
destination->model = model;
|
destination->model = model;
|
||||||
destination->sun_color = sun_color;
|
destination->sun_color = sun_color;
|
||||||
destination->sun_radius = sun_radius;
|
destination->sun_radius = sun_radius;
|
||||||
|
|
|
@ -241,7 +241,18 @@ void DefinitionNode::copy(DefinitionNode* destination) const
|
||||||
if (destination->getTypeName() == getTypeName())
|
if (destination->getTypeName() == getTypeName())
|
||||||
{
|
{
|
||||||
destination->setName(name);
|
destination->setName(name);
|
||||||
// TODO Copy children ?
|
for (auto &child: children)
|
||||||
|
{
|
||||||
|
DefinitionNode *dest_child = destination->findChildByName(child->name);
|
||||||
|
if (dest_child)
|
||||||
|
{
|
||||||
|
child->copy(dest_child);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logs::warning() << "Can't copy to child " << child->name << " of " << destination->getTypeName() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,26 +18,12 @@ static const int DATA_VERSION = 1;
|
||||||
Scenery::Scenery():
|
Scenery::Scenery():
|
||||||
DefinitionNode(NULL, "scenery", "scenery")
|
DefinitionNode(NULL, "scenery", "scenery")
|
||||||
{
|
{
|
||||||
addChild(atmosphere = new AtmosphereDefinition(this));
|
atmosphere = new AtmosphereDefinition(this);
|
||||||
addChild(camera = new CameraDefinition);
|
camera = new CameraDefinition(this);
|
||||||
addChild(clouds = new CloudsDefinition(this));
|
clouds = new CloudsDefinition(this);
|
||||||
addChild(terrain = new TerrainDefinition(this));
|
terrain = new TerrainDefinition(this);
|
||||||
addChild(textures = new TexturesDefinition(this));
|
textures = new TexturesDefinition(this);
|
||||||
addChild(water = new WaterDefinition(this));
|
water = new WaterDefinition(this);
|
||||||
}
|
|
||||||
|
|
||||||
void Scenery::copy(DefinitionNode *destination_) const
|
|
||||||
{
|
|
||||||
Scenery* destination = (Scenery*)destination_;
|
|
||||||
|
|
||||||
atmosphere->copy(destination->atmosphere);
|
|
||||||
camera->copy(destination->camera);
|
|
||||||
clouds->copy(destination->clouds);
|
|
||||||
terrain->copy(destination->terrain);
|
|
||||||
textures->copy(destination->textures);
|
|
||||||
water->copy(destination->water);
|
|
||||||
|
|
||||||
destination->validate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scenery::validate()
|
void Scenery::validate()
|
||||||
|
|
|
@ -29,7 +29,6 @@ public:
|
||||||
Scenery();
|
Scenery();
|
||||||
|
|
||||||
virtual void validate() override;
|
virtual void validate() override;
|
||||||
virtual void copy(DefinitionNode *destination) const override;
|
|
||||||
|
|
||||||
FileOperationResult saveGlobal(const std::string &filepath) const;
|
FileOperationResult saveGlobal(const std::string &filepath) const;
|
||||||
FileOperationResult loadGlobal(const std::string &filepath);
|
FileOperationResult loadGlobal(const std::string &filepath);
|
||||||
|
|
|
@ -52,8 +52,6 @@ void TerrainDefinition::copy(DefinitionNode* _destination) const
|
||||||
|
|
||||||
height_map->copy(destination->height_map);
|
height_map->copy(destination->height_map);
|
||||||
|
|
||||||
water_height->copy(destination->water_height);
|
|
||||||
|
|
||||||
_height_noise->copy(destination->_height_noise);
|
_height_noise->copy(destination->_height_noise);
|
||||||
|
|
||||||
destination->validate();
|
destination->validate();
|
||||||
|
|
|
@ -65,7 +65,7 @@ TEST(DefinitionNode, attachDetach)
|
||||||
delete root;
|
delete root;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(DefinitionNode, saveLoad)
|
TEST(DefinitionNode, saveLoadCopy)
|
||||||
{
|
{
|
||||||
PackStream *stream;
|
PackStream *stream;
|
||||||
int check_in = 42, check_out = 0;
|
int check_in = 42, check_out = 0;
|
||||||
|
@ -105,6 +105,18 @@ TEST(DefinitionNode, saveLoad)
|
||||||
EXPECT_DOUBLE_EQ(0.0, after4->getValue());
|
EXPECT_DOUBLE_EQ(0.0, after4->getValue());
|
||||||
EXPECT_EQ(42, check_out);
|
EXPECT_EQ(42, check_out);
|
||||||
|
|
||||||
|
// Test copy, that should work like "save then load"
|
||||||
|
after12->setValue(1.1);
|
||||||
|
after13->setValue(1.1);
|
||||||
|
after3->setValue(1.1);
|
||||||
|
after4->setValue(1.1);
|
||||||
|
before->copy(after);
|
||||||
|
|
||||||
|
EXPECT_DOUBLE_EQ(-4.3, after12->getValue());
|
||||||
|
EXPECT_DOUBLE_EQ(1.1, after13->getValue());
|
||||||
|
EXPECT_DOUBLE_EQ(6.7, after3->getValue());
|
||||||
|
EXPECT_DOUBLE_EQ(1.1, after4->getValue());
|
||||||
|
|
||||||
delete before;
|
delete before;
|
||||||
delete after;
|
delete after;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue