mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 07:47:30 +02:00
add flags to support asking for specific messages, update examples
This commit is contained in:
parent
a3d86a0242
commit
b883d006c8
4 changed files with 58 additions and 4 deletions
|
@ -62,6 +62,16 @@ bool EntityEditFilters::filter(glm::vec3& position, EntityItemProperties& proper
|
||||||
return false;
|
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 oldProperties = propertiesIn.getDesiredProperties();
|
||||||
auto specifiedProperties = propertiesIn.getChangedProperties();
|
auto specifiedProperties = propertiesIn.getChangedProperties();
|
||||||
propertiesIn.setDesiredProperties(specifiedProperties);
|
propertiesIn.setDesiredProperties(specifiedProperties);
|
||||||
|
@ -254,6 +264,22 @@ void EntityEditFilters::scriptRequestFinished(EntityItemID entityID) {
|
||||||
filterData.rejectAll=true;
|
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
|
// check to see if the filterFn has properties asking for Original props
|
||||||
QScriptValue wantsOriginalPropertiesValue = filterData.filterFn.property("wantsOriginalProperties");
|
QScriptValue wantsOriginalPropertiesValue = filterData.filterFn.property("wantsOriginalProperties");
|
||||||
// if the wantsOriginalProperties is a boolean, or a string, or list of strings, then evaluate as follows:
|
// if the wantsOriginalProperties is a boolean, or a string, or list of strings, then evaluate as follows:
|
||||||
|
|
|
@ -30,6 +30,12 @@ public:
|
||||||
QScriptValue filterFn;
|
QScriptValue filterFn;
|
||||||
bool wantsOriginalProperties { false };
|
bool wantsOriginalProperties { false };
|
||||||
bool wantsZoneProperties { false };
|
bool wantsZoneProperties { false };
|
||||||
|
|
||||||
|
bool wantsToFilterAdd { true };
|
||||||
|
bool wantsToFilterEdit { true };
|
||||||
|
bool wantsToFilterPhysics { true };
|
||||||
|
bool wantsToFilterDelete { true };
|
||||||
|
|
||||||
EntityPropertyFlags includedOriginalProperties;
|
EntityPropertyFlags includedOriginalProperties;
|
||||||
EntityPropertyFlags includedZoneProperties;
|
EntityPropertyFlags includedZoneProperties;
|
||||||
bool wantsZoneBoundingBox { false };
|
bool wantsZoneBoundingBox { false };
|
||||||
|
|
22
scripts/tutorials/entity_edit_filters/prevent-all-deletes.js
Normal file
22
scripts/tutorials/entity_edit_filters/prevent-all-deletes.js
Normal 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;
|
|
@ -5,13 +5,14 @@
|
||||||
// Created by Brad Hefta-Gaub to use Entities on Jan. 25, 2018
|
// Created by Brad Hefta-Gaub to use Entities on Jan. 25, 2018
|
||||||
// Copyright 2018 High Fidelity, Inc.
|
// 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.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// 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) {
|
if (type == Entities.DELETE_FILTER_TYPE) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -19,6 +20,5 @@ function filter(properties, type, originalProperties, zoneProperties) {
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
filter.wantsOriginalProperties = true;
|
filter.wantsToFilterDelete = true; // do run on deletes
|
||||||
filter.wantsZoneProperties = true;
|
|
||||||
filter;
|
filter;
|
Loading…
Reference in a new issue