if script sets parent or jointIndex, don't pop entity off to someplace

This commit is contained in:
Seth Alves 2015-12-05 15:15:33 -08:00
parent 1f0150f65f
commit d518a4573e

View file

@ -202,7 +202,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, EntityItemProperties script
bool updatedEntity = false;
_entityTree->withWriteLock([&] {
if (scriptSideProperties.parentDependentPropertyChanged()) {
// if the script sets a location property but didn't include parent information, grab the needed
// if the script set a location property but didn't include parent information, grab the needed
// properties from the entity.
if (!scriptSideProperties.parentIDChanged() || !scriptSideProperties.parentJointIndexChanged()) {
EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
@ -214,6 +214,18 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, EntityItemProperties script
}
}
}
if (scriptSideProperties.parentIDChanged() || scriptSideProperties.parentJointIndexChanged()) {
// if the script set parentID or parentJointIndex but didn't include position and rotation, grab
// the missing properties from the entity
if (!scriptSideProperties.localPositionChanged() && !scriptSideProperties.positionChanged()) {
EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
properties.setPosition(entity->getPosition());
}
if (!scriptSideProperties.localRotationChanged() && !scriptSideProperties.rotationChanged()) {
EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
properties.setRotation(entity->getOrientation());
}
}
properties = convertLocationFromScriptSemantics(properties);
updatedEntity = _entityTree->updateEntity(entityID, properties);
});