diff --git a/src/js/utilJS.js b/src/js/utilJS.js index c982c37540715160597d85ab232e440b3d2e0833..63be179ba01e8936f86f0d65b7aee1b9c30b9527 100644 --- a/src/js/utilJS.js +++ b/src/js/utilJS.js @@ -52,7 +52,7 @@ * There's also limitHeight which you're not using. It's basically limitMult in different units. */ window.Height = (function() { - 'use strict'; + "use strict"; // Global configuration (for different game modes/options/types) let minMult = -3.0; @@ -67,8 +67,12 @@ window.Height = (function() { if (_.isUndefined(conf)) { return {limitMult: [minMult, maxMult], limitHeight: [minHeight, maxHeight], skew: skew, spread: spread}; } - if (_.isFinite(conf.skew)) { skew = Math.clamp(conf.skew, -1000, 1000); } - if (_.isFinite(conf.spread)) { spread = Math.clamp(conf.spread, 0.001, 0.5); } + if (_.isFinite(conf.skew)) { + skew = Math.clamp(conf.skew, -1000, 1000); + } + if (_.isFinite(conf.spread)) { + spread = Math.clamp(conf.spread, 0.001, 0.5); + } if (_.isArray(conf.limitMult) && conf.limitMult.length === 2 && conf.limitMult[0] !== conf.limitMult[1] && _.isFinite(conf.limitMult[0]) && _.isFinite(conf.limitMult[1])) { minMult = Math.min(conf.limitMult[0], conf.limitMult[1]); @@ -180,20 +184,20 @@ window.Height = (function() { } let minHeight = 0; let midHeight = 0; let midAge = 15; switch (genes) { - case 'XX': // female - case 'XXX': // Triple X syndrome female + case "XX": // female + case "XXX": // Triple X syndrome female minHeight = 85; midHeight = height * 157 / 164; midAge = 13; break; - case 'XY': // male - case 'XXY': // Klinefelter syndrome male - case 'XYY': // XYY syndrome male + case "XY": // male + case "XXY": // Klinefelter syndrome male + case "XYY": // XYY syndrome male minHeight = 86; midHeight = height * 170 / 178; midAge = 15; break; - case 'X0': case 'X': // Turner syndrome female + case "X0": case "X": // Turner syndrome female minHeight = 85 * 0.93; midHeight = height * 157 / 164; midAge = 13; @@ -220,26 +224,26 @@ window.Height = (function() { } let result = 0; switch (genes) { - case 'XX': // female + case "XX": // female result = nationalityMeanHeight(xxMeanHeight, nationality, race); break; - case 'XY': // male + case "XY": // male result = nationalityMeanHeight(xyMeanHeight, nationality, race); break; // special cases. Extra SHOX genes on X and Y chromosomes make for larger people - case 'X0': case 'X': // Turner syndrome female + case "X0": case "X": // Turner syndrome female result = nationalityMeanHeight(xxMeanHeight, nationality, race) * 0.93; break; - case 'XXX': // Triple X syndrome female + case "XXX": // Triple X syndrome female result = nationalityMeanHeight(xxMeanHeight, nationality, race) * 1.03; break; - case 'XXY': // Klinefelter syndrome male + case "XXY": // Klinefelter syndrome male result = nationalityMeanHeight(xyMeanHeight, nationality, race) * 1.03; break; - case 'XYY': // XYY syndrome male + case "XYY": // XYY syndrome male result = nationalityMeanHeight(xyMeanHeight, nationality, race) * 1.04; break; - case 'Y': case 'Y0': case 'YY': case 'YYY': + case "Y": case "Y0": case "YY": case "YYY": console.log(`Height.mean(): non-viable genes ${ genes}`); break; default: @@ -313,7 +317,7 @@ window.Height = (function() { * This was modeled using the Height generator above. For some more information, see the comments for that. */ window.Intelligence = (function() { - 'use strict'; + "use strict"; // Global configuration (for different game modes/options/types) let mean = 0; @@ -329,9 +333,15 @@ window.Intelligence = (function() { if (_.isUndefined(conf)) { return {mean: mean, limitMult: [minMult, maxMult], limitIntelligence: [minIntelligence, maxIntelligence], skew: skew, spread: spread}; } - if (_.isFinite(conf.mean)) { mean = Math.clamp(conf.mean, -100, 100); } - if (_.isFinite(conf.skew)) { skew = Math.clamp(conf.skew, -1000, 1000); } - if (_.isFinite(conf.spread)) { spread = Math.clamp(conf.spread, 0.1, 100); } + if (_.isFinite(conf.mean)) { + mean = Math.clamp(conf.mean, -100, 100); + } + if (_.isFinite(conf.skew)) { + skew = Math.clamp(conf.skew, -1000, 1000); + } + if (_.isFinite(conf.spread)) { + spread = Math.clamp(conf.spread, 0.1, 100); + } if (_.isArray(conf.limitMult) && conf.limitMult.length === 2 && conf.limitMult[0] !== conf.limitMult[1] && _.isFinite(conf.limitMult[0]) && _.isFinite(conf.limitMult[1])) { minMult = Math.min(conf.limitMult[0], conf.limitMult[1]); @@ -403,10 +413,10 @@ window.gaussianPair = function() { if (!Array.prototype.findIndex) { Array.prototype.findIndex = function(predicate) { if (this == null) { - throw new TypeError('Array.prototype.find called on null or undefined'); + throw new TypeError("Array.prototype.find called on null or undefined"); } - if (typeof predicate !== 'function') { - throw new TypeError('predicate must be a function'); + if (typeof predicate !== "function") { + throw new TypeError("predicate must be a function"); } let list = Object(this); let length = list.length >>> 0; @@ -458,14 +468,21 @@ As a categorizer window.Categorizer = function() { this.cats = Array.prototype.slice.call(arguments) .filter(function(e, i, a) { - return e instanceof Array && e.length === 2 && typeof e[0] === 'number' && !isNaN(e[0]) && - a.findIndex(function(val) { return e[0] === val[0]; }) === i; /* uniqueness test */ }) - .sort(function(a, b) { return b[0] - a[0]; /* reverse sort */ }); + return e instanceof Array && e.length === 2 && typeof e[0] === "number" && !isNaN(e[0]) && + a.findIndex(function(val) { + return e[0] === val[0]; + }) === i; /* uniqueness test */ + }) + .sort(function(a, b) { + return b[0] - a[0]; /* reverse sort */ + }); }; window.Categorizer.prototype.cat = function(val, def) { let result = def; - if (typeof val === 'number' && !isNaN(val)) { - let foundCat = this.cats.find(function(e) { return val >= e[0]; }); + if (typeof val === "number" && !isNaN(val)) { + let foundCat = this.cats.find(function(e) { + return val >= e[0]; + }); if (foundCat) { result = foundCat[1]; } @@ -479,13 +496,19 @@ window.Categorizer.prototype.cat = function(val, def) { }; window.commaNum = function(s) { - if (!s) { return 0; } - if (State.variables.formatNumbers !== 1) { return s; } + if (!s) { + return 0; + } + if (State.variables.formatNumbers !== 1) { + return s; + } return s.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }; window.cashFormat = function(s) { - if (!s) { s = 0; } + if (!s) { + s = 0; + } return `¤${ commaNum(s)}`; }; @@ -504,27 +527,27 @@ window.repFormat = function(s) { /* In order to calculate just how much any one category matters so we can show a "fuzzy" symbolic value to the player, we need to know how "busy" reputation was this week. To calculate this, I ADD income to expenses. Why? 100 - 100 and 10000 - 10000 BOTH are 0, but a +50 event matters a lot more in the first case than the second. I exclude overflow from the calculation because it's not a "real" expense for our purposes, and divide by half just to make percentages a bit easier. */ let weight = s/(((V.lastWeeksRepIncome.Total - V.lastWeeksRepExpenses.Total) + V.lastWeeksRepExpenses.overflow)/2); if (weight > 0.60) { - return `@@.green;+++++ rep@@`; + return "@@.green;+++++ rep@@"; } else if (weight > 0.45) { - return `@@.green;++++ rep@@`; + return "@@.green;++++ rep@@"; } else if (weight > 0.30) { - return `@@.green;+++ rep@@`; + return "@@.green;+++ rep@@"; } else if (weight > 0.15) { - return `@@.green;++ rep@@`; + return "@@.green;++ rep@@"; } else if (weight > 0.0) { - return `@@.green;+ rep@@`; + return "@@.green;+ rep@@"; } else if (weight === 0) { - return `0 rep`; + return "0 rep"; } else if (weight < -0.60) { - return `@@.red;----- rep@@`; + return "@@.red;----- rep@@"; } else if (weight < -0.45) { - return `@@.red;---- rep@@`; + return "@@.red;---- rep@@"; } else if (weight < -0.30) { - return `@@.red;--- rep@@`; + return "@@.red;--- rep@@"; } else if (weight < -0.15) { - return `@@.red;-- rep@@`; + return "@@.red;-- rep@@"; } else if (weight < 0) { - return `@@.red;- rep@@`; + return "@@.red;- rep@@"; } /* return weight;*/ } @@ -582,7 +605,9 @@ window.budgetLine = function(category, title) { }; window.massFormat = function(s) { - if (!s) { s = 0; } + if (!s) { + s = 0; + } if (s >= 1000) { s = commaNum(Math.trunc(s / 1000)); if (s !== 1) { @@ -744,7 +769,7 @@ if(typeof Categorizer === 'function') { jQuery(document).one('categorizer.ready', doSomething); } */ -jQuery(document).trigger('categorizer.ready'); +jQuery(document).trigger("categorizer.ready"); window.hashChoice = function hashChoice(obj) { let randint = Math.floor(Math.random()*hashSum(obj)); @@ -763,13 +788,17 @@ window.hashChoice = function hashChoice(obj) { window.hashSum = function hashSum(obj) { let sum = 0; - Object.keys(obj).forEach((key) => { sum += obj[key]; }); + Object.keys(obj).forEach((key) => { + sum += obj[key]; + }); return sum; }; window.arr2obj = function arr2obj(arr) { const obj = {}; - arr.forEach((item) => { obj[item] = 1; }); + arr.forEach((item) => { + obj[item] = 1; + }); return obj; }; @@ -799,10 +828,10 @@ window.between = function between(a, low, high) { // generate a random, almost unique ID that is compliant (possibly) with RFC 4122 window.generateNewID = function generateNewID() { let date = Date.now(); // high-precision timer - let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { + let uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) { let r = (date + Math.random()*16)%16 | 0; date = Math.floor(date/16); - return (c==='x' ? r : (r & 0x3 | 0x8)).toString(16); + return (c==="x" ? r : (r & 0x3 | 0x8)).toString(16); }); return uuid; }; @@ -815,21 +844,22 @@ window.arraySwap = function arraySwap(array, a, b) { // circumvents sugarcube, allowing a plain HTML5 UI within it window.html5passage = function html5passage(passage_function) { - $(document).one(':passagedisplay', (ev) => { + $(document).one(":passagedisplay", (ev) => { const element = document.createElement("div"); element.classList.add("passage"); document.getElementById("passages").appendChild(element); passage_function(element); - $(document).off(':passagedisplay'); + $(document).off(":passagedisplay"); }); }; // If you want to include a SugarCube passage in a JS function use this. The result must be printed using the <<print>> macro. passageTitle must be a string. window.jsInclude = function(passageTitle) { - if (Story.has(passageTitle)) + if (Story.has(passageTitle)) { return Story.get(passageTitle).processText(); - else + } else { return `<span class="red">Error: Passage ${passageTitle} does not exist.</span>`; + } }; window.capFirstChar = function capFirstChar(string) { @@ -837,50 +867,55 @@ window.capFirstChar = function capFirstChar(string) { }; window.getSlaveDevotionClass = /** @param {App.Entity.SlaveState} slave */ function(slave) { - if ((!slave) || (!State)) + if ((!slave) || (!State)) { return undefined; - if ('mindbroken' === slave.fetish) - return 'mindbroken'; - if (slave.devotion < -95) - return 'very-hateful'; - else if (slave.devotion < -50) - return 'hateful'; - else if (slave.devotion < -20) - return 'resistant'; - else if (slave.devotion <= 20) - return 'ambivalent'; - else if (slave.devotion <= 50) - return 'accepting'; - else if (slave.devotion <= 95) - return 'devoted'; - else - return 'worshipful'; + } + if ("mindbroken" === slave.fetish) { + return "mindbroken"; + } + if (slave.devotion < -95) { + return "very-hateful"; + } else if (slave.devotion < -50) { + return "hateful"; + } else if (slave.devotion < -20) { + return "resistant"; + } else if (slave.devotion <= 20) { + return "ambivalent"; + } else if (slave.devotion <= 50) { + return "accepting"; + } else if (slave.devotion <= 95) { + return "devoted"; + } else { + return "worshipful"; + } }; window.getSlaveTrustClass = /** @param {App.Entity.SlaveState} slave */ function(slave) { - if ((!slave) || (!State)) + if ((!slave) || (!State)) { return undefined; + } - if ('mindbroken' === slave.fetish) - return ''; - - if (slave.trust < -95) - return 'extremely-terrified'; - else if (slave.trust < -50) - return 'terrified'; - else if (slave.trust < -20) - return 'frightened'; - else if (slave.trust <= 20) - return 'fearful'; - else if (slave.trust <= 50) { - if (slave.devotion < -20) return 'hate-careful'; - else return 'careful'; + if ("mindbroken" === slave.fetish) { + return ""; + } + + if (slave.trust < -95) { + return "extremely-terrified"; + } else if (slave.trust < -50) { + return "terrified"; + } else if (slave.trust < -20) { + return "frightened"; + } else if (slave.trust <= 20) { + return "fearful"; + } else if (slave.trust <= 50) { + if (slave.devotion < -20) return "hate-careful"; + else return "careful"; } else if (slave.trust <= 95) { - if (slave.devotion < -20) return 'bold'; - else return 'trusting'; + if (slave.devotion < -20) return "bold"; + else return "trusting"; } else { - if (slave.devotion < -20) return 'defiant'; - else return 'profoundly-trusting'; + if (slave.devotion < -20) return "defiant"; + else return "profoundly-trusting"; } }; @@ -891,8 +926,9 @@ window.cmToInchString = function(s) { // takes an integer e.g. $activeSlave.height, returns a string in the format 6'5" window.cmToFootInchString = function(s) { - if (Math.round(s/2.54) < 12) + if (Math.round(s/2.54) < 12) { return cmToInchString(s); + } return `${Math.trunc(Math.round(s/2.54)/12) }'${ Math.round(s/2.54)%12 }"`; }; @@ -913,44 +949,53 @@ window.ballsToInchString = function(s) { // takes a ball value e.g. $activeSlave.balls, returns an int of the ball size in cm window.ballsToCM = function(s) { - if (s < 2) + if (s < 2) { return 0; + } return (s<10?(s-1)*2:s*2); }; // takes a dick value e.g. $activeSlave.dick, returns a string in the format of either `20cm (8 inches)`, `8 inches`, or `20cm` window.dickToEitherUnit = function(s) { - if (State.variables.showInches === 1) + if (State.variables.showInches === 1) { return `${dickToCM(s) }cm (${ dickToInchString(s) })`; - if (State.variables.showInches === 2) + } + if (State.variables.showInches === 2) { return dickToInchString(s); + } return `${dickToCM(s) }cm`; }; // takes a ball value e.g. $activeSlave.balls, returns a string in the format of either `20cm (8 inches)`, `8 inches`, or `20cm` window.ballsToEitherUnit = function(s) { - if (State.variables.showInches === 1) + if (State.variables.showInches === 1) { return `${ballsToCM(s) }cm (${ ballsToInchString(s) })`; - if (State.variables.showInches === 2) + } + if (State.variables.showInches === 2) { return ballsToInchString(s); + } return `${ballsToCM(s) }cm`; }; // takes an int in centimeters e.g. $activeSlave.height, returns a string in the format of either `200cm (6'7")`, `6'7"`, or `200cm` window.heightToEitherUnit = function(s) { - if (State.variables.showInches === 1) + if (State.variables.showInches === 1) { return `${s }cm (${ cmToFootInchString(s) })`; - if (State.variables.showInches === 2) + } + if (State.variables.showInches === 2) { return cmToFootInchString(s); + } return `${s }cm`; }; // takes an int in centimeters e.g. $activeSlave.hLength, returns a string in the format of either `30cm (12 inches)`, `12 inches`, or `30cm` window.lengthToEitherUnit = function(s) { - if (State.variables.showInches === 1) + if (State.variables.showInches === 1) { return `${s }cm (${ cmToInchString(s) })`; - if (State.variables.showInches === 2) + } + if (State.variables.showInches === 2) { return cmToInchString(s); + } return `${s }cm`; }; @@ -1359,7 +1404,7 @@ window.removeDuplicates = function removeDuplicates(array) { window.induceLactation = /** @param {App.Entity.SlaveState} slave */ function induceLactation(slave) { let pronouns = getPronouns(slave); let His = capFirstChar(pronouns.possessive); - let r = ``; + let r = ""; if (slave.induceLactation >= 10) { if (jsRandom(1, 100) < slave.induceLactation) { r += `${His} breasts have been stimulated often enough to @@.lime;induce lactation.@@`; @@ -1469,18 +1514,31 @@ window.originPronounReplace = /** @param {App.Entity.SlaveState} slave */ functi window.HSM = function() { const V = State.variables; - if (V.PC.hacking <= -100) {return 1.5;} - else if (V.PC.hacking <= -75) {return 1.35;} - else if (V.PC.hacking <= -50) {return 1.25;} - else if (V.PC.hacking <= -25) {return 1.15;} - else if (V.PC.hacking < 0) {return 1.10;} - else if (V.PC.hacking === 0) {return 1;} - else if (V.PC.hacking <= 10) {return 0.97;} - else if (V.PC.hacking <= 25) {return 0.95;} - else if (V.PC.hacking <= 50) {return 0.90;} - else if (V.PC.hacking <= 75) {return 0.85;} - else if (V.PC.hacking <= 100) {return 0.80;} - else {return 0.75;} + if (V.PC.hacking <= -100) { + return 1.5; + } else if (V.PC.hacking <= -75) { + return 1.35; + } else if (V.PC.hacking <= -50) { + return 1.25; + } else if (V.PC.hacking <= -25) { + return 1.15; + } else if (V.PC.hacking < 0) { + return 1.10; + } else if (V.PC.hacking === 0) { + return 1; + } else if (V.PC.hacking <= 10) { + return 0.97; + } else if (V.PC.hacking <= 25) { + return 0.95; + } else if (V.PC.hacking <= 50) { + return 0.90; + } else if (V.PC.hacking <= 75) { + return 0.85; + } else if (V.PC.hacking <= 100) { + return 0.80; + } else { + return 0.75; + } }; window.opentab = function(evt, tabName) { @@ -1517,7 +1575,7 @@ window.opentab = function(evt, tabName) { * App.UI.passageLink("Go to town", "Town") */ App.UI.passageLink = function(linkText, passage, setter, elementType) { - if (!elementType) elementType = 'a'; + if (!elementType) elementType = "a"; let res = `<${elementType} data-passage="${passage}"`; if (setter) {