mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 12:17:45 +02:00
add EntityItemProperties::copyFromJSONString()
This commit is contained in:
parent
ec384d7dbb
commit
fe2ee68b79
4 changed files with 32 additions and 25 deletions
|
@ -50,7 +50,6 @@
|
||||||
#include <RecordingScriptingInterface.h>
|
#include <RecordingScriptingInterface.h>
|
||||||
#include <trackers/FaceTracker.h>
|
#include <trackers/FaceTracker.h>
|
||||||
#include <RenderableModelEntityItem.h>
|
#include <RenderableModelEntityItem.h>
|
||||||
#include <VariantMapToScriptValue.h>
|
|
||||||
|
|
||||||
#include "MyHead.h"
|
#include "MyHead.h"
|
||||||
#include "MySkeletonModel.h"
|
#include "MySkeletonModel.h"
|
||||||
|
@ -1305,14 +1304,14 @@ void MyAvatar::saveData() {
|
||||||
|
|
||||||
void MyAvatar::saveAvatarEntityDataToSettings() {
|
void MyAvatar::saveAvatarEntityDataToSettings() {
|
||||||
// save new settings
|
// save new settings
|
||||||
uint32_t numEntities = _avatarEntitiesAsPropertiesStrings.size();
|
uint32_t numEntities = _avatarEntityStrings.size();
|
||||||
_avatarEntityCountSetting.set(numEntities);
|
_avatarEntityCountSetting.set(numEntities);
|
||||||
uint32_t prevNumEntities = _avatarEntityCountSetting.get(0);
|
uint32_t prevNumEntities = _avatarEntityCountSetting.get(0);
|
||||||
resizeAvatarEntitySettingHandles(std::max<uint32_t>(numEntities, prevNumEntities));
|
resizeAvatarEntitySettingHandles(std::max<uint32_t>(numEntities, prevNumEntities));
|
||||||
if (numEntities > 0) {
|
if (numEntities > 0) {
|
||||||
_avatarEntitiesLock.withReadLock([&] {
|
_avatarEntitiesLock.withReadLock([&] {
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
for (const auto& mapEntry : _avatarEntitiesAsPropertiesStrings) {
|
for (const auto& mapEntry : _avatarEntityStrings) {
|
||||||
_avatarEntityDataSettings[i].set(mapEntry.second);
|
_avatarEntityDataSettings[i].set(mapEntry.second);
|
||||||
_avatarEntityIDSettings[i].set(mapEntry.first.toString());
|
_avatarEntityIDSettings[i].set(mapEntry.first.toString());
|
||||||
++i;
|
++i;
|
||||||
|
@ -1430,7 +1429,13 @@ void MyAvatar::setEnableInverseKinematics(bool isEnabled) {
|
||||||
_skeletonModel->getRig().setEnableInverseKinematics(isEnabled);
|
_skeletonModel->getRig().setEnableInverseKinematics(isEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::updateAvatarEntity(const QUuid& entityID, const EntityItemProperties& properties) {
|
void MyAvatar::updateAvatarEntity(const QUuid& entityID, const QString& entityPropertiesString) {
|
||||||
|
/* TODO: implement this so JS can add/update (and delete?) AvatarEntitieskj:w
|
||||||
|
// convert string to properties
|
||||||
|
// NOTE: this path from EntityItemProperties JSON string to EntityItemProperties is NOT efficient
|
||||||
|
EntityItemProperties properties;
|
||||||
|
properties.copyFromJSONString(scriptEngine, entityPropertiesString);
|
||||||
|
|
||||||
auto entityTreeRenderer = qApp->getEntities();
|
auto entityTreeRenderer = qApp->getEntities();
|
||||||
EntityTreePointer entityTree = entityTreeRenderer ? entityTreeRenderer->getTree() : nullptr;
|
EntityTreePointer entityTree = entityTreeRenderer ? entityTreeRenderer->getTree() : nullptr;
|
||||||
EntityItemPointer entity;
|
EntityItemPointer entity;
|
||||||
|
@ -1460,12 +1465,9 @@ void MyAvatar::updateAvatarEntity(const QUuid& entityID, const EntityItemPropert
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//QByteArray tempArray = QByteArray::fromRawData((const char*)packetData.getUncompressedData(), packetData.getUncompressedSize());
|
QByteArray tempArray = QByteArray::fromRawData((const char*)packetData.getUncompressedData(), packetData.getUncompressedSize());
|
||||||
QByteArray tempArray((const char*)packetData.getUncompressedData(), packetData.getUncompressedSize());
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
|
||||||
tempArray[i] = (uint8_t)(0xff);
|
|
||||||
}
|
|
||||||
storeAvatarEntityDataPayload(entity->getID(), tempArray);
|
storeAvatarEntityDataPayload(entity->getID(), tempArray);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::updateAvatarEntities() {
|
void MyAvatar::updateAvatarEntities() {
|
||||||
|
@ -1558,22 +1560,14 @@ void MyAvatar::loadAvatarEntityDataFromSettings() {
|
||||||
entitiesToLoad.resize(numEntities);
|
entitiesToLoad.resize(numEntities);
|
||||||
resizeAvatarEntitySettingHandles(numEntities);
|
resizeAvatarEntitySettingHandles(numEntities);
|
||||||
for (int i = 0; i < numEntities; i++) {
|
for (int i = 0; i < numEntities; i++) {
|
||||||
// NOTE: this path from EntityItemProperties JSON string to EntityItemProperties is NOT efficient
|
// DANGER: this JSONString --> EntityItemProperties operation is expensive
|
||||||
QString propertiesString = _avatarEntityDataSettings[i].get();
|
|
||||||
QJsonDocument propertiesDoc = QJsonDocument::fromJson(propertiesString.toUtf8());
|
|
||||||
QJsonObject propertiesObj = propertiesDoc.object();
|
|
||||||
QVariant propertiesVariant(propertiesObj);
|
|
||||||
QVariantMap propertiesMap = propertiesVariant.toMap();
|
|
||||||
QScriptValue propertiesScriptValue = variantMapToScriptValue(propertiesMap, scriptEngine);
|
|
||||||
|
|
||||||
// NOTE: we grab properties by reference and wrangle it:
|
|
||||||
EntityItemProperties& properties = entitiesToLoad[i];
|
EntityItemProperties& properties = entitiesToLoad[i];
|
||||||
EntityItemPropertiesFromScriptValueIgnoreReadOnly(propertiesScriptValue, properties);
|
properties.copyFromJSONString(scriptEngine, _avatarEntityDataSettings[i].get());
|
||||||
// the ClientOnly property can get stripped out elsewhere so we need to always set it true here
|
// the ClientOnly property can get stripped out elsewhere so we need to always set it true here
|
||||||
properties.setClientOnly(true);
|
properties.setClientOnly(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
_avatarEntitiesAsPropertiesStrings.clear();
|
_avatarEntityStrings.clear();
|
||||||
auto entityTreeRenderer = qApp->getEntities();
|
auto entityTreeRenderer = qApp->getEntities();
|
||||||
EntityTreePointer entityTree = entityTreeRenderer ? entityTreeRenderer->getTree() : nullptr;
|
EntityTreePointer entityTree = entityTreeRenderer ? entityTreeRenderer->getTree() : nullptr;
|
||||||
if (entityTree) {
|
if (entityTree) {
|
||||||
|
@ -1592,7 +1586,7 @@ void MyAvatar::loadAvatarEntityDataFromSettings() {
|
||||||
// only remember an AvatarEntity that successfully loads and can be packed
|
// only remember an AvatarEntity that successfully loads and can be packed
|
||||||
QByteArray tempArray = QByteArray::fromRawData((const char*)packetData.getUncompressedData(), packetData.getUncompressedSize());
|
QByteArray tempArray = QByteArray::fromRawData((const char*)packetData.getUncompressedData(), packetData.getUncompressedSize());
|
||||||
storeAvatarEntityDataPayload(entityID, tempArray);
|
storeAvatarEntityDataPayload(entityID, tempArray);
|
||||||
_avatarEntitiesAsPropertiesStrings[entityID] = _avatarEntityDataSettings[i].get();
|
_avatarEntityStrings[entityID] = _avatarEntityDataSettings[i].get();
|
||||||
}
|
}
|
||||||
packetData.reset();
|
packetData.reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1407,8 +1407,7 @@ public slots:
|
||||||
*/
|
*/
|
||||||
bool getEnableMeshVisible() const override;
|
bool getEnableMeshVisible() const override;
|
||||||
|
|
||||||
// TODO: make this invokable, probably also move down to AvatarData
|
void updateAvatarEntity(const QUuid& entityID, const QString& entityPropertiesString) override;
|
||||||
void updateAvatarEntity(const QUuid& entityID, const EntityItemProperties& properties);
|
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* Set whether or not your avatar mesh is visible.
|
* Set whether or not your avatar mesh is visible.
|
||||||
|
@ -1947,7 +1946,8 @@ private:
|
||||||
Setting::Handle<bool> _allowTeleportingSetting { "allowTeleporting", true };
|
Setting::Handle<bool> _allowTeleportingSetting { "allowTeleporting", true };
|
||||||
std::vector<Setting::Handle<QString>> _avatarEntityIDSettings;
|
std::vector<Setting::Handle<QString>> _avatarEntityIDSettings;
|
||||||
std::vector<Setting::Handle<QString>> _avatarEntityDataSettings;
|
std::vector<Setting::Handle<QString>> _avatarEntityDataSettings;
|
||||||
std::map<QUuid, QString> _avatarEntitiesAsPropertiesStrings;
|
std::map<QUuid, QString> _avatarEntityStrings;
|
||||||
|
std::map<QUuid, QString> _avatarEntityProperties;
|
||||||
};
|
};
|
||||||
|
|
||||||
QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode);
|
QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode);
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <GLMHelpers.h>
|
#include <GLMHelpers.h>
|
||||||
#include <RegisteredMetaTypes.h>
|
#include <RegisteredMetaTypes.h>
|
||||||
#include <Extents.h>
|
#include <Extents.h>
|
||||||
|
#include <VariantMapToScriptValue.h>
|
||||||
|
|
||||||
#include "EntitiesLogging.h"
|
#include "EntitiesLogging.h"
|
||||||
#include "EntityItem.h"
|
#include "EntityItem.h"
|
||||||
|
@ -2033,6 +2034,18 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool
|
||||||
_lastEdited = usecTimestampNow();
|
_lastEdited = usecTimestampNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntityItemProperties::copyFromJSONString(QScriptEngine& scriptEngine, const QString& jsonString) {
|
||||||
|
// DANGER: this method is expensive
|
||||||
|
QJsonDocument propertiesDoc = QJsonDocument::fromJson(jsonString.toUtf8());
|
||||||
|
QJsonObject propertiesObj = propertiesDoc.object();
|
||||||
|
QVariant propertiesVariant(propertiesObj);
|
||||||
|
QVariantMap propertiesMap = propertiesVariant.toMap();
|
||||||
|
QScriptValue propertiesScriptValue = variantMapToScriptValue(propertiesMap, scriptEngine);
|
||||||
|
bool honorReadOnly = true;
|
||||||
|
copyFromScriptValue(propertiesScriptValue, honorReadOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void EntityItemProperties::merge(const EntityItemProperties& other) {
|
void EntityItemProperties::merge(const EntityItemProperties& other) {
|
||||||
// Core
|
// Core
|
||||||
COPY_PROPERTY_IF_CHANGED(simulationOwner);
|
COPY_PROPERTY_IF_CHANGED(simulationOwner);
|
||||||
|
@ -2262,7 +2275,6 @@ void EntityItemPropertiesFromScriptValueHonorReadOnly(const QScriptValue &object
|
||||||
properties.copyFromScriptValue(object, true);
|
properties.copyFromScriptValue(object, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QScriptValue EntityPropertyFlagsToScriptValue(QScriptEngine* engine, const EntityPropertyFlags& flags) {
|
QScriptValue EntityPropertyFlagsToScriptValue(QScriptEngine* engine, const EntityPropertyFlags& flags) {
|
||||||
return EntityItemProperties::entityPropertyFlagsToScriptValue(engine, flags);
|
return EntityItemProperties::entityPropertyFlagsToScriptValue(engine, flags);
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,7 @@ public:
|
||||||
virtual QScriptValue copyToScriptValue(QScriptEngine* engine, bool skipDefaults, bool allowUnknownCreateTime = false,
|
virtual QScriptValue copyToScriptValue(QScriptEngine* engine, bool skipDefaults, bool allowUnknownCreateTime = false,
|
||||||
bool strictSemantics = false, EntityPsuedoPropertyFlags psueudoPropertyFlags = EntityPsuedoPropertyFlags()) const;
|
bool strictSemantics = false, EntityPsuedoPropertyFlags psueudoPropertyFlags = EntityPsuedoPropertyFlags()) const;
|
||||||
virtual void copyFromScriptValue(const QScriptValue& object, bool honorReadOnly);
|
virtual void copyFromScriptValue(const QScriptValue& object, bool honorReadOnly);
|
||||||
|
void copyFromJSONString(QScriptEngine& scriptEngine, const QString& jsonString);
|
||||||
|
|
||||||
static QScriptValue entityPropertyFlagsToScriptValue(QScriptEngine* engine, const EntityPropertyFlags& flags);
|
static QScriptValue entityPropertyFlagsToScriptValue(QScriptEngine* engine, const EntityPropertyFlags& flags);
|
||||||
static void entityPropertyFlagsFromScriptValue(const QScriptValue& object, EntityPropertyFlags& flags);
|
static void entityPropertyFlagsFromScriptValue(const QScriptValue& object, EntityPropertyFlags& flags);
|
||||||
|
|
Loading…
Reference in a new issue