// // tryDeleteAvatarEntity.js // // Author: Liv Erickson // Copyright High Fidelity 2018 // // Licensed under the Apache 2.0 License // See accompanying license file or http://apache.org/ // (function(){ var REQUEST_PROPERTIES = ['type', 'script', 'dimensions', 'collision']; // Get these properties var BLACKLIST_ENTITY_TYPES = ['web', 'text', 'zone']; // Remove these entities var NOT_IN_ARRAY_INDEX = -1; var MAX_DIMENSION = 0.5; // When avatar entities are added, the user will self-delete them var deleteAvatarEntityAdd = function(entityID) { var props = Entities.getEntityProperties(entityID, ['clientOnly', 'owningAvatarID']); if (props.clientOnly && props.owningAvatarID === MyAvatar.sessionUUID) { Entities.deleteEntity(entityID); } }; var fromQml = function(message) { filterExistingAvatarEntities(); }; // When we load this script, we will have clients check existing avatar entities // Currently, we remove text and web entities // We will remove scripts // We will remove collisions var filterExistingAvatarEntity = function(entityID) { print("Checking..." + entityID); var properties = Entities.getEntityProperties(entityID, REQUEST_PROPERTIES); try { if (BLACKLIST_ENTITY_TYPES.indexOf(properties.type.toLowerCase()) !== NOT_IN_ARRAY_INDEX) { Entities.deleteEntity(entityID); } if (properties.dimensions.x > MAX_DIMENSION || properties.dimensions.y > MAX_DIMENSION || properties.dimensions.z > MAX_DIMENSION) { Entities.deleteEntity(entityID); } if (!properties.collisionless) { Entities.editEntity(entityID, {'collisionless' : 'true'}); } } catch (e) { print ("Exception: " , e); } }; var filterExistingAvatarEntities = function() { var myAvatarEntities = MyAvatar.getAvatarEntityData(); var entitiesArray = []; for (var i in myAvatarEntities) { entitiesArray.push([i, myAvatarEntities [i]]); } entitiesArray.forEach(function(entity) { filterExistingAvatarEntity(entity[0]); }); }; this.preload = function(){ Entities.addingEntity.connect(deleteAvatarEntityAdd); filterExistingAvatarEntities(); Tablet.getTablet("com.highfidelity.interface.tablet.system").screenChanged.connect(fromQml); }; this.unload = function() { Entities.addingEntity.disconnect(deleteAvatarEntityAdd); Tablet.getTablet("com.highfidelity.interface.tablet.system").screenChanged.disconnect(fromQml); }; });