diff --git a/game/01-config/sugarcubeConfig.js b/game/01-config/sugarcubeConfig.js index d4125ea528bfce25dd97c5502462cefa853ee65d..3ef192b6fc1ea84c54a693c440fabcd597cc4725 100644 --- a/game/01-config/sugarcubeConfig.js +++ b/game/01-config/sugarcubeConfig.js @@ -17,10 +17,10 @@ Config.saves.onSave = function (save) { /*LinkNumberify and images will enable or disable the feature completely*/ /*debug will enable or disable the feature only for new games*/ window.StartConfig = { - "debug": false, - "enableImages": true, - "enableLinkNumberify": true, - "version": "0.2.12.3", + "debug": false, + "enableImages": true, + "enableLinkNumberify": true, + "version": "0.2.12.3", } config.saves.autosave = "autosave"; @@ -33,12 +33,12 @@ Config.saves.isAllowed = function () { }; importStyles("style.css") -.then(function () { - console.log("External Style Sheet Active") -}) -.catch(function (err) { - console.log("External Style Sheet Missing"); -}); + .then(function () { + console.log("External Style Sheet Active") + }) + .catch(function (err) { + console.log("External Style Sheet Missing"); + }); console.log("Game Version:", StartConfig.version); @@ -54,11 +54,11 @@ l10nStrings.errorTitle = StartConfig.version + " Error"; * than it's worth in this instance. Be advised that updating sugarcube * may break this */ -const VIRTUAL_CURRENT = "_"; -const vStack = [] -const vContext = [] -const d = JSON.stringify.bind(JSON); -let devOptions = { +var VIRTUAL_CURRENT = "_"; +var vStack = [] +var vContext = [] +var d = JSON.stringify.bind(JSON); +var devOptions = { trace: false, invocationId: false } @@ -71,7 +71,7 @@ setTimeout(() => State.variables.devOptions = devOptions) // Note that clog is currently non-configured and will always be invoked // TODO: add more granular debug log levels if needed function clog() { - console.log(`${State.passage}:${d(vContext)}`,...arguments) + console.log(`${State.passage}:${d(vContext)}`, ...arguments) } function trace() { if (devOptions.trace) { @@ -81,18 +81,18 @@ function trace() { function allMagical() { return Object.keys(State.variables).filter(key => key.startsWith(VIRTUAL_CURRENT) && key != VIRTUAL_CURRENT) } -let uniqueInvocation = 0; +var uniqueInvocation = 0; function widgetHandler(widgetName, contents) { - let argsCache; + var argsCache; trace('declaring fn', widgetName); return function () { - const context = devOptions.invocationId + var context = devOptions.invocationId ? `${State.passage}:${widgetName}:${uniqueInvocation++}` : `${State.passage}:${widgetName}`; trace('invoking', context); vContext.push(context); // Custom code - const newFrame = {}; + var newFrame = {}; State.variables[VIRTUAL_CURRENT] = newFrame; vStack.push(newFrame); /** @@ -101,8 +101,8 @@ function widgetHandler(widgetName, contents) { * note: that would mean the $_var was defined in the body, * as we clean our local magic variables */ - const priorFrame = vStack[vStack.length - 2] - const magicals = allMagical(); + var priorFrame = vStack[vStack.length - 2] + var magicals = allMagical(); if (magicals.length > 0) { trace(`saving ${d(magicals)} to ${d(priorFrame)}`) } @@ -128,8 +128,8 @@ function widgetHandler(widgetName, contents) { try { // Set up the error trapping variables. - const resFrag = document.createDocumentFragment(); - const errList = []; + var resFrag = document.createDocumentFragment(); + var errList = []; // Wikify the widget contents. new Wikifier(resFrag, contents); @@ -155,7 +155,7 @@ function widgetHandler(widgetName, contents) { vStack.pop(); vContext.pop(); State.variables[VIRTUAL_CURRENT] = priorFrame - const magicals = allMagical(); + var magicals = allMagical(); if (magicals.length > 0) { trace(`cleaning up ${d(magicals)}`) magicals.forEach(key => { @@ -180,14 +180,14 @@ function widgetHandler(widgetName, contents) { } Macro.delete('widget'); Macro.add('widget', { - tags : null, + tags: null, handler() { if (this.args.length === 0) { return this.error('no widget name specified'); } - const widgetName = this.args[0]; + var widgetName = this.args[0]; if (Macro.has(widgetName)) { if (!Macro.get(widgetName).isWidget) { @@ -200,8 +200,8 @@ Macro.add('widget', { try { Macro.add(widgetName, { - isWidget : true, - handler : widgetHandler(widgetName, this.payload[0].contents) + isWidget: true, + handler: widgetHandler(widgetName, this.payload[0].contents) }); // Custom debug view setup. diff --git a/game/03-JavaScript/UI.js b/game/03-JavaScript/UI.js index 94976a1ec8fce595156fe4bf3285e9471cf0e724..d95f498e091faadb3722c5a9302087acae92ef73 100644 --- a/game/03-JavaScript/UI.js +++ b/game/03-JavaScript/UI.js @@ -1,29 +1,29 @@ -window.overlayShowHide = function(elementId){ +window.overlayShowHide = function (elementId) { var div = document.getElementById(elementId); - if(div != undefined){ + if (div != undefined) { div.classList.toggle("hidden"); - if(elementId === "debugOverlay"){ + if (elementId === "debugOverlay") { SugarCube.State.variables.debugMenu[0] = !SugarCube.State.variables.debugMenu[0]; } } } -window.overlayMenu = function(elementId, type){ - switch(type){ +window.overlayMenu = function (elementId, type) { + switch (type) { case "debug": - var debug = ["debugMain", "debugCharacter", "debugEvents"] - for(var i = 0, l = debug.length; i < l; i++){ - var div = document.getElementById(debug[i]); - if(div != undefined){ - SugarCube.State.variables.debugMenu[1] = elementId; - if(elementId === debug[i]){ - div.classList.remove("hidden"); - }else{ - div.classList.add("hidden"); + var debug = ["debugMain", "debugCharacter", "debugEvents"] + for (var i = 0, l = debug.length; i < l; i++) { + var div = document.getElementById(debug[i]); + if (div != undefined) { + SugarCube.State.variables.debugMenu[1] = elementId; + if (elementId === debug[i]) { + div.classList.remove("hidden"); + } else { + div.classList.add("hidden"); + } } } - } - break; + break; } } @@ -36,7 +36,7 @@ var yDown = null; function getTouches(evt) { return evt.touches || // browser API - evt.originalEvent.touches; // jQuery + evt.originalEvent.touches; // jQuery } function handleTouchStart(evt) { @@ -46,7 +46,7 @@ function handleTouchStart(evt) { }; function handleTouchMove(evt) { - if ( ! xDown || ! yDown ) { + if (!xDown || !yDown) { return; } @@ -55,13 +55,12 @@ function handleTouchMove(evt) { * 50px - +/- width of unstowed UI Bar * 280px - +/- width of unstowed UI bar */ - if ( isUIBarStowed() ) { - if ( xDown > 50 ) { + if (isUIBarStowed()) { + if (xDown > 50) { return; } - } else - { - if ( xDown > 280 ) { + } else { + if (xDown > 280) { return; } } @@ -72,14 +71,14 @@ function handleTouchMove(evt) { var xDiff = xDown - xUp; var yDiff = yDown - yUp; - if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {/*most significant*/ - if ( xDiff > 0 ) { + if (Math.abs(xDiff) > Math.abs(yDiff)) {/*most significant*/ + if (xDiff > 0) { UIBar.stow();/* left swipe */ } else { UIBar.unstow();/* right swipe */ } } else { - if ( yDiff > 0 ) { + if (yDiff > 0) { /* up swipe */ } else { /* down swipe */ @@ -91,7 +90,7 @@ function handleTouchMove(evt) { }; function isUIBarStowed() { - return $( '#ui-bar' ).hasClass( 'stowed' ); + return $('#ui-bar').hasClass('stowed'); } var disableNumberifyInVisibleElements = [ @@ -123,18 +122,20 @@ function getPrettyKeyNumber(counter) { return str; } -$(document).on(':passagerender', function(ev) { +$(document).on(':passagerender', function (ev) { currentLinks = []; if (passage() == "GiveBirth") { - $(ev.content).find("[type=checkbox]").on('propertychange change', function() { new Wikifier(null, '<<resetPregButtons>>'); - generateNumbers(ev);} ); + $(ev.content).find("[type=checkbox]").on('propertychange change', function () { + new Wikifier(null, '<<resetPregButtons>>'); + generateNumbers(ev); + }); } generateNumbers(ev); }); -function generateNumbers(ev){ +function generateNumbers(ev) { if (!State.variables.numberify_enabled || !StartConfig.enableLinkNumberify) return; @@ -143,17 +144,17 @@ function generateNumbers(ev){ return; // simply skip this render } - // wanted to use .macro-link, but wardrobe and something else doesn't get selected, lmao + // wanted to use .macro-link, but wardrobe and something else doesn't get selected, lmao currentLinks = $(ev.content) .find(".link-internal") .not(".no-numberify *, .no-numberify"); - $(currentLinks).each(function(i, el) { + $(currentLinks).each(function (i, el) { $(el).html("(" + getPrettyKeyNumber(i + 1) + ") " + $(el).html()); }); } -$(document).on('keyup', function(ev) { +$(document).on('keyup', function (ev) { if (!State.variables.numberify_enabled || !StartConfig.enableLinkNumberify || State.variables.tempDisable) return; @@ -185,94 +186,94 @@ $(document).on('keyup', function(ev) { } }); -const defaultSkinColorRanges = { +var defaultSkinColorRanges = { "hStart": 45, "hEnd": 45, "sStart": 0.2, "sEnd": 0.4, "bStart": 4.5, "bEnd": 0.7, }; -window.skinColor = function(enabled, percent, overwrite) { +window.skinColor = function (enabled, percent, overwrite) { if (enabled === "f") { return ""; } - const ranges = ensureIsArray(overwrite || defaultSkinColorRanges); - const totalProgress = percent / 100; + var ranges = ensureIsArray(overwrite || defaultSkinColorRanges); + var totalProgress = percent / 100; - const scaledProgress = ranges.length * totalProgress; - const rangeIndex = totalProgress === 1 + var scaledProgress = ranges.length * totalProgress; + var rangeIndex = totalProgress === 1 ? ranges.length - 1 : Math.floor(scaledProgress); - const progress = totalProgress === 1 + var progress = totalProgress === 1 ? 1 : scaledProgress - rangeIndex; - const {hStart, hEnd, sStart, sEnd, bStart, bEnd} = ranges[rangeIndex]; + var { hStart, hEnd, sStart, sEnd, bStart, bEnd } = ranges[rangeIndex]; - const hue = (hEnd - hStart) * progress + hStart; - const saturation = (sEnd - sStart) * progress + sStart; - const brightness = (bEnd - bStart) * progress + bStart; + var hue = (hEnd - hStart) * progress + hStart; + var saturation = (sEnd - sStart) * progress + sStart; + var brightness = (bEnd - bStart) * progress + bStart; - const hueCss = `hue-rotate(${hue}deg)`; - const saturationCss = `saturate(${saturation.toFixed(2)})`; - const brightnessCss = `brightness(${brightness.toFixed(2)})`; + var hueCss = `hue-rotate(${hue}deg)`; + var saturationCss = `saturate(${saturation.toFixed(2)})`; + var brightnessCss = `brightness(${brightness.toFixed(2)})`; return `${hueCss} ${saturationCss} ${brightnessCss}`; } -window.closeFeats = function(id){ +window.closeFeats = function (id) { var div1 = document.getElementById("feat-" + id); var div2 = document.getElementById("closeFeat-" + id); div1.style.display = "none"; div2.style.display = "none"; } -window.filterFeats = function(){ +window.filterFeats = function () { new Wikifier(null, '<<replace #featsList>><<featsList>><</replace>>'); } -window.getTimeNumber = function(t){ +window.getTimeNumber = function (t) { var time = new Date(t); var result = time.getTime(); - if(isNaN(result)){ + if (isNaN(result)) { return 9999999999999999; } return result; } -window.extendStats = function(){ +window.extendStats = function () { SugarCube.State.variables.extendedStats = !SugarCube.State.variables.extendedStats; var captionDiv = document.getElementById('storyCaptionDiv'), statsDiv = document.getElementById('stats'); - if(SugarCube.State.variables.extendedStats === true){ + if (SugarCube.State.variables.extendedStats === true) { captionDiv.classList.add("storyCaptionDivExtended"); statsDiv.classList.add("statsExtended"); - }else{ + } else { captionDiv.classList.remove("storyCaptionDivExtended"); statsDiv.classList.remove("statsExtended"); } new Wikifier(null, '<<replace #stats>><<statsCaption>><</replace>>'); } -window.customColor = function(color, saturation, brightness, contrast, sepia){ - return 'filter: hue-rotate('+color+'deg) saturate('+saturation+') brightness('+brightness+') contrast('+contrast+') sepia('+sepia+')'; +window.customColor = function (color, saturation, brightness, contrast, sepia) { + return 'filter: hue-rotate(' + color + 'deg) saturate(' + saturation + ') brightness(' + brightness + ') contrast(' + contrast + ') sepia(' + sepia + ')'; } -window.zoom = function(size, set){ - if(size === undefined){ +window.zoom = function (size, set) { + if (size === undefined) { size = document.getElementById("numberslider-input-zoom").value; } var parsedSize = parseInt(size); var body = document.getElementsByTagName("body")[0]; - if(parsedSize >= 50 && parsedSize <= 200 && parsedSize !== 100){ + if (parsedSize >= 50 && parsedSize <= 200 && parsedSize !== 100) { body.style.zoom = size + "%"; - if(set === true){ + if (set === true) { SugarCube.State.variables.zoom = size; } - }else{ + } else { body.style.zoom = ""; - if(set === true){ + if (set === true) { SugarCube.State.variables.zoom = 100; } } -} \ No newline at end of file +}