Fixed sorting error.

There's no plain object.forEach().
This commit is contained in:
WrinklyNinja
2014-08-18 12:49:03 +01:00
parent b8b28f700f
commit fed515f038
2 changed files with 12 additions and 11 deletions
+6 -8
View File
@@ -422,32 +422,30 @@ function sortPlugins(evt) {
updateMasterlist(evt);
}
loot.query('sortPlugins').then(JSON.parse).then(function(result){
var plugins = [];
result.forEach(function(value, key){
plugins.push(key);
for (var key in result.crcs) {
for (var i = 0; i < loot.game.plugins.length; ++i) {
if (loot.game.plugins[i].name == key) {
loot.game.plugins[i].crc = value;
loot.game.plugins[i].crc = result.crcs[key];
break;
}
}
});
}
if (loot.neverTellMeTheOdds) {
/* Array shuffler from <https://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array-in-javascript> */
for(var j, x, i = plugins.length; i; j = Math.floor(Math.random() * i), x = plugins[--i], plugins[i] = plugins[j], plugins[j] = x);
for(var j, x, i = result.loadOrder.length; i; j = Math.floor(Math.random() * i), x = result.loadOrder[--i], result.loadOrder[i] = result.loadOrder[j], result.loadOrder[j] = x);
}
/* Record the previous order in case the user cancels sorting. */
/* Start at 2 to skip summary and general messages. */
var cards = document.getElementById('main').children;
loot.newLoadOrder = plugins;
loot.newLoadOrder = result.loadOrder;
loot.lastLoadOrder = [];
for (var i = 2; i < cards.length; ++i) {
loot.lastLoadOrder.push(cards[i].getElementsByTagName('h1')[0].textContent);
}
/* Now update the UI for the new order. */
sortUIElements(plugins);
sortUIElements(result.loadOrder);
/* Now hide the masterlist update buttons, and display the accept and
cancel sort buttons. */
+6 -3
View File
@@ -188,12 +188,15 @@ namespace loot {
//Sort plugins into their load order.
list<Plugin> plugins = g_app_state.CurrentGame().Sort(language, [](const string& message){});
map<string, uint32_t> loadOrder;
map<string, uint32_t> crcs;
list<string> loadOrder;
YAML::Node node;
for (const auto &plugin : plugins) {
loadOrder.emplace(plugin.Name(), plugin.Crc());
node["loadOrder"].push_back(plugin.Name());
node["crcs"][plugin.Name()] = plugin.Crc();
}
callback->Success(JSON::stringify(YAML::Node(loadOrder)));
callback->Success(JSON::stringify(node));
return true;
}
else {