Refine chat layout and collapse consecutive match events

This commit is contained in:
2026-10-02 13:44:44 -04:00
parent d7b3e124e6
commit a2e2311aa9
4 changed files with 172 additions and 41 deletions
+22
View File
@@ -0,0 +1,22 @@
import type { ContextualChatEntry } from '../game-chat.js';
export type ChatMessageEntry = Extract<ContextualChatEntry, { type: 'message' }>;
export type ChatBoundaryEntry = Extract<ContextualChatEntry, { type: 'boundary' }>;
export type ChatTimelineItem =
| { type: 'message'; entry: ChatMessageEntry }
| { type: 'boundaries'; entries: ChatBoundaryEntry[] };
/** Group adjacent lifecycle events for display without discarding log history. */
export function groupChatTimeline(entries: readonly ContextualChatEntry[]): ChatTimelineItem[] {
const timeline: ChatTimelineItem[] = [];
for (const entry of entries) {
if (entry.type === 'message') {
timeline.push({ type: 'message', entry });
} else {
const previous = timeline.at(-1);
if (previous?.type === 'boundaries') previous.entries.push(entry);
else timeline.push({ type: 'boundaries', entries: [entry] });
}
}
return timeline;
}