X-Git-Url: https://git.xangelo.ca/?a=blobdiff_plain;f=src%2Frender%2Fcosts.ts;h=4f9617b6084c734da545f22b4d2cbce7d7b08937;hb=9cb3a0584377f61cf3382fef4541246d1b1202bc;hp=03082a33a397506b500cf048b4eb6644a9396242;hpb=944376c3f73772268ec774ccc2a3fa0788fc246e;p=browser-rts.git diff --git a/src/render/costs.ts b/src/render/costs.ts index 03082a3..4f9617b 100644 --- a/src/render/costs.ts +++ b/src/render/costs.ts @@ -1,3 +1,5 @@ +import {City} from "../repository/city"; + type Cost = { credits: number, time: number, @@ -11,44 +13,52 @@ type Cost = { defenders?: number } -function lineItem(display: string, value: number): string { +function lineItem(display: string, value: number, available: number): string { + let className = ''; + + if(available < value && available >= 0) { + className = 'danger-text'; + } + else if(available >= value) { + className = 'success-text'; + } return `
${display}: - ${value.toLocaleString()} + ${value.toLocaleString()}
`; } -export function renderCost(cost: Cost): string { +export function renderCost(cost: Cost, city: City): string { const costAsArray = []; - costAsArray.push(lineItem('Credits', cost.credits)); - costAsArray.push(lineItem('Time', cost.time)); + costAsArray.push(lineItem('Credits', cost.credits, city.credits)); + costAsArray.push(lineItem('Time', cost.time, -1)); if(cost.alloys) { - costAsArray.push(lineItem('Alloys', cost.alloys)); + costAsArray.push(lineItem('Alloys', cost.alloys, city.alloys)); } if(cost.food) { - costAsArray.push(lineItem('Food', cost.food)); + costAsArray.push(lineItem('Food', cost.food, city.food)); } if(cost.energy) { - costAsArray.push(lineItem('Energy', cost.energy)); + costAsArray.push(lineItem('Energy', cost.energy, city.energy)); } if(cost.land) { - costAsArray.push(lineItem('Space', cost.land)); + costAsArray.push(lineItem('Space', cost.land, city.totalSpace - city.usedSpace)); } if(cost.population) { - costAsArray.push(lineItem('Pop', cost.population)); + costAsArray.push(lineItem('Pop', cost.population, city.population)); } if(cost.soldiers) { - costAsArray.push(lineItem('Soldiers', cost.soldiers)); + costAsArray.push(lineItem('Soldiers', cost.soldiers, city.soldiers)); } if(cost.attackers) { - costAsArray.push(lineItem('Attackers', cost.attackers)); + costAsArray.push(lineItem('Attackers', cost.attackers, city.attackers)); } if(cost.defenders) { - costAsArray.push(lineItem('Defenders', cost.defenders)); + costAsArray.push(lineItem('Defenders', cost.defenders, city.defenders)); }