getting there, but not yet complete

This commit is contained in:
howard-stearns 2017-01-13 16:59:51 -08:00
parent f6446c6806
commit 121d79ef36
3 changed files with 9 additions and 8 deletions

View file

@ -346,11 +346,11 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const {
return changedProperties;
}
QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool skipDefaults) const {
QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool skipDefaults, bool allowUknownCreateTime) const {
QScriptValue properties = engine->newObject();
EntityItemProperties defaultEntityProperties;
if (_created == UNKNOWN_CREATED_TIME) {
if (_created == UNKNOWN_CREATED_TIME && !allowUknownCreateTime) {
// No entity properties can have been set so return without setting any default, zero property values.
return properties;
}

View file

@ -73,7 +73,7 @@ public:
EntityTypes::EntityType getType() const { return _type; }
void setType(EntityTypes::EntityType type) { _type = type; }
virtual QScriptValue copyToScriptValue(QScriptEngine* engine, bool skipDefaults) const;
virtual QScriptValue copyToScriptValue(QScriptEngine* engine, bool skipDefaults, bool allowUknownCreateTime = false) const;
virtual void copyFromScriptValue(const QScriptValue& object, bool honorReadOnly);
static QScriptValue entityPropertyFlagsToScriptValue(QScriptEngine* engine, const EntityPropertyFlags& flags);

View file

@ -931,7 +931,7 @@ bool EntityTree::filterProperties(const EntityItemProperties& propertiesIn, Enti
wasChanged = false; // not changed
return true; // allowed
}
QScriptValue inputValues = propertiesIn.copyToScriptValue(&_entityEditFilterEngine, false);
QScriptValue inputValues = propertiesIn.copyToScriptValue(&_entityEditFilterEngine, true, true);
QScriptValueList args;
args << inputValues;
@ -940,6 +940,7 @@ bool EntityTree::filterProperties(const EntityItemProperties& propertiesIn, Enti
propertiesOut.copyFromScriptValue(result, false);
wasChanged = result.equals(inputValues); // not changed
qDebug() << "result" << propertiesOut << result.toVariant() << wasChanged;
return result.isObject(); // filters should return null or false to completely reject edit or add
}
@ -1028,17 +1029,17 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
if (validEditPacket) {
startFilter = usecTimestampNow();
QScriptValue originalValues = properties.copyToScriptValue(&_entityEditFilterEngine, true);
bool wasChanged = false;
bool allowed = filterProperties(properties, properties, wasChanged);
QScriptValue filteredResult = properties.copyToScriptValue(&_entityEditFilterEngine, true);
if (wasChanged) {
if (!allowed) {
properties = EntityItemProperties(); // Maybe other behavior
} else if (wasChanged) {
if (properties.getLastEdited() == UNKNOWN_CREATED_TIME) {
properties.setLastEdited(usecTimestampNow());
}
properties.setLastEdited(properties.getLastEdited() + LAST_EDITED_SERVERSIDE_BUMP);
}
qDebug() << "FIXME changed/allowed" << wasChanged << allowed;
qDebug() << "filtered:" << properties;
endFilter = usecTimestampNow();
// search for the entity by EntityItemID