From 5f83907123ece53a5f464af6f770eefe504b26cd Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Mon, 22 Jan 2024 21:35:14 -0800 Subject: [PATCH] Add method to get viewport HTMLElement --- srcjs/stendhal/ui/ViewPort.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/srcjs/stendhal/ui/ViewPort.ts b/srcjs/stendhal/ui/ViewPort.ts index b41c129e7f9..52e6e7db01e 100644 --- a/srcjs/stendhal/ui/ViewPort.ts +++ b/srcjs/stendhal/ui/ViewPort.ts @@ -81,12 +81,22 @@ export class ViewPort { * Hidden singleton constructor. */ private constructor() { - const element = document.getElementById("gamewindow")! as HTMLCanvasElement; + const element = this.getElement() as HTMLCanvasElement; this.ctx = element.getContext("2d")!; this.width = element.width; this.height = element.height; } + /** + * Retrieves the viewport element. + * + * @return + * Viewport `HTMLElement`. + */ + public getElement(): HTMLElement { + return document.getElementById("gamewindow")!; + } + draw() { var startTime = new Date().getTime(); @@ -442,7 +452,7 @@ export class ViewPort { var x = pos.canvasRelativeX + stendhal.ui.gamewindow.offsetX; var y = pos.canvasRelativeY + stendhal.ui.gamewindow.offsetY; var entity = stendhal.zone.entityAt(x, y); - document.getElementById("gamewindow")!.style.cursor = entity.getCursor(x, y); + this.getElement().style.cursor = entity.getCursor(x, y); } /**