From 74cad570d157af1a98e32958f40879d56347aadc Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Fri, 30 May 2025 12:02:07 -0400 Subject: [PATCH 01/10] Resolve code scanning warning about HTML injection (#953) ## Description: Resolve code scanning warning about HTML injection with copilot suggested fix. ## 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 - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com> --- src/client/graphics/layers/NameLayer.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/client/graphics/layers/NameLayer.ts b/src/client/graphics/layers/NameLayer.ts index 2f8c36a3d..0d56c76e4 100644 --- a/src/client/graphics/layers/NameLayer.ts +++ b/src/client/graphics/layers/NameLayer.ts @@ -218,10 +218,19 @@ export class NameLayer implements Layer { shieldDiv.style.display = "flex"; shieldDiv.style.alignItems = "center"; shieldDiv.style.gap = "0px"; - shieldDiv.innerHTML = ` - - 0 - `; + const shieldImg = document.createElement("img"); + shieldImg.src = this.shieldIconImage.src; + shieldImg.style.width = "16px"; + shieldImg.style.height = "16px"; + + const shieldSpan = document.createElement("span"); + shieldSpan.textContent = "0"; + shieldSpan.style.color = "black"; + shieldSpan.style.fontSize = "10px"; + shieldSpan.style.marginTop = "-2px"; + + shieldDiv.appendChild(shieldImg); + shieldDiv.appendChild(shieldSpan); element.appendChild(shieldDiv); // Start off invisible so it doesn't flash at 0,0 From 838973a11b82a3ef07fdb20d0fb6b818f26ceb9f Mon Sep 17 00:00:00 2001 From: Demonessica <37988730+Demonessica@users.noreply.github.com> Date: Fri, 30 May 2025 09:03:04 -0700 Subject: [PATCH 02/10] Fix invalid username popup being behind public game button (#951) ## Description: one hour of fucking around with git later: fixes the invalid username popup being behind the public game button and accepts the close label fix from #949 ![image](https://github.com/user-attachments/assets/ab65ab56-79fc-4c72-8c99-a50521c2faaf) ## 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 - [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: demonessica --- src/client/UsernameInput.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/UsernameInput.ts b/src/client/UsernameInput.ts index 1f699da06..c0cd900c9 100644 --- a/src/client/UsernameInput.ts +++ b/src/client/UsernameInput.ts @@ -47,7 +47,7 @@ export class UsernameInput extends LitElement { /> ${this.validationError ? html`
${this.validationError}
` From 2a3240da1c70213b73c83120cd8912b6c2167201 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Fri, 30 May 2025 12:10:00 -0400 Subject: [PATCH 03/10] Server role lookup (#954) ## Description: - Validate that user tokens are accepted by the API server, in case of token revoked / remote logout. - Lookup user roles by their token. - Sets the groundwork for validating custom flag codes, patterns, etc. ## 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 - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com> --- src/core/ApiSchemas.ts | 4 ---- src/server/Client.ts | 1 + src/server/Worker.ts | 18 ++++++++++++++++-- src/server/jwt.ts | 35 ++++++++++++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/core/ApiSchemas.ts b/src/core/ApiSchemas.ts index 1c594e1a7..112ddc8b9 100644 --- a/src/core/ApiSchemas.ts +++ b/src/core/ApiSchemas.ts @@ -28,10 +28,6 @@ export const TokenPayloadSchema = z.object({ iss: z.string(), aud: z.string(), exp: z.number(), - rol: z - .string() - .optional() - .transform((val) => (val ?? "").split(",")), }); export type TokenPayload = z.infer; diff --git a/src/server/Client.ts b/src/server/Client.ts index 216150dbf..6eff8b1b8 100644 --- a/src/server/Client.ts +++ b/src/server/Client.ts @@ -12,6 +12,7 @@ export class Client { public readonly clientID: ClientID, public readonly persistentID: string, public readonly claims: TokenPayload | null, + public readonly roles: string[] | null, public readonly ip: string, public readonly username: string, public readonly ws: WebSocket, diff --git a/src/server/Worker.ts b/src/server/Worker.ts index e9fb2131a..2ec20a3fd 100644 --- a/src/server/Worker.ts +++ b/src/server/Worker.ts @@ -19,7 +19,7 @@ import { archive, readGameRecord } from "./Archive"; import { Client } from "./Client"; import { GameManager } from "./GameManager"; import { gatekeeper, LimiterType } from "./Gatekeeper"; -import { verifyClientToken } from "./jwt"; +import { getUserMe, verifyClientToken } from "./jwt"; import { logger } from "./Logger"; import { initWorkerMetrics } from "./WorkerMetrics"; @@ -316,11 +316,25 @@ export function startWorker() { config, ); + const roles: string[] | null = null; + + // Check user roles + if (claims !== null) { + const result = await getUserMe(clientMsg.token, config); + if (result === false) { + log.warn("Token is not valid", claims); + return; + } + } + + // TODO: Validate client settings based on roles + // Create client and add to game const client = new Client( clientMsg.clientID, persistentId, - claims ?? null, + claims, + roles, ip, clientMsg.username, ws, diff --git a/src/server/jwt.ts b/src/server/jwt.ts index 150402a5f..c7896bd91 100644 --- a/src/server/jwt.ts +++ b/src/server/jwt.ts @@ -1,5 +1,10 @@ import { jwtVerify } from "jose"; -import { TokenPayload, TokenPayloadSchema } from "../core/ApiSchemas"; +import { + TokenPayload, + TokenPayloadSchema, + UserMeResponse, + UserMeResponseSchema, +} from "../core/ApiSchemas"; import { ServerConfig } from "../core/configuration/Config"; type TokenVerificationResult = { @@ -27,3 +32,31 @@ export async function verifyClientToken( const persistentId = claims.sub; return { persistentId, claims }; } + +export async function getUserMe( + token: string, + config: ServerConfig, +): Promise { + try { + // Get the user object + const response = await fetch(config.jwtIssuer() + "/users/@me", { + headers: { + authorization: `Bearer ${token}`, + }, + }); + if (response.status !== 200) return false; + const body = await response.json(); + const result = UserMeResponseSchema.safeParse(body); + if (!result.success) { + console.error( + "Invalid response", + JSON.stringify(body), + JSON.stringify(result.error), + ); + return false; + } + return result.data; + } catch (e) { + return false; + } +} From d61efdc1de25c15d61fbfd216adb90996d0f1214 Mon Sep 17 00:00:00 2001 From: VariableVince <24507472+VariableVince@users.noreply.github.com> Date: Fri, 30 May 2025 18:52:40 +0200 Subject: [PATCH 04/10] Flag fixes in several maps (#957) ## Description: Thanks to J.Dimlight for reporting this. Flag images were not displayed on maps. Or the wrong flag was displayed. Because of no flag code, or pointing to non-existant or incorrect flag file names. There are currently no flags to display for these Nations, as there is no flag file present in resources: Gateway to the Atlantic - Jesuit Monks - Wine Japan and Neighbors: - Sakhalin Mars: - European Space Agency South America: - The Biggest Snakes - Normal Capybaras - Just Otters ## 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 - [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: tryout33 --- resources/maps/Europe.json | 8 ++++---- resources/maps/GatewayToTheAtlantic.json | 12 ++++++------ resources/maps/Mars.json | 2 +- resources/maps/NorthAmerica.json | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/resources/maps/Europe.json b/resources/maps/Europe.json index 2fdc5694f..d0029e0f0 100644 --- a/resources/maps/Europe.json +++ b/resources/maps/Europe.json @@ -187,7 +187,7 @@ "coordinates": [1254, 899], "name": "Slovak Republic", "strength": 3, - "flag": "SK" + "flag": "sk" }, { "coordinates": [1002, 1061], @@ -259,7 +259,7 @@ "coordinates": [1522, 48], "name": "Polar Bears", "strength": 2, - "flag": "polar_bear" + "flag": "polar_bears" }, { "coordinates": [821, 628], @@ -289,13 +289,13 @@ "coordinates": [1919, 1608], "name": "Hashemite Kingdom of Jordan", "strength": 1, - "flag": "hu" + "flag": "jo" }, { "coordinates": [1898, 1535], "name": "Lebanese Republic", "strength": 1, - "flag": "hu" + "flag": "lb" } ] } diff --git a/resources/maps/GatewayToTheAtlantic.json b/resources/maps/GatewayToTheAtlantic.json index c36454b2a..9f3846102 100644 --- a/resources/maps/GatewayToTheAtlantic.json +++ b/resources/maps/GatewayToTheAtlantic.json @@ -19,7 +19,7 @@ "coordinates": [1334, 537], "name": "Duchy of Aquitaine", "strength": 2, - "flag": "aquitane" + "flag": "aquitaine" }, { "coordinates": [2115, 684], @@ -31,7 +31,7 @@ "coordinates": [1207, 763], "name": "The Basque", "strength": 3, - "flag": "" + "flag": "es-pv" }, { "coordinates": [1281, 1142], @@ -49,7 +49,7 @@ "coordinates": [561, 764], "name": "Kingdom of Galicia", "strength": 2, - "flag": "galicia" + "flag": "es-ga" }, { "coordinates": [1004, 1436], @@ -115,7 +115,7 @@ "coordinates": [1755, 1130], "name": "The Old Ones", "strength": 3, - "flag": "nuragic" + "flag": "neuragic_empire" }, { "coordinates": [2097, 1670], @@ -151,7 +151,7 @@ "coordinates": [1017, 180], "name": "Kingdom of Brittany", "strength": 2, - "flag": "britanny" + "flag": "brittany" }, { "coordinates": [2072, 567], @@ -175,7 +175,7 @@ "coordinates": [1475, 1657], "name": "French Foreign Legion", "strength": 3, - "flag": "french_foreign_legion" + "flag": "French foreign legion" }, { "coordinates": [1685, 417], diff --git a/resources/maps/Mars.json b/resources/maps/Mars.json index 342c707ec..c5d0a9f2d 100644 --- a/resources/maps/Mars.json +++ b/resources/maps/Mars.json @@ -13,7 +13,7 @@ "coordinates": [122, 750], "name": "USSR", "strength": 2, - "flag": "" + "flag": "ussr" }, { "coordinates": [1232, 735], diff --git a/resources/maps/NorthAmerica.json b/resources/maps/NorthAmerica.json index ac55c5ef6..9422284f9 100644 --- a/resources/maps/NorthAmerica.json +++ b/resources/maps/NorthAmerica.json @@ -283,7 +283,7 @@ "coordinates": [1189, 240], "name": "Polar Bears", "strength": 3, - "flag": "polar_bear" + "flag": "polar_bears" }, { "coordinates": [1480, 343], From f6687302c654fdcf5144f0471baf760a8033bd90 Mon Sep 17 00:00:00 2001 From: Duwibi <86431918+Duwibi@users.noreply.github.com> Date: Fri, 30 May 2025 22:50:25 +0300 Subject: [PATCH 05/10] Fix map jsons (#960) ## Description: Quite a bit of maps have problems with their jsons. In this PR, I'll try to fix some of them. ## 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: Nikola123 --- resources/maps/Europe.json | 4 ++-- resources/maps/Japan.json | 4 ++-- resources/maps/NorthAmerica.json | 18 +++++++++--------- resources/maps/SouthAmerica.json | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/resources/maps/Europe.json b/resources/maps/Europe.json index d0029e0f0..33ff48987 100644 --- a/resources/maps/Europe.json +++ b/resources/maps/Europe.json @@ -244,7 +244,7 @@ "flag": "gb-sct" }, { - "coordinates": [2239, 3215], + "coordinates": [2300, 510], "name": "USSR", "strength": 3, "flag": "ussr" @@ -280,7 +280,7 @@ "flag": "eg" }, { - "coordinates": [1188, 1612], + "coordinates": [1115, 1650], "name": "State of Libya", "strength": 1, "flag": "ly" diff --git a/resources/maps/Japan.json b/resources/maps/Japan.json index 3f9ab541d..7996d5724 100644 --- a/resources/maps/Japan.json +++ b/resources/maps/Japan.json @@ -4,7 +4,7 @@ "height": 1646, "nations": [ { - "coordinates": [1151, 709], + "coordinates": [1150, 660], "name": "Hokkaido", "strength": 1, "flag": "jp" @@ -40,7 +40,7 @@ "flag": "jp" }, { - "coordinates": [8612, 1183], + "coordinates": [595, 1190], "name": "Shikoku", "strength": 2, "flag": "jp" diff --git a/resources/maps/NorthAmerica.json b/resources/maps/NorthAmerica.json index 9422284f9..ea8ee8494 100644 --- a/resources/maps/NorthAmerica.json +++ b/resources/maps/NorthAmerica.json @@ -4,37 +4,37 @@ "height": 1448, "nations": [ { - "coordinates": [1693, 1045], + "coordinates": [1625, 1040], "name": "Florida", "strength": 3, "flag": "Florida" }, { - "coordinates": [1001, 427], + "coordinates": [1010, 435], "name": "Canada", "strength": 2, "flag": "ca" }, { - "coordinates": [1364, 1179], + "coordinates": [1250, 1130], "name": "Mexico", "strength": 2, "flag": "mx" }, { - "coordinates": [1556, 1295], + "coordinates": [1460, 1275], "name": "Guatemala", "strength": 1, "flag": "gt" }, { - "coordinates": [1612, 1289], + "coordinates": [1530, 1290], "name": "Honduras", "strength": 1, "flag": "hn" }, { - "coordinates": [1642, 1348], + "coordinates": [1570, 1350], "name": "Nicaragua", "strength": 1, "flag": "ni" @@ -58,7 +58,7 @@ "flag": "ve" }, { - "coordinates": [1775, 1183], + "coordinates": [1725, 1180], "name": "Cuba", "strength": 1, "flag": "cu" @@ -94,7 +94,7 @@ "flag": "Georgia_US" }, { - "coordinates": [420, 1209], + "coordinates": [250, 1200], "name": "Hawaii", "strength": 1, "flag": "Hawaii" @@ -286,7 +286,7 @@ "flag": "polar_bears" }, { - "coordinates": [1480, 343], + "coordinates": [1480, 350], "name": "Frost Giants", "strength": 3, "flag": "frost_giant" diff --git a/resources/maps/SouthAmerica.json b/resources/maps/SouthAmerica.json index 36807cf01..fc31ad2a8 100644 --- a/resources/maps/SouthAmerica.json +++ b/resources/maps/SouthAmerica.json @@ -1,7 +1,7 @@ { "name": "Americas", "width": 1746, - "height": 2380, + "height": 2378, "nations": [ { "coordinates": [438, 58], @@ -94,7 +94,7 @@ "flag": "gf" }, { - "coordinates": [801, 242], + "coordinates": [800, 410], "name": "Guyana", "strength": 1, "flag": "gy" From 9ad2cfaffd66ed1e816dbc9b94995e18bf3f6361 Mon Sep 17 00:00:00 2001 From: 1brucben <1benjbruce@gmail.com> Date: Fri, 30 May 2025 22:22:50 +0200 Subject: [PATCH 06/10] change defaults to reflect meta (#942) ## Description: Changes default target troop ratio and attack size to reflect better early game strategies in v23 ## 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 - [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: 1brucben --- src/client/graphics/layers/ControlPanel.ts | 10 +++++----- src/core/game/PlayerImpl.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/client/graphics/layers/ControlPanel.ts b/src/client/graphics/layers/ControlPanel.ts index 19d2bd02c..9ce3cc7cf 100644 --- a/src/client/graphics/layers/ControlPanel.ts +++ b/src/client/graphics/layers/ControlPanel.ts @@ -16,13 +16,13 @@ export class ControlPanel extends LitElement implements Layer { public uiState: UIState; @state() - private attackRatio: number = 0.2; + private attackRatio: number = 0.3; @state() - private targetTroopRatio = 0.95; + private targetTroopRatio = 0.6; @state() - private currentTroopRatio = 0.95; + private currentTroopRatio = 0.6; @state() private _population: number; @@ -59,10 +59,10 @@ export class ControlPanel extends LitElement implements Layer { init() { this.attackRatio = Number( - localStorage.getItem("settings.attackRatio") ?? "0.2", + localStorage.getItem("settings.attackRatio") ?? "0.3", ); this.targetTroopRatio = Number( - localStorage.getItem("settings.troopRatio") ?? "0.95", + localStorage.getItem("settings.troopRatio") ?? "0.6", ); this.init_ = true; this.uiState.attackRatio = this.attackRatio; diff --git a/src/core/game/PlayerImpl.ts b/src/core/game/PlayerImpl.ts index 49aa91777..46e4fe0a9 100644 --- a/src/core/game/PlayerImpl.ts +++ b/src/core/game/PlayerImpl.ts @@ -109,7 +109,7 @@ export class PlayerImpl implements Player { ) { this._flag = playerInfo.flag; this._name = sanitizeUsername(playerInfo.name); - this._targetTroopRatio = 95n; + this._targetTroopRatio = 60n; this._troops = toInt(startTroops); this._workers = 0n; this._gold = 0n; From a0e00e1fb03ac67c6e8fa4632394bd62918b05a0 Mon Sep 17 00:00:00 2001 From: VariableVince <24507472+VariableVince@users.noreply.github.com> Date: Fri, 30 May 2025 22:25:07 +0200 Subject: [PATCH 07/10] Even more flag flair (#959) ## Description: Add Sakhalin flag for nation on Japan map. Use Aztec flag for Biggest Snakes nation. Change 'Jesuit Monks' nation into 'Tamazgha' with corresponding flag. Thanks @ N0ur and J. Dimlight ## 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 - [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: tryout33 --- resources/flags/Sakhalin.svg | 3 +++ resources/maps/GatewayToTheAtlantic.json | 4 ++-- resources/maps/Japan.json | 2 +- resources/maps/SouthAmerica.json | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 resources/flags/Sakhalin.svg diff --git a/resources/flags/Sakhalin.svg b/resources/flags/Sakhalin.svg new file mode 100644 index 000000000..ff85f0646 --- /dev/null +++ b/resources/flags/Sakhalin.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/resources/maps/GatewayToTheAtlantic.json b/resources/maps/GatewayToTheAtlantic.json index 9f3846102..0f90f7fb3 100644 --- a/resources/maps/GatewayToTheAtlantic.json +++ b/resources/maps/GatewayToTheAtlantic.json @@ -119,9 +119,9 @@ }, { "coordinates": [2097, 1670], - "name": "Jesuit Monks", + "name": "Tamazgha", "strength": 2, - "flag": "" + "flag": "Amazigh flag" }, { "coordinates": [979, 1013], diff --git a/resources/maps/Japan.json b/resources/maps/Japan.json index 7996d5724..9f3c53bd9 100644 --- a/resources/maps/Japan.json +++ b/resources/maps/Japan.json @@ -31,7 +31,7 @@ "coordinates": [1162, 154], "name": "Sakhalin", "strength": 2, - "flag": "" + "flag": "Sakhalin" }, { "coordinates": [571, 1116], diff --git a/resources/maps/SouthAmerica.json b/resources/maps/SouthAmerica.json index fc31ad2a8..ed56a9f8d 100644 --- a/resources/maps/SouthAmerica.json +++ b/resources/maps/SouthAmerica.json @@ -133,7 +133,7 @@ "coordinates": [1270, 1035], "name": "The Biggest Snakes", "strength": 3, - "flag": "" + "flag": "Aztec Empire" }, { "coordinates": [894, 693], From 851526ba4eab43e6c3ee848057f1ee7b062fb248 Mon Sep 17 00:00:00 2001 From: 1brucben <1benjbruce@gmail.com> Date: Fri, 30 May 2025 23:19:39 +0200 Subject: [PATCH 08/10] Only load tiles when viewed by player (#887) ## Description: Tiles are only run through putImageData() if they are currently viewed by the player. This significantly (usually between 20-80%) reduces the computation time of putImageData() on large maps. ## 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: 1brucben --------- Co-authored-by: evanpelle --- src/client/graphics/GameRenderer.ts | 2 +- src/client/graphics/layers/TerritoryLayer.ts | 90 ++++++++++---------- 2 files changed, 44 insertions(+), 48 deletions(-) diff --git a/src/client/graphics/GameRenderer.ts b/src/client/graphics/GameRenderer.ts index ad114234c..149706c8f 100644 --- a/src/client/graphics/GameRenderer.ts +++ b/src/client/graphics/GameRenderer.ts @@ -191,7 +191,7 @@ export function createRenderer( const layers: Layer[] = [ new TerrainLayer(game, transformHandler), - new TerritoryLayer(game, eventBus), + new TerritoryLayer(game, eventBus, transformHandler), structureLayer, new UnitLayer(game, eventBus, transformHandler), new FxLayer(game), diff --git a/src/client/graphics/layers/TerritoryLayer.ts b/src/client/graphics/layers/TerritoryLayer.ts index deb2cfd0a..550bab478 100644 --- a/src/client/graphics/layers/TerritoryLayer.ts +++ b/src/client/graphics/layers/TerritoryLayer.ts @@ -8,6 +8,7 @@ import { GameUpdateType } from "../../../core/game/GameUpdates"; import { GameView, PlayerView } from "../../../core/game/GameView"; import { PseudoRandom } from "../../../core/PseudoRandom"; import { AlternateViewEvent, DragEvent } from "../../InputHandler"; +import { TransformHandler } from "../TransformHandler"; import { Layer } from "./Layer"; export class TerritoryLayer implements Layer { @@ -32,7 +33,7 @@ export class TerritoryLayer implements Layer { private lastDragTime = 0; private nodrawDragDuration = 200; - private refreshRate = 10; + private refreshRate = 10; //refresh every 10ms private lastRefresh = 0; private lastFocusedPlayer: PlayerView | null = null; @@ -40,6 +41,7 @@ export class TerritoryLayer implements Layer { constructor( private game: GameView, private eventBus: EventBus, + private transformHandler: TransformHandler, ) { this.theme = game.config().theme(); } @@ -48,11 +50,10 @@ export class TerritoryLayer implements Layer { return true; } - paintPlayerBorder(player: PlayerView) { - player.borderTiles().then((playerBorderTiles) => { - playerBorderTiles.borderTiles.forEach((tile: TileRef) => { - this.paintTerritory(tile, true); // Immediately paint the tile instead of enqueueing - }); + async paintPlayerBorder(player: PlayerView) { + const tiles = await player.borderTiles(); + tiles.borderTiles.forEach((tile: TileRef) => { + this.paintTerritory(tile, true); // Immediately paint the tile instead of enqueueing }); } @@ -128,11 +129,7 @@ export class TerritoryLayer implements Layer { euclDistFN(centerTile, 9, true), )) { if (!this.game.hasOwner(tile)) { - this.paintHighlightCell( - new Cell(this.game.x(tile), this.game.y(tile)), - color, - 255, - ); + this.paintHighlightTile(tile, color, 255); } } } @@ -155,16 +152,16 @@ export class TerritoryLayer implements Layer { const context = this.canvas.getContext("2d"); if (context === null) throw new Error("2d context not supported"); this.context = context; + this.canvas.width = this.game.width(); + this.canvas.height = this.game.height(); this.imageData = this.context.getImageData( 0, 0, - this.game.width(), - this.game.height(), + this.canvas.width, + this.canvas.height, ); this.initImageData(); - this.canvas.width = this.game.width(); - this.canvas.height = this.game.height(); this.context.putImageData(this.imageData, 0, 0); // Add a second canvas for highlights @@ -199,7 +196,19 @@ export class TerritoryLayer implements Layer { ) { this.lastRefresh = now; this.renderTerritory(); - this.context.putImageData(this.imageData, 0, 0); + + const [topLeft, bottomRight] = this.transformHandler.screenBoundingRect(); + const vx0 = Math.max(0, topLeft.x); + const vy0 = Math.max(0, topLeft.y); + const vx1 = Math.min(this.game.width() - 1, bottomRight.x); + const vy1 = Math.min(this.game.height() - 1, bottomRight.y); + + const w = vx1 - vx0 + 1; + const h = vy1 - vy0 + 1; + + if (w > 0 && h > 0) { + this.context.putImageData(this.imageData, 0, 0, vx0, vy0, w, h); + } } if (this.alternativeView) { return; @@ -245,15 +254,10 @@ export class TerritoryLayer implements Layer { } if (!this.game.hasOwner(tile)) { if (this.game.hasFallout(tile)) { - this.paintCell( - this.game.x(tile), - this.game.y(tile), - this.theme.falloutColor(), - 150, - ); + this.paintTile(tile, this.theme.falloutColor(), 150); return; } - this.clearCell(new Cell(this.game.x(tile), this.game.y(tile))); + this.clearTile(tile); return; } const owner = this.game.owner(tile) as PlayerView; @@ -273,40 +277,28 @@ export class TerritoryLayer implements Layer { const lightTile = (x % 2 === 0 && y % 2 === 0) || (y % 2 === 1 && x % 2 === 1); const borderColor = lightTile ? borderColors.light : borderColors.dark; - this.paintCell(x, y, borderColor, 255); + this.paintTile(tile, borderColor, 255); } else { const useBorderColor = playerIsFocused ? this.theme.focusedBorderColor() : this.theme.borderColor(owner); - this.paintCell( - this.game.x(tile), - this.game.y(tile), - useBorderColor, - 255, - ); + this.paintTile(tile, useBorderColor, 255); } } else { - this.paintCell( - this.game.x(tile), - this.game.y(tile), - this.theme.territoryColor(owner), - 150, - ); + this.paintTile(tile, this.theme.territoryColor(owner), 150); } } - paintCell(x: number, y: number, color: Colord, alpha: number) { - const index = y * this.game.width() + x; - const offset = index * 4; + paintTile(tile: TileRef, color: Colord, alpha: number) { + const offset = tile * 4; this.imageData.data[offset] = color.rgba.r; this.imageData.data[offset + 1] = color.rgba.g; this.imageData.data[offset + 2] = color.rgba.b; this.imageData.data[offset + 3] = alpha; } - clearCell(cell: Cell) { - const index = cell.y * this.game.width() + cell.x; - const offset = index * 4; + clearTile(tile: TileRef) { + const offset = tile * 4; this.imageData.data[offset + 3] = 0; // Set alpha to 0 (fully transparent) } @@ -324,13 +316,17 @@ export class TerritoryLayer implements Layer { }); } - paintHighlightCell(cell: Cell, color: Colord, alpha: number) { - this.clearCell(cell); + paintHighlightTile(tile: TileRef, color: Colord, alpha: number) { + this.clearTile(tile); + const x = this.game.x(tile); + const y = this.game.y(tile); this.highlightContext.fillStyle = color.alpha(alpha / 255).toRgbString(); - this.highlightContext.fillRect(cell.x, cell.y, 1, 1); + this.highlightContext.fillRect(x, y, 1, 1); } - clearHighlightCell(cell: Cell) { - this.highlightContext.clearRect(cell.x, cell.y, 1, 1); + clearHighlightTile(tile: TileRef) { + const x = this.game.x(tile); + const y = this.game.y(tile); + this.highlightContext.clearRect(x, y, 1, 1); } } From b24814cb7d15a0b48faaf505e337789e10ad77ca Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Fri, 30 May 2025 23:05:35 -0400 Subject: [PATCH 09/10] Hide login button (#965) ## Description: Hide login button when logged in. ## 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 - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com> --- src/client/Main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/Main.ts b/src/client/Main.ts index 8fdc0cfdb..c4b877eaa 100644 --- a/src/client/Main.ts +++ b/src/client/Main.ts @@ -188,8 +188,8 @@ class Client { logoutDiscordButton.hidden = true; return; } - // TODO: Update the page for logged in user loginDiscordButton.translationKey = "main.logged_in"; + loginDiscordButton.hidden = true; const { user, player } = userMeResponse; }); } From 5c750f13d175563ae17b13bd0ae25aa62a6720c5 Mon Sep 17 00:00:00 2001 From: Demonessica <37988730+Demonessica@users.noreply.github.com> Date: Thu, 29 May 2025 15:17:15 -0700 Subject: [PATCH 10/10] Fix CSS performance issues from #857 while preserving functionality (#928) ## Description: Replaces the `all` selector with a specific class to reduce CSS computation. Maintains functionality of hiding the news button. ## 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: `demonessica` --- src/client/index.html | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/client/index.html b/src/client/index.html index 025003b45..ae94e0ae7 100644 --- a/src/client/index.html +++ b/src/client/index.html @@ -99,6 +99,11 @@ display: none; } } + + /* display:none if child has class parent-hidden since we can't use shadow DOM in Lit due to Tailwind */ + .component-hideable:has(> .parent-hidden) { + display: none; + } @@ -224,7 +229,9 @@
- +