Refine chat layout and collapse consecutive match events
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user