add flags to support asking for specific messages, update examples

This commit is contained in:
ZappoMan 2018-01-26 18:26:48 -08:00
parent a3d86a0242
commit b883d006c8
4 changed files with 58 additions and 4 deletions

View file

@ -62,6 +62,16 @@ bool EntityEditFilters::filter(glm::vec3& position, EntityItemProperties& proper
return false;
}
// check to see if this filter wants to filter this message type
if ((!filterData.wantsToFilterEdit && filterType == EntityTree::FilterType::Edit) ||
(!filterData.wantsToFilterPhysics && filterType == EntityTree::FilterType::Physics) ||
(!filterData.wantsToFilterDelete && filterType == EntityTree::FilterType::Delete) ||
(!filterData.wantsToFilterAdd && filterType == EntityTree::FilterType::Add)) {
wasChanged = false;
return true; // accept the message
}
auto oldProperties = propertiesIn.getDesiredProperties();
auto specifiedProperties = propertiesIn.getChangedProperties();
propertiesIn.setDesiredProperties(specifiedProperties);
@ -254,6 +264,22 @@ void EntityEditFilters::scriptRequestFinished(EntityItemID entityID) {
filterData.rejectAll=true;
}
// if the wantsToFilterEdit is a boolean evaluate as a boolean, otherwise assume true
QScriptValue wantsToFilterAddValue = filterData.filterFn.property("wantsToFilterAdd");
filterData.wantsToFilterAdd = wantsToFilterAddValue.isBool() ? wantsToFilterAddValue.toBool() : true;
// if the wantsToFilterEdit is a boolean evaluate as a boolean, otherwise assume true
QScriptValue wantsToFilterEditValue = filterData.filterFn.property("wantsToFilterEdit");
filterData.wantsToFilterEdit = wantsToFilterEditValue.isBool() ? wantsToFilterEditValue.toBool() : true;
// if the wantsToFilterPhysics is a boolean evaluate as a boolean, otherwise assume true
QScriptValue wantsToFilterPhysicsValue = filterData.filterFn.property("wantsToFilterPhysics");
filterData.wantsToFilterPhysics = wantsToFilterPhysicsValue.isBool() ? wantsToFilterPhysicsValue.toBool() : true;
// if the wantsToFilterDelete is a boolean evaluate as a boolean, otherwise assume false
QScriptValue wantsToFilterDeleteValue = filterData.filterFn.property("wantsToFilterDelete");
filterData.wantsToFilterDelete = wantsToFilterDeleteValue.isBool() ? wantsToFilterDeleteValue.toBool() : false;
// check to see if the filterFn has properties asking for Original props
QScriptValue wantsOriginalPropertiesValue = filterData.filterFn.property("wantsOriginalProperties");
// if the wantsOriginalProperties is a boolean, or a string, or list of strings, then evaluate as follows:

View file

@ -30,6 +30,12 @@ public:
QScriptValue filterFn;
bool wantsOriginalProperties { false };
bool wantsZoneProperties { false };
bool wantsToFilterAdd { true };
bool wantsToFilterEdit { true };
bool wantsToFilterPhysics { true };
bool wantsToFilterDelete { true };
EntityPropertyFlags includedOriginalProperties;
EntityPropertyFlags includedZoneProperties;
bool wantsZoneBoundingBox { false };

View file

@ -0,0 +1,22 @@
//
// prevent-all-deletes.js
//
//
// Created by Brad Hefta-Gaub to use Entities on Jan. 25, 2018
// Copyright 2018 High Fidelity, Inc.
//
// This sample entity edit filter script will prevent deletes of any entities.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
function filter() {
return false; // all deletes are blocked
}
filter.wantsToFilterAdd = false; // don't run on adds
filter.wantsToFilterEdit = false; // don't run on edits
filter.wantsToFilterPhysics = false; // don't run on physics
filter.wantsToFilterDelete = true; // do run on deletes
filter;

View file

@ -5,13 +5,14 @@
// Created by Brad Hefta-Gaub to use Entities on Jan. 25, 2018
// Copyright 2018 High Fidelity, Inc.
//
// This sample entity edit filter script will keep prevent any entity inside the zone from being deleted.
// This sample entity edit filter script will get all edits, adds, physcis, and deletes, but will only block
// deletes, and will pass through all others.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
function filter(properties, type, originalProperties, zoneProperties) {
function filter(properties, type) {
if (type == Entities.DELETE_FILTER_TYPE) {
return false;
@ -19,6 +20,5 @@ function filter(properties, type, originalProperties, zoneProperties) {
return properties;
}
filter.wantsOriginalProperties = true;
filter.wantsZoneProperties = true;
filter.wantsToFilterDelete = true; // do run on deletes
filter;