mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 04:37:48 +02:00
save on no selections, select another entity, etc
This commit is contained in:
parent
3abbc98857
commit
a5054487ba
2 changed files with 72 additions and 22 deletions
|
@ -1427,7 +1427,10 @@ var PropertiesTool = function (opts) {
|
||||||
}
|
}
|
||||||
pushCommandForSelections();
|
pushCommandForSelections();
|
||||||
selectionManager._update();
|
selectionManager._update();
|
||||||
} else if (data.type === "showMarketplace") {
|
}else if(data.type==='saveUserData'){
|
||||||
|
Entities.editEntity(data.id,data.properties)
|
||||||
|
}
|
||||||
|
else if (data.type === "showMarketplace") {
|
||||||
showMarketplace();
|
showMarketplace();
|
||||||
} else if (data.type === "action") {
|
} else if (data.type === "action") {
|
||||||
if (data.action === "moveSelectionToGrid") {
|
if (data.action === "moveSelectionToGrid") {
|
||||||
|
|
|
@ -26,7 +26,7 @@ var ICON_FOR_TYPE = {
|
||||||
var EDITOR_TIMEOUT_DURATION = 1500;
|
var EDITOR_TIMEOUT_DURATION = 1500;
|
||||||
|
|
||||||
var colorPickers = [];
|
var colorPickers = [];
|
||||||
|
var lastEntityID=null;
|
||||||
debugPrint = function(message) {
|
debugPrint = function(message) {
|
||||||
EventBridge.emitWebEvent(
|
EventBridge.emitWebEvent(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
@ -84,7 +84,7 @@ function showElements(els, show) {
|
||||||
function createEmitCheckedPropertyUpdateFunction(propertyName) {
|
function createEmitCheckedPropertyUpdateFunction(propertyName) {
|
||||||
return function() {
|
return function() {
|
||||||
EventBridge.emitWebEvent(
|
EventBridge.emitWebEvent(
|
||||||
'{ "type":"update", "properties":{"' + propertyName + '":' + this.checked + '}}'
|
'{"id":' + lastEntityID + ', "type":"update", "properties":{"' + propertyName + '":' + this.checked + '}}'
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,7 @@ function createEmitGroupCheckedPropertyUpdateFunction(group, propertyName) {
|
||||||
properties[group][propertyName] = this.checked;
|
properties[group][propertyName] = this.checked;
|
||||||
EventBridge.emitWebEvent(
|
EventBridge.emitWebEvent(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
id: lastEntityID,
|
||||||
type: "update",
|
type: "update",
|
||||||
properties: properties
|
properties: properties
|
||||||
})
|
})
|
||||||
|
@ -119,7 +120,7 @@ function createEmitNumberPropertyUpdateFunction(propertyName, decimals) {
|
||||||
var value = parseFloat(this.value).toFixed(decimals);
|
var value = parseFloat(this.value).toFixed(decimals);
|
||||||
|
|
||||||
EventBridge.emitWebEvent(
|
EventBridge.emitWebEvent(
|
||||||
'{ "type":"update", "properties":{"' + propertyName + '":' + value + '}}'
|
'{"id":' + lastEntityID + ', "type":"update", "properties":{"' + propertyName + '":' + value + '}}'
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -131,6 +132,7 @@ function createEmitGroupNumberPropertyUpdateFunction(group, propertyName) {
|
||||||
properties[group][propertyName] = this.value;
|
properties[group][propertyName] = this.value;
|
||||||
EventBridge.emitWebEvent(
|
EventBridge.emitWebEvent(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
id: lastEntityID,
|
||||||
type: "update",
|
type: "update",
|
||||||
properties: properties,
|
properties: properties,
|
||||||
})
|
})
|
||||||
|
@ -145,6 +147,7 @@ function createEmitTextPropertyUpdateFunction(propertyName) {
|
||||||
properties[propertyName] = this.value;
|
properties[propertyName] = this.value;
|
||||||
EventBridge.emitWebEvent(
|
EventBridge.emitWebEvent(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
id: lastEntityID,
|
||||||
type: "update",
|
type: "update",
|
||||||
properties: properties,
|
properties: properties,
|
||||||
})
|
})
|
||||||
|
@ -159,6 +162,7 @@ function createEmitGroupTextPropertyUpdateFunction(group, propertyName) {
|
||||||
properties[group][propertyName] = this.value;
|
properties[group][propertyName] = this.value;
|
||||||
EventBridge.emitWebEvent(
|
EventBridge.emitWebEvent(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
id: lastEntityID,
|
||||||
type: "update",
|
type: "update",
|
||||||
properties: properties,
|
properties: properties,
|
||||||
})
|
})
|
||||||
|
@ -169,6 +173,7 @@ function createEmitGroupTextPropertyUpdateFunction(group, propertyName) {
|
||||||
function createEmitVec3PropertyUpdateFunction(property, elX, elY, elZ) {
|
function createEmitVec3PropertyUpdateFunction(property, elX, elY, elZ) {
|
||||||
return function() {
|
return function() {
|
||||||
var data = {
|
var data = {
|
||||||
|
id: lastEntityID,
|
||||||
type: "update",
|
type: "update",
|
||||||
properties: {}
|
properties: {}
|
||||||
};
|
};
|
||||||
|
@ -184,6 +189,7 @@ function createEmitVec3PropertyUpdateFunction(property, elX, elY, elZ) {
|
||||||
function createEmitGroupVec3PropertyUpdateFunction(group, property, elX, elY, elZ) {
|
function createEmitGroupVec3PropertyUpdateFunction(group, property, elX, elY, elZ) {
|
||||||
return function() {
|
return function() {
|
||||||
var data = {
|
var data = {
|
||||||
|
id: lastEntityID,
|
||||||
type: "update",
|
type: "update",
|
||||||
properties: {}
|
properties: {}
|
||||||
};
|
};
|
||||||
|
@ -200,6 +206,7 @@ function createEmitGroupVec3PropertyUpdateFunction(group, property, elX, elY, el
|
||||||
function createEmitVec3PropertyUpdateFunctionWithMultiplier(property, elX, elY, elZ, multiplier) {
|
function createEmitVec3PropertyUpdateFunctionWithMultiplier(property, elX, elY, elZ, multiplier) {
|
||||||
return function() {
|
return function() {
|
||||||
var data = {
|
var data = {
|
||||||
|
id: lastEntityID,
|
||||||
type: "update",
|
type: "update",
|
||||||
properties: {}
|
properties: {}
|
||||||
};
|
};
|
||||||
|
@ -220,6 +227,7 @@ function createEmitColorPropertyUpdateFunction(property, elRed, elGreen, elBlue)
|
||||||
|
|
||||||
function emitColorPropertyUpdate(property, red, green, blue, group) {
|
function emitColorPropertyUpdate(property, red, green, blue, group) {
|
||||||
var data = {
|
var data = {
|
||||||
|
id: lastEntityID,
|
||||||
type: "update",
|
type: "update",
|
||||||
properties: {}
|
properties: {}
|
||||||
};
|
};
|
||||||
|
@ -244,6 +252,7 @@ function emitColorPropertyUpdate(property, red, green, blue, group) {
|
||||||
function createEmitGroupColorPropertyUpdateFunction(group, property, elRed, elGreen, elBlue) {
|
function createEmitGroupColorPropertyUpdateFunction(group, property, elRed, elGreen, elBlue) {
|
||||||
return function() {
|
return function() {
|
||||||
var data = {
|
var data = {
|
||||||
|
id: lastEntityID,
|
||||||
type: "update",
|
type: "update",
|
||||||
properties: {}
|
properties: {}
|
||||||
};
|
};
|
||||||
|
@ -273,6 +282,7 @@ function updateCheckedSubProperty(propertyName, propertyValue, subPropertyElemen
|
||||||
|
|
||||||
EventBridge.emitWebEvent(
|
EventBridge.emitWebEvent(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
id: lastEntityID,
|
||||||
type: "update",
|
type: "update",
|
||||||
properties: _properties
|
properties: _properties
|
||||||
})
|
})
|
||||||
|
@ -280,7 +290,7 @@ function updateCheckedSubProperty(propertyName, propertyValue, subPropertyElemen
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setUserDataFromEditor() {
|
function setUserDataFromEditor(noUpdate) {
|
||||||
var json = null;
|
var json = null;
|
||||||
try {
|
try {
|
||||||
json = editor.get();
|
json = editor.get();
|
||||||
|
@ -291,20 +301,35 @@ function setUserDataFromEditor() {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
var text = editor.getText()
|
var text = editor.getText()
|
||||||
EventBridge.emitWebEvent(
|
console.log('saving as text:', text)
|
||||||
JSON.stringify({
|
if (noUpdate === true) {
|
||||||
type: "update",
|
EventBridge.emitWebEvent(
|
||||||
properties: {
|
JSON.stringify({
|
||||||
userData: text
|
id: lastEntityID,
|
||||||
},
|
type: "saveUserData",
|
||||||
})
|
properties: {
|
||||||
);
|
userData: text
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
EventBridge.emitWebEvent(
|
||||||
|
JSON.stringify({
|
||||||
|
id: lastEntityID,
|
||||||
|
type: "update",
|
||||||
|
properties: {
|
||||||
|
userData: text
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function userDataChanger(groupName, keyName, checkBoxElement, userDataElement, defaultValue) {
|
function userDataChanger(groupName, keyName, checkBoxElement, userDataElement, defaultValue) {
|
||||||
var properties = {};
|
var properties = {};
|
||||||
var parsedData = {};
|
var parsedData = {};
|
||||||
|
@ -337,6 +362,7 @@ function userDataChanger(groupName, keyName, checkBoxElement, userDataElement, d
|
||||||
|
|
||||||
EventBridge.emitWebEvent(
|
EventBridge.emitWebEvent(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
id: lastEntityID,
|
||||||
type: "update",
|
type: "update",
|
||||||
properties: properties,
|
properties: properties,
|
||||||
})
|
})
|
||||||
|
@ -368,11 +394,12 @@ function createJSONEditor() {
|
||||||
alert('JSON editor:' + e)
|
alert('JSON editor:' + e)
|
||||||
},
|
},
|
||||||
onChange: function() {
|
onChange: function() {
|
||||||
|
var currentJSONString = editor.getText();
|
||||||
|
|
||||||
if (currentJSONString === '{"":""}') {
|
if (currentJSONString === '{"":""}') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$('#userdata-save').attr('disabled', false)
|
$('#userdata-save').attr('disabled', false)
|
||||||
var currentJSONString = editor.getText();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -444,8 +471,9 @@ function deleteJSONEditor() {
|
||||||
|
|
||||||
var savedJSONTimer = null;
|
var savedJSONTimer = null;
|
||||||
|
|
||||||
function saveJSONUserData() {
|
function saveJSONUserData(noUpdate) {
|
||||||
setUserDataFromEditor();
|
console.log('start saving userdata')
|
||||||
|
setUserDataFromEditor(noUpdate);
|
||||||
$('#userdata-saved').show();
|
$('#userdata-saved').show();
|
||||||
$('#userdata-save').attr('disabled', true)
|
$('#userdata-save').attr('disabled', true)
|
||||||
if (savedJSONTimer !== null) {
|
if (savedJSONTimer !== null) {
|
||||||
|
@ -453,7 +481,7 @@ function saveJSONUserData() {
|
||||||
}
|
}
|
||||||
savedJSONTimer = setTimeout(function() {
|
savedJSONTimer = setTimeout(function() {
|
||||||
$('#userdata-saved').hide();
|
$('#userdata-saved').hide();
|
||||||
|
|
||||||
}, 1500)
|
}, 1500)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,12 +495,23 @@ function bindAllNonJSONEditorElements() {
|
||||||
if (e.target.id === "userdata-new-editor" || e.target.id === "userdata-clear") {
|
if (e.target.id === "userdata-new-editor" || e.target.id === "userdata-clear") {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
saveJSONUserData();
|
console.log('save on focus',e)
|
||||||
|
saveJSONUserData(true);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function unbindAllInputs() {
|
||||||
|
var inputs = $('input');
|
||||||
|
var i;
|
||||||
|
for (i = 0; i < inputs.length; i++) {
|
||||||
|
var input = inputs[i];
|
||||||
|
var field = $(input);
|
||||||
|
field.unbind();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function loaded() {
|
function loaded() {
|
||||||
openEventBridge(function() {
|
openEventBridge(function() {
|
||||||
var allSections = [];
|
var allSections = [];
|
||||||
|
@ -667,7 +706,9 @@ function loaded() {
|
||||||
if (data.type == "update") {
|
if (data.type == "update") {
|
||||||
|
|
||||||
if (data.selections.length == 0) {
|
if (data.selections.length == 0) {
|
||||||
if (editor !== null) {
|
if (editor !== null && lastEntityID!==null) {
|
||||||
|
console.log('save on no selections')
|
||||||
|
saveJSONUserData(true);
|
||||||
deleteJSONEditor();
|
deleteJSONEditor();
|
||||||
}
|
}
|
||||||
elTypeIcon.style.display = "none";
|
elTypeIcon.style.display = "none";
|
||||||
|
@ -707,9 +748,13 @@ function loaded() {
|
||||||
disableProperties();
|
disableProperties();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
||||||
properties = data.selections[0].properties;
|
properties = data.selections[0].properties;
|
||||||
|
if (lastEntityID !== properties.id && lastEntityID!==null) {
|
||||||
|
console.log('save on init')
|
||||||
|
saveJSONUserData(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
lastEntityID = properties.id;
|
||||||
elID.innerHTML = properties.id;
|
elID.innerHTML = properties.id;
|
||||||
|
|
||||||
elType.innerHTML = properties.type;
|
elType.innerHTML = properties.type;
|
||||||
|
@ -1112,6 +1157,7 @@ function loaded() {
|
||||||
properties['userData'] = elUserData.value;
|
properties['userData'] = elUserData.value;
|
||||||
EventBridge.emitWebEvent(
|
EventBridge.emitWebEvent(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
id: lastEntityID,
|
||||||
type: "update",
|
type: "update",
|
||||||
properties: properties,
|
properties: properties,
|
||||||
})
|
})
|
||||||
|
@ -1122,7 +1168,8 @@ function loaded() {
|
||||||
|
|
||||||
|
|
||||||
elSaveUserData.addEventListener("click", function() {
|
elSaveUserData.addEventListener("click", function() {
|
||||||
saveJSONUserData();
|
console.log('save on click')
|
||||||
|
saveJSONUserData(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
elUserData.addEventListener('change', createEmitTextPropertyUpdateFunction('userData'));
|
elUserData.addEventListener('change', createEmitTextPropertyUpdateFunction('userData'));
|
||||||
|
|
Loading…
Reference in a new issue