Display alliance timer in player panel (#805)

## Description:
Below Traitor: , There will be Alliance Status. And will display timer,
after timer ends will show Alliance Expired. Also this Alliance Status
will only show if player had alliance.

## 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:
dovg
This commit is contained in:
tnhnblgl
2025-05-20 01:29:40 +03:00
committed by GitHub
parent 2cdce06244
commit ca66656b5c
4 changed files with 50 additions and 0 deletions
+1
View File
@@ -403,6 +403,7 @@
"gold": "Gold",
"troops": "Troops",
"traitor": "Traitor",
"alliance_time_remaining": "Time Remaining",
"embargo": "Stopped trading with you",
"nuke": "Nukes sent by them to you",
"start_trade": "Start trading",
+44
View File
@@ -45,6 +45,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;
@@ -170,11 +173,38 @@ export class PlayerPanel extends LitElement implements Layer {
const myPlayer = this.g.myPlayer();
if (myPlayer !== null && myPlayer.isAlive()) {
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);
}
} 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) {
@@ -309,6 +339,20 @@ export class PlayerPanel extends LitElement implements Layer {
</div>
</div>
${this.allianceExpiryText !== null
? html`
<div class="flex flex-col gap-1">
<div class="text-white text-opacity-80 text-sm px-2">
${translateText("player_panel.alliance_time_remaining")}
</div>
<div
class="bg-opacity-50 bg-gray-700 rounded p-2 text-white"
>
${this.allianceExpiryText}
</div>
</div>
`
: ""}
<!-- Stats -->
<div class="flex flex-col gap-1">
<div class="text-white text-opacity-80 text-sm px-2">
+4
View File
@@ -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;
+1
View File
@@ -616,6 +616,7 @@ export interface PlayerInteraction {
canTarget: boolean;
canDonate: boolean;
canEmbargo: boolean;
allianceCreatedAtTick?: Tick;
}
export interface EmojiMessage {