From a4329d42ee9c454b3cd472c8f72323318a22e913 Mon Sep 17 00:00:00 2001 From: michaelabilliot Date: Sat, 19 Apr 2025 22:09:41 +0300 Subject: [PATCH] Add category to singleplayer (#449) ## Description: Just simply adds categories to the single player menu ![Screenshot 2025-04-11 at 05 40 49](https://github.com/user-attachments/assets/e6811b69-5abf-427f-9989-55f4538b034f) Fixes #453 ## Please complete the following: - [X] I have added screenshots for all UI updates - [X] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [X] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors ## Please put your Discord username so you can be contacted if a bug or regression is found: lunhuiyan1718 --- resources/lang/en.json | 5 +++ src/client/HostLobbyModal.ts | 60 +++++++++++++++++++++++---------- src/client/SinglePlayerModal.ts | 59 +++++++++++++++++++++----------- src/core/game/Game.ts | 23 +++++++++++++ 4 files changed, 109 insertions(+), 38 deletions(-) diff --git a/resources/lang/en.json b/resources/lang/en.json index c2b7d0425..aa090c7b0 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -123,6 +123,11 @@ "knownworld": "Known World", "faroeislands": "Faroe Islands" }, + "map_categories": { + "continental": "Continental", + "regional": "Regional", + "fantasy": "Other" + }, "private_lobby": { "title": "Join Private Lobby", "enter_id": "Enter Lobby ID", diff --git a/src/client/HostLobbyModal.ts b/src/client/HostLobbyModal.ts index 5dbe32865..a9d605eb3 100644 --- a/src/client/HostLobbyModal.ts +++ b/src/client/HostLobbyModal.ts @@ -4,7 +4,12 @@ import randomMap from "../../resources/images/RandomMap.webp"; import { translateText } from "../client/Utils"; import { getServerConfigFromClient } from "../core/configuration/ConfigLoader"; import { consolex } from "../core/Consolex"; -import { Difficulty, GameMapType, GameMode } from "../core/game/Game"; +import { + Difficulty, + GameMapType, + GameMode, + mapCategories, +} from "../core/game/Game"; import { GameConfig, GameInfo } from "../core/Schemas"; import { generateID } from "../core/Util"; import "./components/baseComponents/Modal"; @@ -74,23 +79,40 @@ export class HostLobbyModal extends LitElement {
${translateText("map.map")}
-
- ${Object.entries(GameMapType) - .filter(([key]) => isNaN(Number(key))) - .map( - ([key, value]) => html` -
this.handleMapSelection(value)}> - +
+ + ${Object.entries(mapCategories).map( + ([categoryKey, maps]) => html` +
+

+ ${translateText(`map_categories.${categoryKey}`)} +

+
+ ${maps.map((mapValue) => { + const mapKey = Object.keys(GameMapType).find( + (key) => GameMapType[key] === mapValue, + ); + return html` +
this.handleMapSelection(mapValue)} + > + +
+ `; + })}
- `, - )} +
+ `, + )}
-
${translateText("map.random")}
+
+ ${translateText("map.random")} +
diff --git a/src/client/SinglePlayerModal.ts b/src/client/SinglePlayerModal.ts index d7dd675ff..6a8438f6f 100644 --- a/src/client/SinglePlayerModal.ts +++ b/src/client/SinglePlayerModal.ts @@ -3,7 +3,13 @@ import { customElement, query, state } from "lit/decorators.js"; import randomMap from "../../resources/images/RandomMap.webp"; import { translateText } from "../client/Utils"; import { consolex } from "../core/Consolex"; -import { Difficulty, GameMapType, GameMode, GameType } from "../core/game/Game"; +import { + Difficulty, + GameMapType, + GameMode, + GameType, + mapCategories, +} from "../core/game/Game"; import { generateID } from "../core/Util"; import "./components/baseComponents/Button"; import "./components/baseComponents/Modal"; @@ -39,27 +45,40 @@ export class SinglePlayerModal extends LitElement {
${translateText("map.map")}
-
- ${Object.entries(GameMapType) - .filter(([key]) => isNaN(Number(key))) - .map( - ([key, value]) => html` -
+ + ${Object.entries(mapCategories).map( + ([categoryKey, maps]) => html` +
+

- + ${translateText(`map_categories.${categoryKey}`)} +

+
+ ${maps.map((mapValue) => { + const mapKey = Object.keys(GameMapType).find( + (key) => GameMapType[key] === mapValue, + ); + return html` +
this.handleMapSelection(mapValue)} + > + +
+ `; + })}
- `, - )} +
+ `, + )}
= { + continental: [ + GameMapType.World, + GameMapType.NorthAmerica, + GameMapType.SouthAmerica, + GameMapType.Europe, + GameMapType.Asia, + GameMapType.Africa, + GameMapType.Oceania, + ], + regional: [ + GameMapType.BlackSea, + GameMapType.Britannia, + GameMapType.GatewayToTheAtlantic, + GameMapType.BetweenTwoSeas, + GameMapType.Iceland, + GameMapType.Japan, + GameMapType.Mena, + GameMapType.Australia, + ], + fantasy: [GameMapType.Pangaea, GameMapType.Mars, GameMapType.KnownWorld], +}; + export enum GameType { Singleplayer = "Singleplayer", Public = "Public",