diff --git a/js/utils.js b/js/utils.js index 6c7d7f8cfee61be92ca2324cea2623b14b713a17..1ae61021a84ecd78a35bc5f0c424cad0cf95c5b4 100644 --- a/js/utils.js +++ b/js/utils.js @@ -157,6 +157,14 @@ function capFirstChar(string) { return string.charAt(0).toUpperCase() + string.substr(1); } +/** + * @param {string} string + * @returns {string} + */ +function uncapFirstChar(string) { + return string.charAt(0).toLowerCase() + string.substr(1); +} + /** * @param {string} word * @returns {string} diff --git a/src/events/intro/customizeSlaveTrade/customizeSlaveTrade.js b/src/events/intro/customizeSlaveTrade/customizeSlaveTrade.js index 0d3858239aa11ac36ec753fb2b8ba3169618160a..186861aa9b5fda008e21ce435cb40a4ec17bc156 100644 --- a/src/events/intro/customizeSlaveTrade/customizeSlaveTrade.js +++ b/src/events/intro/customizeSlaveTrade/customizeSlaveTrade.js @@ -52,7 +52,7 @@ App.UI.CustomSlaveTrade = function() { array = []; for (let i = 0; i < setup.filterRaces.length; i++) { const race = setup.filterRaces[i]; - if (baseControlsFilter === race.toLowerCase().replace(/[ -]/g, '')) { + if (baseControlsFilter === uncapFirstChar(race).replace(/[ -]/g, '')) { array.push( App.UI.DOM.disabledLink( race, @@ -64,7 +64,7 @@ App.UI.CustomSlaveTrade = function() { App.UI.DOM.link( race, () => { - baseControlsFilter = setup.filterRaces[i].toLowerCase().replace(/[ -]/g, ''); + baseControlsFilter = uncapFirstChar(setup.filterRaces[i]).replace(/[ -]/g, ''); refresh(); } ) @@ -79,7 +79,7 @@ App.UI.CustomSlaveTrade = function() { array = []; for (let i = 0; i < setup.filterRegions.length; i++) { const region = setup.filterRegions[i]; - if (baseControlsFilter === region.toLowerCase().replace(/[ -]/g, '')) { + if (baseControlsFilter === uncapFirstChar(region).replace(/[ -]/g, '')) { array.push( App.UI.DOM.disabledLink( region, @@ -91,7 +91,7 @@ App.UI.CustomSlaveTrade = function() { App.UI.DOM.link( region, () => { - baseControlsFilter = setup.filterRegions[i].toLowerCase().replace(/[ -]/g, ''); + baseControlsFilter = uncapFirstChar(setup.filterRegions[i]).replace(/[ -]/g, ''); refresh(); } ) @@ -172,7 +172,7 @@ App.UI.CustomSlaveTrade = function() { for (const race of setup.filterRaces) { const racialNationalities = setup.baseNationalities.filter(function(n) { let races = setup.raceSelector[n] || setup.raceSelector['']; - return races[race.toLowerCase()] * 3.5 > hashSum(races); + return races[uncapFirstChar(race)] * 3.5 > hashSum(races); }); if (racialNationalities.length > 0) { @@ -190,7 +190,7 @@ App.UI.CustomSlaveTrade = function() { () => { setup.baseNationalities.filter(function(n) { let races = setup.raceSelector[n] || setup.raceSelector['']; - return races['" + _race.toLowerCase() + "'] * 3.5 > hashSum(races); + return races[uncapFirstChar(race)] * 3.5 > hashSum(races); }).forEach(function(n) { hashPush(V.nationalities, n); }); refresh(); } @@ -205,7 +205,7 @@ App.UI.CustomSlaveTrade = function() { () => { setup.baseNationalities.filter(function(n) { let races = setup.raceSelector[n] || setup.raceSelector['']; - return races['" + _race.toLowerCase() + "'] * 3.5 > hashSum(races); + return races[uncapFirstChar(race)] * 3.5 > hashSum(races); }).forEach(function(n) { delete V.nationalities[n]; }); refresh();