mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-23 10:02:35 +00:00
2c4d2334dd
## 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>
135 lines
3.2 KiB
TypeScript
135 lines
3.2 KiB
TypeScript
import {
|
|
PlayerActions,
|
|
PlayerBorderTiles,
|
|
PlayerID,
|
|
PlayerProfile,
|
|
} from "../game/Game";
|
|
import { TileRef } from "../game/GameMap";
|
|
import { GameUpdateViewData } from "../game/GameUpdates";
|
|
import { ClientID, GameStartInfo, Turn } from "../Schemas";
|
|
|
|
export type WorkerMessageType =
|
|
| "heartbeat"
|
|
| "init"
|
|
| "initialized"
|
|
| "turn"
|
|
| "game_update"
|
|
| "player_actions"
|
|
| "player_actions_result"
|
|
| "player_profile"
|
|
| "player_profile_result"
|
|
| "player_border_tiles"
|
|
| "player_border_tiles_result"
|
|
| "attack_average_position"
|
|
| "attack_average_position_result"
|
|
| "transport_ship_spawn"
|
|
| "transport_ship_spawn_result";
|
|
|
|
// Base interface for all messages
|
|
interface BaseWorkerMessage {
|
|
type: WorkerMessageType;
|
|
id?: string;
|
|
}
|
|
|
|
export interface HeartbeatMessage extends BaseWorkerMessage {
|
|
type: "heartbeat";
|
|
}
|
|
|
|
// Messages from main thread to worker
|
|
export interface InitMessage extends BaseWorkerMessage {
|
|
type: "init";
|
|
gameStartInfo: GameStartInfo;
|
|
clientID: ClientID;
|
|
}
|
|
|
|
export interface TurnMessage extends BaseWorkerMessage {
|
|
type: "turn";
|
|
turn: Turn;
|
|
}
|
|
|
|
// Messages from worker to main thread
|
|
export interface InitializedMessage extends BaseWorkerMessage {
|
|
type: "initialized";
|
|
}
|
|
|
|
export interface GameUpdateMessage extends BaseWorkerMessage {
|
|
type: "game_update";
|
|
gameUpdate: GameUpdateViewData;
|
|
}
|
|
|
|
export interface PlayerActionsMessage extends BaseWorkerMessage {
|
|
type: "player_actions";
|
|
playerID: PlayerID;
|
|
x: number;
|
|
y: number;
|
|
}
|
|
|
|
export interface PlayerActionsResultMessage extends BaseWorkerMessage {
|
|
type: "player_actions_result";
|
|
result: PlayerActions;
|
|
}
|
|
|
|
export interface PlayerProfileMessage extends BaseWorkerMessage {
|
|
type: "player_profile";
|
|
playerID: number;
|
|
}
|
|
|
|
export interface PlayerProfileResultMessage extends BaseWorkerMessage {
|
|
type: "player_profile_result";
|
|
result: PlayerProfile;
|
|
}
|
|
|
|
export interface PlayerBorderTilesMessage extends BaseWorkerMessage {
|
|
type: "player_border_tiles";
|
|
playerID: PlayerID;
|
|
}
|
|
|
|
export interface PlayerBorderTilesResultMessage extends BaseWorkerMessage {
|
|
type: "player_border_tiles_result";
|
|
result: PlayerBorderTiles;
|
|
}
|
|
|
|
export interface AttackAveragePositionMessage extends BaseWorkerMessage {
|
|
type: "attack_average_position";
|
|
playerID: number;
|
|
attackID: string;
|
|
}
|
|
|
|
export interface AttackAveragePositionResultMessage extends BaseWorkerMessage {
|
|
type: "attack_average_position_result";
|
|
x: number | null;
|
|
y: number | null;
|
|
}
|
|
|
|
export interface TransportShipSpawnMessage extends BaseWorkerMessage {
|
|
type: "transport_ship_spawn";
|
|
playerID: PlayerID;
|
|
targetTile: TileRef;
|
|
}
|
|
|
|
export interface TransportShipSpawnResultMessage extends BaseWorkerMessage {
|
|
type: "transport_ship_spawn_result";
|
|
result: TileRef | false;
|
|
}
|
|
|
|
// Union types for type safety
|
|
export type MainThreadMessage =
|
|
| HeartbeatMessage
|
|
| InitMessage
|
|
| TurnMessage
|
|
| PlayerActionsMessage
|
|
| PlayerProfileMessage
|
|
| PlayerBorderTilesMessage
|
|
| AttackAveragePositionMessage
|
|
| TransportShipSpawnMessage;
|
|
|
|
// Message send from worker
|
|
export type WorkerMessage =
|
|
| InitializedMessage
|
|
| GameUpdateMessage
|
|
| PlayerActionsResultMessage
|
|
| PlayerProfileResultMessage
|
|
| PlayerBorderTilesResultMessage
|
|
| AttackAveragePositionResultMessage
|
|
| TransportShipSpawnResultMessage;
|