import { events } from "../core/events.js";
const MAX_MESSAGES = 50;
/**
* Message log — appends game messages to the #message-list element and
* auto-scrolls to the bottom.
*/
export function initMessageLog() {
const list = document.getElementById("message-list");
if (!list) return;
function append(text) {
const li = document.createElement("li");
li.innerHTML = text;
list.appendChild(li);
// Trim old messages
while (list.children.length > MAX_MESSAGES) {
list.removeChild(list.firstChild);
}
list.scrollTop = list.scrollHeight;
}
// Regular game messages (from a cell context)
events.onMessage((_cell, text) => {
if (text) {
append(text);
}
});
// Cancel messages routed through the message log (not modals)
// These arrive via events.fireMessage(cell, text) — same channel.
}