From 27094c3be82a77f51348091fae538f678468d88a Mon Sep 17 00:00:00 2001 From: tnhnblgl <51187395+tnhnblgl@users.noreply.github.com> Date: Sun, 18 May 2025 18:06:46 +0300 Subject: [PATCH 01/10] Update Game.ts --- src/core/game/Game.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/game/Game.ts b/src/core/game/Game.ts index 61f4051d5b..dea576ffec 100644 --- a/src/core/game/Game.ts +++ b/src/core/game/Game.ts @@ -609,6 +609,7 @@ export interface PlayerInteraction { canTarget: boolean; canDonate: boolean; canEmbargo: boolean; + allianceCreatedAtTick?: Tick; } export interface EmojiMessage { From f689eae7531c441b135d2778c412a36af0fc2cc4 Mon Sep 17 00:00:00 2001 From: tnhnblgl <51187395+tnhnblgl@users.noreply.github.com> Date: Sun, 18 May 2025 18:16:36 +0300 Subject: [PATCH 02/10] Update GameRunner.ts --- src/core/GameRunner.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/GameRunner.ts b/src/core/GameRunner.ts index e64909307f..58631aaddf 100644 --- a/src/core/GameRunner.ts +++ b/src/core/GameRunner.ts @@ -201,6 +201,10 @@ export class GameRunner { canDonate: player.canDonate(other), canEmbargo: !player.hasEmbargoAgainst(other), }; + const alliance = player.allianceWith(other as Player); + if (alliance) { + actions.interaction.allianceCreatedAtTick = alliance.createdAt(); + } } return actions; From 5755ccfad26e1a7889f04cd3446a2aa6bf00e7a1 Mon Sep 17 00:00:00 2001 From: tnhnblgl <51187395+tnhnblgl@users.noreply.github.com> Date: Sun, 18 May 2025 18:42:16 +0300 Subject: [PATCH 03/10] Update PlayerPanel.ts --- src/client/graphics/layers/PlayerPanel.ts | 45 ++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/client/graphics/layers/PlayerPanel.ts b/src/client/graphics/layers/PlayerPanel.ts index 547bd54fd4..680e620420 100644 --- a/src/client/graphics/layers/PlayerPanel.ts +++ b/src/client/graphics/layers/PlayerPanel.ts @@ -13,6 +13,7 @@ import { AllPlayers, PlayerActions, PlayerID, + Tick, UnitType, } from "../../../core/game/Game"; import { TileRef } from "../../../core/game/GameMap"; @@ -45,6 +46,9 @@ export class PlayerPanel extends LitElement implements Layer { @state() private isVisible: boolean = false; + @state() + private allianceExpiryText: string | null = null; + public show(actions: PlayerActions, tile: TileRef) { this.actions = actions; this.tile = tile; @@ -169,12 +173,39 @@ export class PlayerPanel extends LitElement implements Layer { if (this.isVisible && this.tile) { const myPlayer = this.g.myPlayer(); if (myPlayer !== null && myPlayer.isAlive()) { - this.actions = await myPlayer.actions(this.tile); + const currentActions = await myPlayer.actions(this.tile); + this.actions = currentActions; + + if (currentActions?.interaction?.allianceCreatedAtTick !== undefined) { + const createdAt = currentActions.interaction.allianceCreatedAtTick; + const durationTicks = this.g.config().allianceDuration(); + const expiryTick = createdAt + durationTicks; + const remainingTicks = expiryTick - this.g.ticks(); + + if (remainingTicks > 0) { + const remainingSeconds = Math.max(0, Math.floor(remainingTicks / 10)); // 10 ticks per second + this.allianceExpiryText = this.formatDuration(remainingSeconds); + } else { + this.allianceExpiryText = translateText("player_panel.alliance_expired_status"); + } + } else { + this.allianceExpiryText = null; + } this.requestUpdate(); } } } + private formatDuration(totalSeconds: number): string { + if (totalSeconds <= 0) return "0s"; + const minutes = Math.floor(totalSeconds / 60); + const seconds = totalSeconds % 60; + let time = ""; + if (minutes > 0) time += `${minutes}m `; + time += `${seconds}s`; + return time.trim(); + } + getTotalNukesSent(otherId: PlayerID): number { const stats = this.g.player(otherId).stats(); if (!stats) { @@ -305,6 +336,18 @@ export class PlayerPanel extends LitElement implements Layer { + ${this.allianceExpiryText !== null + ? html` +
+
+ ${translateText("player_panel.alliance_status")} +
+
+ ${this.allianceExpiryText} +
+
+ ` + : ""}
From 5cb0d5d9d1ec2bc43f20cfc38f33538079366011 Mon Sep 17 00:00:00 2001 From: tnhnblgl <51187395+tnhnblgl@users.noreply.github.com> Date: Sun, 18 May 2025 18:47:18 +0300 Subject: [PATCH 04/10] Update en.json --- resources/lang/en.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/lang/en.json b/resources/lang/en.json index 0ef2d64d92..e6d1356262 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -400,6 +400,8 @@ "gold": "Gold", "troops": "Troops", "traitor": "Traitor", + "alliance_status": "Alliance Status", + "alliance_expired_status": "Alliance Expired", "embargo": "Stopped trading with you", "nuke": "Nukes sent by them to you", "start_trade": "Start trading", From 2fd2350f40a5762fbb6ceb68bad92c4beed5e36b Mon Sep 17 00:00:00 2001 From: tnhnblgl <51187395+tnhnblgl@users.noreply.github.com> Date: Sun, 18 May 2025 23:47:30 +0300 Subject: [PATCH 05/10] Update PlayerPanel.ts --- src/client/graphics/layers/PlayerPanel.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/client/graphics/layers/PlayerPanel.ts b/src/client/graphics/layers/PlayerPanel.ts index 680e620420..9af6f7d85f 100644 --- a/src/client/graphics/layers/PlayerPanel.ts +++ b/src/client/graphics/layers/PlayerPanel.ts @@ -173,11 +173,10 @@ export class PlayerPanel extends LitElement implements Layer { if (this.isVisible && this.tile) { const myPlayer = this.g.myPlayer(); if (myPlayer !== null && myPlayer.isAlive()) { - const currentActions = await myPlayer.actions(this.tile); - this.actions = currentActions; + this.actions = await myPlayer.actions(this.tile); - if (currentActions?.interaction?.allianceCreatedAtTick !== undefined) { - const createdAt = currentActions.interaction.allianceCreatedAtTick; + if (this.actions?.interaction?.allianceCreatedAtTick !== undefined) { + const createdAt = this.actions.interaction.allianceCreatedAtTick; const durationTicks = this.g.config().allianceDuration(); const expiryTick = createdAt + durationTicks; const remainingTicks = expiryTick - this.g.ticks(); @@ -185,8 +184,6 @@ export class PlayerPanel extends LitElement implements Layer { if (remainingTicks > 0) { const remainingSeconds = Math.max(0, Math.floor(remainingTicks / 10)); // 10 ticks per second this.allianceExpiryText = this.formatDuration(remainingSeconds); - } else { - this.allianceExpiryText = translateText("player_panel.alliance_expired_status"); } } else { this.allianceExpiryText = null; From 19b43b598cafcdc08c7df380f7f0a187e5df20aa Mon Sep 17 00:00:00 2001 From: tnhnblgl <51187395+tnhnblgl@users.noreply.github.com> Date: Sun, 18 May 2025 23:48:51 +0300 Subject: [PATCH 06/10] Update en.json --- resources/lang/en.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/resources/lang/en.json b/resources/lang/en.json index e6d1356262..cbdcc4949b 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -400,8 +400,7 @@ "gold": "Gold", "troops": "Troops", "traitor": "Traitor", - "alliance_status": "Alliance Status", - "alliance_expired_status": "Alliance Expired", + "alliance_time_remaining": "Time Remaining", "embargo": "Stopped trading with you", "nuke": "Nukes sent by them to you", "start_trade": "Start trading", From 5920e591f4756a8729511e2a89828c012f989987 Mon Sep 17 00:00:00 2001 From: tnhnblgl <51187395+tnhnblgl@users.noreply.github.com> Date: Sun, 18 May 2025 23:50:13 +0300 Subject: [PATCH 07/10] Update PlayerPanel.ts --- src/client/graphics/layers/PlayerPanel.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/graphics/layers/PlayerPanel.ts b/src/client/graphics/layers/PlayerPanel.ts index 9af6f7d85f..6dcefce3b6 100644 --- a/src/client/graphics/layers/PlayerPanel.ts +++ b/src/client/graphics/layers/PlayerPanel.ts @@ -337,7 +337,7 @@ export class PlayerPanel extends LitElement implements Layer { ? html`
- ${translateText("player_panel.alliance_status")} + ${translateText("player_panel.alliance_time_remaining")}
${this.allianceExpiryText} From 1b960bd8be36edaefb5086efb0a81ef106c5766c Mon Sep 17 00:00:00 2001 From: tnhnblgl <51187395+tnhnblgl@users.noreply.github.com> Date: Mon, 19 May 2025 23:37:11 +0300 Subject: [PATCH 08/10] Update PlayerPanel.ts --- src/client/graphics/layers/PlayerPanel.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/client/graphics/layers/PlayerPanel.ts b/src/client/graphics/layers/PlayerPanel.ts index 16edfe4bbd..0f2f405d9f 100644 --- a/src/client/graphics/layers/PlayerPanel.ts +++ b/src/client/graphics/layers/PlayerPanel.ts @@ -349,13 +349,6 @@ export class PlayerPanel extends LitElement implements Layer {
` : ""} - -
-
- ${translateText("player_panel.nuke")} -
-
- ${this.getTotalNukesSent(other.id())}
From 11dce0a6c4156eae888fe603d203d9b71b6665be Mon Sep 17 00:00:00 2001 From: tnhnblgl <51187395+tnhnblgl@users.noreply.github.com> Date: Tue, 20 May 2025 00:03:32 +0300 Subject: [PATCH 09/10] Prettier --- src/client/graphics/layers/PlayerPanel.ts | 26 +++++++++++++---------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/client/graphics/layers/PlayerPanel.ts b/src/client/graphics/layers/PlayerPanel.ts index 0f2f405d9f..c1524f323d 100644 --- a/src/client/graphics/layers/PlayerPanel.ts +++ b/src/client/graphics/layers/PlayerPanel.ts @@ -337,18 +337,22 @@ export class PlayerPanel extends LitElement implements Layer {
- ${this.allianceExpiryText !== null - ? html` -
-
- ${translateText("player_panel.alliance_time_remaining")} + ${ + this.allianceExpiryText !== null + ? html` +
+
+ ${translateText("player_panel.alliance_time_remaining")} +
+
+ ${this.allianceExpiryText} +
-
- ${this.allianceExpiryText} -
-
- ` - : ""} + ` + : "" + }
From a6cddea72bba19a05d80aae00553dcbee88c5726 Mon Sep 17 00:00:00 2001 From: tnhnblgl <51187395+tnhnblgl@users.noreply.github.com> Date: Mon, 19 May 2025 21:21:27 +0000 Subject: [PATCH 10/10] Prettier --- src/client/graphics/layers/PlayerPanel.ts | 30 +++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/client/graphics/layers/PlayerPanel.ts b/src/client/graphics/layers/PlayerPanel.ts index c1524f323d..c37659e78f 100644 --- a/src/client/graphics/layers/PlayerPanel.ts +++ b/src/client/graphics/layers/PlayerPanel.ts @@ -13,7 +13,6 @@ import { AllPlayers, PlayerActions, PlayerID, - Tick, UnitType, } from "../../../core/game/Game"; import { TileRef } from "../../../core/game/GameMap"; @@ -176,17 +175,20 @@ export class PlayerPanel extends LitElement implements Layer { this.actions = await myPlayer.actions(this.tile); if (this.actions?.interaction?.allianceCreatedAtTick !== undefined) { - const createdAt = this.actions.interaction.allianceCreatedAtTick; - const durationTicks = this.g.config().allianceDuration(); - const expiryTick = createdAt + durationTicks; - const remainingTicks = expiryTick - this.g.ticks(); - - if (remainingTicks > 0) { - const remainingSeconds = Math.max(0, Math.floor(remainingTicks / 10)); // 10 ticks per second - this.allianceExpiryText = this.formatDuration(remainingSeconds); - } + const createdAt = this.actions.interaction.allianceCreatedAtTick; + const durationTicks = this.g.config().allianceDuration(); + const expiryTick = createdAt + durationTicks; + const remainingTicks = expiryTick - this.g.ticks(); + + if (remainingTicks > 0) { + const remainingSeconds = Math.max( + 0, + Math.floor(remainingTicks / 10), + ); // 10 ticks per second + this.allianceExpiryText = this.formatDuration(remainingSeconds); + } } else { - this.allianceExpiryText = null; + this.allianceExpiryText = null; } this.requestUpdate(); } @@ -337,8 +339,7 @@ export class PlayerPanel extends LitElement implements Layer {
- ${ - this.allianceExpiryText !== null + ${this.allianceExpiryText !== null ? html`
@@ -351,8 +352,7 @@ export class PlayerPanel extends LitElement implements Layer {
` - : "" - } + : ""}