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); }