also guard deleteEntity and getEntityProperties with canEdit. make canEdit available to javascript

This commit is contained in:
Seth Alves 2015-02-05 16:22:52 -08:00
parent d19ab4c36f
commit bad44c540a
2 changed files with 29 additions and 20 deletions

View file

@ -73,30 +73,33 @@ EntityItemID EntityScriptingInterface::identifyEntity(EntityItemID entityID) {
EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID entityID) { EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID entityID) {
EntityItemProperties results; EntityItemProperties results;
EntityItemID identity = identifyEntity(entityID);
if (_entityTree) { if (canEdit()) {
_entityTree->lockForRead(); EntityItemID identity = identifyEntity(entityID);
EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByEntityItemID(identity)); if (_entityTree) {
_entityTree->lockForRead();
EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByEntityItemID(identity));
if (entity) { if (entity) {
results = entity->getProperties(); results = entity->getProperties();
// TODO: improve sitting points and naturalDimensions in the future, // TODO: improve sitting points and naturalDimensions in the future,
// for now we've included the old sitting points model behavior for entity types that are models // for now we've included the old sitting points model behavior for entity types that are models
// we've also added this hack for setting natural dimensions of models // we've also added this hack for setting natural dimensions of models
if (entity->getType() == EntityTypes::Model) { if (entity->getType() == EntityTypes::Model) {
const FBXGeometry* geometry = _entityTree->getGeometryForEntity(entity); const FBXGeometry* geometry = _entityTree->getGeometryForEntity(entity);
if (geometry) { if (geometry) {
results.setSittingPoints(geometry->sittingPoints); results.setSittingPoints(geometry->sittingPoints);
Extents meshExtents = geometry->getUnscaledMeshExtents(); Extents meshExtents = geometry->getUnscaledMeshExtents();
results.setNaturalDimensions(meshExtents.maximum - meshExtents.minimum); results.setNaturalDimensions(meshExtents.maximum - meshExtents.minimum);
}
} }
}
} else { } else {
results.setIsUnknownID(); results.setIsUnknownID();
}
_entityTree->unlock();
} }
_entityTree->unlock();
} }
return results; return results;
@ -148,6 +151,9 @@ EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const E
void EntityScriptingInterface::deleteEntity(EntityItemID entityID) { void EntityScriptingInterface::deleteEntity(EntityItemID entityID) {
if (! canEdit())
return;
EntityItemID actualID = entityID; EntityItemID actualID = entityID;
// if the entity is unknown, attempt to look it up // if the entity is unknown, attempt to look it up

View file

@ -60,9 +60,12 @@ public:
void setEntityTree(EntityTree* modelTree) { _entityTree = modelTree; } void setEntityTree(EntityTree* modelTree) { _entityTree = modelTree; }
EntityTree* getEntityTree(EntityTree*) { return _entityTree; } EntityTree* getEntityTree(EntityTree*) { return _entityTree; }
bool canEdit();
public slots: public slots:
// returns true if the DomainServer will allow this Node/Avatar to make changes
Q_INVOKABLE bool canEdit();
/// adds a model with the specific properties /// adds a model with the specific properties
Q_INVOKABLE EntityItemID addEntity(const EntityItemProperties& properties); Q_INVOKABLE EntityItemID addEntity(const EntityItemProperties& properties);