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 results;
EntityItemID identity = identifyEntity(entityID);
if (_entityTree) {
_entityTree->lockForRead();
EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByEntityItemID(identity));
if (canEdit()) {
EntityItemID identity = identifyEntity(entityID);
if (_entityTree) {
_entityTree->lockForRead();
EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByEntityItemID(identity));
if (entity) {
results = entity->getProperties();
if (entity) {
results = entity->getProperties();
// 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
// we've also added this hack for setting natural dimensions of models
if (entity->getType() == EntityTypes::Model) {
const FBXGeometry* geometry = _entityTree->getGeometryForEntity(entity);
if (geometry) {
results.setSittingPoints(geometry->sittingPoints);
Extents meshExtents = geometry->getUnscaledMeshExtents();
results.setNaturalDimensions(meshExtents.maximum - meshExtents.minimum);
// 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
// we've also added this hack for setting natural dimensions of models
if (entity->getType() == EntityTypes::Model) {
const FBXGeometry* geometry = _entityTree->getGeometryForEntity(entity);
if (geometry) {
results.setSittingPoints(geometry->sittingPoints);
Extents meshExtents = geometry->getUnscaledMeshExtents();
results.setNaturalDimensions(meshExtents.maximum - meshExtents.minimum);
}
}
}
} else {
results.setIsUnknownID();
} else {
results.setIsUnknownID();
}
_entityTree->unlock();
}
_entityTree->unlock();
}
return results;
@ -148,6 +151,9 @@ EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const E
void EntityScriptingInterface::deleteEntity(EntityItemID entityID) {
if (! canEdit())
return;
EntityItemID actualID = entityID;
// if the entity is unknown, attempt to look it up

View file

@ -60,9 +60,12 @@ public:
void setEntityTree(EntityTree* modelTree) { _entityTree = modelTree; }
EntityTree* getEntityTree(EntityTree*) { return _entityTree; }
bool canEdit();
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
Q_INVOKABLE EntityItemID addEntity(const EntityItemProperties& properties);