Home
/
browser-rts.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ability to cancel construction and have a portion of the funds returned
[browser-rts.git]
/
src
/
render
/
costs.ts
diff --git
a/src/render/costs.ts
b/src/render/costs.ts
index 03082a33a397506b500cf048b4eb6644a9396242..4f9617b6084c734da545f22b4d2cbce7d7b08937 100644
(file)
--- 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,
type Cost = {
credits: number,
time: number,
@@
-11,44
+13,52
@@
type Cost = {
defenders?: number
}
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 `
<div>
<b>${display}:</b>
return `
<div>
<b>${display}:</b>
- <span class="text">${value.toLocaleString()}</span>
+ <span class="text
${className}
">${value.toLocaleString()}</span>
</div>
`;
}
</div>
`;
}
-export function renderCost(cost: Cost): string {
+export function renderCost(cost: Cost
, city: City
): string {
const costAsArray = [];
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) {
if(cost.alloys) {
- costAsArray.push(lineItem('Alloys', cost.alloys));
+ costAsArray.push(lineItem('Alloys', cost.alloys
, city.alloys
));
}
if(cost.food) {
}
if(cost.food) {
- costAsArray.push(lineItem('Food', cost.food));
+ costAsArray.push(lineItem('Food', cost.food
, city.food
));
}
if(cost.energy) {
}
if(cost.energy) {
- costAsArray.push(lineItem('Energy', cost.energy));
+ costAsArray.push(lineItem('Energy', cost.energy
, city.energy
));
}
if(cost.land) {
}
if(cost.land) {
- costAsArray.push(lineItem('Space', cost.land));
+ costAsArray.push(lineItem('Space', cost.land
, city.totalSpace - city.usedSpace
));
}
if(cost.population) {
}
if(cost.population) {
- costAsArray.push(lineItem('Pop', cost.population));
+ costAsArray.push(lineItem('Pop', cost.population
, city.population
));
}
if(cost.soldiers) {
}
if(cost.soldiers) {
- costAsArray.push(lineItem('Soldiers', cost.soldiers));
+ costAsArray.push(lineItem('Soldiers', cost.soldiers
, city.soldiers
));
}
if(cost.attackers) {
}
if(cost.attackers) {
- costAsArray.push(lineItem('Attackers', cost.attackers));
+ costAsArray.push(lineItem('Attackers', cost.attackers
, city.attackers
));
}
if(cost.defenders) {
}
if(cost.defenders) {
- costAsArray.push(lineItem('Defenders', cost.defenders));
+ costAsArray.push(lineItem('Defenders', cost.defenders
, city.defenders
));
}
}