diff --git a/src/js/itemAvailability.js b/src/js/itemAvailability.js index c00d459196f5e7dc12d9130b077da63a6726e6b3..af4eb1135a41eb78aed1fcf92061eaf3d3fc2a8c 100644 --- a/src/js/itemAvailability.js +++ b/src/js/itemAvailability.js @@ -200,45 +200,76 @@ window.isItemAccessible = function(string) { } }; -window.isClothingAccessible = function(string) { - if (V.cheatMode === 1) { - return true; - } +window.isClothingAccessible = (function() { + return { + array: array, + entry: entry, + }; - let item = App.Data.misc.niceClothes.find((i) => i.value === string); - if (!item) { - item = App.Data.misc.harshClothes.find((i) => i.value === string); - } - if (!item) { - console.log(`${string} is not a registered piece of clothing! Check App.Data.Misc.`); - return false; /* couldn't be found */ + /** + * Checks whether clothing is accessible + * @param {string} string Name of wearable item + * @returns {boolean} + */ + + function entry(string) { + if (V.cheatMode === 1) { + return true; + } + let item = App.Data.misc.niceClothes.find((i) => i.value === string); + if (!item) { + item = App.Data.misc.harshClothes.find((i) => i.value === string); + } + if (!item) { + console.log(`${string} is not a registered piece of clothing! Check App.Data.Misc.`); + return false; /* couldn't be found */ + } + return isAvailable(item); } - if (!(item.hasOwnProperty("unlock")) && !(item.hasOwnProperty("fs"))) { - return true; + /** + * Returns array of wearable clothing in format [name, value], or player facing / game data. + * @param {string} db Name of array to look in (such as "App.Data.misc.niceClothes") + * @returns {Array} + */ + // returns array [.name, .value] + function array(db) { + const array = []; + db.forEach((i) => { + if (V.cheatMode || isAvailable(i)) { + array.push([i.name, i.value]); + } + }); + return array; } - if (item.hasOwnProperty("fs")) { - if (V.arcologies[0][item.fs] > 0) { + function isAvailable(item) { + if (!(item.hasOwnProperty("unlock")) && !(item.hasOwnProperty("fs"))) { + // No restriction, this clothing item is available to everyone return true; } - } - if (item.hasOwnProperty("unlock")) { - let keys = Object.keys(item.unlock); - for (let key in keys) { - if (keys[key] === "continent" && V.continent === item.unlock[keys[key]]) { - return true; - } else if (V[keys[key]] > 0 ) { + if (item.hasOwnProperty("fs")) { + if (V.arcologies[0][item.fs] > 0) { return true; } } - // special case where they must both be true - if (item.unlock.clothesBoughtSports && item.unlock.clothesBoughtCasual) { - if (V.clothesBoughtSports && V.clothesBoughtCasual) { - return true; + if (item.hasOwnProperty("unlock")) { + let keys = Object.keys(item.unlock); + for (let key in keys) { + if (keys[key] === "continent" && V.continent === item.unlock[keys[key]]) { + return true; + } else if (V[keys[key]] > 0 ) { + return true; + } + } + // special case where they must both be true + if (item.unlock.clothesBoughtSports && item.unlock.clothesBoughtCasual) { + if (V.clothesBoughtSports && V.clothesBoughtCasual) { + return true; + } } } + return false; } - return false; -}; +})(); /** * @param {App.Entity.SlaveState} slave diff --git a/src/js/rulesAssistantOptions.js b/src/js/rulesAssistantOptions.js index f94a65a56802b9318f39bbe2e06e7eb457693235..4ecefd19e6bd91bc30dd3829ba27c688d40cb2d0 100644 --- a/src/js/rulesAssistantOptions.js +++ b/src/js/rulesAssistantOptions.js @@ -1743,13 +1743,11 @@ window.rulesAssistantOptions = (function() { ]; super("Clothes", items); - const nclothes = []; - App.Data.misc.niceClothes.forEach(pair => { if (isClothingAccessible(pair.value)) { nclothes.push([pair.name, pair.value]); } }); //add FS + const nclothes = isClothingAccessible.array(App.Data.misc.niceClothes); nclothes.sort(function(a, b) { if (a[0] < b[0]) { return -1; } if (a[0] > b[0]) { return 1; } return 0; }); this._nice = new ListSubSection(this, "Nice", nclothes); - const hclothes = []; - App.Data.misc.harshClothes.forEach(pair => { if (isClothingAccessible(pair.value)) { hclothes.push([pair.name, pair.value]); } }); + const hclothes = isClothingAccessible.array(App.Data.misc.harshClothes); hclothes.sort(function(a, b) { if (a[0] < b[0]) { return -1; } if (a[0] > b[0]) { return 1; } return 0; }); this._harsh = new ListSubSection(this, "Harsh", hclothes); diff --git a/src/js/wardrobeUse.js b/src/js/wardrobeUse.js index f1ae754633ace4afb08c5b740f968c7756f1eb53..6ff864ee5edf6f039c2fe835a23842b0d00b9134 100644 --- a/src/js/wardrobeUse.js +++ b/src/js/wardrobeUse.js @@ -95,7 +95,7 @@ App.UI.Wardrobe.clothes = function(slave) { break; } } - if (array[i].updateSlave.clothes === `choosing her own clothes` || isClothingAccessible(array[i].updateSlave.clothes)) { + if (array[i].updateSlave.clothes === `choosing her own clothes` || isClothingAccessible.entry(array[i].updateSlave.clothes)) { // is it just text? if (array[i].disabled) { link = App.UI.DOM.disabledLink(array[i].text, [array[i].disabled]);