mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:24:00 +02:00
set up EntityItemPropertiesFromScript to either ignore or honor read-only properties
This commit is contained in:
parent
6913c62b84
commit
a96520ca74
6 changed files with 31 additions and 14 deletions
|
@ -477,7 +477,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool
|
|||
return properties;
|
||||
}
|
||||
|
||||
void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) {
|
||||
void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool honorReadOnly) {
|
||||
QScriptValue typeScriptValue = object.property("type");
|
||||
if (typeScriptValue.isValid()) {
|
||||
setType(typeScriptValue.toVariant().toString());
|
||||
|
@ -494,11 +494,12 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) {
|
|||
COPY_PROPERTY_FROM_QSCRIPTVALUE(restitution, float, setRestitution);
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE(friction, float, setFriction);
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE(lifetime, float, setLifetime);
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(created, QDateTime, setCreated, [this]() {
|
||||
auto result = QDateTime::fromMSecsSinceEpoch(_created / 1000, Qt::UTC); // usec per msec
|
||||
// result.setTimeSpec(Qt::OffsetFromUTC);
|
||||
return result;
|
||||
});
|
||||
if (!honorReadOnly) {
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(created, QDateTime, setCreated, [this]() {
|
||||
auto result = QDateTime::fromMSecsSinceEpoch(_created / 1000, Qt::UTC); // usec per msec
|
||||
return result;
|
||||
});
|
||||
}
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE(script, QString, setScript);
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE(registrationPoint, glmVec3, setRegistrationPoint);
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE(angularVelocity, glmVec3, setAngularVelocity);
|
||||
|
@ -523,7 +524,9 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) {
|
|||
COPY_PROPERTY_FROM_QSCRIPTVALUE(locked, bool, setLocked);
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE(textures, QString, setTextures);
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE(userData, QString, setUserData);
|
||||
//COPY_PROPERTY_FROM_QSCRIPTVALUE(simulatorID, QUuid, setSimulatorID); DO NOT accept this info from QScriptValue
|
||||
if (!honorReadOnly) {
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE(simulatorID, QUuid, setSimulatorID);
|
||||
}
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE(text, QString, setText);
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE(lineHeight, float, setLineHeight);
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE(textColor, xColor, setTextColor);
|
||||
|
@ -565,10 +568,15 @@ QScriptValue EntityItemNonDefaultPropertiesToScriptValue(QScriptEngine* engine,
|
|||
return properties.copyToScriptValue(engine, true);
|
||||
}
|
||||
|
||||
void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemProperties& properties) {
|
||||
properties.copyFromScriptValue(object);
|
||||
void EntityItemPropertiesFromScriptValueIgnoreReadOnly(const QScriptValue &object, EntityItemProperties& properties) {
|
||||
properties.copyFromScriptValue(object, false);
|
||||
}
|
||||
|
||||
void EntityItemPropertiesFromScriptValueHonorReadOnly(const QScriptValue &object, EntityItemProperties& properties) {
|
||||
properties.copyFromScriptValue(object, true);
|
||||
}
|
||||
|
||||
|
||||
// TODO: Implement support for edit packets that can span an MTU sized buffer. We need to implement a mechanism for the
|
||||
// encodeEntityEditPacket() method to communicate the the caller which properties couldn't fit in the buffer. Similar
|
||||
// to how we handle this in the Octree streaming case.
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
void setType(EntityTypes::EntityType type) { _type = type; }
|
||||
|
||||
virtual QScriptValue copyToScriptValue(QScriptEngine* engine, bool skipDefaults) const;
|
||||
virtual void copyFromScriptValue(const QScriptValue& object);
|
||||
virtual void copyFromScriptValue(const QScriptValue& object, bool honorReadOnly);
|
||||
|
||||
// editing related features supported by all entities
|
||||
quint64 getLastEdited() const { return _lastEdited; }
|
||||
|
@ -218,7 +218,8 @@ private:
|
|||
Q_DECLARE_METATYPE(EntityItemProperties);
|
||||
QScriptValue EntityItemPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties);
|
||||
QScriptValue EntityItemNonDefaultPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties);
|
||||
void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemProperties& properties);
|
||||
void EntityItemPropertiesFromScriptValueIgnoreReadOnly(const QScriptValue &object, EntityItemProperties& properties);
|
||||
void EntityItemPropertiesFromScriptValueHonorReadOnly(const QScriptValue &object, EntityItemProperties& properties);
|
||||
|
||||
|
||||
// define these inline here so the macros work
|
||||
|
|
|
@ -360,7 +360,7 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra
|
|||
quuidFromScriptValue(entityIDValue, value.entityID);
|
||||
QScriptValue entityPropertiesValue = object.property("properties");
|
||||
if (entityPropertiesValue.isValid()) {
|
||||
EntityItemPropertiesFromScriptValue(entityPropertiesValue, value.properties);
|
||||
EntityItemPropertiesFromScriptValueHonorReadOnly(entityPropertiesValue, value.properties);
|
||||
}
|
||||
value.distance = object.property("distance").toVariant().toFloat();
|
||||
|
||||
|
|
|
@ -1055,7 +1055,7 @@ bool EntityTree::readFromMap(QVariantMap& map) {
|
|||
QVariantMap entityMap = entityVariant.toMap();
|
||||
QScriptValue entityScriptValue = variantMapToScriptValue(entityMap, scriptEngine);
|
||||
EntityItemProperties properties;
|
||||
EntityItemPropertiesFromScriptValue(entityScriptValue, properties);
|
||||
EntityItemPropertiesFromScriptValueIgnoreReadOnly(entityScriptValue, properties);
|
||||
|
||||
EntityItemID entityItemID;
|
||||
if (entityMap.contains("id")) {
|
||||
|
|
|
@ -2096,7 +2096,15 @@ void Octree::writeToJSONFile(const char* fileName, OctreeElement* element) {
|
|||
top = _rootElement;
|
||||
}
|
||||
|
||||
// include the "bitstream" version
|
||||
PacketType expectedType = expectedDataPacketType();
|
||||
PacketVersion expectedVersion = versionForPacketType(expectedType);
|
||||
entityDescription["Version"] = (int) expectedVersion;
|
||||
|
||||
// store the entity data
|
||||
bool entityDescriptionSuccess = writeToMap(entityDescription, top, true);
|
||||
|
||||
// convert the QVariantMap to JSON
|
||||
if (entityDescriptionSuccess && persistFile.open(QIODevice::WriteOnly)) {
|
||||
persistFile.write(QJsonDocument::fromVariant(entityDescription).toJson());
|
||||
} else {
|
||||
|
|
|
@ -318,7 +318,7 @@ void ScriptEngine::init() {
|
|||
registerAvatarTypes(this);
|
||||
registerAudioMetaTypes(this);
|
||||
|
||||
qScriptRegisterMetaType(this, EntityItemPropertiesToScriptValue, EntityItemPropertiesFromScriptValue);
|
||||
qScriptRegisterMetaType(this, EntityItemPropertiesToScriptValue, EntityItemPropertiesFromScriptValueHonorReadOnly);
|
||||
qScriptRegisterMetaType(this, EntityItemIDtoScriptValue, EntityItemIDfromScriptValue);
|
||||
qScriptRegisterMetaType(this, RayToEntityIntersectionResultToScriptValue, RayToEntityIntersectionResultFromScriptValue);
|
||||
qScriptRegisterSequenceMetaType<QVector<QUuid>>(this);
|
||||
|
|
Loading…
Reference in a new issue