stage: the ticker folds a battle's hits into one damage row, with two ticker mockups

This commit is contained in:
acamilo 2026-09-30 02:14:41 +00:00
parent 9462c2e28a
commit d10aa09afa
8 changed files with 164 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

View file

@ -698,6 +698,24 @@ export function App() {
ingest.commit(hot.lastSnapshotMs, true); ingest.commit(hot.lastSnapshotMs, true);
return useStage.getState().chat.length; return useStage.getState().chat.length;
}, },
/**
* Feed reward events into the ticker by hand, `stepMs` of feed time apart, for the ticker
* mockups (a battle's hits, a KO), and settle the dwell gate five seconds after the last.
* The events go through the same `TickerQueue.push` a snapshot's do.
*/
ticker: (events, stepMs = 7000) => {
let at = hot.lastSnapshotMs;
for (const [index, item] of events.entries()) {
at = hot.lastSnapshotMs + index * stepMs;
ingest.queue().push(
{ id: 900_000 + index, wallMs: 0, brainMs: 0, kind: 'reward', label: item.label, value: item.value },
at,
);
}
at += 5000;
ingest.commit(at, true);
return useStage.getState().ticker.map((row) => `${row.label} ${String(row.amount ?? '')}`);
},
/** /**
* Put a notice on the recovery splash by hand, the same way `fire` drives a moment: for the * Put a notice on the recovery splash by hand, the same way `fire` drives a moment: for the
* splash mockups and e2e assertions. The raw object goes through the same validation as a * splash mockups and e2e assertions. The raw object goes through the same validation as a
@ -790,6 +808,8 @@ declare global {
fire: (type: MomentType, label?: string, detail?: string) => number | null; fire: (type: MomentType, label?: string, detail?: string) => number | null;
/** Replace the held feed's chat ring by hand; returns how many lines the panel accepted. */ /** Replace the held feed's chat ring by hand; returns how many lines the panel accepted. */
chat: (lines: readonly { by: string; text: string; bot?: boolean }[]) => number; chat: (lines: readonly { by: string; text: string; bot?: boolean }[]) => number;
/** Push reward events into the ticker by hand; returns the rows shown. */
ticker: (events: readonly { label: string; value: number }[], stepMs?: number) => string[];
/** Show a recovery notice by hand (validated like a polled one); null clears it. */ /** Show a recovery notice by hand (validated like a polled one); null clears it. */
recovery: (notice: unknown, nowS?: number) => RecoveryView | null; recovery: (notice: unknown, nowS?: number) => RecoveryView | null;
fly: () => { fly: () => {

View file

@ -89,6 +89,11 @@ export const pokemonRed: GameConfig = {
badge: { label: 'gym badge', tier: 'moment', dedupeMs: 0 }, badge: { label: 'gym badge', tier: 'moment', dedupeMs: 0 },
}, },
// The fly's own hits (adapter `damage`): several a battle, no protocol kind, so one row per
// battle that counts up. 45 s covers the slowest turn seen (about 7 s from press to payout)
// several times over and is far shorter than the gap between two battles.
hitCopy: { label: 'damage dealt', gapMs: 45_000, tier: 'quiet', koTier: 'notable' },
counters: [ counters: [
{ field: 'badges', label: 'badges', outOf: 8 }, { field: 'badges', label: 'badges', outOf: 8 },
{ field: 'uniqueLocations', label: 'places' }, { field: 'uniqueLocations', label: 'places' },

View file

@ -29,6 +29,21 @@ export interface RewardCopy {
collapsedNoun?: string; collapsedNoun?: string;
} }
/**
* Copy and window for the adapter's per-hit reward, which the protocol has no `rewardKind` for
* (Pokémon Red's `damage`, `HIT #<species> FOR <n> HP[ KO]`). Hits are folded stage-side into one
* row per battle instead of one row per hit.
*/
export interface HitCopy {
/** Row text. Constant; the feed's label is only read for the KO suffix. */
label: string;
/** A row is joined by a hit up to this long after the previous hit folded into it. */
gapMs: number;
/** Tier of the row; a KO raises it to `koTier`. */
tier: RewardTier;
koTier: RewardTier;
}
/** A counter shown in the progress row beside the milestone ladder. */ /** A counter shown in the progress row beside the milestone ladder. */
export interface GameCounter { export interface GameCounter {
/** Which `FeedGame` field to read. */ /** Which `FeedGame` field to read. */
@ -64,6 +79,8 @@ export interface GameConfig {
modeLabels: Record<GameMode, string>; modeLabels: Record<GameMode, string>;
/** Human copy and presentation tier for each reward kind. */ /** Human copy and presentation tier for each reward kind. */
rewardCopy: Record<RewardKind, RewardCopy>; rewardCopy: Record<RewardKind, RewardCopy>;
/** How a reward event with no `rewardKind` that reads as a hit is rolled up. Absent: never. */
hitCopy?: HitCopy;
/** /**
* Counters shown on the progress cluster's footer line (`ProgressCluster`), e.g. * Counters shown on the progress cluster's footer line (`ProgressCluster`), e.g.
* "3/8 badges · 214 places". Per-game *data*, not copy: the values come * "3/8 badges · 214 places". Per-game *data*, not copy: the values come

View file

@ -68,6 +68,9 @@ export const DEFAULT_TICKER_OPTIONS = {
*/ */
const HIDDEN_KINDS: ReadonlySet<FeedEventKind> = new Set<FeedEventKind>(['checkpoint', 'viewer']); const HIDDEN_KINDS: ReadonlySet<FeedEventKind> = new Set<FeedEventKind>(['checkpoint', 'viewer']);
/** The adapter's hit label: `HIT #<species> FOR <n> HP` with ` KO` when the hit felled a trainer's Pokémon. */
const HIT_LABEL = /^HIT #\d+ FOR \d+ HP( KO)?$/;
export class TickerQueue { export class TickerQueue {
private readonly visibleRows: number; private readonly visibleRows: number;
private readonly minDwellMs: number; private readonly minDwellMs: number;
@ -77,6 +80,8 @@ export class TickerQueue {
private visible: TickerItem[] = []; private visible: TickerItem[] = [];
private pending: TickerItem[] = []; private pending: TickerItem[] = [];
private lastPromotionMs = Number.NEGATIVE_INFINITY; private lastPromotionMs = Number.NEGATIVE_INFINITY;
/** Feed time of the last hit folded into each hit row, by the row. */
private readonly lastHitMs = new WeakMap<TickerItem, number>();
/** Bumped whenever the visible list changes, so the store can push to React on change only. */ /** Bumped whenever the visible list changes, so the store can push to React on change only. */
private revision = 0; private revision = 0;
@ -106,10 +111,11 @@ export class TickerQueue {
push(event: FeedEvent, nowMs: number): boolean { push(event: FeedEvent, nowMs: number): boolean {
if (HIDDEN_KINDS.has(event.kind)) return false; if (HIDDEN_KINDS.has(event.kind)) return false;
const tier = this.tierOf(event); const hit = this.hitOf(event);
const label = this.labelOf(event); const tier = hit ? this.hitTier(hit.ko) : this.tierOf(event);
const label = hit ? `${this.game.hitCopy?.label ?? event.label}${hit.ko ? ' KO' : ''}` : this.labelOf(event);
const folded = this.fold(event, nowMs); const folded = hit ? this.foldHit(event, hit.ko, nowMs) : this.fold(event, nowMs);
if (folded) return true; if (folded) return true;
const item: TickerItem = { const item: TickerItem = {
@ -125,6 +131,8 @@ export class TickerQueue {
...(event.by === undefined ? {} : { by: event.by }), ...(event.by === undefined ? {} : { by: event.by }),
}; };
if (hit) this.lastHitMs.set(item, nowMs);
if (tier === 'moment') { if (tier === 'moment') {
// Jump the gate: the badge is the reason anyone is watching. // Jump the gate: the badge is the reason anyone is watching.
this.promote(item, nowMs); this.promote(item, nowMs);
@ -176,6 +184,42 @@ export class TickerQueue {
return false; return false;
} }
/** Is this a hit the game rolls up? Only a reward with no `rewardKind` and the adapter's own label. */
private hitOf(event: FeedEvent): { ko: boolean } | null {
if (!this.game.hitCopy || event.kind !== 'reward' || event.rewardKind) return null;
const match = HIT_LABEL.exec(event.label);
return match ? { ko: match[1] !== undefined } : null;
}
private hitTier(ko: boolean): TickerTier {
const copy = this.game.hitCopy;
return copy ? (ko ? copy.koTier : copy.tier) : 'quiet';
}
/**
* Fold a hit into the battle's row: the newest hit row whose last hit is within `gapMs`. The
* window slides with each hit (unlike `fold`'s, which is from creation) because a battle has
* no fixed length; a row that has left the panel is not resurrected, the next hit starts one.
* The row shows the summed reward, a `x<n>` count and a KO once any hit in it felled a Pokémon.
*/
private foldHit(event: FeedEvent, ko: boolean, nowMs: number): boolean {
const copy = this.game.hitCopy;
if (!copy) return false;
for (const item of [...this.visible, ...this.pending]) {
const last = this.lastHitMs.get(item);
if (last === undefined || nowMs - last > copy.gapMs) continue;
item.count += 1;
if (event.value !== undefined) item.amount = (item.amount ?? 0) + event.value;
const knocked = ko || item.label.endsWith(' KO');
item.label = `${copy.label} x${item.count}${knocked ? ' KO' : ''}`;
if (knocked) item.tier = copy.koTier;
this.lastHitMs.set(item, nowMs);
this.revision += 1;
return true;
}
return false;
}
private tierOf(event: FeedEvent): TickerTier { private tierOf(event: FeedEvent): TickerTier {
if (event.kind === 'reward' && event.rewardKind) { if (event.kind === 'reward' && event.rewardKind) {
return this.game.rewardCopy[event.rewardKind]?.tier ?? 'quiet'; return this.game.rewardCopy[event.rewardKind]?.tier ?? 'quiet';

View file

@ -147,3 +147,41 @@ test('the platformer config paces the same way with different copy', async () =>
queue.push(reward('explore'), 100); queue.push(reward('explore'), 100);
assert.equal(queue.items()[0]?.label, '2 new ground'); assert.equal(queue.items()[0]?.label, '2 new ground');
}); });
function hit(hp: number, value: number, ko = false): FeedEvent {
return event('reward', `HIT #59 FOR ${hp} HP${ko ? ' KO' : ''}`, { value });
}
test('a battle\'s hits fold into one damage row that sums and counts', () => {
const queue = new TickerQueue(pokemonRed, { minDwellMs: 0 });
queue.push(hit(10, 0.06), 0);
queue.push(hit(9, 0.05), 7_000);
queue.push(hit(4, 0.03), 15_000);
assert.equal(queue.items().length, 1);
const row = queue.items()[0];
assert.equal(row?.label, 'damage dealt x3');
assert.equal(row?.count, 3);
assert.ok(Math.abs((row?.amount ?? 0) - 0.14) < 1e-9);
assert.equal(row?.tier, 'quiet');
});
test('a KO marks the row and raises its tier; the window slides, then a new battle is a new row', () => {
const queue = new TickerQueue(pokemonRed, { minDwellMs: 0 });
queue.push(hit(10, 0.06), 0);
queue.push(hit(5, 0.08, true), 30_000);
assert.equal(queue.items()[0]?.label, 'damage dealt x2 KO');
assert.equal(queue.items()[0]?.tier, 'notable');
queue.push(hit(3, 0.02), 70_000);
assert.equal(queue.items().length, 1, 'still inside 45 s of the last hit');
queue.push(hit(3, 0.02), 200_000);
assert.equal(queue.items().length, 2, 'a later battle gets its own row');
assert.equal(queue.items()[0]?.label, 'damage dealt');
});
test('a hit is not confused with other rewards, and a lone KO says so', () => {
const queue = new TickerQueue(pokemonRed, { minDwellMs: 0 });
queue.push(hit(31, 0.25, true), 0);
assert.equal(queue.items()[0]?.label, 'damage dealt KO');
queue.push(event('reward', 'NEW MAP', { value: 0.1 }), 10);
assert.equal(queue.items().length, 2, 'an unrelated no-kind reward keeps its own row');
});

View file

@ -93,6 +93,31 @@ const CHAT_WRAP: { by: string; text: string; bot?: boolean }[] = [
}, },
]; ];
/**
* The ticker in a battle (row 68): the fly's hits arrive as `HIT #<species> FOR <n> HP` rewards and
* fold into one "damage dealt" row. Injected by hand through `window.__stage.ticker`, seven feed
* seconds apart, because no fixture holds a battle recorded on adapter v8.
*/
const TICKER_SHOTS: { name: string; events: { label: string; value: number }[] }[] = [
{
name: 'row68-ticker-hits',
events: [
{ label: 'HIT #59 FOR 10 HP', value: 0.07 },
{ label: 'HIT #59 FOR 9 HP', value: 0.06 },
{ label: 'HIT #59 FOR 4 HP', value: 0.03 },
{ label: 'HIT #59 FOR 4 HP', value: 0.03 },
],
},
{
name: 'row68-ticker-ko',
events: [
{ label: 'HIT #59 FOR 10 HP', value: 0.07 },
{ label: 'HIT #59 FOR 9 HP', value: 0.06 },
{ label: 'HIT #59 FOR 12 HP KO', value: 0.13 },
],
},
];
const STILLS: { name: string; fixture: string; t: number; tab?: Tab; chat?: typeof CHAT_WRAP }[] = [ const STILLS: { name: string; fixture: string; t: number; tab?: Tab; chat?: typeof CHAT_WRAP }[] = [
{ name: 'steady-t1-senses', fixture: 'steady', t: 95, tab: 'senses' }, { name: 'steady-t1-senses', fixture: 'steady', t: 95, tab: 'senses' },
{ name: 'steady-t1-connectome', fixture: 'steady', t: 95, tab: 'connectome' }, { name: 'steady-t1-connectome', fixture: 'steady', t: 95, tab: 'connectome' },
@ -294,6 +319,18 @@ async function main(): Promise<void> {
console.log(` ${path} (${String(state?.moment)} ${String(state?.momentPhase)}, ${String(state?.particles)} particles, tab ${String(state?.tab)})`); console.log(` ${path} (${String(state?.moment)} ${String(state?.momentPhase)}, ${String(state?.particles)} particles, tab ${String(state?.tab)})`);
} }
for (const shot of TICKER_SHOTS) {
if (!wanted(shot.name)) continue;
await page.goto(url(baseUrl, { fixture: 'steady', t: 95, tab: 'senses' }));
await settle(page);
const rows = await page.evaluate((events) => window.__stage?.ticker(events) ?? [], shot.events);
await page.waitForTimeout(500);
const path = resolve(outDir, `${shot.name}.png`);
await page.screenshot({ path, clip: FRAME });
written.push(path);
console.log(` ${path} (${rows.join(' | ')})`);
}
for (const shot of RECOVERY_SHOTS) { for (const shot of RECOVERY_SHOTS) {
if (!wanted(shot.name)) continue; if (!wanted(shot.name)) continue;
await page.goto(url(baseUrl, { fixture: 'steady', t: 95, tab: 'senses' })); await page.goto(url(baseUrl, { fixture: 'steady', t: 95, tab: 'senses' }));