From 96f0ba05a9f0f9e3e6565718cd2247158aeb2eb0 Mon Sep 17 00:00:00 2001 From: xangelo Date: Fri, 3 Jun 2022 15:40:37 -0400 Subject: [PATCH] display the total number of queues availabe to the user --- src/render/land-development.ts | 42 ++++++++++++++++++---- src/render/unit-training.ts | 65 +++++++++++++++++++++++----------- 2 files changed, 80 insertions(+), 27 deletions(-) diff --git a/src/render/land-development.ts b/src/render/land-development.ts index 9cd4eb7..e3643a9 100644 --- a/src/render/land-development.ts +++ b/src/render/land-development.ts @@ -3,7 +3,16 @@ import { CityWithLocation } from "../repository/city"; import { Building } from '../repository/buildings'; import _ from "lodash"; -function progressBar(current, max): string { +const emptyBuilding: BuildQueue = { + id: '', + owner: '', + amount: 0, + created: 0, + due: 0, + building_type: 'empty', +}; + +function progressBar(current: number, max: number): string { const percent = Math.ceil((current/max) * 100); return `

Construction

@@ -47,19 +60,33 @@ export function renderLandDevelopment(city: CityWithLocation, buildings: Buildin `; const quickFindBuilding = _.keyBy(buildings, 'slug'); + const finalBuildQueues = sortedBuildQueues; + + if (finalBuildQueues.length < city.max_construction_queue) { + while(finalBuildQueues.length < city.max_construction_queue) { + finalBuildQueues.push(emptyBuilding); + } + } + const queues = `

Build Queues

- - - + + + - ${buildQueues.sort((a, b) => { - return a.due - b.due; - }).map(queue => { + ${sortedBuildQueues.map(queue => { + if(queue.building_type === 'empty') { + return ` + + + + ` + } + else { const now = Date.now() - queue.created; const duration = queue.due - queue.created; @@ -70,6 +97,7 @@ export function renderLandDevelopment(city: CityWithLocation, buildings: Buildin `; + } }).join("\n")}
BuildingAmount ExpectedProgressBuildingAmount ExpectedProgress
You have sufficient capacity to build something.
${progressBar(now, duration)}
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)}
+
+
-- 2.25.1