diff --git a/src/js/utilsMisc.js b/src/js/utilsMisc.js index ab9e8f6928c3a475339641231554e4dd3d127654..27574a559520d9b2545c348285433c9a5f5299ea 100644 --- a/src/js/utilsMisc.js +++ b/src/js/utilsMisc.js @@ -1,3 +1,35 @@ +/** +A categorizer is used to "slice" a value range into distinct categories in an efficient manner. + +If the values are objects their property named 'value' will be set to whatever +the value used for the choice was. This is important for getters, where it can be accessed +via this.value. + +--- Example --- +Original SugarCube code +<<if _Slave.muscles > 95>> + Musc++ +<<elseif _Slave.muscles > 30>> + Musc+ +<<elseif _Slave.muscles > 5>> + Toned +<<elseif _Slave.muscles > -6>> +<<elseif _Slave.muscles > -31>> + <span class="red">weak</span> +<<elseif _Slave.muscles > -96>> + <span class="red">weak+</span> +<<else>> + <span class="red">weak++</span> +<</if>> + +As a categorizer +<<if ndef $cats>><<set $cats = {}>><</if>> +<<if ndef $cats.muscleCat>> + <!-- This only gets set once, skipping much of the code evaluation, and can be set outside of the code in an "init" passage for further optimization --> + <<set $cats.muscleCat = new Categorizer([96, 'Musc++'], [31, 'Musc+'], [6, 'Toned'], [-5, ''], [-30, '<span class="red">weak</span>'], [-95, '<span class="red">weak+</span>'], [-Infinity, '<span class="red">weak++</span>'])>> +<</if>> +<<print $cats.muscleCat.cat(_Slave.muscles)>> +*/ globalThis.Categorizer = class { /** * @param {...[]} pairs diff --git a/src/js/utilsSlave.js b/src/js/utilsSlave.js index 9d055f0f8b2cd0565aced7afa8dc2983195db75f..3f1d71dbeb7b14954aaed3d25f4f3bd924c6ca2d 100644 --- a/src/js/utilsSlave.js +++ b/src/js/utilsSlave.js @@ -877,39 +877,12 @@ globalThis.Intelligence = (function() { config: _config, }; })(); -/* -A categorizer is used to "slice" a value range into distinct categories in an efficient manner. - -If the values are objects their property named 'value' will be set to whatever -the value used for the choice was. This is important for getters, where it can be accessed -via this.value. - ---- Example --- -Original SugarCube code -<<if _Slave.muscles > 95>> - Musc++ -<<elseif _Slave.muscles > 30>> - Musc+ -<<elseif _Slave.muscles > 5>> - Toned -<<elseif _Slave.muscles > -6>> -<<elseif _Slave.muscles > -31>> - <span class="red">weak</span> -<<elseif _Slave.muscles > -96>> - <span class="red">weak+</span> -<<else>> - <span class="red">weak++</span> -<</if>> - -As a categorizer -<<if ndef $cats>><<set $cats = {}>><</if>> -<<if ndef $cats.muscleCat>> - <!-- This only gets set once, skipping much of the code evaluation, and can be set outside of the code in an "init" passage for further optimization --> - <<set $cats.muscleCat = new Categorizer([96, 'Musc++'], [31, 'Musc+'], [6, 'Toned'], [-5, ''], [-30, '<span class="red">weak</span>'], [-95, '<span class="red">weak+</span>'], [-Infinity, '<span class="red">weak++</span>'])>> -<</if>> -<<print $cats.muscleCat.cat(_Slave.muscles)>> -*/ +/** + * Takes a string with a baked in pronoun ("Her mother offered her") and returns it with SC variable pronouns("$His mother offered $him") + * @param {string} slavetext + * @returns {string} + */ globalThis.pronounReplacer = function(slavetext) { switch (slavetext) { case "After her short but very promising slave racing career, during which she made it through several competitions as a virgin, many people fondly remember fantasizing about taking her.": @@ -1372,6 +1345,11 @@ globalThis.pronounReplacer = function(slavetext) { return slavetext; }; +/** + * Describes a slaves pre-slavery career in a gender sensitive way. If career is "a dominatrix" but the slave is male and the pronoun system is on, returns "a dominator" + * @param {App.Entity.SlaveState} slave + * @returns {FC.Zeroable<string>} + */ globalThis.convertCareer = function(slave) { let job = slave.career; if ((V.diversePronouns === 1) && (slave.pronoun === App.Data.Pronouns.Kind.male)) { @@ -3447,14 +3425,6 @@ globalThis.slaveSkillIncrease = function(targetSkill, slave, skillIncrease = 1) return r; }; -/* -//Example -getBestSlaves({part:"butt", count: 5}); -getBestSlaves({part:"boobs"});//defaults to top 3 -getBestSlaves({part:"dick", smallest:true, filter:(slave)=>slave.dick > 0});//defaults to top 3 -getBestSlaves({part:slave=>slave.intelligence+slave.intelligenceImplant}); -*/ - /** * Generates a new slave ID that is guaranteed to be unused * @returns {number} slave ID diff --git a/src/js/utilsSlaves.js b/src/js/utilsSlaves.js index 79222bba4de3558011b209d9be326bb6d86eba17..56de9d67046c5b315738aeffce056f910fe6f582 100644 --- a/src/js/utilsSlaves.js +++ b/src/js/utilsSlaves.js @@ -122,6 +122,11 @@ globalThis.slaveSortMinor = function(slaves) { */ /** + * Example: + * getBestSlaves({part:"butt", count: 5}); + * getBestSlaves({part:"boobs"});//defaults to top 3 + * getBestSlaves({part:"dick", smallest:true, filter:(slave)=>slave.dick > 0});//defaults to top 3 + * getBestSlaves({part:slave=>slave.intelligence+slave.intelligenceImplant}); * @param {getBestSlavesParams} params * @returns {App.Entity.SlaveState[]} sorted from best to worst */ @@ -180,6 +185,10 @@ App.Utils.masterSuiteAverages = (function() { }; })(); +/** + * Updates the globals roomsPopulation and dormitoryPopulation + * @returns {void} + */ globalThis.penthouseCensus = function() { function occupiesRoom(slave) { if (slave.rules.living !== "luxurious") {