From 9c1ebecda7c068a44955c8e5a6fae15925ebbc23 Mon Sep 17 00:00:00 2001 From: Andrea Rendine Date: Wed, 29 Apr 2015 23:52:58 +0200 Subject: [PATCH] Buildings alphabetical sorting The bulk of this small change was to sort buildings by alphabetical order according to translated names, instead of english strings. This meant removing the ID splitting as well as hyphen/space replacing, as the ID is not considered for the test. Also changed: 1. line 366: as the original english string is no longer necessary in the iteration, "name" takes the value of translated string. "name" is then used for alphabetical comparison (as before) with the right value. 2. line 378: removed the test on curPrev variable. Items already listed have been placed in alphabetical order, so there is no need to check whether each item actually follows value of control variable. --- script/outside.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/script/outside.js b/script/outside.js index 6f59805..fac05ee 100644 --- a/script/outside.js +++ b/script/outside.js @@ -363,26 +363,27 @@ var Outside = { updateVillageRow: function(name, num, village) { var id = 'building_row_' + name.replace(' ', '-'); + name = _(name); var row = $('div#' + id, village); if(row.length === 0 && num > 0) { row = $('
').attr('id', id).addClass('storeRow'); - $('
').addClass('row_key').text(_(name)).appendTo(row); + $('
').addClass('row_key').text(name).appendTo(row); $('
').addClass('row_val').text(num).appendTo(row); $('
').addClass('clear').appendTo(row); var curPrev = null; village.children().each(function(i) { var child = $(this); if(child.attr('id') != 'population') { - var cName = child.attr('id').substring(13).replace('-', ' '); - if(cName < name && (curPrev == null || cName > curPrev)) { - curPrev = cName; + var cName = child.children('.row_key').text(); + if(cName < name) { + curPrev = child.attr('id'); } } }); if(curPrev == null) { row.prependTo(village); } else { - row.insertAfter('#building_row_' + curPrev.replace(' ', '-')); + row.insertAfter('#' + curPrev); } } else if(num > 0) { $('div#' + row.attr('id') + ' > div.row_val', village).text(num);