From 579f9e5b9c9172d3679b252f1ca34aefdee52563 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Tue, 17 Dec 2019 22:46:20 -0500 Subject: [PATCH] Reformat the js files --- constants.js | 84 ++++++++++++++++++------------------- gorge.js | 114 +++++++++++++++++++++++++-------------------------- numbers.js | 4 +- polyfill.js | 8 ++-- 4 files changed, 105 insertions(+), 105 deletions(-) diff --git a/constants.js b/constants.js index 2127a96..2373510 100644 --- a/constants.js +++ b/constants.js @@ -11,7 +11,7 @@ const buildings = { "plural": "Micros", "desc": "A tasty, squirmy treat.", "cost": 1e1, - "prod": 1e-1/1, + "prod": 1e-1 / 1, "icon": "fa-universal-access" }, "anthro": { @@ -19,7 +19,7 @@ const buildings = { "plural": "Anthros", "desc": "Something more substantial to sate your hunger.", "cost": 1e2, - "prod": 1e0/1.1, + "prod": 1e0 / 1.1, "icon": "fa-male" }, "car": { @@ -27,7 +27,7 @@ const buildings = { "plural": "Cars", "desc": "Crunchy shell, tasty center.", "cost": 1.2e3, - "prod": 1e1/1.2, + "prod": 1e1 / 1.2, "icon": "fa-car" }, "bus": { @@ -35,7 +35,7 @@ const buildings = { "plural": "Buses", "desc": "Probably the worst place to be when a macro is aroud.", "cost": 1.4e4, - "prod": 1e2/1.3, + "prod": 1e2 / 1.3, "icon": "fa-bus" }, "house": { @@ -43,7 +43,7 @@ const buildings = { "plural": "Houses", "desc": "Home sweet home - but it doesn't taste sweet?", "cost": 1.6e5, - "prod": 1e3/1.4, + "prod": 1e3 / 1.4, "icon": "fa-home" }, "apartment": { @@ -51,7 +51,7 @@ const buildings = { "plural": "Apartments", "desc": "More snacks, less packaging.", "cost": 1.8e6, - "prod": 1e4/1.5, + "prod": 1e4 / 1.5, "icon": "fa-building" }, "block": { @@ -59,7 +59,7 @@ const buildings = { "plural": "Blocks", "desc": "A whole pile of buildings.", "cost": 2e7, - "prod": 1e5/1.6, + "prod": 1e5 / 1.6, "icon": "fa-warehouse" }, "town": { @@ -67,7 +67,7 @@ const buildings = { "plural": "Towns", "desc": "'Tourist trap' has never been this literal.", "cost": 2.2e8, - "prod": 1e6/1.7, + "prod": 1e6 / 1.7, "icon": "fa-store" }, "city": { @@ -75,7 +75,7 @@ const buildings = { "plural": "Cities", "desc": "Please no sitty on our city.", "cost": 2.4e9, - "prod": 1e7/1.8, + "prod": 1e7 / 1.8, "icon": "fa-city" }, "metro": { @@ -83,7 +83,7 @@ const buildings = { "plural": "Metropolises", "desc": "A big ol' city. Tasty, too.", "cost": 2.6e10, - "prod": 1e8/1.9, + "prod": 1e8 / 1.9, "icon": "fa-landmark" }, "county": { @@ -91,7 +91,7 @@ const buildings = { "plural": "Counties", "desc": "Why salt the land when you can slurp it?", "cost": 2.8e11, - "prod": 1e9/2, + "prod": 1e9 / 2, "icon": "fa-map" }, "state": { @@ -99,7 +99,7 @@ const buildings = { "plural": "States", "desc": "The United States is made up of...43 states - no, 42...", "cost": 3e12, - "prod": 1e10/2.1, + "prod": 1e10 / 2.1, "icon": "fa-map-signs" }, "country": { @@ -107,7 +107,7 @@ const buildings = { "plural": "Countries", "desc": "One nation, under paw.", "cost": 3.2e13, - "prod": 1e11/2.2, + "prod": 1e11 / 2.2, "icon": "fa-flag" }, "continent": { @@ -115,7 +115,7 @@ const buildings = { "plural": "Continents", "desc": "Earth-shattering appetite!", "cost": 3.4e14, - "prod": 1e12/2.3, + "prod": 1e12 / 2.3, "icon": "fa-mountain" }, "planet": { @@ -123,7 +123,7 @@ const buildings = { "plural": "Planets", "desc": "Earth appetite!", "cost": 3.6e15, - "prod": 1e13/2.4, + "prod": 1e13 / 2.4, "icon": "fa-globe-europe" }, "solar-system": { @@ -131,7 +131,7 @@ const buildings = { "plural": "Solar Systems", "desc": "Earths appetite!", "cost": 3.8e16, - "prod": 1e14/2.5, + "prod": 1e14 / 2.5, "icon": "fa-meteor" }, "galaxy": { @@ -139,7 +139,7 @@ const buildings = { "plural": "Galaxies", "desc": "In a galaxy far, far down your gullet...", "cost": 4.0e17, - "prod": 1e15/2.6, + "prod": 1e15 / 2.6, "icon": "fa-sun" }, "universe": { @@ -147,7 +147,7 @@ const buildings = { "plural": "Universes", "desc": "Into the you-verse.", "cost": 4.2e18, - "prod": 1e16/2.7, + "prod": 1e16 / 2.7, "icon": "fa-asterisk" }, "multiverse": { @@ -155,54 +155,54 @@ const buildings = { "plural": "Multiverses", "desc": "This is getting very silly.", "cost": 4.4e19, - "prod": 1e17/2.8, + "prod": 1e17 / 2.8, "icon": "fa-infinity" } } const effect_types = { "prod": { - "apply": function(effect, productivity) { + "apply": function (effect, productivity) { return productivity * effect.amount; }, - "desc": function(effect) { + "desc": function (effect) { return round(effect.amount, 2) + "x food production from " + buildings[effect.target].plural; } }, "prod-all": { - "apply": function(effect, productivity) { + "apply": function (effect, productivity) { return productivity * effect.amount; }, - "desc": function(effect) { + "desc": function (effect) { return round((effect.amount - 1) * 100) + "% increase to food production"; } }, "helper": { - "apply": function(effect, productivity, helperCount) { + "apply": function (effect, productivity, helperCount) { return productivity * (1 + effect.amount * helperCount); }, - "desc": function(effect) { + "desc": function (effect) { return "+" + round(effect.amount * 100) + "% food/sec from " + buildings[effect.helped].name + " for every " + buildings[effect.helper].name + " owned."; } }, "click": { - "apply": function(effect, bonus, productivity) { + "apply": function (effect, bonus, productivity) { return bonus + productivity * effect.amount; }, - "desc": function(effect) { + "desc": function (effect) { return round(effect.amount * 100) + "% of food/sec gained per click"; } }, "click-victim": { - "desc": function(effect) { + "desc": function (effect) { return "Devour larger prey"; } }, "powerup-freq": { - "apply": function(effect, delay) { + "apply": function (effect, delay) { return delay * effect.amount; }, - "desc": function(effect) { + "desc": function (effect) { return "Speed up powerup spawns by " + Math.round((1 / effect.amount - 1) * 100) + "%"; } } @@ -233,7 +233,7 @@ function createProdUpgrades() { "desc": contents.desc, "icon": buildings[key].icon, "cost": { - "food": buildings[key].cost * 5 * Math.pow(10,counter - 1) + "food": buildings[key].cost * 5 * Math.pow(10, counter - 1) }, "effects": [ { @@ -250,7 +250,7 @@ function createProdUpgrades() { if (counter > 1) { upgrades[prefix + counter]["prereqs"]["upgrades"] = [ - prefix + (counter - 1) + prefix + (counter - 1) ]; } @@ -270,7 +270,7 @@ function createProdAllUpgrades() { "desc": contents.desc, "icon": "fa-cogs", "cost": { - "food": 5 * Math.pow(10, counter+1) + "food": 5 * Math.pow(10, counter + 1) }, "effects": [ { @@ -298,7 +298,7 @@ function createProdAllUpgrades() { function createClickUpgrades() { let prefix = "prod-click-"; - let counter = 1 ; + let counter = 1; for (let contents of clickUpgradeText) { upgrades[prefix + counter] = { @@ -306,7 +306,7 @@ function createClickUpgrades() { desc: contents.desc, icon: "fa-hand-pointer", cost: { - food: Math.pow(10, (counter*2)+1) + food: Math.pow(10, (counter * 2) + 1) }, effects: [ { @@ -361,7 +361,7 @@ function createHelperUpgrades() { ], "prereqs": { "buildings": { - + }, "upgrades": [ helper + "-prod-1" @@ -371,12 +371,12 @@ function createHelperUpgrades() { upgrades[key]["prereqs"]["buildings"][helper] = 10 * counter; if (counter > 1) { - upgrades[key]["prereqs"]["upgrades"].push(prefix + infix + suffix + "-" + (counter - 1) ) + upgrades[key]["prereqs"]["upgrades"].push(prefix + infix + suffix + "-" + (counter - 1)) } counter += 1; } - - + + }); }); } @@ -401,7 +401,7 @@ function createClickVictimUpgrades() { ], "prereqs": { "upgrades": [ - + ] } }; @@ -434,7 +434,7 @@ function createPowerupFreqUpgrades() { ], "prereqs": { "upgrades": [ - + ] } }; @@ -1140,4 +1140,4 @@ const powerups = { clickPopup("VROOM!", "gulp", [e.clientX, e.clientY]); } } -} \ No newline at end of file +} diff --git a/gorge.js b/gorge.js index 4196f8b..6eaaa77 100644 --- a/gorge.js +++ b/gorge.js @@ -29,7 +29,7 @@ function tickPowerups(delta) { const powerupList = document.querySelector("#powerup-list"); let changed = false; // I love mutating arrays as I traverse them. - for (let i = activePowerups.length-1; i >= 0; i--) { + for (let i = activePowerups.length - 1; i >= 0; i--) { activePowerups[i].lifetime -= delta; if (activePowerups[i].lifetime <= 0) { const entry = activePowerups[i]; @@ -56,12 +56,12 @@ function addPowerup(powerup) { const powerupEntry = document.createElement("div"); powerupEntry.classList.add("powerup-entry"); - + powerupEntry.innerText = powerup.name; powerupList.appendChild(powerupEntry); - activePowerups.push({powerup: powerup, lifetime: powerup.duration, element: powerupEntry}); + activePowerups.push({ powerup: powerup, lifetime: powerup.duration, element: powerupEntry }); updateAll(); } @@ -81,7 +81,7 @@ function calculateProductivity() { let productivity = 0; for (const [key, value] of Object.entries(belongings)) { - productivity += productivityOf(key); + productivity += productivityOf(key); } return productivity; @@ -128,7 +128,7 @@ function costOfBuilding(type, count = 1) { total += countCost; count--; } - + return Math.round(total); } @@ -143,7 +143,7 @@ function buildingCount() { } } function buyBuilding(type, e) { - + const count = buildingCount(); let cost = costOfBuilding(type, count); @@ -177,7 +177,7 @@ function updateDisplay() { displayUpgrades(showOwnedUpgrades); tickPowerups(delta); - setTimeout(updateDisplay, 1000/updateRate); + setTimeout(updateDisplay, 1000 / updateRate); } function updateProductivity() { @@ -185,7 +185,7 @@ function updateProductivity() { activePowerups.forEach(entry => { const powerup = entry.powerup; - + const state = { ownedUpgrades: ownedUpgrades, resources: resources, @@ -196,7 +196,7 @@ function updateProductivity() { console.log(currentProductivity); powerup.effect(state); - + console.log(currentProductivity); }) } @@ -221,8 +221,8 @@ function renderResources() { let line1 = render(value, 3, 0) + " " + resourceTypes[key].name; let line2 = render(currentProductivity[key], 1, 1) + " " + resourceTypes[key].name + "/sec"; - list.push({"text": line1, "class": "resource-quantity"}); - list.push({"text": line2, "class": "resource-rate"}); + list.push({ "text": line1, "class": "resource-quantity" }); + list.push({ "text": line2, "class": "resource-rate" }); } return renderLines(list); @@ -238,8 +238,8 @@ function displayBuildings() { } else { continue; } - belongings[key].visible = true; - document.querySelector("#building-" + key).classList.remove("hidden"); + belongings[key].visible = true; + document.querySelector("#building-" + key).classList.remove("hidden"); } let button = document.querySelector("#building-" + key); @@ -249,7 +249,7 @@ function displayBuildings() { name.innerText = value.count + " " + (value.count == 1 ? buildings[key].name : buildings[key].plural); cost.innerText = render(costOfBuilding(key, count)) + " food"; - + if (costOfBuilding(key, count) > resources.food) { button.classList.add("building-button-disabled"); cost.classList.add("building-button-cost-invalid"); @@ -300,7 +300,7 @@ function displayUpgrades(owned) { else { for (let id of remainingUpgrades) { let button = document.querySelector("#upgrade-" + id); - + if (ownedUpgrades[id]) { button.classList.add("hidden"); continue; @@ -316,7 +316,7 @@ function displayUpgrades(owned) { button.classList.add("upgrade-button-inactive"); } } - + // we aren't trimming the list of upgrades now // because we need to switch between owned and unowned upgrades // - thus we need to be able to show or hide anything @@ -451,7 +451,7 @@ function initializeData() { // I'm using apply() to pass on any number of arguments to the // apply() function of the effect type - newEffect.apply = function(...args) { return effect_types[effect.type].apply.apply(null, [effect].concat(args)); } + newEffect.apply = function (...args) { return effect_types[effect.type].apply.apply(null, [effect].concat(args)); } effects[effect.type].push(newEffect); } @@ -516,10 +516,10 @@ function createBuildings() { button.appendChild(buttonName); button.appendChild(buttonCost); button.appendChild(buildingIcon); - button.addEventListener("mousemove", function(e) { mouseTarget = button; buildingTooltip(key, e); }); - button.addEventListener("mouseleave", function() { mouseTarget = undefined; buildingTooltipRemove(); }); - button.addEventListener("click", function(e) { buyBuilding(key, e); }); - button.addEventListener("click", function(e) { buildingTooltip(key, e); }); + button.addEventListener("mousemove", function (e) { mouseTarget = button; buildingTooltip(key, e); }); + button.addEventListener("mouseleave", function () { mouseTarget = undefined; buildingTooltipRemove(); }); + button.addEventListener("click", function (e) { buyBuilding(key, e); }); + button.addEventListener("click", function (e) { buildingTooltip(key, e); }); container.appendChild(button); } @@ -533,7 +533,7 @@ function upgradeReachable(id) { return false; } - if (upgrades[id].prereqs !== undefined ){ + if (upgrades[id].prereqs !== undefined) { for (const [type, reqs] of Object.entries(upgrades[id].prereqs)) { if (type == "buildings") { for (const [building, amount] of Object.entries(reqs)) { @@ -604,14 +604,14 @@ function createUpgrades() { let upgradeIcon = document.createElement("i"); upgradeIcon.classList.add("fas"); upgradeIcon.classList.add(value.icon); - + button.appendChild(buttonName); button.appendChild(upgradeIcon); - button.addEventListener("mouseenter", function(e) { mouseTarget = button; upgradeTooltip(key, e); }); - button.addEventListener("mousemove", function(e) { mouseTarget = button; upgradeTooltip(key, e); }); - button.addEventListener("mouseleave", function() { mouseTarget = undefined; upgradeTooltipRemove(); }); - button.addEventListener("click", function(e) { buyUpgrade(key, e); }); + button.addEventListener("mouseenter", function (e) { mouseTarget = button; upgradeTooltip(key, e); }); + button.addEventListener("mousemove", function (e) { mouseTarget = button; upgradeTooltip(key, e); }); + button.addEventListener("mouseleave", function () { mouseTarget = undefined; upgradeTooltipRemove(); }); + button.addEventListener("click", function (e) { buyUpgrade(key, e); }); container.appendChild(button); } @@ -661,7 +661,7 @@ function renderCost(cost) { for (const [key, value] of Object.entries(cost)) { list.push({ - "text": render(value,0) + " " + resourceTypes[key].name, + "text": render(value, 0) + " " + resourceTypes[key].name, "valid": resources[key] >= value }); } @@ -684,14 +684,14 @@ function renderPrereqs(prereqs) { if (key == "buildings") { for (const [id, amount] of Object.entries(prereqs.buildings)) { list.push({ - "text": buildings[id].name + " x" + render(amount,0), + "text": buildings[id].name + " x" + render(amount, 0), "valid": belongings[id].count >= amount }); } } else if (key == "productivity") { for (const [id, amount] of Object.entries(prereqs.productivity)) { list.push({ - "text": render(amount,0) + " " + resourceTypes[id].name + "/s", + "text": render(amount, 0) + " " + resourceTypes[id].name + "/s", "valid": currentProductivity[id] >= amount }); } @@ -705,7 +705,7 @@ function renderEffects(effectList) { let list = []; for (let effect of effectList) { - list.push({"text": effect_types[effect.type].desc(effect)}); + list.push({ "text": effect_types[effect.type].desc(effect) }); } return renderLines(list); @@ -796,7 +796,7 @@ function doPowerup() { button.classList.add("powerup"); - button.style.setProperty("--lifetime", lifetime/1000 + "s"); + button.style.setProperty("--lifetime", lifetime / 1000 + "s"); button.style.setProperty("--leftpos", left); button.style.setProperty("--toppos", top); @@ -813,7 +813,7 @@ function doPowerup() { const choice = Math.floor(Math.random() * choices.length); const powerup = powerups[choices[choice]]; - + const icon = document.createElement("div"); icon.classList.add("fas"); @@ -850,12 +850,12 @@ function doPowerup() { } else { powerup.effect(state); } - + powerup.popup(powerup, e); button.classList.add("powerup-clicked"); resources.food += 1000; clearTimeout(remove); - + setTimeout(() => { body.removeChild(button); }, 500); @@ -867,7 +867,7 @@ function doPowerup() { function fillTooltip(type, field, content) { let item = document.querySelector("#" + type + "-tooltip-" + field); - if (typeof(content) === "string") { + if (typeof (content) === "string") { item.innerText = content; } else { replaceChildren(item, content); @@ -910,11 +910,11 @@ function prodSummary(id) { let list = []; list.push( - {"text": "Each " + buildings[id].name + " produces " + round(productivityMultiplierOf(id) * buildings[id].prod,1) + " food/sec"} + { "text": "Each " + buildings[id].name + " produces " + round(productivityMultiplierOf(id) * buildings[id].prod, 1) + " food/sec" } ); list.push( - {"text": "Your " + render(belongings[id].count) + " " + (belongings[id].count == 1 ? buildings[id].name + " is": buildings[id].plural + " are") + " producing " + round(productivityOf(id),1) + " food/sec"} + { "text": "Your " + render(belongings[id].count) + " " + (belongings[id].count == 1 ? buildings[id].name + " is" : buildings[id].plural + " are") + " producing " + round(productivityOf(id), 1) + " food/sec" } ); let percentage = round(100 * productivityOf(id) / currentProductivity["food"], 2); @@ -923,7 +923,7 @@ function prodSummary(id) { percentage = 0; } list.push( - {"text": "(" + percentage + "% of all food)"} + { "text": "(" + percentage + "% of all food)" } ); return renderLines(list); @@ -933,26 +933,26 @@ function buildingTooltip(id, event) { let tooltip = document.querySelector("#building-tooltip"); tooltip.style.setProperty("display", "inline-block"); - + const count = buildingCount(); - fillTooltip("building", "name", (count != 1 ? count +"x " : "") + buildings[id].name); + fillTooltip("building", "name", (count != 1 ? count + "x " : "") + buildings[id].name); fillTooltip("building", "desc", buildings[id].desc); fillTooltip("building", "cost", render(costOfBuilding(id, count)) + " food"); fillTooltip("building", "prod", prodSummary(id)); let xPos = tooltip.parentElement.getBoundingClientRect().x - 450; - + // wow browsers are bad var body = document.body, html = document.documentElement; - var height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight ); + var height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight); let yPos = Math.min(event.clientY, height - 200); - tooltip.style.setProperty("transform", "translate(" + xPos + "px, " + yPos + "px)") + tooltip.style.setProperty("transform", "translate(" + xPos + "px, " + yPos + "px)") } function buildingTooltipRemove() { @@ -961,7 +961,7 @@ function buildingTooltipRemove() { tooltip.style.setProperty("display", "none"); } -window.onload = function() { +window.onload = function () { setup(); lastTime = performance.now(); @@ -969,7 +969,7 @@ window.onload = function() { doNews(); doPowerup(); - setTimeout(updateDisplay, 1000/updateRate); + setTimeout(updateDisplay, 1000 / updateRate); setTimeout(autosave, 60000); } @@ -998,8 +998,8 @@ function saveGame() { storage.setItem("resources", JSON.stringify(resources)); storage.setItem("belongings", JSON.stringify(belongings)); - } catch(e) { - clickPopup("Can't save - no access to local storage.", "info", [window.innerWidth/2, window.innerHeight/5]); + } catch (e) { + clickPopup("Can't save - no access to local storage.", "info", [window.innerWidth / 2, window.innerHeight / 5]); } } @@ -1010,28 +1010,28 @@ function load() { if (!storage.getItem("save-version")) { return; } - + let newOwnedUpgrades = JSON.parse(storage.getItem("ownedUpgrades")); - + for (const [key, value] of Object.entries(newOwnedUpgrades)) { ownedUpgrades[key] = value; } - + let newResources = JSON.parse(storage.getItem("resources")); - + for (const [key, value] of Object.entries(newResources)) { resources[key] = value; } - + let newBelongings = JSON.parse(storage.getItem("belongings")); - + for (const [key, value] of Object.entries(newBelongings)) { belongings[key] = value; } - } catch(e) { - clickPopup("Can't load - no access to local storage.", "info", [window.innerWidth/2, window.innerHeight/5]); + } catch (e) { + clickPopup("Can't load - no access to local storage.", "info", [window.innerWidth / 2, window.innerHeight / 5]); } - + } function reset() { diff --git a/numbers.js b/numbers.js index 929487d..35a8caf 100644 --- a/numbers.js +++ b/numbers.js @@ -1,8 +1,8 @@ -function render(val, places=1, smallPlaces = 0) { +function render(val, places = 1, smallPlaces = 0) { return numberText(val, places, smallPlaces); } -function numberText(val, places=1, smallPlaces = 0) { +function numberText(val, places = 1, smallPlaces = 0) { if (val < 1000) { return round(val, smallPlaces); } diff --git a/polyfill.js b/polyfill.js index 8460c6c..6e2304c 100644 --- a/polyfill.js +++ b/polyfill.js @@ -1,9 +1,9 @@ if (!Object.entries) { console.log("Your browser doesn't support Object.entries()") - Object.entries = function( obj ){ - var ownProps = Object.keys( obj ), - i = ownProps.length, - resArray = new Array(i); // preallocate the Array + Object.entries = function (obj) { + var ownProps = Object.keys(obj), + i = ownProps.length, + resArray = new Array(i); // preallocate the Array while (i--) resArray[i] = [ownProps[i], obj[ownProps[i]]];