void EmberEntity::updateAttachment() { //Get the new location. We use getEmberLocation() since we always know that all entities are of type EmberEntity. EmberEntity* newLocationEntity = getEmberLocation(); if (newLocationEntity && newLocationEntity->getAttachment()) { try { IEntityAttachment* newAttachment = newLocationEntity->getAttachment()->attachEntity(*this); setAttachment(newAttachment); if (newAttachment) { newAttachment->updateScale(); } } catch (const std::exception& ex) { S_LOG_WARNING("Problem when creating new attachment for entity." << ex); } //If we're the top level entity the attachment has been set from the outside and shouldn't be changed. //FIXME This is a little hackish; how can we improve it to not require special cases? } else if (m_view->getTopLevel() == this) { return; } else { try { setAttachment(nullptr); } catch (const std::exception& ex) { S_LOG_WARNING("Problem when setting attachment for entity." << ex); } } }
void EmberEntity::onLocationChanged(Eris::Entity *oldLocation) { //Get the new location. We use getEmberLocation() since we always know that all entities are of type EmberEntity. EmberEntity* newLocationEntity = getEmberLocation(); if (newLocationEntity && newLocationEntity->getAttachment()) { try { IEntityAttachment* newAttachment = newLocationEntity->getAttachment()->attachEntity(*this); setAttachment(newAttachment); if (newAttachment) { newAttachment->updateScale(); } } catch (const std::exception& ex) { S_LOG_WARNING("Problem when creating new attachment for entity." << ex); } } else { try { setAttachment(0); } catch (const std::exception& ex) { S_LOG_WARNING("Problem when setting attachment for entity." << ex); } } Eris::Entity::onLocationChanged(oldLocation); }
void EntityMoveManager::startMove(EmberEntity& entity) { //disallow moving of the root entity if (entity.getLocation()) { //Only provide movement for entities which have a node attachment. NodeAttachment* attachment = dynamic_cast<NodeAttachment*> (entity.getAttachment()); if (attachment) { EntityMover* mover = new EntityMover(*attachment, *this); mMoveAdapter.attachToBridge(mover); //The EntityMoveInstance will delete itself when either movement is finished or the entity is deleted, so we don't need to hold a reference to it. new EntityMoveInstance(entity, mMoveAdapter, EventFinishedMoving, EventCancelledMoving); EventStartMoving.emit(entity, *mover); } } }