Skip to content

Commit

Permalink
#5643: Make sure func_* entities that are inserted for merge preview …
Browse files Browse the repository at this point in the history
…purposes are keeping their model and name spawnargs synced.
  • Loading branch information
codereader committed Jul 3, 2021
1 parent c34710e commit bbbe4dc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
24 changes: 17 additions & 7 deletions libs/scene/merge/MergeAction.h
Expand Up @@ -127,6 +127,9 @@ class AddCloneToParentAction :
assert(_node);
assert(Node_getCloneable(node));

auto* entity = Node_getEntity(node);
_modelIsEqualToName = entity && entity->getKeyValue("name") == entity->getKeyValue("model");

// No post-clone callback since we don't care about selection groups right now
_cloneToBeInserted = cloneNodeIncludingDescendants(_node, PostCloneCallback());

Expand All @@ -143,17 +146,12 @@ class AddCloneToParentAction :
{
child->moveToLayer(activeLayer); return true;
});

auto* entity = Node_getEntity(_cloneToBeInserted);

_modelIsEqualToName = entity && entity->getKeyValue("name") == entity->getKeyValue("model");
}

public:
void applyChanges() override
void addSourceNodeToScene()
{
if (!isActive()) return;

// Get the clone and add it to the target scene, it needs to be renderable here
addNodeToContainer(_cloneToBeInserted, _parent);

// Check if we need to synchronise the model and name key values
Expand All @@ -173,6 +171,18 @@ class AddCloneToParentAction :
}
}

void removeSourceNodeFromScene()
{
removeNodeFromParent(_cloneToBeInserted);
}

void applyChanges() override
{
if (!isActive()) return;

addSourceNodeToScene();
}

const INodePtr& getParent() const
{
return _parent;
Expand Down
4 changes: 2 additions & 2 deletions libs/scene/merge/MergeActionNode.cpp
Expand Up @@ -313,7 +313,7 @@ void RegularMergeActionNode::addPreviewNodeForAddAction()
if (addNodeAction)
{
// Get the clone and add it to the target scene, it needs to be renderable here
addNodeToContainer(_affectedNode, addNodeAction->getParent());
addNodeAction->addSourceNodeToScene();
}
}

Expand All @@ -323,7 +323,7 @@ void RegularMergeActionNode::removePreviewNodeForAddAction()

if (addNodeAction)
{
removeNodeFromParent(_affectedNode);
addNodeAction->removeSourceNodeFromScene();
}
}

Expand Down
2 changes: 1 addition & 1 deletion libs/scene/merge/MergeLib.h
Expand Up @@ -248,7 +248,7 @@ inline void resolveConflictByKeepingBothEntities()

// Add the action to import the source node as a whole
const auto& pair = *sourceAndTargetEntities.begin();
auto addSourceEntityAction = std::make_shared<AddEntityAction>(pair.first, pair.second->getRootNode()); // TODO: AddEntityAction needs to check model spawnarg
auto addSourceEntityAction = std::make_shared<AddEntityAction>(pair.first, pair.second->getRootNode());

operation->addAction(addSourceEntityAction); // TODO: Observer pattern to notify Map class

Expand Down

0 comments on commit bbbe4dc

Please sign in to comment.