X-Git-Url: https://git.xangelo.ca/?a=blobdiff_plain;f=src%2Frender%2Funit-training.ts;h=a1bd4b8756bef6a275f1c07b9609229bf510ce90;hb=9cb3a0584377f61cf3382fef4541246d1b1202bc;hp=85cf78d8c1a5ef00d1b75c738ea60d6ccf8eb6a1;hpb=516deaa637cb322ddbb4fb9121d56d23fef5d7a8;p=browser-rts.git
diff --git a/src/render/unit-training.ts b/src/render/unit-training.ts
index 85cf78d..a1bd4b8 100644
--- a/src/render/unit-training.ts
+++ b/src/render/unit-training.ts
@@ -1,113 +1,152 @@
import _ from "lodash";
-import { City } from "../repository/city";
-import { UnitTrainingQueue } from "../repository/training-queue";
+import { CityWithLocation } from "../repository/city";
+import { UnitTrainingQueueWithName } from "../repository/training-queue";
import { Unit } from "../repository/unit";
+import { DateTime } from "luxon";
-function progressBar(current, max): string {
+const emptyQueue: UnitTrainingQueueWithName = {
+ display: '',
+ id: '',
+ owner: '',
+ amount: 0,
+ created: 0,
+ due: 0,
+ unit_type: 'empty'
+}
+
+function progressBar(current: number, max: number): string {
const percent = Math.ceil((current/max) * 100);
return `
-
+
${percent}%
`;
}
-export function renderUnitTraining(city: City, units: Unit[], trainingQueues: UnitTrainingQueue[]): string {
+export function renderUnitTraining(city: CityWithLocation, units: Unit[], trainingQueues: UnitTrainingQueueWithName[]): string {
const unit = _.keyBy(units, 'slug');
+ const sortedTrainingQueue = trainingQueues.sort((a, b) => {
+ return a.due - b.due;
+ });
let html = `
-
+
+
Unit Training
+
+ Unit |
+ Avail.
+ | |
+ Cost |
+
Soldiers |
- ${city.population} Avail. |
+ ${city.soldiers} |
-
-
|
+
|
Attackers |
- ${city.soldiers} Avail. |
+ ${city.attackers} |
-
-
|
+
|
Defenders |
- ${city.soldiers} Avail. |
+ ${city.defenders} |
-
-
|
+ |
Special Attackers |
- ${city.attackers} Avail. |
+ ${city.sp_attackers} |
-
|
+ |
Special Defenders |
- ${city.defenders} Avail. |
+ ${city.sp_defenders} |
-
-
|
+ |
`;
+ const finalTrainingQueue = sortedTrainingQueue;
+ if(finalTrainingQueue.length < city.max_training_queue) {
+ while(finalTrainingQueue.length < city.max_construction_queue) {
+ finalTrainingQueue.push(emptyQueue);
+ }
+ }
+
const queues = `
-
Training Queues
+
Training Queues
- Unit Type |
- Amount Expected |
+ Unit Type |
+ Amount Expected |
Progress |
-
- ${trainingQueues.sort((a, b) => {
- return a.due - b.due;
- }).map(queue => {
+ ${sortedTrainingQueue.map(queue => {
+ if(queue.unit_type === 'empty') {
+ return `
+ You have sufficient queue capacity to train more units. |
+
`;
+ }
+ else {
+ const created = DateTime.fromMillis(queue.created);
+ const due = DateTime.fromMillis(queue.due);
const now = Date.now() - queue.created;
const duration = queue.due - queue.created;
return `
- ${queue.unit_type} |
+ ${queue.display} |
${queue.amount} |
- ${progressBar(now, duration)} |
+
+
+ ${progressBar(now, duration)}
+
+ |
`;
+ }
}).join("\n")}
`;
return html + queues;
-}
\ No newline at end of file
+}