allow cancelling of training queues
[browser-rts.git] / src / render / kingdom-overview.ts
index d82f6a411d80042c23423a5fd1155f0aaf351eb8..2e787d6bdf82daaebe49e27d11d21ef142463366 100644 (file)
@@ -1,53 +1,78 @@
 import { Account } from "../repository/accounts";
-import { CityWithLocation } from "../repository/city";
+import { CityWithLocation, CityRepository } from "../repository/city";
 import * as _ from 'lodash';
 
-export function renderKingomOverview(city: CityWithLocation, account: Account): string {
+function percent(curr: number, max: number, cap?: number): number {
+  const val = Math.ceil((curr/max) * 100);
+  if(cap && val > cap) {
+    return cap;
+  }
+
+  return val;
+}
+
+type Usage = {
+  foodUsagePerTick: number;
+  foodProductionPerTick: number;
+  energyUsagePerTick: number;
+  energyProductionPerTick: number;
+}
+
+const cityRepo = new CityRepository();
+
+export function renderKingomOverview(city: CityWithLocation & Usage, account: Account): string {
+  const foodRateOfChange = city.foodProductionPerTick - city.foodUsagePerTick;
+  const energyRateOfChange = city.energyProductionPerTick - city.energyUsagePerTick;
     return `
        <div hx-trigger="every 600s" hx-get="/poll/overview">
-       <h2 data-augmented-ui="tl-clip bl-clip none">Kingdom Overview</h2>
+       <h2 data-augmented-ui="tl-clip bl-clip none">Overview</h2>
        <table>
        <tr>
-               <th>Lord</th>
+               <th>Captain</th>
                <td>${account.username}</td>
                <th>Population</th>
-               <td>${city.population.toLocaleString()}/${_.max([city.farms * 70, city.population])}</td>
+               <td>${city.population.toLocaleString()}/${cityRepo.maxPopulation(city)}</td>
        </tr>
        <tr>
-               <th>Land</th>
+               <th>Space</th>
                <td>${city.totalSpace.toLocaleString()} (${Math.ceil(city.usedSpace/city.totalSpace * 100)}% used)</td>
                <th>Soldiers</th>
                <td>${city.soldiers.toLocaleString()}</td>
        </tr>
        <tr>
                <th>Location</th>
-               <td>${city.location_x},${city.location_y}</td>
+               <td>Sector ${city.sector_id} - (${city.location_x},${city.location_y})</td>
                <th>Attackers</th>
                <td>${city.attackers.toLocaleString()}</td>
        </tr>
        <tr>
-               <th>Gold</th>
-               <td>${city.gold.toLocaleString()}</td>
+               <th>Credits</th>
+               <td>${city.credits.toLocaleString()}</td>
                <th>Defenders</th>
                <td>${city.defenders.toLocaleString()}</td>
        </tr>
        <tr>
-               <th>Ore</th>
-               <td>${city.ore.toLocaleString()}</td>
+               <th>Alloys</th>
+               <td>${city.alloys.toLocaleString()} @ ${percent(city.alloys, cityRepo.maxAlloy(city), 100)} % Ore Refiniery Utilization</td>
                <th>Special Attackers</th>
                <td>${city.sp_attackers.toLocaleString()}</td>
        </tr>
        <tr>
-               <th>Logs</th>
-               <td>${city.logs.toLocaleString()}</td>
+               <th>Energy</th>
+               <td>
+    ${city.energy.toLocaleString()} (<span class="rate-of-change ${energyRateOfChange < 0 ? 'danger-text' : 'success-text'}">${energyRateOfChange.toLocaleString()}</span>)
+    @ ${percent(city.energy, cityRepo.maxEnergy(city), 100)}% Accumulator Utilization
+    </td>
                <th>Special Defenders</th>
                <td>${city.sp_defenders.toLocaleString()}</td>
        </tr>
        <tr>
-               <th>Bushels</th>
-               <td>${city.bushels.toLocaleString()}</td>
+               <th>Food</th>
+               <td>
+    ${city.food.toLocaleString()} (<span class="rate-of-change ${foodRateOfChange < 0 ? 'danger-text' : 'success-text'}">${foodRateOfChange.toLocaleString()}</span>) @ ${percent(city.food, cityRepo.maxFood(city), 100)}% Warehouse utilization
+    </td>
        </tr>
        </table>
        </div>
        `;
-}
\ No newline at end of file
+}