From ff0d614b1eb0b4b407da8aa0a54952d274af7fd4 Mon Sep 17 00:00:00 2001 From: Aotumuri Date: Thu, 25 Sep 2025 03:11:18 +0900 Subject: [PATCH] Add game-list (#2087) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description: This PR adds the game-list component, which displays a player’s recent games. It provides basic functionality such as toggling details and viewing a specific game, but does not yet include full UI integration. In later PRs, this component will be shown together with the modal for viewing player stats. It should look like this: スクリーンショット 2025-09-23 10 04 19 ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: aotumuri https://github.com/openfrontio/OpenFrontIO/pull/1758 --- resources/lang/en.json | 13 ++ .../baseComponents/stats/GameList.ts | 150 ++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 src/client/components/baseComponents/stats/GameList.ts diff --git a/resources/lang/en.json b/resources/lang/en.json index ff4251dff..4f41c9347 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -647,5 +647,18 @@ "radial_menu": { "delete_unit_title": "Delete Unit", "delete_unit_description": "Click to delete the nearest unit" + }, + "game_list": { + "recent_games": "Recent Games", + "game_id": "Game ID", + "mode": "Mode", + "mode_ffa": "Free-for-All", + "mode_team": "Team", + "view": "View", + "details": "Details", + "started": "Started", + "map": "Map", + "difficulty": "Difficulty", + "type": "Type" } } diff --git a/src/client/components/baseComponents/stats/GameList.ts b/src/client/components/baseComponents/stats/GameList.ts new file mode 100644 index 000000000..83b50489b --- /dev/null +++ b/src/client/components/baseComponents/stats/GameList.ts @@ -0,0 +1,150 @@ +import { LitElement, css, html } from "lit"; +import { customElement, property, state } from "lit/decorators.js"; +import { PlayerGame } from "../../../../core/ApiSchemas"; +import { GameMode } from "../../../../core/game/Game"; +import { translateText } from "../../../Utils"; + +@customElement("game-list") +export class GameList extends LitElement { + static styles = css` + .section-title { + color: #888; + font-size: 1rem; + font-weight: bold; + margin-bottom: 0.5rem; + } + .card { + background: rgba(255, 255, 255, 0.05); + border: 1px solid rgba(255, 255, 255, 0.1); + border-radius: 0.5rem; + overflow: hidden; + transition: all 0.3s ease; + } + .row { + display: flex; + align-items: center; + justify-content: space-between; + padding: 0.5rem 1rem; + } + .title { + font-size: 0.875rem; + font-weight: 600; + color: white; + } + .subtle { + font-size: 0.75rem; + color: #9ca3af; + } + .btn { + font-size: 0.875rem; + color: #d1d5db; + background: #374151; + padding: 0.25rem 0.75rem; + border-radius: 0.25rem; + } + .btn.secondary { + background: #4b5563; + } + .details { + padding: 0 1rem 0.5rem 1rem; + font-size: 0.75rem; + color: #d1d5db; + transition: all 0.3s ease; + } + `; + + @property({ type: Array }) games: PlayerGame[] = []; + @property({ attribute: false }) onViewGame?: (id: string) => void; + + @state() private expandedGameId: string | null = null; + + private toggle(gameId: string) { + this.expandedGameId = this.expandedGameId === gameId ? null : gameId; + } + + render() { + return html`
+
+
+ 🎮 ${translateText("game_list.recent_games")} +
+
+ ${this.games.map( + (game) => html` +
+
+
+
+ ${translateText("game_list.game_id")}: ${game.gameId} +
+
+ ${translateText("game_list.mode")}: + ${game.mode === GameMode.FFA + ? translateText("game_list.mode_ffa") + : html`${translateText("game_list.mode_team")}`} +
+
+
+ + +
+
+
+
+ ${translateText("game_list.started")}: + ${new Date(game.start).toLocaleString()} +
+
+ ${translateText("game_list.mode")}: + ${game.mode === GameMode.FFA + ? translateText("game_list.mode_ffa") + : translateText("game_list.mode_team")} +
+
+ ${translateText("game_list.map")}: + ${game.map} +
+
+ ${translateText("game_list.difficulty")}: + ${game.difficulty} +
+
+ ${translateText("game_list.type")}: + ${game.type} +
+
+
+ `, + )} +
+
+
`; + } +}