Feat : focus attack average position and some movement camera fixes (#740)

## Description:

Makes so that when clicking on the attack warning message in chat, the
camera focuses on the "average position" of the attack, instead of just
the player.

The average position is calculated by taking the average position of all
attacking border cells. It makes the calculation for every AttackUpdate,
which adds some calculations every tick, but it shouldn't affect
performance that much, as it's just a sum of coordinates.
If you have a better way of getting the averagePosition information
(calculating it only when necessary instead of every tick), it would be
great.

closes #703 

## 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:
leo21_

---------

Co-authored-by: Scott Anderson <scottanderson@users.noreply.github.com>
Co-authored-by: evanpelle <evanpelle@gmail.com>
This commit is contained in:
Léo Kosman
2025-05-23 19:03:53 -07:00
committed by GitHub
co-authored by Scott Anderson evanpelle
parent c30839b12b
commit 2c4d2334dd
12 changed files with 279 additions and 65 deletions
+36
View File
@@ -1,4 +1,5 @@
import {
Cell,
PlayerActions,
PlayerBorderTiles,
PlayerID,
@@ -189,6 +190,41 @@ export class WorkerClient {
});
}
attackAveragePosition(
playerID: number,
attackID: string,
): Promise<Cell | null> {
return new Promise((resolve, reject) => {
if (!this.isInitialized) {
reject(new Error("Worker not initialized"));
return;
}
const messageId = generateID();
this.messageHandlers.set(messageId, (message) => {
if (
message.type === "attack_average_position_result" &&
message.x !== undefined &&
message.y !== undefined
) {
if (message.x === null || message.y === null) {
resolve(null);
} else {
resolve(new Cell(message.x, message.y));
}
}
});
this.worker.postMessage({
type: "attack_average_position",
id: messageId,
playerID: playerID,
attackID: attackID,
});
});
}
transportShipSpawn(
playerID: PlayerID,
targetTile: TileRef,