소스 검색

Reformat the js files

tags/v0.0.5
Fen Dweller 5 년 전
부모
커밋
579f9e5b9c
No known key found for this signature in database GPG 키 ID: E80B35A6F11C3656
4개의 변경된 파일105개의 추가작업 그리고 105개의 파일을 삭제
  1. +42
    -42
      constants.js
  2. +57
    -57
      gorge.js
  3. +2
    -2
      numbers.js
  4. +4
    -4
      polyfill.js

+ 42
- 42
constants.js 파일 보기

@@ -11,7 +11,7 @@ const buildings = {
"plural": "Micros", "plural": "Micros",
"desc": "A tasty, squirmy treat.", "desc": "A tasty, squirmy treat.",
"cost": 1e1, "cost": 1e1,
"prod": 1e-1/1,
"prod": 1e-1 / 1,
"icon": "fa-universal-access" "icon": "fa-universal-access"
}, },
"anthro": { "anthro": {
@@ -19,7 +19,7 @@ const buildings = {
"plural": "Anthros", "plural": "Anthros",
"desc": "Something more substantial to sate your hunger.", "desc": "Something more substantial to sate your hunger.",
"cost": 1e2, "cost": 1e2,
"prod": 1e0/1.1,
"prod": 1e0 / 1.1,
"icon": "fa-male" "icon": "fa-male"
}, },
"car": { "car": {
@@ -27,7 +27,7 @@ const buildings = {
"plural": "Cars", "plural": "Cars",
"desc": "Crunchy shell, tasty center.", "desc": "Crunchy shell, tasty center.",
"cost": 1.2e3, "cost": 1.2e3,
"prod": 1e1/1.2,
"prod": 1e1 / 1.2,
"icon": "fa-car" "icon": "fa-car"
}, },
"bus": { "bus": {
@@ -35,7 +35,7 @@ const buildings = {
"plural": "Buses", "plural": "Buses",
"desc": "Probably the worst place to be when a macro is aroud.", "desc": "Probably the worst place to be when a macro is aroud.",
"cost": 1.4e4, "cost": 1.4e4,
"prod": 1e2/1.3,
"prod": 1e2 / 1.3,
"icon": "fa-bus" "icon": "fa-bus"
}, },
"house": { "house": {
@@ -43,7 +43,7 @@ const buildings = {
"plural": "Houses", "plural": "Houses",
"desc": "Home sweet home - but it doesn't taste sweet?", "desc": "Home sweet home - but it doesn't taste sweet?",
"cost": 1.6e5, "cost": 1.6e5,
"prod": 1e3/1.4,
"prod": 1e3 / 1.4,
"icon": "fa-home" "icon": "fa-home"
}, },
"apartment": { "apartment": {
@@ -51,7 +51,7 @@ const buildings = {
"plural": "Apartments", "plural": "Apartments",
"desc": "More snacks, less packaging.", "desc": "More snacks, less packaging.",
"cost": 1.8e6, "cost": 1.8e6,
"prod": 1e4/1.5,
"prod": 1e4 / 1.5,
"icon": "fa-building" "icon": "fa-building"
}, },
"block": { "block": {
@@ -59,7 +59,7 @@ const buildings = {
"plural": "Blocks", "plural": "Blocks",
"desc": "A whole pile of buildings.", "desc": "A whole pile of buildings.",
"cost": 2e7, "cost": 2e7,
"prod": 1e5/1.6,
"prod": 1e5 / 1.6,
"icon": "fa-warehouse" "icon": "fa-warehouse"
}, },
"town": { "town": {
@@ -67,7 +67,7 @@ const buildings = {
"plural": "Towns", "plural": "Towns",
"desc": "'Tourist trap' has never been this literal.", "desc": "'Tourist trap' has never been this literal.",
"cost": 2.2e8, "cost": 2.2e8,
"prod": 1e6/1.7,
"prod": 1e6 / 1.7,
"icon": "fa-store" "icon": "fa-store"
}, },
"city": { "city": {
@@ -75,7 +75,7 @@ const buildings = {
"plural": "Cities", "plural": "Cities",
"desc": "Please no sitty on our city.", "desc": "Please no sitty on our city.",
"cost": 2.4e9, "cost": 2.4e9,
"prod": 1e7/1.8,
"prod": 1e7 / 1.8,
"icon": "fa-city" "icon": "fa-city"
}, },
"metro": { "metro": {
@@ -83,7 +83,7 @@ const buildings = {
"plural": "Metropolises", "plural": "Metropolises",
"desc": "A big ol' city. Tasty, too.", "desc": "A big ol' city. Tasty, too.",
"cost": 2.6e10, "cost": 2.6e10,
"prod": 1e8/1.9,
"prod": 1e8 / 1.9,
"icon": "fa-landmark" "icon": "fa-landmark"
}, },
"county": { "county": {
@@ -91,7 +91,7 @@ const buildings = {
"plural": "Counties", "plural": "Counties",
"desc": "Why salt the land when you can slurp it?", "desc": "Why salt the land when you can slurp it?",
"cost": 2.8e11, "cost": 2.8e11,
"prod": 1e9/2,
"prod": 1e9 / 2,
"icon": "fa-map" "icon": "fa-map"
}, },
"state": { "state": {
@@ -99,7 +99,7 @@ const buildings = {
"plural": "States", "plural": "States",
"desc": "The United States is made up of...43 states - no, 42...", "desc": "The United States is made up of...43 states - no, 42...",
"cost": 3e12, "cost": 3e12,
"prod": 1e10/2.1,
"prod": 1e10 / 2.1,
"icon": "fa-map-signs" "icon": "fa-map-signs"
}, },
"country": { "country": {
@@ -107,7 +107,7 @@ const buildings = {
"plural": "Countries", "plural": "Countries",
"desc": "One nation, under paw.", "desc": "One nation, under paw.",
"cost": 3.2e13, "cost": 3.2e13,
"prod": 1e11/2.2,
"prod": 1e11 / 2.2,
"icon": "fa-flag" "icon": "fa-flag"
}, },
"continent": { "continent": {
@@ -115,7 +115,7 @@ const buildings = {
"plural": "Continents", "plural": "Continents",
"desc": "Earth-shattering appetite!", "desc": "Earth-shattering appetite!",
"cost": 3.4e14, "cost": 3.4e14,
"prod": 1e12/2.3,
"prod": 1e12 / 2.3,
"icon": "fa-mountain" "icon": "fa-mountain"
}, },
"planet": { "planet": {
@@ -123,7 +123,7 @@ const buildings = {
"plural": "Planets", "plural": "Planets",
"desc": "Earth appetite!", "desc": "Earth appetite!",
"cost": 3.6e15, "cost": 3.6e15,
"prod": 1e13/2.4,
"prod": 1e13 / 2.4,
"icon": "fa-globe-europe" "icon": "fa-globe-europe"
}, },
"solar-system": { "solar-system": {
@@ -131,7 +131,7 @@ const buildings = {
"plural": "Solar Systems", "plural": "Solar Systems",
"desc": "Earths appetite!", "desc": "Earths appetite!",
"cost": 3.8e16, "cost": 3.8e16,
"prod": 1e14/2.5,
"prod": 1e14 / 2.5,
"icon": "fa-meteor" "icon": "fa-meteor"
}, },
"galaxy": { "galaxy": {
@@ -139,7 +139,7 @@ const buildings = {
"plural": "Galaxies", "plural": "Galaxies",
"desc": "In a galaxy far, far down your gullet...", "desc": "In a galaxy far, far down your gullet...",
"cost": 4.0e17, "cost": 4.0e17,
"prod": 1e15/2.6,
"prod": 1e15 / 2.6,
"icon": "fa-sun" "icon": "fa-sun"
}, },
"universe": { "universe": {
@@ -147,7 +147,7 @@ const buildings = {
"plural": "Universes", "plural": "Universes",
"desc": "Into the you-verse.", "desc": "Into the you-verse.",
"cost": 4.2e18, "cost": 4.2e18,
"prod": 1e16/2.7,
"prod": 1e16 / 2.7,
"icon": "fa-asterisk" "icon": "fa-asterisk"
}, },
"multiverse": { "multiverse": {
@@ -155,54 +155,54 @@ const buildings = {
"plural": "Multiverses", "plural": "Multiverses",
"desc": "This is getting very silly.", "desc": "This is getting very silly.",
"cost": 4.4e19, "cost": 4.4e19,
"prod": 1e17/2.8,
"prod": 1e17 / 2.8,
"icon": "fa-infinity" "icon": "fa-infinity"
} }
} }


const effect_types = { const effect_types = {
"prod": { "prod": {
"apply": function(effect, productivity) {
"apply": function (effect, productivity) {
return productivity * effect.amount; return productivity * effect.amount;
}, },
"desc": function(effect) {
"desc": function (effect) {
return round(effect.amount, 2) + "x food production from " + buildings[effect.target].plural; return round(effect.amount, 2) + "x food production from " + buildings[effect.target].plural;
} }
}, },
"prod-all": { "prod-all": {
"apply": function(effect, productivity) {
"apply": function (effect, productivity) {
return productivity * effect.amount; return productivity * effect.amount;
}, },
"desc": function(effect) {
"desc": function (effect) {
return round((effect.amount - 1) * 100) + "% increase to food production"; return round((effect.amount - 1) * 100) + "% increase to food production";
} }
}, },
"helper": { "helper": {
"apply": function(effect, productivity, helperCount) {
"apply": function (effect, productivity, helperCount) {
return productivity * (1 + effect.amount * 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."; return "+" + round(effect.amount * 100) + "% food/sec from " + buildings[effect.helped].name + " for every " + buildings[effect.helper].name + " owned.";
} }
}, },
"click": { "click": {
"apply": function(effect, bonus, productivity) {
"apply": function (effect, bonus, productivity) {
return bonus + productivity * effect.amount; return bonus + productivity * effect.amount;
}, },
"desc": function(effect) {
"desc": function (effect) {
return round(effect.amount * 100) + "% of food/sec gained per click"; return round(effect.amount * 100) + "% of food/sec gained per click";
} }
}, },
"click-victim": { "click-victim": {
"desc": function(effect) {
"desc": function (effect) {
return "Devour larger prey"; return "Devour larger prey";
} }
}, },
"powerup-freq": { "powerup-freq": {
"apply": function(effect, delay) {
"apply": function (effect, delay) {
return delay * effect.amount; return delay * effect.amount;
}, },
"desc": function(effect) {
"desc": function (effect) {
return "Speed up powerup spawns by " + Math.round((1 / effect.amount - 1) * 100) + "%"; return "Speed up powerup spawns by " + Math.round((1 / effect.amount - 1) * 100) + "%";
} }
} }
@@ -233,7 +233,7 @@ function createProdUpgrades() {
"desc": contents.desc, "desc": contents.desc,
"icon": buildings[key].icon, "icon": buildings[key].icon,
"cost": { "cost": {
"food": buildings[key].cost * 5 * Math.pow(10,counter - 1)
"food": buildings[key].cost * 5 * Math.pow(10, counter - 1)
}, },
"effects": [ "effects": [
{ {
@@ -250,7 +250,7 @@ function createProdUpgrades() {


if (counter > 1) { if (counter > 1) {
upgrades[prefix + counter]["prereqs"]["upgrades"] = [ upgrades[prefix + counter]["prereqs"]["upgrades"] = [
prefix + (counter - 1)
prefix + (counter - 1)
]; ];
} }


@@ -270,7 +270,7 @@ function createProdAllUpgrades() {
"desc": contents.desc, "desc": contents.desc,
"icon": "fa-cogs", "icon": "fa-cogs",
"cost": { "cost": {
"food": 5 * Math.pow(10, counter+1)
"food": 5 * Math.pow(10, counter + 1)
}, },
"effects": [ "effects": [
{ {
@@ -298,7 +298,7 @@ function createProdAllUpgrades() {
function createClickUpgrades() { function createClickUpgrades() {
let prefix = "prod-click-"; let prefix = "prod-click-";


let counter = 1 ;
let counter = 1;


for (let contents of clickUpgradeText) { for (let contents of clickUpgradeText) {
upgrades[prefix + counter] = { upgrades[prefix + counter] = {
@@ -306,7 +306,7 @@ function createClickUpgrades() {
desc: contents.desc, desc: contents.desc,
icon: "fa-hand-pointer", icon: "fa-hand-pointer",
cost: { cost: {
food: Math.pow(10, (counter*2)+1)
food: Math.pow(10, (counter * 2) + 1)
}, },
effects: [ effects: [
{ {
@@ -361,7 +361,7 @@ function createHelperUpgrades() {
], ],
"prereqs": { "prereqs": {
"buildings": { "buildings": {
}, },
"upgrades": [ "upgrades": [
helper + "-prod-1" helper + "-prod-1"
@@ -371,12 +371,12 @@ function createHelperUpgrades() {
upgrades[key]["prereqs"]["buildings"][helper] = 10 * counter; upgrades[key]["prereqs"]["buildings"][helper] = 10 * counter;


if (counter > 1) { 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; counter += 1;
} }
}); });
}); });
} }
@@ -401,7 +401,7 @@ function createClickVictimUpgrades() {
], ],
"prereqs": { "prereqs": {
"upgrades": [ "upgrades": [
] ]
} }
}; };
@@ -434,7 +434,7 @@ function createPowerupFreqUpgrades() {
], ],
"prereqs": { "prereqs": {
"upgrades": [ "upgrades": [
] ]
} }
}; };
@@ -1140,4 +1140,4 @@ const powerups = {
clickPopup("VROOM!", "gulp", [e.clientX, e.clientY]); clickPopup("VROOM!", "gulp", [e.clientX, e.clientY]);
} }
} }
}
}

+ 57
- 57
gorge.js 파일 보기

@@ -29,7 +29,7 @@ function tickPowerups(delta) {
const powerupList = document.querySelector("#powerup-list"); const powerupList = document.querySelector("#powerup-list");
let changed = false; let changed = false;
// I love mutating arrays as I traverse them. // 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; activePowerups[i].lifetime -= delta;
if (activePowerups[i].lifetime <= 0) { if (activePowerups[i].lifetime <= 0) {
const entry = activePowerups[i]; const entry = activePowerups[i];
@@ -56,12 +56,12 @@ function addPowerup(powerup) {


const powerupEntry = document.createElement("div"); const powerupEntry = document.createElement("div");
powerupEntry.classList.add("powerup-entry"); powerupEntry.classList.add("powerup-entry");
powerupEntry.innerText = powerup.name; powerupEntry.innerText = powerup.name;


powerupList.appendChild(powerupEntry); powerupList.appendChild(powerupEntry);


activePowerups.push({powerup: powerup, lifetime: powerup.duration, element: powerupEntry});
activePowerups.push({ powerup: powerup, lifetime: powerup.duration, element: powerupEntry });


updateAll(); updateAll();
} }
@@ -81,7 +81,7 @@ function calculateProductivity() {
let productivity = 0; let productivity = 0;


for (const [key, value] of Object.entries(belongings)) { for (const [key, value] of Object.entries(belongings)) {
productivity += productivityOf(key);
productivity += productivityOf(key);
} }


return productivity; return productivity;
@@ -128,7 +128,7 @@ function costOfBuilding(type, count = 1) {
total += countCost; total += countCost;
count--; count--;
} }


return Math.round(total); return Math.round(total);
} }
@@ -143,7 +143,7 @@ function buildingCount() {
} }
} }
function buyBuilding(type, e) { function buyBuilding(type, e) {
const count = buildingCount(); const count = buildingCount();


let cost = costOfBuilding(type, count); let cost = costOfBuilding(type, count);
@@ -177,7 +177,7 @@ function updateDisplay() {
displayUpgrades(showOwnedUpgrades); displayUpgrades(showOwnedUpgrades);
tickPowerups(delta); tickPowerups(delta);


setTimeout(updateDisplay, 1000/updateRate);
setTimeout(updateDisplay, 1000 / updateRate);
} }


function updateProductivity() { function updateProductivity() {
@@ -185,7 +185,7 @@ function updateProductivity() {


activePowerups.forEach(entry => { activePowerups.forEach(entry => {
const powerup = entry.powerup; const powerup = entry.powerup;
const state = { const state = {
ownedUpgrades: ownedUpgrades, ownedUpgrades: ownedUpgrades,
resources: resources, resources: resources,
@@ -196,7 +196,7 @@ function updateProductivity() {
console.log(currentProductivity); console.log(currentProductivity);


powerup.effect(state); powerup.effect(state);
console.log(currentProductivity); console.log(currentProductivity);
}) })
} }
@@ -221,8 +221,8 @@ function renderResources() {
let line1 = render(value, 3, 0) + " " + resourceTypes[key].name; let line1 = render(value, 3, 0) + " " + resourceTypes[key].name;
let line2 = render(currentProductivity[key], 1, 1) + " " + resourceTypes[key].name + "/sec"; 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); return renderLines(list);
@@ -238,8 +238,8 @@ function displayBuildings() {
} else { } else {
continue; 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); 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); name.innerText = value.count + " " + (value.count == 1 ? buildings[key].name : buildings[key].plural);
cost.innerText = render(costOfBuilding(key, count)) + " food"; cost.innerText = render(costOfBuilding(key, count)) + " food";
if (costOfBuilding(key, count) > resources.food) { if (costOfBuilding(key, count) > resources.food) {
button.classList.add("building-button-disabled"); button.classList.add("building-button-disabled");
cost.classList.add("building-button-cost-invalid"); cost.classList.add("building-button-cost-invalid");
@@ -300,7 +300,7 @@ function displayUpgrades(owned) {
else { else {
for (let id of remainingUpgrades) { for (let id of remainingUpgrades) {
let button = document.querySelector("#upgrade-" + id); let button = document.querySelector("#upgrade-" + id);
if (ownedUpgrades[id]) { if (ownedUpgrades[id]) {
button.classList.add("hidden"); button.classList.add("hidden");
continue; continue;
@@ -316,7 +316,7 @@ function displayUpgrades(owned) {
button.classList.add("upgrade-button-inactive"); button.classList.add("upgrade-button-inactive");
} }
} }
// we aren't trimming the list of upgrades now // we aren't trimming the list of upgrades now
// because we need to switch between owned and unowned upgrades // because we need to switch between owned and unowned upgrades
// - thus we need to be able to show or hide anything // - 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 // I'm using apply() to pass on any number of arguments to the
// apply() function of the effect type // 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); effects[effect.type].push(newEffect);
} }
@@ -516,10 +516,10 @@ function createBuildings() {
button.appendChild(buttonName); button.appendChild(buttonName);
button.appendChild(buttonCost); button.appendChild(buttonCost);
button.appendChild(buildingIcon); 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); container.appendChild(button);
} }
@@ -533,7 +533,7 @@ function upgradeReachable(id) {
return false; return false;
} }


if (upgrades[id].prereqs !== undefined ){
if (upgrades[id].prereqs !== undefined) {
for (const [type, reqs] of Object.entries(upgrades[id].prereqs)) { for (const [type, reqs] of Object.entries(upgrades[id].prereqs)) {
if (type == "buildings") { if (type == "buildings") {
for (const [building, amount] of Object.entries(reqs)) { for (const [building, amount] of Object.entries(reqs)) {
@@ -604,14 +604,14 @@ function createUpgrades() {
let upgradeIcon = document.createElement("i"); let upgradeIcon = document.createElement("i");
upgradeIcon.classList.add("fas"); upgradeIcon.classList.add("fas");
upgradeIcon.classList.add(value.icon); upgradeIcon.classList.add(value.icon);
button.appendChild(buttonName); button.appendChild(buttonName);
button.appendChild(upgradeIcon); 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); container.appendChild(button);
} }
@@ -661,7 +661,7 @@ function renderCost(cost) {


for (const [key, value] of Object.entries(cost)) { for (const [key, value] of Object.entries(cost)) {
list.push({ list.push({
"text": render(value,0) + " " + resourceTypes[key].name,
"text": render(value, 0) + " " + resourceTypes[key].name,
"valid": resources[key] >= value "valid": resources[key] >= value
}); });
} }
@@ -684,14 +684,14 @@ function renderPrereqs(prereqs) {
if (key == "buildings") { if (key == "buildings") {
for (const [id, amount] of Object.entries(prereqs.buildings)) { for (const [id, amount] of Object.entries(prereqs.buildings)) {
list.push({ list.push({
"text": buildings[id].name + " x" + render(amount,0),
"text": buildings[id].name + " x" + render(amount, 0),
"valid": belongings[id].count >= amount "valid": belongings[id].count >= amount
}); });
} }
} else if (key == "productivity") { } else if (key == "productivity") {
for (const [id, amount] of Object.entries(prereqs.productivity)) { for (const [id, amount] of Object.entries(prereqs.productivity)) {
list.push({ list.push({
"text": render(amount,0) + " " + resourceTypes[id].name + "/s",
"text": render(amount, 0) + " " + resourceTypes[id].name + "/s",
"valid": currentProductivity[id] >= amount "valid": currentProductivity[id] >= amount
}); });
} }
@@ -705,7 +705,7 @@ function renderEffects(effectList) {
let list = []; let list = [];


for (let effect of effectList) { 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); return renderLines(list);
@@ -796,7 +796,7 @@ function doPowerup() {


button.classList.add("powerup"); 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("--leftpos", left);
button.style.setProperty("--toppos", top); button.style.setProperty("--toppos", top);


@@ -813,7 +813,7 @@ function doPowerup() {
const choice = Math.floor(Math.random() * choices.length); const choice = Math.floor(Math.random() * choices.length);


const powerup = powerups[choices[choice]]; const powerup = powerups[choices[choice]];
const icon = document.createElement("div"); const icon = document.createElement("div");


icon.classList.add("fas"); icon.classList.add("fas");
@@ -850,12 +850,12 @@ function doPowerup() {
} else { } else {
powerup.effect(state); powerup.effect(state);
} }
powerup.popup(powerup, e); powerup.popup(powerup, e);
button.classList.add("powerup-clicked"); button.classList.add("powerup-clicked");
resources.food += 1000; resources.food += 1000;
clearTimeout(remove); clearTimeout(remove);
setTimeout(() => { setTimeout(() => {
body.removeChild(button); body.removeChild(button);
}, 500); }, 500);
@@ -867,7 +867,7 @@ function doPowerup() {


function fillTooltip(type, field, content) { function fillTooltip(type, field, content) {
let item = document.querySelector("#" + type + "-tooltip-" + field); let item = document.querySelector("#" + type + "-tooltip-" + field);
if (typeof(content) === "string") {
if (typeof (content) === "string") {
item.innerText = content; item.innerText = content;
} else { } else {
replaceChildren(item, content); replaceChildren(item, content);
@@ -910,11 +910,11 @@ function prodSummary(id) {
let list = []; let list = [];


list.push( 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( 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); let percentage = round(100 * productivityOf(id) / currentProductivity["food"], 2);
@@ -923,7 +923,7 @@ function prodSummary(id) {
percentage = 0; percentage = 0;
} }
list.push( list.push(
{"text": "(" + percentage + "% of all food)"}
{ "text": "(" + percentage + "% of all food)" }
); );


return renderLines(list); return renderLines(list);
@@ -933,26 +933,26 @@ function buildingTooltip(id, event) {


let tooltip = document.querySelector("#building-tooltip"); let tooltip = document.querySelector("#building-tooltip");
tooltip.style.setProperty("display", "inline-block"); tooltip.style.setProperty("display", "inline-block");
const count = buildingCount(); 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", "desc", buildings[id].desc);
fillTooltip("building", "cost", render(costOfBuilding(id, count)) + " food"); fillTooltip("building", "cost", render(costOfBuilding(id, count)) + " food");
fillTooltip("building", "prod", prodSummary(id)); fillTooltip("building", "prod", prodSummary(id));


let xPos = tooltip.parentElement.getBoundingClientRect().x - 450; let xPos = tooltip.parentElement.getBoundingClientRect().x - 450;
// wow browsers are bad // wow browsers are bad


var body = document.body, var body = document.body,
html = document.documentElement; 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); 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() { function buildingTooltipRemove() {
@@ -961,7 +961,7 @@ function buildingTooltipRemove() {
tooltip.style.setProperty("display", "none"); tooltip.style.setProperty("display", "none");
} }


window.onload = function() {
window.onload = function () {
setup(); setup();


lastTime = performance.now(); lastTime = performance.now();
@@ -969,7 +969,7 @@ window.onload = function() {
doNews(); doNews();
doPowerup(); doPowerup();


setTimeout(updateDisplay, 1000/updateRate);
setTimeout(updateDisplay, 1000 / updateRate);


setTimeout(autosave, 60000); setTimeout(autosave, 60000);
} }
@@ -998,8 +998,8 @@ function saveGame() {
storage.setItem("resources", JSON.stringify(resources)); storage.setItem("resources", JSON.stringify(resources));


storage.setItem("belongings", JSON.stringify(belongings)); 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")) { if (!storage.getItem("save-version")) {
return; return;
} }
let newOwnedUpgrades = JSON.parse(storage.getItem("ownedUpgrades")); let newOwnedUpgrades = JSON.parse(storage.getItem("ownedUpgrades"));
for (const [key, value] of Object.entries(newOwnedUpgrades)) { for (const [key, value] of Object.entries(newOwnedUpgrades)) {
ownedUpgrades[key] = value; ownedUpgrades[key] = value;
} }
let newResources = JSON.parse(storage.getItem("resources")); let newResources = JSON.parse(storage.getItem("resources"));
for (const [key, value] of Object.entries(newResources)) { for (const [key, value] of Object.entries(newResources)) {
resources[key] = value; resources[key] = value;
} }
let newBelongings = JSON.parse(storage.getItem("belongings")); let newBelongings = JSON.parse(storage.getItem("belongings"));
for (const [key, value] of Object.entries(newBelongings)) { for (const [key, value] of Object.entries(newBelongings)) {
belongings[key] = value; 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() { function reset() {


+ 2
- 2
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); return numberText(val, places, smallPlaces);
} }


function numberText(val, places=1, smallPlaces = 0) {
function numberText(val, places = 1, smallPlaces = 0) {
if (val < 1000) { if (val < 1000) {
return round(val, smallPlaces); return round(val, smallPlaces);
} }


+ 4
- 4
polyfill.js 파일 보기

@@ -1,9 +1,9 @@
if (!Object.entries) { if (!Object.entries) {
console.log("Your browser doesn't support 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--) while (i--)
resArray[i] = [ownProps[i], obj[ownProps[i]]]; resArray[i] = [ownProps[i], obj[ownProps[i]]];




불러오는 중...
취소
저장