mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
more robustness for optional properties
This commit is contained in:
parent
2da3192c33
commit
2cdda23169
3 changed files with 80 additions and 62 deletions
|
@ -2373,7 +2373,6 @@ function selectParticleEntity(entityID) {
|
|||
particleExplorerTool.createWebView();
|
||||
|
||||
particleExplorerTool.setActiveParticleEntity(entityID);
|
||||
particleExplorerTool.setActiveParticleProperties(properties);
|
||||
|
||||
// Switch to particle explorer
|
||||
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||
|
|
|
@ -61,12 +61,18 @@ function HifiEntityUI(parent) {
|
|||
this.parent = parent;
|
||||
|
||||
var self = this;
|
||||
this.sendPackage = {};
|
||||
this.settingsUpdateLock = false;
|
||||
this.webBridgeSync = _.debounce(function (id, val) {
|
||||
if (self.EventBridge && !self.settingsUpdateLock) {
|
||||
var sendPackage = {};
|
||||
sendPackage[id] = val;
|
||||
self.submitChanges(sendPackage);
|
||||
this.webBridgeSync = function(id, val) {
|
||||
if (!this.settingsUpdateLock) {
|
||||
this.sendPackage[id] = val;
|
||||
this.webBridgeSyncDebounce();
|
||||
}
|
||||
};
|
||||
this.webBridgeSyncDebounce = _.debounce(function () {
|
||||
if (self.EventBridge) {
|
||||
self.submitChanges(self.sendPackage);
|
||||
self.sendPackage = {};
|
||||
}
|
||||
}, DEBOUNCE_TIMEOUT);
|
||||
}
|
||||
|
@ -159,7 +165,6 @@ HifiEntityUI.prototype = {
|
|||
var self = this;
|
||||
var fields = document.getElementsByTagName("input");
|
||||
|
||||
self.settingsUpdateLock = true;
|
||||
if (!currentProperties.locked) {
|
||||
for (var i = 0; i < fields.length; i++) {
|
||||
fields[i].removeAttribute("disabled");
|
||||
|
@ -179,7 +184,7 @@ HifiEntityUI.prototype = {
|
|||
for (var e in keys) {
|
||||
if (keys.hasOwnProperty(e)) {
|
||||
var value = keys[e];
|
||||
|
||||
|
||||
var property = currentProperties[value];
|
||||
var field = self.builtRows[value];
|
||||
if (field) {
|
||||
|
@ -235,10 +240,6 @@ HifiEntityUI.prototype = {
|
|||
}
|
||||
}
|
||||
}
|
||||
// Now unlocking settings Update lock for sending messages on callbacks.
|
||||
setTimeout(function () {
|
||||
self.settingsUpdateLock = false;
|
||||
}, DEBOUNCE_TIMEOUT * 2.5);
|
||||
},
|
||||
connect: function (EventBridge) {
|
||||
this.EventBridge = EventBridge;
|
||||
|
@ -253,28 +254,9 @@ HifiEntityUI.prototype = {
|
|||
data = JSON.parse(data);
|
||||
|
||||
if (data.messageType === 'particle_settings') {
|
||||
// Update settings
|
||||
var currentProperties = data.currentProperties;
|
||||
// Update uninitialized variables
|
||||
if (!currentProperties.alphaStart) {
|
||||
currentProperties.alphaStart = currentProperties.alpha;
|
||||
}
|
||||
if (!currentProperties.alphaFinish) {
|
||||
currentProperties.alphaFinish = currentProperties.alpha;
|
||||
}
|
||||
if (!currentProperties.radiusStart) {
|
||||
currentProperties.radiusStart = currentProperties.particleRadius;
|
||||
}
|
||||
if (!currentProperties.radiusFinish) {
|
||||
currentProperties.radiusFinish = currentProperties.particleRadius;
|
||||
}
|
||||
if (!currentProperties.colorStart || !currentProperties.colorStart.red) {
|
||||
currentProperties.colorStart = currentProperties.color;
|
||||
}
|
||||
if (!currentProperties.colorFinish || !currentProperties.colorFinish.red) {
|
||||
currentProperties.colorFinish = currentProperties.color;
|
||||
}
|
||||
self.fillFields(currentProperties);
|
||||
self.settingsUpdateLock = true;
|
||||
self.fillFields(data.currentProperties);
|
||||
self.settingsUpdateLock = false;
|
||||
// Do expected property match with structure;
|
||||
} else if (data.messageType === 'particle_close') {
|
||||
self.disableFields();
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
/* global window, alert, ParticleExplorerTool, EventBridge, dat, listenForSettingsUpdates,createVec3Folder,createQuatFolder,writeVec3ToInterface,writeDataToInterface*/
|
||||
/* global window, alert, ParticleExplorerTool, EventBridge, dat, listenForSettingsUpdates, createVec3Folder,
|
||||
createQuatFolder, writeVec3ToInterface, writeDataToInterface */
|
||||
|
||||
|
||||
var PARTICLE_EXPLORER_HTML_URL = Script.resolvePath('particleExplorer.html');
|
||||
|
@ -17,7 +18,7 @@ var PARTICLE_EXPLORER_HTML_URL = Script.resolvePath('particleExplorer.html');
|
|||
ParticleExplorerTool = function() {
|
||||
var that = {};
|
||||
that.activeParticleEntity = 0;
|
||||
that.activeParticleProperties = {};
|
||||
that.updatedActiveParticleProperties = {};
|
||||
|
||||
that.createWebView = function() {
|
||||
that.webView = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||
|
@ -30,7 +31,7 @@ ParticleExplorerTool = function() {
|
|||
return;
|
||||
}
|
||||
that.activeParticleEntity = 0;
|
||||
that.activeParticleProperties = {};
|
||||
that.updatedActiveParticleProperties = {};
|
||||
|
||||
var messageData = {
|
||||
messageType: "particle_close"
|
||||
|
@ -38,46 +39,86 @@ ParticleExplorerTool = function() {
|
|||
that.webView.emitScriptEvent(JSON.stringify(messageData));
|
||||
};
|
||||
|
||||
function sendActiveParticleProperties() {
|
||||
function sendParticleProperties(properties) {
|
||||
that.webView.emitScriptEvent(JSON.stringify({
|
||||
messageType: "particle_settings",
|
||||
currentProperties: that.activeParticleProperties
|
||||
currentProperties: properties
|
||||
}));
|
||||
}
|
||||
|
||||
function sendActiveParticleProperties() {
|
||||
var properties = Entities.getEntityProperties(that.activeParticleEntity);
|
||||
if (properties.emitOrientation) {
|
||||
properties.emitOrientation = Quat.safeEulerAngles(properties.emitOrientation);
|
||||
}
|
||||
// Update uninitialized variables
|
||||
if (isNaN(properties.alphaStart)) {
|
||||
properties.alphaStart = properties.alpha;
|
||||
}
|
||||
if (isNaN(properties.alphaFinish)) {
|
||||
properties.alphaFinish = properties.alpha;
|
||||
}
|
||||
if (isNaN(properties.radiusStart)) {
|
||||
properties.radiusStart = properties.particleRadius;
|
||||
}
|
||||
if (isNaN(properties.radiusFinish)) {
|
||||
properties.radiusFinish = properties.particleRadius;
|
||||
}
|
||||
if (isNaN(properties.colorStart) || isNaN(properties.colorStart.red)) {
|
||||
properties.colorStart = properties.color;
|
||||
}
|
||||
if (isNaN(properties.colorFinish) || isNaN(properties.colorFinish.red)) {
|
||||
properties.colorFinish = properties.color;
|
||||
}
|
||||
sendParticleProperties(properties);
|
||||
}
|
||||
|
||||
function sendUpdatedActiveParticleProperties() {
|
||||
sendParticleProperties(that.updatedActiveParticleProperties);
|
||||
that.updatedActiveParticleProperties = {};
|
||||
}
|
||||
|
||||
that.webEventReceived = function(message) {
|
||||
var data = JSON.parse(message);
|
||||
if (data.messageType === "settings_update") {
|
||||
if (data.updatedSettings.emitOrientation) {
|
||||
data.updatedSettings.emitOrientation = Quat.fromVec3Degrees(data.updatedSettings.emitOrientation);
|
||||
}
|
||||
Entities.editEntity(that.activeParticleEntity, data.updatedSettings);
|
||||
|
||||
for (var key in data.updatedSettings) {
|
||||
if (that.activeParticleProperties.hasOwnProperty(key)) {
|
||||
that.activeParticleProperties[key] = data.updatedSettings[key];
|
||||
}
|
||||
}
|
||||
var updatedSettings = data.updatedSettings;
|
||||
|
||||
var optionalProps = ["alphaStart", "alphaFinish", "radiusStart", "radiusFinish", "colorStart", "colorFinish"];
|
||||
var fallbackProps = ["alpha", "particleRadius", "color"];
|
||||
var entityProps = Entities.getEntityProperties(that.activeParticleProperties, optionalProps);
|
||||
for (var i = 0; i < optionalProps.length; i++) {
|
||||
var fallbackProp = fallbackProps[Math.floor(i / 2)];
|
||||
var optionalValue = updatedSettings[optionalProps[i]];
|
||||
var fallbackValue = updatedSettings[fallbackProp];
|
||||
if (optionalValue && fallbackValue) {
|
||||
delete updatedSettings[optionalProps[i]];
|
||||
}
|
||||
}
|
||||
|
||||
if (updatedSettings.emitOrientation) {
|
||||
updatedSettings.emitOrientation = Quat.fromVec3Degrees(updatedSettings.emitOrientation);
|
||||
}
|
||||
|
||||
Entities.editEntity(that.activeParticleEntity, updatedSettings);
|
||||
|
||||
var entityProps = Entities.getEntityProperties(that.activeParticleEntity, optionalProps);
|
||||
|
||||
var needsUpdate = false;
|
||||
for (var i = 0; i < optionalProps.length; i++) {
|
||||
var fallback = fallbackProps[Math.floor(i / 2)];
|
||||
if (data.updatedSettings[fallback]) {
|
||||
var prop = optionalProps[i];
|
||||
if (!that.activeParticleProperties[prop] || (fallback === "color" && !that.activeParticleProperties[prop].red)) {
|
||||
that.activeParticleProperties[prop] = entityProps[fallback];
|
||||
var fallbackProp = fallbackProps[Math.floor(i / 2)];
|
||||
var fallbackValue = updatedSettings[fallbackProp];
|
||||
if (fallbackValue) {
|
||||
var optionalProp = optionalProps[i];
|
||||
if (isNaN(entityProps[optionalProp]) || (fallbackProp === "color" && isNaN(entityProps[optionalProp].red))) {
|
||||
that.updatedActiveParticleProperties[optionalProp] = fallbackValue;
|
||||
needsUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (needsUpdate) {
|
||||
sendActiveParticleProperties();
|
||||
sendUpdatedActiveParticleProperties();
|
||||
}
|
||||
|
||||
|
||||
} else if (data.messageType === "page_loaded") {
|
||||
sendActiveParticleProperties();
|
||||
}
|
||||
|
@ -85,12 +126,8 @@ ParticleExplorerTool = function() {
|
|||
|
||||
that.setActiveParticleEntity = function(id) {
|
||||
that.activeParticleEntity = id;
|
||||
};
|
||||
|
||||
that.setActiveParticleProperties = function(properties) {
|
||||
that.activeParticleProperties = properties;
|
||||
sendActiveParticleProperties();
|
||||
};
|
||||
|
||||
|
||||
return that;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue