Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 11 files). Show all
Unified · Split
| @@ -26,22 +26,32 @@ void EntityScriptingInterface::queueEntityMessage(PacketType packetType, · 25 unmodified lines | |||
| 26 | getEntityPacketSender()->queueEditEntityMessage(packetType, entityID, properties); | 26 | getEntityPacketSender()->queueEditEntityMessage(packetType, entityID, properties); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | |||
| 30 | bool EntityScriptingInterface::canEdit() { | ||
| 31 | auto nodeList = DependencyManager::get<NodeList>(); | ||
| 32 | return nodeList->getThisNodeCanEdit(); | ||
| 33 | } | ||
| 34 | |||
| 35 | |||
| 29 | EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& properties) { | 36 | EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& properties) { |
| 30 | 37 | ||
| 38 | |||
| 31 | // The application will keep track of creatorTokenID | 39 | // The application will keep track of creatorTokenID |
| 32 | uint32_t creatorTokenID = EntityItemID::getNextCreatorTokenID(); | 40 | uint32_t creatorTokenID = EntityItemID::getNextCreatorTokenID(); |
| 33 | 41 | ||
| 34 | EntityItemID id(NEW_ENTITY, creatorTokenID, false ); | 42 | EntityItemID id(NEW_ENTITY, creatorTokenID, false ); |
| 35 | 43 | ||
| 36 | // If we have a local entity tree set, then also update it. | 44 | if (canEdit()) { |
| 37 | if (_entityTree) { | 45 | // If we have a local entity tree set, then also update it. |
| 38 | _entityTree->lockForWrite(); | 46 | if (_entityTree) { |
| 39 | _entityTree->addEntity(id, properties); | 47 | _entityTree->lockForWrite(); |
| 40 | _entityTree->unlock(); | 48 | _entityTree->addEntity(id, properties); |
| 41 | } | 49 | _entityTree->unlock(); |
| 50 | } | ||
| 42 | 51 | ||
| 43 | // queue the packet | 52 | // queue the packet |
| 44 | queueEntityMessage(PacketTypeEntityAddOrEdit, id, properties); | 53 | queueEntityMessage(PacketTypeEntityAddOrEdit, id, properties); |
| 54 | } | ||
| 45 | 55 | ||
| 46 | return id; | 56 | return id; |
| 47 | } | 57 | } |
| @@ -94,6 +104,11 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID · 46 unmodified lines | |||
| 94 | } | 104 | } |
| 95 | 105 | ||
| 96 | EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const EntityItemProperties& properties) { | 106 | EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const EntityItemProperties& properties) { |
| 107 | |||
| 108 | if (! canEdit()) { | ||
| 109 | return entityID; | ||
| 110 | } | ||
| 111 | |||
| 97 | EntityItemID actualID = entityID; | 112 | EntityItemID actualID = entityID; |
| 98 | // if the entity is unknown, attempt to look it up | 113 | // if the entity is unknown, attempt to look it up |
| 99 | if (!entityID.isKnownID) { | 114 | if (!entityID.isKnownID) { |