Some improvements

This commit is contained in:
schmelczerandras 2020-09-11 21:06:40 +02:00
parent 23a6b473ae
commit b1b3ca685a
20 changed files with 259 additions and 217 deletions

View file

@ -2,6 +2,8 @@ import { RenderCommand } from '../../drawing/commands/render';
import { GameObject } from '../game-object';
export class InfoText extends GameObject {
private static MinRowLength = 60;
constructor() {
super();
@ -10,13 +12,25 @@ export class InfoText extends GameObject {
private static records: Map<string, string> = new Map();
public static modifyRecord(key: string, value: string) {
public static modifyRecord(key: string, value: string | any) {
if (typeof value == 'string') {
value = ' ' + value;
} else {
value = JSON.stringify(
value,
(_, v) => (v.toFixed ? Number(v.toFixed(2)) : v),
' '
);
}
InfoText.records.set(key, value);
}
private draw(e: RenderCommand) {
let text = '';
InfoText.records.forEach((v, k) => (text += `${k}\n\t${v}\n`));
InfoText.records.forEach(
(v, k) => (text += `${k}\n${v.padEnd(InfoText.MinRowLength)}\n`)
);
e.renderer.drawInfoText(text);
}
}