Show queued live notices for other players actions
This commit is contained in:
parent
1bad2d616a
commit
c8a2db0d49
9 changed files with 91 additions and 3 deletions
|
|
@ -353,3 +353,5 @@ Viewer 0.1.116 / engine 0.4.85 shortens influence roll bonuses to “rolls a 2 (
|
|||
Viewer 0.1.117 makes hover more audible, sustains action sounds longer, and adds battle-roll, unit-loss and ship-sinking cues. Action sounds wait for browser audio to resume and respect mute cancellation. Adds a local-only sound tester. Engine remains 0.4.85.
|
||||
|
||||
Viewer 0.1.118 shows floating resource icons for bartering, research rewards and other gains without a map origin. City and collection gains retain their map locations; other rewards identify the civilization without inventing a city. Storage waste is excluded. Engine remains 0.4.85.
|
||||
|
||||
Viewer 0.1.119 queues brief public-action notices while watching other players live, naming their civilization and research, buildings, moves or rewards. Spectators see all players. Initial snapshots, own actions, repeated states and undo do not produce notices. Replay uses its existing captions. Engine remains 0.4.85.
|
||||
|
|
|
|||
4
web-client/package-lock.json
generated
4
web-client/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.118",
|
||||
"version": "0.1.119",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.118",
|
||||
"version": "0.1.119",
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.9.0",
|
||||
"lucide-svelte": "^0.577.0",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.118",
|
||||
"version": "0.1.119",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -1926,6 +1926,9 @@
|
|||
cards={$session.view?.cardCatalog ?? []}
|
||||
onClose={() => (effectsOpen = false)}
|
||||
/>{/if}
|
||||
{#if $session.liveAction && !$session.playback && !$session.toast}
|
||||
<div class="toast live-action" role="status"><ResourceText text={$session.liveAction} /></div>
|
||||
{/if}
|
||||
{#if $session.toast}<div class="toast" role="status"><Check size={16} />{$session.toast}</div>{/if}
|
||||
{#if $session.objectivesOpen && $session.seat !== undefined}
|
||||
<dialog
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { liveActionMessages } from './live-actions';
|
||||
import { eventNotices, liveEventNotices } from './event-notices';
|
||||
import { publicActions } from './replay-actions';
|
||||
import { boardingPlan, type BoardingGroup } from './boarding';
|
||||
|
|
@ -139,6 +140,8 @@ export class Controller {
|
|||
private destroyed = false;
|
||||
private playbackTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
private effectTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
private liveActionQueue: string[] = [];
|
||||
private liveActionTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
private battleSoundTimers: ReturnType<typeof setTimeout>[] = [];
|
||||
private battleTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
private chatOff: () => void;
|
||||
|
|
@ -696,6 +699,8 @@ export class Controller {
|
|||
return;
|
||||
}
|
||||
} else if (!old.game.board_history?.id || old.game.board_history?.id === game.board_history?.id) {
|
||||
this.liveActionQueue.push(...liveActionMessages(old.game, game, s.seat, s.view));
|
||||
this.showNextLiveAction();
|
||||
const before = battleCursor(old.game);
|
||||
const after = battleCursor(game);
|
||||
if (after < before) this.showBattles([]);
|
||||
|
|
@ -714,6 +719,15 @@ export class Controller {
|
|||
// Predicted positions are marked seen once the server confirms them.
|
||||
if (confirmed) this.markSeen();
|
||||
}
|
||||
private showNextLiveAction() {
|
||||
if (this.liveActionTimer || !this.liveActionQueue.length) return;
|
||||
this.patch({ liveAction: this.liveActionQueue.shift() });
|
||||
this.liveActionTimer = setTimeout(() => {
|
||||
this.liveActionTimer = undefined;
|
||||
this.patch({ liveAction: undefined });
|
||||
this.showNextLiveAction();
|
||||
}, 4500);
|
||||
}
|
||||
replayLastTurn() {
|
||||
const s = get(this.session);
|
||||
if (!s.game || s.pending) return;
|
||||
|
|
@ -728,6 +742,10 @@ export class Controller {
|
|||
) {
|
||||
const s = get(this.session);
|
||||
if (s.analysis || !s.game) return;
|
||||
clearTimeout(this.liveActionTimer);
|
||||
this.liveActionTimer = undefined;
|
||||
this.liveActionQueue = [];
|
||||
this.patch({ liveAction: undefined });
|
||||
clearTimeout(this.playbackTimer);
|
||||
const frames = s.game.board_history?.frames ?? [];
|
||||
const steps = playbackSteps(s.game, index, end ?? Math.max(0, frames.length - 1));
|
||||
|
|
@ -1950,6 +1968,7 @@ export class Controller {
|
|||
clearTimeout(this.refreshTimer);
|
||||
this.chatOff();
|
||||
this.clearBattleSounds();
|
||||
clearTimeout(this.liveActionTimer);
|
||||
this.audio.destroy();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
35
web-client/src/live-actions.test.ts
Normal file
35
web-client/src/live-actions.test.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { liveActionMessages } from './live-actions.ts';
|
||||
import type { Game } from './types.ts';
|
||||
|
||||
function state(count: number): Game {
|
||||
const players = [{ id: 1, civilization: 'Greece', cities: [], units: [] }];
|
||||
const actions = ['Philosophy', 'Arts'].slice(0, count).map((advance) => ({
|
||||
player: 1, action: { Playing: { Advance: { advance } } },
|
||||
items: [{ player: 1, Advance: { advance, balance: 'Gain' } }],
|
||||
}));
|
||||
const base = { actor: 1, age: 1, round: 1, tiles: [], players, ended_turn: false, title: 'Research' };
|
||||
return {
|
||||
players, log_index: count,
|
||||
log: [{ age: 1, rounds: [{ round: 1, turns: [{ turn_type: { Player: 1 }, actions }] }] }],
|
||||
board_history: { id: 'live', frames: Array.from({ length: count + 1 }, (_, cursor) => ({ ...base, cursor })) },
|
||||
} as unknown as Game;
|
||||
}
|
||||
|
||||
test('live opponent and spectator notices name researched advances and retain multiple actions', () => {
|
||||
assert.deepEqual(liveActionMessages(state(0), state(2), 0), [
|
||||
'Greece · researched Philosophy', 'Greece · researched Arts',
|
||||
]);
|
||||
assert.deepEqual(liveActionMessages(state(0), state(1)), ['Greece · researched Philosophy']);
|
||||
});
|
||||
|
||||
test('live notices exclude own actions, repeated snapshots, undo, and replaced histories', () => {
|
||||
assert.deepEqual(liveActionMessages(state(0), state(1), 1), []);
|
||||
assert.deepEqual(liveActionMessages(state(1), state(1), 0), []);
|
||||
assert.deepEqual(liveActionMessages(state(2), state(1), 0), []);
|
||||
const replaced = state(2);
|
||||
replaced.board_history!.id = 'replayed';
|
||||
assert.deepEqual(liveActionMessages(state(1), replaced, 0), []);
|
||||
assert.deepEqual(liveActionMessages(state(1), state(2), 0), ['Greece · researched Arts']);
|
||||
});
|
||||
18
web-client/src/live-actions.ts
Normal file
18
web-client/src/live-actions.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { frameDetails } from './playback.ts';
|
||||
import { frameHasContent, publicActions } from './replay-actions.ts';
|
||||
import type { Game, View } from './types.ts';
|
||||
|
||||
export function liveActionMessages(before: Game, game: Game, seat?: number, view?: View | null): string[] {
|
||||
if (before.board_history?.id !== game.board_history?.id) return [];
|
||||
const cursor = publicActions(before).length;
|
||||
if (publicActions(game).length <= cursor) return [];
|
||||
const frames = game.board_history?.frames ?? [];
|
||||
return frames.flatMap((frame, index) => {
|
||||
if (frame.cursor <= cursor || frame.actor === seat) return [];
|
||||
const previous = frames[index - 1] ?? before.board_history?.frames.at(-1);
|
||||
if (!previous) return [];
|
||||
const start = { ...previous, cursor: Math.max(previous.cursor, cursor) };
|
||||
if (!frameHasContent(game, start, frame)) return [];
|
||||
return [frameDetails(start, frame, game, view?.advances, view?.cardCatalog).caption];
|
||||
});
|
||||
}
|
||||
|
|
@ -6252,3 +6252,13 @@ small {
|
|||
max-width: calc(100% - clamp(118px, 35vw, 140px) - 22px);
|
||||
}
|
||||
}
|
||||
|
||||
.toast.live-action {
|
||||
max-width: min(560px, calc(100vw - 32px));
|
||||
width: max-content;
|
||||
bottom: 110px;
|
||||
pointer-events: none;
|
||||
background: var(--paper);
|
||||
color: var(--ink);
|
||||
border-color: var(--line);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -618,6 +618,7 @@ export interface Session {
|
|||
locale: string;
|
||||
selectedAdvance: string | null;
|
||||
toast: string;
|
||||
liveAction?: string;
|
||||
homeAtBottom: boolean;
|
||||
topDown: boolean;
|
||||
strategyMap: boolean;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue