import { Avatar, IconButton, ImageList, ImageListItem, ListItem, ListItemAvatar, ListItemText, Typography } from '@mui/material'; import React, { Fragment, MutableRefObject } from 'react'; import { Camera } from '@mui/icons-material'; import { formatters } from './format.js'; import { GameEvent } from './models.js'; export function openImage(image: string) { const byteCharacters = atob(image); const byteNumbers = new Array(byteCharacters.length); for (let i = 0; i < byteCharacters.length; i++) { byteNumbers[i] = byteCharacters.charCodeAt(i); } const byteArray = new Uint8Array(byteNumbers); const file = new Blob([byteArray], { type: 'image/jpeg;base64' }); const fileURL = URL.createObjectURL(file); window.open(fileURL, '_blank'); } export interface EventItemProps { // eslint-disable-next-line @typescript-eslint/no-explicit-any event: any; // eslint-disable-next-line @typescript-eslint/no-explicit-any focusRef?: MutableRefObject; renderEvent: (event: GameEvent) => void; } export function ActionEventItem(props: EventItemProps) { const { event, renderEvent } = props; const { id, actor, room, type } = event; const content = formatters[type](event); return renderEvent(id)}> } > {actor.name} {content} } /> ; } export function SnapshotEventItem(props: EventItemProps) { const { event } = props; const { step, world } = event; const { name, theme } = world; return Step: {step} World Theme: {theme} } /> ; } export function ReplyEventItem(props: EventItemProps) { const { event } = props; const { text } = event; return {text} } /> ; } export function PlayerEventItem(props: EventItemProps) { const { event } = props; const { character, status, client } = event; let primary = ''; let secondary = ''; if (status === 'join') { primary = 'Player Joined'; secondary = `${client} is now playing as ${character}`; } if (status === 'leave') { primary = 'Player Left'; secondary = `${client} has left the game. ${character} is now controlled by an LLM`; } return {secondary} } /> ; } export function RenderEventItem(props: EventItemProps) { const { event } = props; const { images } = event; return {Object.entries(images).map(([name, image]) => openImage(image)} alt="Render" /> )} } /> ; } export function EventItem(props: EventItemProps) { const { event } = props; const { type } = event; switch (type) { case 'action': case 'result': return ; case 'reply': case 'status': // TODO: should have a different component return ; case 'player': return ; case 'render': return ; case 'snapshot': return ; default: return ; } }