make sure true results for delete actually work, add more examples

This commit is contained in:
ZappoMan 2018-01-26 18:49:55 -08:00
parent b883d006c8
commit efc63a41e9
2 changed files with 38 additions and 1 deletions

View file

@ -125,7 +125,7 @@ bool EntityEditFilters::filter(glm::vec3& position, EntityItemProperties& proper
return false;
}
if (result.isObject()){
if (result.isObject()) {
// make propertiesIn reflect the changes, for next filter...
propertiesIn.copyFromScriptValue(result, false);
@ -134,6 +134,17 @@ bool EntityEditFilters::filter(glm::vec3& position, EntityItemProperties& proper
// Javascript objects are == only if they are the same object. To compare arbitrary values, we need to use JSON.
auto out = QJsonValue::fromVariant(result.toVariant());
wasChanged |= (in != out);
} else if (result.isBool()) {
// if the filter returned false, then it's authoritative
if (!result.toBool()) {
return false;
}
// otherwise, assume it wants to pass all properties
propertiesOut = propertiesIn;
wasChanged = false;
} else {
return false;
}

View file

@ -0,0 +1,26 @@
//
// prevent-add-of-entities-named-bob-example.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 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) {
if (properties.name == "bob") {
return false;
}
return properties;
}
filter.wantsToFilterAdd = true; // do run on add
filter.wantsToFilterEdit = false; // do not run on edit
filter.wantsToFilterPhysics = false; // do not run on physics
filter.wantsToFilterDelete = false; // do not run on delete
filter;