oden/game/log.ts
John Doty 93d4e3eb91 [oden][game] Multiple screens, logging, pre/post, bluescreen
Better blue screens and also logging and whatnot
2023-09-11 20:41:11 -07:00

35 lines
728 B
TypeScript

import { color, print } from "./graphics";
interface LogEntry {
frame_age: number;
line: string;
}
const lines: Map<string, LogEntry> = new Map();
export function log(key: string, ...args: unknown[]) {
const entry = {
frame_age: 60,
line: key + " " + args.join(" "),
};
lines.set(key, entry);
}
export function draw_log() {
color(1, 1, 1, 1);
let line_y = 3;
const keys = [...lines.keys()].sort();
for (const key of keys) {
const entry = lines.get(key);
if (entry) {
// Life is too short for me to convince typescript.
print(3, line_y, entry.line);
line_y += 8;
entry.frame_age -= 1;
if (entry.frame_age <= 0) {
lines.delete(key);
}
}
}
}