pass attacks from worker thread to main thread

This commit is contained in:
Evan
2025-02-11 10:32:32 -08:00
parent 6f02bd250e
commit 78dddaf610
4 changed files with 57 additions and 14 deletions
+8
View File
@@ -70,6 +70,12 @@ export interface UnitUpdate {
constructionType?: UnitType;
}
export interface AttackUpdate {
attackerID: number;
targetID: number;
troops: number;
}
export interface PlayerUpdate {
type: GameUpdateType.Player;
nameViewData?: NameViewData;
@@ -90,6 +96,8 @@ export interface PlayerUpdate {
isTraitor: boolean;
targets: number[];
outgoingEmojis: EmojiMessage[];
outgoingAttacks: AttackUpdate[];
incomingAttacks: AttackUpdate[];
}
export interface AllianceRequestUpdate {
+9 -1
View File
@@ -7,7 +7,7 @@ import {
PlayerProfile,
Unit,
} from "./Game";
import { PlayerUpdate } from "./GameUpdates";
import { AttackUpdate, PlayerUpdate } from "./GameUpdates";
import { UnitUpdate } from "./GameUpdates";
import { NameViewData } from "./Game";
import { GameUpdateType } from "./GameUpdates";
@@ -106,6 +106,14 @@ export class PlayerView {
);
}
outgoingAttacks(): AttackUpdate[] {
return this.data.outgoingAttacks;
}
incomingAttacks(): AttackUpdate[] {
return this.data.incomingAttacks;
}
units(...types: UnitType[]): UnitView[] {
return this.game
.units(...types)
+17 -1
View File
@@ -19,7 +19,7 @@ import {
PlayerProfile,
Attack,
} from "./Game";
import { PlayerUpdate } from "./GameUpdates";
import { AttackUpdate, PlayerUpdate } from "./GameUpdates";
import { GameUpdateType } from "./GameUpdates";
import { ClientID } from "../Schemas";
import {
@@ -116,6 +116,22 @@ export class PlayerImpl implements Player {
isTraitor: this.isTraitor(),
targets: this.targets().map((p) => p.smallID()),
outgoingEmojis: this.outgoingEmojis(),
outgoingAttacks: this._outgoingAttacks.map(
(a) =>
({
attackerID: a.attacker().smallID(),
targetID: a.target().smallID(),
troops: a.troops(),
} as AttackUpdate)
),
incomingAttacks: this._incomingAttacks.map(
(a) =>
({
attackerID: a.attacker().smallID(),
targetID: a.target().smallID(),
troops: a.troops(),
} as AttackUpdate)
),
};
}