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

@@ -23,96 +37,116 @@ export function renderUnitTraining(city: CityWithLocation, units: Unit[], traini Unit Avail. + Cost Soldiers - ${city.population} + ${city.soldiers} -
- + +
- + Attackers - ${city.soldiers} + ${city.attackers} -
- + +
- + Defenders - ${city.soldiers} + ${city.defenders} -
- + +
- + Special Attackers - ${city.attackers} + ${city.sp_attackers} -
- + +
+ Special Defenders - ${city.defenders} + ${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

- - + + - ${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)}
+
+
`; return html + queues; -} \ No newline at end of file +}