23 lines
980 B
TypeScript
23 lines
980 B
TypeScript
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;
|
|
}
|