diff --git a/src/main.ts b/src/main.ts index dd9b2c5b..18e7fe7b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,7 @@ import "./style.css"; +// Constants + const GAME_TITLE = "Feed the Fire"; const GAME_PREMISE = ` You have discovered a new way to generate energy @@ -18,19 +20,6 @@ const BASIC_ACTION_DESCRIPTION = "🔥 Makes things hotter."; const ITEM_COST_GROWTH_BASE = 1.15; const DECIMAL_PRECISION = 1; -function arrayToRecord( - ts: readonly T[], k: (t: T) => K, v: (t: T) => V -) { - return Object.fromEntries(ts.map(t => [k(t), v(t)])) as Record; -} - -interface Item { - name: ItemName, - cost: number, - rate: number, - description: string -} - const availableItems = [ {name: 'Cellphone', cost: 10, rate: 0.1, description: "📱 " + "Hello? Hello? Can you hear me?"}, @@ -44,12 +33,25 @@ const availableItems = [ "Invented to... hm... No, wait, this hasn't been invented yet."} ] as const; -type ItemName = typeof availableItems[number]['name']; +// Interfaces and utility functions -function getItemRealCost(item: Item, alreadyHave: number): number { - return item.cost*(ITEM_COST_GROWTH_BASE**alreadyHave); +function arrayToRecord( + ts: readonly T[], k: (t: T) => K, v: (t: T) => V +) { + return Object.fromEntries(ts.map(t => [k(t), v(t)])) as Record; +} + +interface Item { + name: ItemName, + cost: number, + rate: number, + description: string } +type ItemName = typeof availableItems[number]['name']; + +// Game logic + let gameState = { globalWarmingIndex: 0, globalWarmingRate: 0, @@ -60,6 +62,10 @@ function doBasicAction(state: typeof gameState) { state.globalWarmingIndex += 1; } +function getItemRealCost(item: Item, alreadyHave: number): number { + return item.cost*(ITEM_COST_GROWTH_BASE**alreadyHave); +} + function canAffordItem(state: typeof gameState, item: Item): boolean { return state.globalWarmingIndex >= getItemRealCost(item, state.itemQuantities[item.name]); @@ -79,6 +85,8 @@ function tickGameState(state: typeof gameState, interval: number) { state.globalWarmingIndex += state.globalWarmingRate*interval/MSEC_PER_SEC; } +// UI + document.title = GAME_TITLE; const app: HTMLDivElement = document.querySelector('#app')!;