X-Git-Url: https://git.xangelo.ca/?a=blobdiff_plain;f=src%2Frender%2Funit-training.ts;h=a1bd4b8756bef6a275f1c07b9609229bf510ce90;hb=9cb3a0584377f61cf3382fef4541246d1b1202bc;hp=5742d9453bf4704df05134fe07f70100e2f8a909;hpb=4e6a9902eb6f57e35e06a03d1e0fa7ba781f8992;p=browser-rts.git diff --git a/src/render/unit-training.ts b/src/render/unit-training.ts index 5742d94..a1bd4b8 100644 --- a/src/render/unit-training.ts +++ b/src/render/unit-training.ts @@ -4,6 +4,16 @@ import { UnitTrainingQueueWithName } from "../repository/training-queue"; import { Unit } from "../repository/unit"; import { DateTime } from "luxon"; +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 ` @@ -16,6 +26,9 @@ function progressBar(current: number, max: number): 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

@@ -90,34 +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 => { - const created = DateTime.fromMillis(queue.created); - const due = DateTime.fromMillis(queue.due); - const now = Date.now() - queue.created; - const duration = queue.due - queue.created; + ${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 ` - - - - - - `; + return ` + + + + + + `; + } }).join("\n")}
Unit TypeAmount ExpectedUnit TypeAmount Expected Progress
You have sufficient queue capacity to train more units.
${queue.display}${queue.amount} - - ${progressBar(now, duration)}
-
-
${queue.display}${queue.amount} + + ${progressBar(now, duration)}
+
+