X-Git-Url: https://git.xangelo.ca/?a=blobdiff_plain;f=src%2Frender%2Funit-training.ts;h=a1bd4b8756bef6a275f1c07b9609229bf510ce90;hb=9cb3a0584377f61cf3382fef4541246d1b1202bc;hp=686b57b16c86bed51b6ba7fc0b74eff256828836;hpb=eb5ad7ba9d5acdbfb1561f0b31483139977bf65c;p=browser-rts.git diff --git a/src/render/unit-training.ts b/src/render/unit-training.ts index 686b57b..a1bd4b8 100644 --- a/src/render/unit-training.ts +++ b/src/render/unit-training.ts @@ -1,9 +1,20 @@ import _ from "lodash"; import { CityWithLocation } from "../repository/city"; -import { UnitTrainingQueue } from "../repository/training-queue"; +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 `

Unit Training

@@ -29,8 +43,8 @@ export function renderUnitTraining(city: CityWithLocation, units: Unit[], traini Soldiers ${city.soldiers} -
- + +
@@ -41,8 +55,8 @@ export function renderUnitTraining(city: CityWithLocation, units: Unit[], traini Attackers ${city.attackers} -
- + +
@@ -53,8 +67,8 @@ export function renderUnitTraining(city: CityWithLocation, units: Unit[], traini Defenders ${city.defenders} -
- + +
@@ -65,8 +79,8 @@ export function renderUnitTraining(city: CityWithLocation, units: Unit[], traini Special Attackers ${city.sp_attackers} -
- + +
@@ -78,8 +92,8 @@ export function renderUnitTraining(city: CityWithLocation, units: Unit[], traini Special Defenders ${city.sp_defenders} -
- + +
@@ -89,28 +103,46 @@ export function renderUnitTraining(city: CityWithLocation, units: Unit[], traini `; + const finalTrainingQueue = sortedTrainingQueue; + if(finalTrainingQueue.length < city.max_training_queue) { + while(finalTrainingQueue.length < city.max_construction_queue) { + finalTrainingQueue.push(emptyQueue); + } + } + const queues = `

Training Queues

- - + + - ${trainingQueues.sort((a, b) => { - return a.due - b.due; - }).map(queue => { + ${sortedTrainingQueue.map(queue => { + if(queue.unit_type === 'empty') { + return ` + + `; + } + 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 ` - + - + `; + } }).join("\n")}
Unit TypeAmount ExpectedUnit TypeAmount Expected Progress
You have sufficient queue capacity to train more units.
${queue.unit_type}${queue.display} ${queue.amount}${progressBar(now, duration)} + + ${progressBar(now, duration)}
+
+