diff --git a/src/js/PenthouseNaming.js b/src/js/PenthouseNaming.js index 398e0f58178544e9f062686672c76e67fe155647..9d84a0be2e16073a2fd0d33129007049d9396bf9 100644 --- a/src/js/PenthouseNaming.js +++ b/src/js/PenthouseNaming.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ /** * @return {string} */ diff --git a/src/js/SetBellySize.js b/src/js/SetBellySize.js index 546c270af5145523a820bb47ad2d5e9b5a244d51..963e39484853c09f46297a41a58772c36f1af06c 100644 --- a/src/js/SetBellySize.js +++ b/src/js/SetBellySize.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ /** @param {App.Entity.SlaveState} slave */ window.SetBellySize = function SetBellySize(slave) { diff --git a/src/js/bugReport.js b/src/js/bugReport.js index b0ace2e4ef770bcdae25c20171e29f4fdcefeee8..5302db55a333a121ab278a62a7f67d349120fb70 100644 --- a/src/js/bugReport.js +++ b/src/js/bugReport.js @@ -1,2 +1,3 @@ +/* eslint-disable */ /*! <<bugreport>> macro for SugarCube 2.x */ !function(){"use strict";if("undefined"==typeof version||"undefined"==typeof version.title||"SugarCube"!==version.title||"undefined"==typeof version.major||version.major<2)throw new Error("<<bugreport>> macro requires SugarCube 2.0 or greater, aborting load");Macro.add("bugreport",{handler:function(){function serializeVariables(varObj,diffObj,doSort){function renderDiff(diff,orig){for(var keys=Object.keys(diff||{}),render=orig?clone(orig):{},i=0,klen=keys.length;klen>i;i++){var p=keys[i],diffP=diff[p];if(diffP===Diff.Op.Delete)delete render[p];else if(Array.isArray(diffP))switch(diffP[0]){case Diff.Op.SpliceArray:try{render.splice(diffP[1],1+(diffP[2]-diffP[1]))}catch(e){}break;case Diff.Op.Copy:render[p]=clone(diffP[1]);break;case Diff.Op.CopyDate:render[p]=new Date(diffP[1])}else{var recurse=renderDiff(diffP,render[p]);0!==Object.keys(recurse).length&&(render[p]=recurse)}}return render}var varList=[],diff=renderDiff(Diff.diff(varObj,diffObj));for(var p in diff){var sName="$"+(-1===p.search(/[^\w]/)?p:'"'+p+'"');varList.push(sName+"="+JSON.stringify(diff[p]))}return doSort&&("function"==typeof doSort?varList.sort(doSort):varList.sort()),0!==varList.length?varList.join(", "):""}var srcMatch,passages,varsPre,varsPost,dialog,dataEl,info=null!=this.args[0]&&Story.has(this.args[0])?Story.get(this.args[0]):null,last=State.length-1,source=unescape(window.location);null!==(srcMatch=/\/([^\/]+)$/.exec(source))&&(source=srcMatch[1]),passages=[];for(var i=0;last>=i;i++)passages.push('"'+State.index(i).title+'"');passages=passages.join(", "),varsPre=serializeVariables(State.index(0).variables,State.index(last).variables),varsPost=serializeVariables(State.index(last).variables,State.variables),dialog=UI.setup("Bug Report","bugreport"),dialog.innerHTML=(null!==info?'<div id="bugreport-info"></div>':"")+'<div><b>Bug report:</b> <a id="bugreport-data-select" class="link-internal macro-bugreport">[Select]</a></div><code id="bugreport-data" tabindex="0"></code>'+(/applewebkit|chrome/.test(Browser.userAgent)?"":'<div class="scroll-pad"> </div>'),dataEl=dialog.querySelector("#bugreport-data"),null!==info&&new Wikifier(dialog.querySelector("#bugreport-info"),info.processText()),addAccessibleClickHandler("#bugreport-data-select",function(self){return function(){jQuery(dataEl).focus(),self.selectData(dataEl)}}(this.self)),insertText(dataEl,"[spoiler][code]"),insertElement(dataEl,"br"),insertText(dataEl,"SOURCE: "+source),insertElement(dataEl,"br"),insertElement(dataEl,"br"),insertText(dataEl,"PASSAGES:"),insertElement(dataEl,"br"),insertText(dataEl,passages),insertElement(dataEl,"br"),insertElement(dataEl,"br"),insertText(dataEl,"VARIABLES (PRE-EXECUTION):"),insertElement(dataEl,"br"),varsPre&&(insertText(dataEl,varsPre),insertElement(dataEl,"br")),insertElement(dataEl,"br"),insertText(dataEl,"VARIABLES (POST-EXECUTION):"),insertElement(dataEl,"br"),varsPost&&(insertText(dataEl,varsPost),insertElement(dataEl,"br")),insertText(dataEl,"[/code][/spoiler]"),UI.open()},selectData:function(e){var s,r;if(window.getSelection){s=window.getSelection();if(s.setBaseAndExtent){var l=(e.innerText.length>1)?e.innerText.length-1:1;try{s.setBaseAndExtent(e,0,e,l)}catch(error){r=document.createRange();r.selectNodeContents(e);s.removeAllRanges();s.addRange(r)}}else{if(window.opera&&e.innerHTML.substring(e.innerHTML.length-4)==='<br>'){e.innerHTML=e.innerHTML+' '}var r=document.createRange();r.selectNodeContents(e);s.removeAllRanges();s.addRange(r)}}else if(document.getSelection){s=document.getSelection();r=document.createRange();r.selectNodeContents(e);s.removeAllRanges();s.addRange(r)}else if(document.selection){r=document.body.createTextRange();r.moveToElementText(e);r.select()}}})}(); diff --git a/src/js/colorModeJS.js b/src/js/colorModeJS.js index a18e3231016867970de95ffc71daf44284514ddb..35f346ec526a30c918d6933a7e71d959bfc9d14c 100644 --- a/src/js/colorModeJS.js +++ b/src/js/colorModeJS.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ window.flipColors = function (lightColorMap) { if (!window.savedColorMap) { window.savedColorMap = setColors(lightColorMap); diff --git a/src/js/dTree.min.js b/src/js/dTree.min.js index b29089b88995fe7df6cab432f07f2e71d7f2e090..a3c51d890ea5194fcd558084455fe68d9db93170 100644 --- a/src/js/dTree.min.js +++ b/src/js/dTree.min.js @@ -1,3 +1,4 @@ +/* eslint-disable */ /* This is the minified version of lodash, d3 and dTree */ ; (function (window, define, exports) { diff --git a/src/js/displayVariables.js b/src/js/displayVariables.js index c153952509e31eab3818533944d8eaf82e651061..f78139b5ccf2d9b728c2061a2111ea19b94ac516 100644 --- a/src/js/displayVariables.js +++ b/src/js/displayVariables.js @@ -1,2 +1,3 @@ +/* eslint-disable */ /*! <<checkvars>> macro for SugarCube 2.x */ !function(){"use strict";if("undefined"==typeof version||"undefined"==typeof version.title||"SugarCube"!==version.title||"undefined"==typeof version.major||version.major<2)throw new Error("<<checkvars>> macro requires SugarCube 2.0 or greater, aborting load");Macro.add("checkvars",{handler:function(){function toString(value,indent){var baseType=typeof value;switch(baseType){case"number":return isNaN(value)?"NaN":isFinite(value)?String(value):"Infinity";case"string":return JSON.stringify(value);case"function":return"(function)";default:if("object"!==baseType||null==value)return String(value);var objType=Object.prototype.toString.call(value);if("[object Date]"===objType)return'(object: Date, value: "'+value.toISOString()+'")';if("[object RegExp]"===objType)return"(object: RegExp, value: "+value.toString()+")";var opener,closer,result=[],indentText=" ";return indent||(indent=""),("[object Set]"===objType||value instanceof Set)&&(value=Array.from(value)),Array.isArray(value)?(opener="[\n",closer="\n"+indent+"]",value.forEach(function(p,i){result.push(indent+indentText+i+" ⇒ "+toString(value[i],indent+indentText))}),Object.keys(value).forEach(function(p){/^\d+$/.test(p)||result.push(indent+indentText+toString(p)+" ⇒ "+toString(value[p],indent+indentText))})):"[object Map]"===objType||value instanceof Map?(opener="{\n",closer="\n"+indent+"}",Array.from(value).map(function(kv){result.push(indent+indentText+toString(kv[0],indent+indentText)+" ⇒ "+toString(kv[1],indent+indentText))})):(opener="{\n",closer="\n"+indent+"}",Object.keys(value).forEach(function(p){result.push(indent+indentText+toString(p)+" ⇒ "+toString(value[p],indent+indentText))})),opener+result.join(",\n")+closer}}var dialog,sv=State.variables,names=Object.keys(sv);if(dialog=UI.setup("Story $variables","checkvars"),0===names.length)return dialog.innerHTML="<h1>Story $variables (<code>State.variables</code>):</h1><p><em>No $variables currently set…</em></p>",void UI.open();dialog.innerHTML="<h1>Story $variables (<code>State.variables</code>):</h1><table><thead><tr><th>Name</th><th>Value</th></tr></thead><tbody></tbody></table>"+(/applewebkit|chrome/.test(Browser.userAgent)?"":'<div class="scroll-pad"> </div>');var tbody=dialog.querySelector("tbody");names.sort(function(a,b){return Util.isNumeric(a)&&Util.isNumeric(b)?Number(a)-Number(b):a.localeCompare(b)});for(var i=0;i<names.length;i++){var tr=document.createElement("tr"),tdName=document.createElement("td"),tdValue=document.createElement("td");tdName.textContent="$"+names[i],tdValue.textContent = toString(sv[names[i]]),tr.appendChild(tdName),tr.appendChild(tdValue),tbody.appendChild(tr)}UI.open()}})}(); diff --git a/src/js/food.js b/src/js/food.js index 098ff5eb52525ed9bae7fcf40ab69ae244a89d92..e1382fb4cc571af5d83d3396660073837d029e82 100644 --- a/src/js/food.js +++ b/src/js/food.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ /** @param {App.Entity.SlaveState} slave */ window.foodAmount = function (slave) { const V = State.variables; diff --git a/src/js/foreachMacroJS.js b/src/js/foreachMacroJS.js index be77e940d959104e722baf5fcc8401f2d96642fe..ea5e0afcd3ffed39d03bb4a9ef4e833376ad54fb 100644 --- a/src/js/foreachMacroJS.js +++ b/src/js/foreachMacroJS.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ Macro.add('foreach', { skipArgs : true, tags : null, diff --git a/src/js/futureSocietyJS.js b/src/js/futureSocietyJS.js index 2453c30d7f1e181150ead99c9458aba9fb97ad24..6978059a94ef3010a2c41179f75d09b8c285ac8c 100644 --- a/src/js/futureSocietyJS.js +++ b/src/js/futureSocietyJS.js @@ -1,3 +1,5 @@ +/* eslint-disable no-console */ +/* eslint-disable no-undef */ window.FutureSocieties = (function() { return { remove: removeFS, diff --git a/src/js/hTagMacroJS.js b/src/js/hTagMacroJS.js index 1f4eaa36511f8c7fc1c955a01d44179843905177..64681ad4b2d674888901a44ca00d456f210377db 100644 --- a/src/js/hTagMacroJS.js +++ b/src/js/hTagMacroJS.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ /* * <<htag>> macro * A simple macro which allows to create wrapping html elements with dynamic IDs. diff --git a/src/js/heroCreator.js b/src/js/heroCreator.js index faa919b75ca7ed098f3cf6ed21d43c1d73f821ad..5fe425a72ad4120d07bd8f3c609d3c8d05201118 100644 --- a/src/js/heroCreator.js +++ b/src/js/heroCreator.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ /** * @param {App.Entity.SlaveState} heroSlave * @param {App.Entity.SlaveState} baseHeroSlave diff --git a/src/js/removeActiveSlave.js b/src/js/removeActiveSlave.js index 9c62e34d070e2848366709ca1caf85cd7714f34d..2844d619479bbf732b57ac33d2264750cf0fea5a 100644 --- a/src/js/removeActiveSlave.js +++ b/src/js/removeActiveSlave.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ window.removeActiveSlave = function removeActiveSlave() { "use strict"; const V = State.variables; diff --git a/src/js/rulesAssistant.js b/src/js/rulesAssistant.js index 6d2db438933c0bcf567979507844c53591478516..8fd3ac027b6755fe3fa2ffb78c8ccc3fe96c9c9a 100644 --- a/src/js/rulesAssistant.js +++ b/src/js/rulesAssistant.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ /** @param {App.Entity.SlaveState} slave */ window.hasSurgeryRule = function (slave, rules) { return rules.some( diff --git a/src/js/rulesAutosurgery.js b/src/js/rulesAutosurgery.js index 86b325ac1a990bbb3651627af38581d50022f837..0fbe86aef48da9cb918db7d58d9be8c5a53d151b 100644 --- a/src/js/rulesAutosurgery.js +++ b/src/js/rulesAutosurgery.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ window.rulesAutosurgery = (function() { "use strict"; let V; diff --git a/src/js/slaveGenerationJS.js b/src/js/slaveGenerationJS.js index df933301d9d3e5f381660f4e43cc1b3e96aff008..f7fa84384cb8ba62a9ed189512cb90181ea7f6ae 100644 --- a/src/js/slaveGenerationJS.js +++ b/src/js/slaveGenerationJS.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ window.nationalityToRace = /** @param {App.Entity.SlaveState} slave */ function nationalityToRace(slave) { slave.race = hashChoice(setup.raceSelector[slave.nationality] || setup.raceSelector[""]); }; diff --git a/src/js/spanMacroJS.js b/src/js/spanMacroJS.js index dead2c13ec466c0cdd881e9c6e75af14ecd84691..005e6d1c7b6f0380b886b610df78d519f66902d8 100644 --- a/src/js/spanMacroJS.js +++ b/src/js/spanMacroJS.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ /* * <<span>> macro * A minimal macro which allows to create <span> elements with dynamic IDs. diff --git a/src/js/summaryWidgets.js b/src/js/summaryWidgets.js index 215c5b2488b8254ace13e0eec080bf988903f853..5c5ccf5b4d1584d88d9ba9246bb0be650f42d25e 100644 --- a/src/js/summaryWidgets.js +++ b/src/js/summaryWidgets.js @@ -1,3 +1,5 @@ +/* eslint-disable no-undef */ +/* eslint-disable no-unused-vars */ /** * @param {App.Entity.SlaveState} slave */ diff --git a/src/js/textInput.js b/src/js/textInput.js index 86d6eebae8327921825d050c38d03b02e984af42..2e4cbbe37898b4f4968f00742529ce14abb33929 100644 --- a/src/js/textInput.js +++ b/src/js/textInput.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ Macro.add("textinput", { // Signifies that the macro is a container macro. tags: null, diff --git a/src/js/textboxJS.js b/src/js/textboxJS.js index 5dd0388fe6f3338e9e3df74875c5ee4610b5bf91..e4917d08c542242f60ab649b681be3889da9901b 100644 --- a/src/js/textboxJS.js +++ b/src/js/textboxJS.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ /* Nicked off greyelf, works for replace textboxes */ window.setReplaceTextboxMaxLength = function (storyVarName, maxLength) { var textboxId = '#textbox-' + Util.slugify(storyVarName); diff --git a/src/js/utilJS.js b/src/js/utilJS.js index 6b50a76a7d45ee2caaea68976d0e3c7cdd164aef..ede3a1c286726e90577b74264be21f31574a3cd5 100644 --- a/src/js/utilJS.js +++ b/src/js/utilJS.js @@ -503,91 +503,91 @@ window.Categorizer.prototype.cat = function(val, def) { window.num = function(x) { const V = State.variables; let max = V.showNumbersMax; - - function commaNum(s) { - if (!s) { - return 0; - } - if (State.variables.formatNumbers !== 1) { - return s; - } else { - return s.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); - } + + var ONE_TO_NINETEEN = [ + 'one', 'two', 'three', 'four', 'five', + 'six', 'seven', 'eight', 'nine', 'ten', + 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', + 'sixteen', 'seventeen', 'eighteen', 'nineteen', + ]; + + var TENS = [ + 'ten', 'twenty', 'thirty', 'forty', 'fifty', + 'sixty', 'seventy', 'eighty', 'ninety', + ]; + + var SCALES = ['thousand', 'million', 'billion', 'trillion']; + + // helper function for use with Array.filter + function isTruthy(item) { + return !!item; } - if (V.showNumbers !== 2) { - if (x === 0) { - return 'zero'; - } - - let ONE_TO_NINETEEN = [ - 'one', 'two', 'three', 'four', 'five', - 'six', 'seven', 'eight', 'nine', 'ten', - 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', - 'sixteen', 'seventeen', 'eighteen', 'nineteen', - ]; + // convert a number into "chunks" of 0-999 + function chunk(number) { + let thousands = []; - let TENS = [ - 'ten', 'twenty', 'thirty', 'forty', 'fifty', - 'sixty', 'seventy', 'eighty', 'ninety', - ]; - - let SCALES = ['thousand', 'million', 'billion', 'trillion']; - - // helper function for use with Array.filter - function isTruthy(item) { - return !!item; + while (number > 0) { + thousands.push(number % 1000); + number = Math.floor(number / 1000); } - // convert a number into "chunks" of 0-999 - function chunk(number) { - let thousands = []; + return thousands; + } - while (number > 0) { - thousands.push(number % 1000); - number = Math.floor(number / 1000); - } + // translate a number from 1-999 into English + function inEnglish(number) { + let hundreds; + let tens; + let ones; + let words = []; - return thousands; + if (number < 20) { + return ONE_TO_NINETEEN[number - 1]; // may be undefined } - // translate a number from 1-999 into English - function inEnglish(number) { - let hundreds; - let tens; - let ones; - let words = []; + if (number < 100) { + ones = number % 10; + tens = number / 10 | 0; // equivalent to Math.floor(number / 10) - if (number < 20) { - return ONE_TO_NINETEEN[number - 1]; // may be undefined - } + words.push(TENS[tens - 1]); + words.push(inEnglish(ones)); - if (number < 100) { - ones = number % 10; - tens = number / 10 | 0; // equivalent to Math.floor(number / 10) + return words.filter(isTruthy).join('-'); + } - words.push(TENS[tens - 1]); - words.push(inEnglish(ones)); + hundreds = number / 100 | 0; + words.push(inEnglish(hundreds)); + words.push('hundred'); + words.push(inEnglish(number % 100)); - return words.filter(isTruthy).join('-'); - } + return words.filter(isTruthy).join(' '); + } - hundreds = number / 100 | 0; - words.push(inEnglish(hundreds)); - words.push('hundred'); - words.push(inEnglish(number % 100)); + // append the word for a scale. Made for use with Array.map + function appendScale(chunk, exp) { + let scale; + if (!chunk) { + return null; + } + scale = SCALES[exp - 1]; + return [chunk, scale].filter(isTruthy).join(' '); + } - return words.filter(isTruthy).join(' '); + function commaNum(s) { + if (!s) { + return 0; } + if (State.variables.formatNumbers !== 1) { + return s; + } else { + return s.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); + } + } - // append the word for a scale. Made for use with Array.map - function appendScale(chunk, exp) { - let scale; - if (!chunk) { - return null; - } - scale = SCALES[exp - 1]; - return [chunk, scale].filter(isTruthy).join(' '); + if (V.showNumbers !== 2) { + if (x === 0) { + return 'zero'; } let string = chunk(x) @@ -709,7 +709,7 @@ window.budgetLine = function(category, title) { <td>${title}</td>\ <td>\ <<if (${income}.${category}) > 0>>\ - @@.yellowgreen;<<print cashFormat(${income}.${category})>>@@\ /*please don't put a plus sign in front of income, it's not done on a budget sheet. Safe to assume money is money unless it's in parenthesis or with a - sign.*/ + @@.yellowgreen;<<print cashFormat(${income}.${category})>>@@ /*please don't put a plus sign in front of income, it's not done on a budget sheet. Safe to assume money is money unless it's in parenthesis or with a - sign.*/ <<else>>\ <<print cashFormat(${income}.${category})>>\ <</if>>\ diff --git a/src/js/vignettes.js b/src/js/vignettes.js index 53ae2ddb2111ed62dcafc5ea1e4a66e07e178a17..b47ce02d1263405100c776bfb233763ed79d0ad7 100644 --- a/src/js/vignettes.js +++ b/src/js/vignettes.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ window.GetVignette = /** @param {App.Entity.SlaveState} slave */ function GetVignette(slave) { const V = State.variables; let vignettes = [];