From 43934c8fa78ab4b3c110f6e5c33b6085fa1ca8c6 Mon Sep 17 00:00:00 2001 From: kotlinc <131211966+kotlinc@users.noreply.github.com> Date: Sun, 15 Oct 2023 07:56:29 +1100 Subject: [PATCH] back to typescript and saves (not loads) --- buildings.ts | 94 +++--- buildings.js => dist/buildings.js | 193 ++++++------ index.html | 2 +- new.coffee | 290 ----------------- new.js | 505 ------------------------------ tsconfig.json | 112 +++++++ 6 files changed, 272 insertions(+), 924 deletions(-) rename buildings.js => dist/buildings.js (63%) delete mode 100644 new.coffee delete mode 100644 new.js create mode 100644 tsconfig.json diff --git a/buildings.ts b/buildings.ts index be3d903..3e8046b 100644 --- a/buildings.ts +++ b/buildings.ts @@ -1,42 +1,42 @@ -var grill: HTMLAudioElement | null = new Audio("designed-fire-winds-swoosh-04-116788.mp3") -var bun: HTMLAudioElement | null = new Audio("crunch-crispy-breadbun-41340.mp3") -var dad: HTMLAudioElement | null = new Audio("dad-says-yummy-113126.mp3") -var farm: HTMLAudioElement | null = new Audio("zapsplat_impacts_hit_loose_ground_dirt_impact_collapse_fall_013_102682.mp3") -var factory: HTMLAudioElement | null = new Audio("some-kind-of-machine-103152.mp3") -var bank: HTMLAudioElement | null = new Audio("cash-register-purchase-87313.mp3") -var ambience: HTMLAudioElement | null = new Audio("./Hotdog-Clicker-Ambience.m4a") +const grill: HTMLAudioElement | null = new Audio("designed-fire-winds-swoosh-04-116788.mp3") +const bun: HTMLAudioElement | null = new Audio("crunch-crispy-breadbun-41340.mp3") +const dad: HTMLAudioElement | null = new Audio("dad-says-yummy-113126.mp3") +const farm: HTMLAudioElement | null = new Audio("zapsplat_impacts_hit_loose_ground_dirt_impact_collapse_fall_013_102682.mp3") +const factory: HTMLAudioElement | null = new Audio("some-kind-of-machine-103152.mp3") +const bank: HTMLAudioElement | null = new Audio("cash-register-purchase-87313.mp3") +const ambience: HTMLAudioElement | null = new Audio("./Hotdog-Clicker-Ambience.m4a") ambience.loop = true; -var bunBuyable: string = "./Can-Buy-Bun-Button.svg" -var bunUnBuyable: string = "./Cant-Buy-Bun-Button.svg" -var bunBuying: string = "./Buying-Bun-Button.svg" +const bunBuyable: string = "./Can-Buy-Bun-Button.svg" +const bunUnBuyable: string = "./Cant-Buy-Bun-Button.svg" +const bunBuying: string = "./Buying-Bun-Button.svg" -var dadBuyable: string = "./Can-Buy-Dad-Button.svg" -var dadUnBuyable: string = "./Cant-Buy-Dad-Button.svg" -var dadBuying: string = "./Buying-Dad-Button.svg" +const dadBuyable: string = "./Can-Buy-Dad-Button.svg" +const dadUnBuyable: string = "./Cant-Buy-Dad-Button.svg" +const dadBuying: string = "./Buying-Dad-Button.svg" -var grillBuyable: string = "./Can-Buy-Grill-Button.svg" -var grillUnBuyable: string = "./Cant-Buy-Grill-Button.svg" -var grillBuying: string = "./Buying-Grill-Button.svg" +const grillBuyable: string = "./Can-Buy-Grill-Button.svg" +const grillUnBuyable: string = "./Cant-Buy-Grill-Button.svg" +const grillBuying: string = "./Buying-Grill-Button.svg" -var farmBuyable: string = "./Can-Buy-Farm-Button.svg" -var farmUnBuyable: string = "./Cant-Buy-Farm-Button.svg" -var farmBuying: string = "./Buying-Farm-Button.svg" +const farmBuyable: string = "./Can-Buy-Farm-Button.svg" +const farmUnBuyable: string = "./Cant-Buy-Farm-Button.svg" +const farmBuying: string = "./Buying-Farm-Button.svg" -var facBuyable: string = "./Can-Buy-Fac-Button.svg" -var facUnBuyable: string = "./Cant-Buy-Fac-Button.svg" -var facBuying: string = "./Buying-Fac-Button.svg" +const facBuyable: string = "./Can-Buy-Fac-Button.svg" +const facUnBuyable: string = "./Cant-Buy-Fac-Button.svg" +const facBuying: string = "./Buying-Fac-Button.svg" -var bankBuyable: string = "./Can-Buy-Bank-Button.svg" -var bankUnBuyable: string = "./Cant-Buy-Bank-Button.svg" -var bankBuying: string = "./Buying-Bank-Button.svg" +const bankBuyable: string = "./Can-Buy-Bank-Button.svg" +const bankUnBuyable: string = "./Cant-Buy-Bank-Button.svg" +const bankBuying: string = "./Buying-Bank-Button.svg" let passiveClicks: number = 0; let clickCount: number = 0; let bunCount: number = 0; let dadCount: number = 0; let grillCount: number = 0; -let dogFarmCount: number = 0; +let farmCount: number = 0; let facCount: number = 0; let bankCount: number = 0; @@ -49,8 +49,8 @@ let dadRate: number = 2; let grillCost: number = 500; let grillRate: number = 10; -let dogFarmCost: number = 5000; -let dogFarmRate: number = 50; +let farmCost: number = 5000; +let farmRate: number = 50; let facCost: number = 50000; let facRate: number = 500; @@ -66,7 +66,7 @@ const clickCountElement: HTMLElement | null = document.getElementById("clickCoun const grillCountElement: HTMLElement | null = document.getElementById("grillCount"); const bunCountElement: HTMLElement | null = document.getElementById("bunCount"); const dadCountElement: HTMLElement | null = document.getElementById("dadCount"); -const dogFarmCountElement: HTMLElement | null = document.getElementById("dogFarmCount"); +const farmCountElement: HTMLElement | null = document.getElementById("farmCount"); const facCountElement: HTMLElement | null = document.getElementById("dogFacCount"); const bankCountElement: HTMLElement | null = document.getElementById("dogBankCount"); @@ -74,7 +74,7 @@ const hotdogButton: HTMLElement | null = document.getElementById("hotdogButton") const bunButton: HTMLElement | null = document.getElementById("bunButton"); const dadButton: HTMLElement | null = document.getElementById("dadButton"); const grillButton: HTMLElement | null = document.getElementById("grillButton"); -const dogFarmButton: HTMLElement | null = document.getElementById("dogFarmButton"); +const farmButton: HTMLElement | null = document.getElementById("farmButton"); const facButton: HTMLElement | null = document.getElementById("dogFacButton"); const bankButton: HTMLElement | null = document.getElementById("dogBankButton") @@ -92,6 +92,21 @@ const farmImage: HTMLImageElement | null = document.getElementById("farmImg") as const facImage: HTMLImageElement | null = document.getElementById("facImg") as HTMLImageElement const bankImage: HTMLImageElement | null = document.getElementById("bankImg") as HTMLImageElement +const save = (): void => { + const set = (key: string, value: string): void => { + localStorage.setItem(key, value) + } + + set('hotdogs', `${clickCount}`) + set('hotdogs/sec', `${passiveClicks}`) + set('bun', `${bunCount},${bunRate},${bunCost}`) + set('dad', `${dadCount},${dadRate},${dadCost}`) + set('grill', `${grillCount},${grillRate},${grillCost}`) + set('farm', `${farmCount},${farmRate},${farmCost}`) + set('factory', `${facCount},${facRate},${facCost}`) + set('bank', `${bankCount},${bankRate},${bankCost}`) +} + const checkBuyables = () => { if (clickCount >= bunCost) { bunImage.src = bunBuyable @@ -126,7 +141,7 @@ const checkBuyables = () => { bankImage.src = bankUnBuyable return } - if (clickCount >= dogFarmCost) { + if (clickCount >= farmCost) { farmImage.src = farmBuyable } else { console.log("Cant buy farm; therefore, cant buy anything more expensive than grill.") @@ -210,17 +225,17 @@ grillButton?.addEventListener("click", function() { grill?.play(); } }); -dogFarmButton?.addEventListener("click", function() { - if (clickCount >= dogFarmCost && farmPriceElement != null && clickCountElement != null && dogFarmCountElement != null && passiveClicksElement != null) { - clickCount -= dogFarmCost; - dogFarmCost *= increment; +farmButton?.addEventListener("click", function() { + if (clickCount >= farmCost && farmPriceElement != null && clickCountElement != null && farmCountElement != null && passiveClicksElement != null) { + clickCount -= farmCost; + farmCost *= increment; checkBuyables(); farmImage.src = farmBuying - farmPriceElement.textContent = String(dogFarmCost.toFixed(1)); + farmPriceElement.textContent = String(farmCost.toFixed(1)); clickCountElement.textContent = String(clickCount.toFixed(1)); - dogFarmCount++; - dogFarmCountElement.textContent = String(dogFarmCount); - passiveClicks += dogFarmRate; + farmCount++; + farmCountElement.textContent = String(farmCount); + passiveClicks += farmRate; passiveClicksElement.textContent = passiveClicks.toFixed(1); farm?.play(); } @@ -303,5 +318,6 @@ setInterval(function() { clickCount += passiveClicks; clickCountElement.textContent = clickCount.toFixed(1); checkBuyables(); + save() } }, 1000); diff --git a/buildings.js b/dist/buildings.js similarity index 63% rename from buildings.js rename to dist/buildings.js index 569538c..13e5778 100644 --- a/buildings.js +++ b/dist/buildings.js @@ -1,78 +1,92 @@ -var grill = new Audio("designed-fire-winds-swoosh-04-116788.mp3"); -var bun = new Audio("crunch-crispy-breadbun-41340.mp3"); -var dad = new Audio("dad-says-yummy-113126.mp3"); -var farm = new Audio("zapsplat_impacts_hit_loose_ground_dirt_impact_collapse_fall_013_102682.mp3"); -var factory = new Audio("some-kind-of-machine-103152.mp3"); -var bank = new Audio("cash-register-purchase-87313.mp3"); -var ambience = new Audio("./Hotdog-Clicker-Ambience.m4a"); +"use strict"; +const grill = new Audio("designed-fire-winds-swoosh-04-116788.mp3"); +const bun = new Audio("crunch-crispy-breadbun-41340.mp3"); +const dad = new Audio("dad-says-yummy-113126.mp3"); +const farm = new Audio("zapsplat_impacts_hit_loose_ground_dirt_impact_collapse_fall_013_102682.mp3"); +const factory = new Audio("some-kind-of-machine-103152.mp3"); +const bank = new Audio("cash-register-purchase-87313.mp3"); +const ambience = new Audio("./Hotdog-Clicker-Ambience.m4a"); ambience.loop = true; -var bunBuyable = "./Can-Buy-Bun-Button.svg"; -var bunUnBuyable = "./Cant-Buy-Bun-Button.svg"; -var bunBuying = "./Buying-Bun-Button.svg"; -var dadBuyable = "./Can-Buy-Dad-Button.svg"; -var dadUnBuyable = "./Cant-Buy-Dad-Button.svg"; -var dadBuying = "./Buying-Dad-Button.svg"; -var grillBuyable = "./Can-Buy-Grill-Button.svg"; -var grillUnBuyable = "./Cant-Buy-Grill-Button.svg"; -var grillBuying = "./Buying-Grill-Button.svg"; -var farmBuyable = "./Can-Buy-Farm-Button.svg"; -var farmUnBuyable = "./Cant-Buy-Farm-Button.svg"; -var farmBuying = "./Buying-Farm-Button.svg"; -var facBuyable = "./Can-Buy-Fac-Button.svg"; -var facUnBuyable = "./Cant-Buy-Fac-Button.svg"; -var facBuying = "./Buying-Fac-Button.svg"; -var bankBuyable = "./Can-Buy-Bank-Button.svg"; -var bankUnBuyable = "./Cant-Buy-Bank-Button.svg"; -var bankBuying = "./Buying-Bank-Button.svg"; -var passiveClicks = 0; -var clickCount = 0; -var bunCount = 0; -var dadCount = 0; -var grillCount = 0; -var dogFarmCount = 0; -var facCount = 0; -var bankCount = 0; -var bunCost = 10; -var bunRate = 0.2; -var dadCost = 100; -var dadRate = 2; -var grillCost = 500; -var grillRate = 10; -var dogFarmCost = 5000; -var dogFarmRate = 50; -var facCost = 50000; -var facRate = 500; -var bankCost = 250000; -var bankRate = 2500; -var increment = 1.3; -var passiveClicksElement = document.getElementById("passive"); -var clickCountElement = document.getElementById("clickCount"); -var grillCountElement = document.getElementById("grillCount"); -var bunCountElement = document.getElementById("bunCount"); -var dadCountElement = document.getElementById("dadCount"); -var dogFarmCountElement = document.getElementById("dogFarmCount"); -var facCountElement = document.getElementById("dogFacCount"); -var bankCountElement = document.getElementById("dogBankCount"); -var hotdogButton = document.getElementById("hotdogButton"); -var bunButton = document.getElementById("bunButton"); -var dadButton = document.getElementById("dadButton"); -var grillButton = document.getElementById("grillButton"); -var dogFarmButton = document.getElementById("dogFarmButton"); -var facButton = document.getElementById("dogFacButton"); -var bankButton = document.getElementById("dogBankButton"); -var bunPriceElement = document.getElementById("bunPrice"); -var dadPriceElement = document.getElementById("dadPrice"); -var grillPriceElement = document.getElementById("grillPrice"); -var farmPriceElement = document.getElementById("farmPrice"); -var facPriceElement = document.getElementById("facPrice"); -var bankPriceElement = document.getElementById("bankPrice"); -var bunImage = document.getElementById("bunImg"); -var dadImage = document.getElementById("dadImg"); -var grillImage = document.getElementById("grillImg"); -var farmImage = document.getElementById("farmImg"); -var facImage = document.getElementById("facImg"); -var bankImage = document.getElementById("bankImg"); -var checkBuyables = function () { +const bunBuyable = "./Can-Buy-Bun-Button.svg"; +const bunUnBuyable = "./Cant-Buy-Bun-Button.svg"; +const bunBuying = "./Buying-Bun-Button.svg"; +const dadBuyable = "./Can-Buy-Dad-Button.svg"; +const dadUnBuyable = "./Cant-Buy-Dad-Button.svg"; +const dadBuying = "./Buying-Dad-Button.svg"; +const grillBuyable = "./Can-Buy-Grill-Button.svg"; +const grillUnBuyable = "./Cant-Buy-Grill-Button.svg"; +const grillBuying = "./Buying-Grill-Button.svg"; +const farmBuyable = "./Can-Buy-Farm-Button.svg"; +const farmUnBuyable = "./Cant-Buy-Farm-Button.svg"; +const farmBuying = "./Buying-Farm-Button.svg"; +const facBuyable = "./Can-Buy-Fac-Button.svg"; +const facUnBuyable = "./Cant-Buy-Fac-Button.svg"; +const facBuying = "./Buying-Fac-Button.svg"; +const bankBuyable = "./Can-Buy-Bank-Button.svg"; +const bankUnBuyable = "./Cant-Buy-Bank-Button.svg"; +const bankBuying = "./Buying-Bank-Button.svg"; +let passiveClicks = 0; +let clickCount = 0; +let bunCount = 0; +let dadCount = 0; +let grillCount = 0; +let farmCount = 0; +let facCount = 0; +let bankCount = 0; +let bunCost = 10; +let bunRate = 0.2; +let dadCost = 100; +let dadRate = 2; +let grillCost = 500; +let grillRate = 10; +let farmCost = 5000; +let farmRate = 50; +let facCost = 50000; +let facRate = 500; +let bankCost = 250000; +let bankRate = 2500; +const increment = 1.3; +const passiveClicksElement = document.getElementById("passive"); +const clickCountElement = document.getElementById("clickCount"); +const grillCountElement = document.getElementById("grillCount"); +const bunCountElement = document.getElementById("bunCount"); +const dadCountElement = document.getElementById("dadCount"); +const farmCountElement = document.getElementById("farmCount"); +const facCountElement = document.getElementById("dogFacCount"); +const bankCountElement = document.getElementById("dogBankCount"); +const hotdogButton = document.getElementById("hotdogButton"); +const bunButton = document.getElementById("bunButton"); +const dadButton = document.getElementById("dadButton"); +const grillButton = document.getElementById("grillButton"); +const farmButton = document.getElementById("farmButton"); +const facButton = document.getElementById("dogFacButton"); +const bankButton = document.getElementById("dogBankButton"); +const bunPriceElement = document.getElementById("bunPrice"); +const dadPriceElement = document.getElementById("dadPrice"); +const grillPriceElement = document.getElementById("grillPrice"); +const farmPriceElement = document.getElementById("farmPrice"); +const facPriceElement = document.getElementById("facPrice"); +const bankPriceElement = document.getElementById("bankPrice"); +const bunImage = document.getElementById("bunImg"); +const dadImage = document.getElementById("dadImg"); +const grillImage = document.getElementById("grillImg"); +const farmImage = document.getElementById("farmImg"); +const facImage = document.getElementById("facImg"); +const bankImage = document.getElementById("bankImg"); +const save = () => { + const set = (key, value) => { + localStorage.setItem(key, value); + }; + set('hotdogs', `${clickCount}`); + set('hotdogs/sec', `${passiveClicks}`); + set('bun', `${bunCount},${bunRate},${bunCost}`); + set('dad', `${dadCount},${dadRate},${dadCost}`); + set('grill', `${grillCount},${grillRate},${grillCost}`); + set('farm', `${farmCount},${farmRate},${farmCost}`); + set('factory', `${facCount},${facRate},${facCost}`); + set('bank', `${bankCount},${bankRate},${bankCost}`); +}; +const checkBuyables = () => { if (clickCount >= bunCost) { bunImage.src = bunBuyable; } @@ -109,7 +123,7 @@ var checkBuyables = function () { bankImage.src = bankUnBuyable; return; } - if (clickCount >= dogFarmCost) { + if (clickCount >= farmCost) { farmImage.src = farmBuyable; } else { @@ -195,17 +209,17 @@ grillButton === null || grillButton === void 0 ? void 0 : grillButton.addEventLi grill === null || grill === void 0 ? void 0 : grill.play(); } }); -dogFarmButton === null || dogFarmButton === void 0 ? void 0 : dogFarmButton.addEventListener("click", function () { - if (clickCount >= dogFarmCost && farmPriceElement != null && clickCountElement != null && dogFarmCountElement != null && passiveClicksElement != null) { - clickCount -= dogFarmCost; - dogFarmCost *= increment; +farmButton === null || farmButton === void 0 ? void 0 : farmButton.addEventListener("click", function () { + if (clickCount >= farmCost && farmPriceElement != null && clickCountElement != null && farmCountElement != null && passiveClicksElement != null) { + clickCount -= farmCost; + farmCost *= increment; checkBuyables(); farmImage.src = farmBuying; - farmPriceElement.textContent = String(dogFarmCost.toFixed(1)); + farmPriceElement.textContent = String(farmCost.toFixed(1)); clickCountElement.textContent = String(clickCount.toFixed(1)); - dogFarmCount++; - dogFarmCountElement.textContent = String(dogFarmCount); - passiveClicks += dogFarmRate; + farmCount++; + farmCountElement.textContent = String(farmCount); + passiveClicks += farmRate; passiveClicksElement.textContent = passiveClicks.toFixed(1); farm === null || farm === void 0 ? void 0 : farm.play(); } @@ -241,12 +255,12 @@ bankButton === null || bankButton === void 0 ? void 0 : bankButton.addEventListe } }); // Upgrades -var mustardCost = 5000; -var tSauceCost = 1000; -var crispCost = 5000; -var tSauceButton = document.getElementById("tSauceButton"); -var mustardButton = document.getElementById("mustardButton"); -var crispButton = document.getElementById("crispButton"); +const mustardCost = 5000; +const tSauceCost = 1000; +const crispCost = 5000; +const tSauceButton = document.getElementById("tSauceButton"); +const mustardButton = document.getElementById("mustardButton"); +const crispButton = document.getElementById("crispButton"); tSauceButton === null || tSauceButton === void 0 ? void 0 : tSauceButton.addEventListener("click", function () { if (clickCount >= tSauceCost && clickCountElement != null && passiveClicksElement != null) { clickCount -= tSauceCost; @@ -281,5 +295,6 @@ setInterval(function () { clickCount += passiveClicks; clickCountElement.textContent = clickCount.toFixed(1); checkBuyables(); + save(); } }, 1000); diff --git a/index.html b/index.html index 506d7aa..21395b3 100644 --- a/index.html +++ b/index.html @@ -63,6 +63,6 @@