From 4d31d9d7484be5229977fdb9be409fb538468d94 Mon Sep 17 00:00:00 2001 From: PeekabooSteam Date: Wed, 18 Oct 2023 10:23:50 +0100 Subject: [PATCH 1/2] Unit spawn qty now sorted numerically. --- client/src/controls/dropdown.ts | 17 +++++++++++++++-- client/src/controls/unitspawnmenu.ts | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/client/src/controls/dropdown.ts b/client/src/controls/dropdown.ts index c7823856..8af9baf9 100644 --- a/client/src/controls/dropdown.ts +++ b/client/src/controls/dropdown.ts @@ -36,8 +36,21 @@ export class Dropdown { return this.#container; } - setOptions(optionsList: string[], sortAlphabetically: boolean = true) { - this.#optionsList = optionsList.sort(); + setOptions(optionsList: string[], sort:""|"string"|"number" = "string") { + + if ( sort === "number" ) { + this.#optionsList = optionsList.sort( (optionA:string, optionB:string) => { + const a = parseInt( optionA ); + const b = parseInt( optionB ); + if ( a > b ) + return 1; + else + return ( b > a ) ? -1 : 0; + }); + } else if ( sort === "string" ) { + this.#optionsList = optionsList.sort(); + } + if (this.#optionsList.length == 0) { optionsList = ["No options available"] this.#value.innerText = "No options available"; diff --git a/client/src/controls/unitspawnmenu.ts b/client/src/controls/unitspawnmenu.ts index f7d53d9d..442f6f73 100644 --- a/client/src/controls/unitspawnmenu.ts +++ b/client/src/controls/unitspawnmenu.ts @@ -346,7 +346,7 @@ export class UnitSpawnMenu { var countOptions: string[] = []; for (let i = 1; i <= maxUnitCount; i++) countOptions.push(i.toString()); - this.#unitCountDropdown.setOptions(countOptions); + this.#unitCountDropdown.setOptions(countOptions, "number"); this.#unitCountDropdown.selectValue(0); } From e4e55430ca0e34a47165b884e05f73d8fd3196c4 Mon Sep 17 00:00:00 2001 From: PeekabooSteam Date: Wed, 18 Oct 2023 11:17:05 +0100 Subject: [PATCH 2/2] Optimised quantity option generator --- client/src/controls/unitspawnmenu.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/client/src/controls/unitspawnmenu.ts b/client/src/controls/unitspawnmenu.ts index 442f6f73..7c5b88ef 100644 --- a/client/src/controls/unitspawnmenu.ts +++ b/client/src/controls/unitspawnmenu.ts @@ -343,10 +343,7 @@ export class UnitSpawnMenu { setMaxUnitCount(maxUnitCount: number) { /* Create the unit count options */ - var countOptions: string[] = []; - for (let i = 1; i <= maxUnitCount; i++) - countOptions.push(i.toString()); - this.#unitCountDropdown.setOptions(countOptions, "number"); + this.#unitCountDropdown.setOptions( [...Array(maxUnitCount).keys()].map( n => (n+1).toString() ), "number"); this.#unitCountDropdown.selectValue(0); }