Revert "send attachment clears through setAvatarEntityData"

This reverts commit 25876bca63.
This commit is contained in:
Stephen Birarda 2018-08-21 12:18:11 -07:00
parent 8226ffb916
commit a177e49877
3 changed files with 30 additions and 6 deletions

View file

@ -151,7 +151,13 @@ bool isWearableEntity(const EntityItemPointer& entity) {
void AvatarBookmarks::updateAvatarEntities(const QVariantList &avatarEntities) {
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
myAvatar->clearAvatarEntities();
auto treeRenderer = DependencyManager::get<EntityTreeRenderer>();
EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr;
myAvatar->removeAvatarEntities([&](const QUuid& entityID) {
auto entity = entityTree->findEntityByID(entityID);
return entity && isWearableEntity(entity);
});
addAvatarEntities(avatarEntities);
}
@ -174,7 +180,12 @@ void AvatarBookmarks::loadBookmark(const QString& bookmarkName) {
if (!bookmark.empty()) {
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
myAvatar->clearAvatarEntities();
auto treeRenderer = DependencyManager::get<EntityTreeRenderer>();
EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr;
myAvatar->removeAvatarEntities([&](const QUuid& entityID) {
auto entity = entityTree->findEntityByID(entityID);
return entity && isWearableEntity(entity);
});
const QString& avatarUrl = bookmark.value(ENTRY_AVATAR_URL, "").toString();
myAvatar->useFullAvatarURL(avatarUrl);
qCDebug(interfaceapp) << "Avatar On " << avatarUrl;

View file

@ -1703,6 +1703,21 @@ void MyAvatar::setSkeletonModelURL(const QUrl& skeletonModelURL) {
emit skeletonChanged();
}
void MyAvatar::removeAvatarEntities(const std::function<bool(const QUuid& entityID)>& condition) {
auto treeRenderer = DependencyManager::get<EntityTreeRenderer>();
EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr;
if (entityTree) {
entityTree->withWriteLock([&] {
AvatarEntityMap avatarEntities = getAvatarEntityData();
for (auto entityID : avatarEntities.keys()) {
if (!condition || condition(entityID)) {
entityTree->deleteEntity(entityID, true, true);
}
}
});
}
}
QVariantList MyAvatar::getAvatarEntitiesVariant() {
QVariantList avatarEntitiesData;
QScriptEngine scriptEngine;
@ -2099,9 +2114,7 @@ void MyAvatar::setAttachmentData(const QVector<AttachmentData>& attachmentData)
attachmentDataToEntityProperties(data, properties);
newEntitiesProperties.push_back(properties);
}
clearAvatarEntities();
removeAvatarEntities();
for (auto& properties : newEntitiesProperties) {
DependencyManager::get<EntityScriptingInterface>()->addEntity(properties, true);
}

View file

@ -931,7 +931,7 @@ public:
* @returns {object[]}
*/
Q_INVOKABLE QVariantList getAvatarEntitiesVariant();
void clearAvatarEntities() { setAvatarEntityData(AvatarEntityMap()); }
void removeAvatarEntities(const std::function<bool(const QUuid& entityID)>& condition = {});
/**jsdoc
* @function MyAvatar.isFlying