Skip to content

Commit

Permalink
Add method to get viewport HTMLElement
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed Jan 23, 2024
1 parent 5c04fb6 commit 5f83907
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions srcjs/stendhal/ui/ViewPort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 5f83907

Please sign in to comment.