Javascript bug fixes.

* Fixed handling of blank C++ callback result strings.
* Fixed metadata being saved when exiting editor with the Cancel button.
* Fixed logic for deciding when the editor's priority value had been
changed.
This commit is contained in:
WrinklyNinja
2014-08-14 15:21:39 +01:00
parent 03ceb6541b
commit 5255cfb69f
2 changed files with 87 additions and 67 deletions
+56 -51
View File
@@ -55,19 +55,23 @@ var pluginMenuProto = Object.create(HTMLElement.prototype, {
]
});
loot.query(request).then(JSON.parse).then(function(result){
/* Need to empty the UI-side user metadata. */
for (var i = 0; i < loot.game.plugins.length; ++i) {
if (loot.game.plugins[i].id == pluginID) {
loot.game.plugins[i].userlist = undefined;
loot.query(request).then(function(result){
if (result) {
result = JSON.parse(result);
loot.game.plugins[i].modPriority = result.modPriority;
loot.game.plugins[i].isGlobalPriority = result.isGlobalPriority;
loot.game.plugins[i].messages = result.messages;
loot.game.plugins[i].tags = result.tags;
loot.game.plugins[i].isDirty = result.isDirty;
/* Need to empty the UI-side user metadata. */
for (var i = 0; i < loot.game.plugins.length; ++i) {
if (loot.game.plugins[i].id == pluginID) {
loot.game.plugins[i].userlist = undefined;
break;
loot.game.plugins[i].modPriority = result.modPriority;
loot.game.plugins[i].isGlobalPriority = result.isGlobalPriority;
loot.game.plugins[i].messages = result.messages;
loot.game.plugins[i].tags = result.tags;
loot.game.plugins[i].isDirty = result.isDirty;
break;
}
}
}
}).catch(processCefError);
@@ -161,13 +165,12 @@ var pluginCardProto = Object.create(HTMLElement.prototype, {
for (var i = 0; i < loot.game.plugins.length; ++i) {
if (loot.game.plugins[i].id == this.id) {
if (this.shadowRoot.getElementById('globalPriority').checked != loot.game.plugins[i].isGlobalPriority) {
/* Priority value has been changed, record it. */
/* If either of the priority values have been changed, the
base priority value they're derived from will have
changed, so record both. */
if (this.shadowRoot.getElementById('globalPriority').checked != loot.game.plugins[i].isGlobalPriority
|| this.shadowRoot.getElementById('priorityValue').value != loot.game.plugins[i].modPriority) {
plugin.isGlobalPriority = this.shadowRoot.getElementById('globalPriority').checked;
}
if (this.shadowRoot.getElementById('priorityValue').value != loot.game.plugins[i].modPriority) {
/* Priority value has been changed, record it. */
plugin.modPriority = this.shadowRoot.getElementById('priorityValue').value;
}
@@ -205,8 +208,8 @@ var pluginCardProto = Object.create(HTMLElement.prototype, {
}
}
}
/* Update the userlist values. This doesn't affect priority,
which will need to be set in the callback. */
/* Now update JS userlist data for the plugin. */
loot.game.plugins[i].userlist = plugin.userlist;
break;
@@ -218,8 +221,9 @@ var pluginCardProto = Object.create(HTMLElement.prototype, {
hideEditor: {
value: function(evt) {
var card = evt.target.parentElement.parentElement.parentNode.host;
var isValid = true;
if (evt.target.className.indexOf('accept') != -1) {
if (evt.target.id == 'accept') {
/* First validate table inputs. */
var inputs = evt.target.parentElement.parentElement.getElementsByTagName('input');
for (var i = 0; i < inputs.length; ++i) {
@@ -228,39 +232,40 @@ var pluginCardProto = Object.create(HTMLElement.prototype, {
console.log(inputs[i]);
}
}
if (isValid) {
/* Need to record the editor control values and work out what's
changed, and update any UI elements necessary. Offload the
majority of the work to the C++ side of things. */
var request = JSON.stringify({
name: 'editorClosed',
args: [
card.readFromEditor()
]
});
loot.query(request).then(function(result){
if (result) {
result = JSON.parse(result);
for (var i = 0; i < loot.game.plugins.length; ++i) {
if (loot.game.plugins[i].id == card.id) {
loot.game.plugins[i].modPriority = result.modPriority;
loot.game.plugins[i].isGlobalPriority = result.isGlobalPriority;
loot.game.plugins[i].messages = result.messages;
loot.game.plugins[i].tags = result.tags;
loot.game.plugins[i].isDirty = result.isDirty;
break;
}
}
}
}).catch(processCefError);
}
}
if (isValid) {
var card = evt.target.parentElement.parentElement.parentNode.host;
/* Need to record the editor control values and work out what's
changed, and update any UI elements necessary. Offload the
majority of the work to the C++ side of things. */
var request = JSON.stringify({
name: 'editorClosed',
args: [
card.getElementsByTagName('h1')[0].textContent,
card.readFromEditor()
]
});
loot.query(request).then(function(result){
for (var i = 0; i < loot.game.plugins.length; ++i) {
if (loot.game.plugins[i].id == this.id) {
loot.game.plugins[i].userlist.priority = result.userlist.priority;
loot.game.plugins[i].modPriority = result.modPriority;
loot.game.plugins[i].isGlobalPriority = result.isGlobalPriority;
loot.game.plugins[i].messages = result.messages;
loot.game.plugins[i].tags = result.tags;
loot.game.plugins[i].isDirty = result.isDirty;
break;
}
}
}).catch(processCefError);
/* Set up table tab event handlers. */
/* Remove table tab event handlers. */
var elements = card.shadowRoot.getElementById('tableTabs').children;
for (var i = 0; i < elements.length; ++i) {
if (elements[i].hasAttribute('data-for')) {
@@ -268,7 +273,7 @@ var pluginCardProto = Object.create(HTMLElement.prototype, {
}
}
/* Set up button event handlers. */
/* Remove button event handlers. */
card.shadowRoot.getElementById('accept').removeEventListener('click', card.hideEditor, false);
card.shadowRoot.getElementById('cancel').removeEventListener('click', card.hideEditor, false);
+31 -16
View File
@@ -38,6 +38,7 @@ loot.query = function(request) {
})
}
function processCefError(err) {
console.log(err);
showMessageBox('error', 'Error', err.message);
}
@@ -113,7 +114,7 @@ function getConflictingPluginsFromFilter() {
]
});
return loot.query(request).then(JSON.parse).catch(processCefError);
return loot.query(request).catch(processCefError);
}
}
@@ -132,6 +133,12 @@ function togglePlugins(evt) {
it is completed.
*/
getConflictingPluginsFromFilter().then(function(conflicts) {
if (conflicts) {
conflicts = JSON.parse(conflicts);
} else {
conflicts = [];
}
/* Start at 3rd section to skip summary and general messages. */
for (var i = 2; i < sections.length; ++i) {
var isConflictingPlugin = false;
@@ -314,23 +321,27 @@ function redatePlugins(evt) {
function clearAllMetadata(evt) {
showMessageDialog('Clear All Metadata', 'Are you sure you want to clear all existing user-added metadata from all plugins?', function(result){
if (result) {
loot.query('clearAllMetadata').then(JSON.parse).then(function(result){
/* Need to empty the UI-side user metadata. */
result.forEach(function(plugin){
for (var i = 0; i < loot.game.plugins.length; ++i) {
if (loot.game.plugins[i].name == plugin.name) {
loot.game.plugins[i].userlist = undefined;
loot.query('clearAllMetadata').then(function(result){
if (result) {
result = JSON.parse(result);
loot.game.plugins[i].modPriority = plugin.modPriority;
loot.game.plugins[i].isGlobalPriority = plugin.isGlobalPriority;
loot.game.plugins[i].messages = plugin.messages;
loot.game.plugins[i].tags = plugin.tags;
loot.game.plugins[i].isDirty = plugin.isDirty;
/* Need to empty the UI-side user metadata. */
result.forEach(function(plugin){
for (var i = 0; i < loot.game.plugins.length; ++i) {
if (loot.game.plugins[i].name == plugin.name) {
loot.game.plugins[i].userlist = undefined;
break;
loot.game.plugins[i].modPriority = plugin.modPriority;
loot.game.plugins[i].isGlobalPriority = plugin.isGlobalPriority;
loot.game.plugins[i].messages = plugin.messages;
loot.game.plugins[i].tags = plugin.tags;
loot.game.plugins[i].isDirty = plugin.isDirty;
break;
}
}
}
});
});
}
}).catch(processCefError);
}
});
@@ -631,7 +642,11 @@ function initVars() {
}
try {
loot.installedGames = JSON.parse(results[1]);
if (results[1]) {
loot.installedGames = JSON.parse(results[1]);
} else {
loot.installedGames = [];
}
} catch (e) {
console.log(e);
console.log('getInstalledGames response: ' + results[1]);