Exemple #1
0
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);
		}
	}
}
Exemple #2
0
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);

}