Some improvements
This commit is contained in:
parent
23a6b473ae
commit
b1b3ca685a
20 changed files with 259 additions and 217 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue