mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 23:21:58 +00:00
41ef675e98
Resolves #3910 ## Description: - Split the events HUD into two components: a new **`<actionable-events>`** that owns alliance prompts (request / renew) and a slimmed-down **`<events-display>`** for everything else. - Reworked `<events-display>` into two visual tiers: dim/scrolling tier 2 on top (trade results, unit losses, donations, alliance status), prominent tier 1 anchored at the bottom (inbound nukes, naval invasion, attack requests, alliance broken, conquered player, chat). Tier 2 caps at the 4 newest entries; events expire after 8s. - Added a transient **+gold pip** above the gold pill in `<control-panel>`, animated with a small fade-in. Fires for trade ships, trains, donations, and conquest. Trade-ship and train arrivals are removed from the events scroll since they're surfaced here instead. - New `MessageType.NUKE_DETONATED` and a server-side emission in `NukeExecution.detonate` — once an inbound nuke lands or gets intercepted, the inbound warning vanishes and a "detonated" entry takes its place. - `displayMessage` gained optional `unitID` and `focusPlayerID` params so events can link to a unit or a player. Unit captures and destructions now navigate to the unit's last tile when clicked; donations navigate to the other player. - ActionableEvents card width matches `<events-display>`; cards persist until the user clicks Accept/Reject/Renew/Ignore or the server-side request timeout expires. - Removed the in-events category filter UI and the gold-amount banner — `<events-display>` is now a lightweight log that hides entirely when empty. <img width="570" height="444" alt="Screenshot 2026-05-21 at 1 42 30 PM" src="https://github.com/user-attachments/assets/f103efb3-0e11-4b72-a11b-91ff6896177c" /> <img width="430" height="296" alt="Screenshot 2026-05-21 at 1 41 34 PM" src="https://github.com/user-attachments/assets/ae58475a-b252-4aa6-9ce5-99dea7575ce3" /> ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: evan
150 lines
4.5 KiB
TypeScript
150 lines
4.5 KiB
TypeScript
import { TradeShipExecution } from "../../../src/core/execution/TradeShipExecution";
|
|
import { Game, Player, Unit } from "../../../src/core/game/Game";
|
|
import { PathStatus } from "../../../src/core/pathfinding/types";
|
|
import { setup } from "../../util/Setup";
|
|
|
|
describe("TradeShipExecution", () => {
|
|
let game: Game;
|
|
let origOwner: Player;
|
|
let dstOwner: Player;
|
|
let pirate: Player;
|
|
let srcPort: Unit;
|
|
let piratePort: Unit;
|
|
let piratePort2: Unit;
|
|
let tradeShip: Unit;
|
|
let dstPort: Unit;
|
|
let tradeShipExecution: TradeShipExecution;
|
|
|
|
beforeEach(async () => {
|
|
// Mock Game, Player, Unit, and required methods
|
|
|
|
game = await setup("ocean_and_land", {
|
|
infiniteGold: true,
|
|
instantBuild: true,
|
|
});
|
|
game.displayMessage = vi.fn();
|
|
origOwner = {
|
|
canBuild: vi.fn(() => true),
|
|
buildUnit: vi.fn((type, spawn, opts) => tradeShip),
|
|
displayName: vi.fn(() => "Origin"),
|
|
addGold: vi.fn(),
|
|
units: vi.fn(() => [dstPort]),
|
|
unitCount: vi.fn(() => 1),
|
|
id: vi.fn(() => 1),
|
|
clientID: vi.fn(() => 1),
|
|
canTrade: vi.fn(() => true),
|
|
} as any;
|
|
|
|
dstOwner = {
|
|
id: vi.fn(() => 2),
|
|
addGold: vi.fn(),
|
|
displayName: vi.fn(() => "Destination"),
|
|
units: vi.fn(() => [dstPort]),
|
|
unitCount: vi.fn(() => 1),
|
|
clientID: vi.fn(() => 2),
|
|
canTrade: vi.fn(() => true),
|
|
} as any;
|
|
|
|
pirate = {
|
|
id: vi.fn(() => 3),
|
|
addGold: vi.fn(),
|
|
displayName: vi.fn(() => "Destination"),
|
|
units: vi.fn(() => [piratePort, piratePort2]),
|
|
unitCount: vi.fn(() => 2),
|
|
canTrade: vi.fn(() => true),
|
|
} as any;
|
|
|
|
piratePort = {
|
|
id: vi.fn(() => 201),
|
|
tile: vi.fn(() => 56),
|
|
owner: vi.fn(() => pirate),
|
|
isActive: vi.fn(() => true),
|
|
isUnderConstruction: vi.fn(() => false),
|
|
isMarkedForDeletion: vi.fn(() => false),
|
|
} as any;
|
|
|
|
piratePort2 = {
|
|
id: vi.fn(() => 202),
|
|
tile: vi.fn(() => 75),
|
|
owner: vi.fn(() => pirate),
|
|
isActive: vi.fn(() => true),
|
|
isUnderConstruction: vi.fn(() => false),
|
|
isMarkedForDeletion: vi.fn(() => false),
|
|
} as any;
|
|
|
|
srcPort = {
|
|
id: vi.fn(() => 101),
|
|
tile: vi.fn(() => 10),
|
|
owner: vi.fn(() => origOwner),
|
|
isActive: vi.fn(() => true),
|
|
isUnderConstruction: vi.fn(() => false),
|
|
isMarkedForDeletion: vi.fn(() => false),
|
|
} as any;
|
|
|
|
dstPort = {
|
|
id: vi.fn(() => 102),
|
|
tile: vi.fn(() => 100),
|
|
owner: vi.fn(() => dstOwner),
|
|
isActive: vi.fn(() => true),
|
|
isUnderConstruction: vi.fn(() => false),
|
|
isMarkedForDeletion: vi.fn(() => false),
|
|
} as any;
|
|
|
|
tradeShip = {
|
|
isActive: vi.fn(() => true),
|
|
owner: vi.fn(() => origOwner),
|
|
id: vi.fn(() => 123),
|
|
move: vi.fn(),
|
|
setTargetUnit: vi.fn(),
|
|
setSafeFromPirates: vi.fn(),
|
|
touch: vi.fn(),
|
|
delete: vi.fn(),
|
|
tile: vi.fn(() => 32),
|
|
} as any;
|
|
|
|
tradeShipExecution = new TradeShipExecution(origOwner, srcPort, dstPort);
|
|
tradeShipExecution.init(game, 0);
|
|
tradeShipExecution["pathFinder"] = {
|
|
next: vi.fn(() => ({ status: PathStatus.NEXT, node: 32 })),
|
|
findPath: vi.fn((from: number) => [from]),
|
|
} as any;
|
|
tradeShipExecution["tradeShip"] = tradeShip;
|
|
});
|
|
|
|
it("should initialize and tick without errors", () => {
|
|
tradeShipExecution.tick(1);
|
|
expect(tradeShipExecution.isActive()).toBe(true);
|
|
});
|
|
|
|
it("should deactivate if tradeShip is not active", () => {
|
|
tradeShip.isActive = vi.fn(() => false);
|
|
tradeShipExecution.tick(1);
|
|
expect(tradeShipExecution.isActive()).toBe(false);
|
|
});
|
|
|
|
it("should delete ship if port owner changes to current owner", () => {
|
|
dstPort.owner = vi.fn(() => origOwner);
|
|
tradeShipExecution.tick(1);
|
|
expect(tradeShip.delete).toHaveBeenCalledWith(false);
|
|
expect(tradeShipExecution.isActive()).toBe(false);
|
|
});
|
|
|
|
it("should pick another port if ship is captured", () => {
|
|
tradeShip.owner = vi.fn(() => pirate);
|
|
tradeShipExecution.tick(1);
|
|
expect(tradeShip.setTargetUnit).toHaveBeenCalledWith(piratePort);
|
|
});
|
|
|
|
it("should complete trade and award gold", () => {
|
|
tradeShipExecution["pathFinder"] = {
|
|
next: vi.fn(() => ({ status: PathStatus.COMPLETE, node: 32 })),
|
|
findPath: vi.fn((from: number) => [from]),
|
|
} as any;
|
|
tradeShipExecution.tick(1);
|
|
expect(tradeShip.delete).toHaveBeenCalledWith(false);
|
|
expect(tradeShipExecution.isActive()).toBe(false);
|
|
expect(origOwner.addGold).toHaveBeenCalled();
|
|
expect(dstOwner.addGold).toHaveBeenCalled();
|
|
});
|
|
});
|