UNPKG

malwoden

Version:

![alt text](./coverage/badge-lines.svg) ![alt text](./coverage/badge-statements.svg) ![alt text](./coverage/badge-functions.svg) ![alt text](./coverage/badge-branches.svg)

60 lines 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Display = void 0; var table_1 = require("../struct/table"); /** Represents glyph data, agnostic to how it is rendered. */ var Display = /** @class */ (function () { /** * Creates a new Display * @param width - The number of glyphs wide the display is * @param height - The number of glyphs tall the display is */ function Display(width, height) { this.width = width; this.height = height; this.glyphs = new table_1.Table(width, height); this.changedGlyphs = new table_1.Table(width, height); } /** * Returns a Vector representing the width/height of the display. */ Display.prototype.size = function () { return { x: this.width, y: this.height }; }; /** * Sets a single glyph in the display. * * @param pos Vector2 - The position of the Glyph * @param glyph Glyph - The Glyph */ Display.prototype.setGlyph = function (pos, glyph) { if (this.glyphs.isInBounds(pos) === false) return; if (glyph.isEqual(this.glyphs.get(pos))) { this.changedGlyphs.set(pos, undefined); } else { this.changedGlyphs.set(pos, glyph); } }; /** * Calls the callback with each x/y/glyph pair. * The terminal needs to decide how to render the display. * The callback is called bottom to top, right to left. */ Display.prototype.render = function (callback) { for (var y = this.height - 1; y >= 0; y--) { for (var x = this.width - 1; x >= 0; x--) { var glyph = this.changedGlyphs.get({ x: x, y: y }); if (!glyph) continue; callback({ x: x, y: y }, glyph); this.glyphs.set({ x: x, y: y }, glyph); this.changedGlyphs.set({ x: x, y: y }, undefined); } } }; return Display; }()); exports.Display = Display; //# sourceMappingURL=display.js.map