96 lines
No EOL
3.3 KiB
JavaScript
96 lines
No EOL
3.3 KiB
JavaScript
//
|
|
// 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;
|
|
var RECHECK_INTERVAL = 1000;
|
|
|
|
var avatarEntityData;
|
|
var interval;
|
|
|
|
// 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 intervalCheck = 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) {
|
|
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'});
|
|
}
|
|
|
|
/** if (properties.name === "Flamethrower Flame") {
|
|
Entities.editEntity(entityID, {'parentID': '{00000000-0000-0000-0000-000000000000}'});
|
|
Entities.deleteEntity(entityID);
|
|
} **/
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
};
|
|
|
|
var filterExistingAvatarEntities = function() {
|
|
avatarEntityData = MyAvatar.getAvatarEntityData();
|
|
if (Object.keys(avatarEntityData).length !== 0) {
|
|
var entitiesArray = [];
|
|
for (var i in avatarEntityData) {
|
|
entitiesArray.push([i, avatarEntityData [i]]);
|
|
}
|
|
if (entitiesArray.length > 0) {
|
|
entitiesArray.forEach(function(entity) {
|
|
filterExistingAvatarEntity(entity[0]);
|
|
});
|
|
}
|
|
} else {
|
|
Script.clearInterval(interval);
|
|
}
|
|
};
|
|
|
|
this.preload = function(){
|
|
Entities.addingEntity.connect(deleteAvatarEntityAdd);
|
|
avatarEntityData = MyAvatar.getAvatarEntityData();
|
|
if (Object.keys(avatarEntityData).length !== 0) {
|
|
filterExistingAvatarEntities();
|
|
interval = Script.setInterval(intervalCheck, RECHECK_INTERVAL);
|
|
}
|
|
};
|
|
|
|
this.unload = function() {
|
|
Entities.addingEntity.disconnect(deleteAvatarEntityAdd);
|
|
if (interval) {
|
|
Script.clearInterval(interval);
|
|
}
|
|
};
|
|
}); |