X-Git-Url: https://git.xangelo.ca/?a=blobdiff_plain;f=src%2Frender%2Funit-training.ts;h=a1bd4b8756bef6a275f1c07b9609229bf510ce90;hb=9cb3a0584377f61cf3382fef4541246d1b1202bc;hp=a177dec3cbec67caf3a1a7d64a99d425ab085f56;hpb=ed54ffb9b589bd35842561fd6cd13779e836b8eb;p=browser-rts.git diff --git a/src/render/unit-training.ts b/src/render/unit-training.ts index a177dec..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

@@ -30,8 +43,8 @@ export function renderUnitTraining(city: CityWithLocation, units: Unit[], traini Soldiers ${city.soldiers} -
- + +
@@ -42,8 +55,8 @@ export function renderUnitTraining(city: CityWithLocation, units: Unit[], traini Attackers ${city.attackers} -
- + +
@@ -54,8 +67,8 @@ export function renderUnitTraining(city: CityWithLocation, units: Unit[], traini Defenders ${city.defenders} -
- + +
@@ -66,8 +79,8 @@ export function renderUnitTraining(city: CityWithLocation, units: Unit[], traini Special Attackers ${city.sp_attackers} -
- + +
@@ -79,8 +92,8 @@ export function renderUnitTraining(city: CityWithLocation, units: Unit[], traini Special Defenders ${city.sp_defenders} -
- + +
@@ -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)}
+
+