History

entity scripting call to get the nestable-type of an object, by id

Seth Alves committed 9 years ago

Commit a7c684e1 parent 51cb5792 files · +29 −6Browse files

Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 2 files). Show all

Unified · Split

libraries/entities/src/EntityScriptingInterface.cpp+27−6
@@ -466,9 +466,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 465 unmodified lines
466466 });
467467 }
468468 });
469− if (entityFound) {
470− queueEntityMessage(PacketType::EntityEdit, entityID, properties);
471− } else {
469+ if (!entityFound) {
472470 // attempt to get a name for the mystery ID
473471 QString name = "unknown";
474472 QSharedPointer<SpatialParentFinder> parentFinder = DependencyManager::get<SpatialParentFinder>();
@@ -478,13 +476,18 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 3 unmodified lines
478476 if (success) {
479477 auto nestable = nestableWP.lock();
480478 if (nestable) {
481− name = nestable->getName();
479+ NestableType nestableType = nestable->getNestableType();
480+ if (nestableType == NestableType::Overlay || nestableType == NestableType::Avatar) {
481+ qCWarning(entities) << "attempted edit on non-entity: " << id << name;
482+ return QUuid(); // null UUID to indicate failure
483+ }
482484 }
483485 }
484486 }
485− qCWarning(entities) << "attempted edit on unknown entity: " << id << name;
486− return QUuid(); // null UUID to indicate failure
487487 }
488+ // we queue edit packets even if we don't know about the entity. This is to allow AC agents
489+ // to edit entities they know only by ID.
490+ queueEntityMessage(PacketType::EntityEdit, entityID, properties);
488491 return id;
489492 }
490493
@@ -1535,6 +1538,24 @@ bool EntityScriptingInterface::isChildOfParent(QUuid childID, QUuid parentID) { · 1044 unmodified lines
15351538 return isChild;
15361539 }
15371540
1541+QString EntityScriptingInterface::getNestableType(QUuid id) {
1542+ QSharedPointer<SpatialParentFinder> parentFinder = DependencyManager::get<SpatialParentFinder>();
1543+ if (!parentFinder) {
1544+ return "unknown";
1545+ }
1546+ bool success;
1547+ SpatiallyNestableWeakPointer objectWP = parentFinder->find(id, success);
1548+ if (!success) {
1549+ return "unknown";
1550+ }
1551+ SpatiallyNestablePointer object = objectWP.lock();
1552+ if (!object) {
1553+ return "unknown";
1554+ }
1555+ NestableType nestableType = object->getNestableType();
1556+ return SpatiallyNestable::nestableTypeToString(nestableType);
1557+}
1558+
15381559 QVector<QUuid> EntityScriptingInterface::getChildrenIDsOfJoint(const QUuid& parentID, int jointIndex) {
15391560 QVector<QUuid> result;
15401561 if (!_entityTree) {