03082a33a397506b500cf048b4eb6644a9396242
[browser-rts.git] / src / render / costs.ts
1 type Cost = {
2   credits: number,
3   time: number,
4   alloys?: number,
5   energy?: number,
6   land?: number,
7   food?: number,
8   population?: number,
9   soldiers?: number
10   attackers?: number,
11   defenders?: number
12 }
13
14 function lineItem(display: string, value: number): string {
15   return `
16   <div>
17     <b>${display}:</b>
18     <span class="text">${value.toLocaleString()}</span>
19   </div>
20   `;
21 }
22
23 export function renderCost(cost: Cost): string {
24   const costAsArray = [];
25
26   costAsArray.push(lineItem('Credits', cost.credits));
27   costAsArray.push(lineItem('Time', cost.time));
28
29   if(cost.alloys) {
30     costAsArray.push(lineItem('Alloys', cost.alloys));
31   }
32   if(cost.food) {
33     costAsArray.push(lineItem('Food', cost.food));
34   }
35   if(cost.energy) {
36     costAsArray.push(lineItem('Energy', cost.energy));
37   }
38   if(cost.land) {
39     costAsArray.push(lineItem('Space', cost.land));
40   }
41   if(cost.population) {
42     costAsArray.push(lineItem('Pop', cost.population));
43   }
44   if(cost.soldiers) {
45     costAsArray.push(lineItem('Soldiers', cost.soldiers));
46   }
47   if(cost.attackers) {
48     costAsArray.push(lineItem('Attackers', cost.attackers));
49   }
50   if(cost.defenders) {
51     costAsArray.push(lineItem('Defenders', cost.defenders));
52   }
53
54
55   return `<div class="cost-display">${costAsArray.join("")}</div>`;
56 }