UNPKG

blaze-2d

Version:

A fast and simple WebGL 2 2D game engine written in TypeScript

61 lines (59 loc) 1.63 kB
import BlazeText from "./text"; const RdIYRpeHAtbz = document.createElement("style"); RdIYRpeHAtbz.textContent = `.blzStat { margin-bottom: 0.4ch; } `; document.head.appendChild(RdIYRpeHAtbz); export default class BlazeStat extends BlazeText { /** * Create a {@link BlazeStat}. * * @param name The stat's name * @param value The stat's default value * @param size The stat's font size in `rem` units, if none is given then size will be `auto` * @param bold Wether or not the stat's text is bold * @param style The style of the element's text */ constructor(name, value, size, bold, style) { super("", size, bold, style); this.element.classList.add("blzStat"); this.name = name; this.value = value; this.refresh(); } /** * Update the stat's dom elements. */ refresh() { const text = `${this.name}: ${this.valueToString()}`; this.setText(text); } valueToString() { const type = typeof this.value; if (type === "number" || type === "string" || type === "boolean" || type === "bigint") { return String(this.value); } else if (this.value.toString) { return this.value.toString(); } } /** * Sets the stat's value. * * @param value The stat's value */ setValue(value) { this.value = value; this.refresh(); } /** * Gets the stat's value. * * @returns The stat's value */ getValue() { return this.value; } } //# sourceMappingURL=stat.js.map