Use canvas instead of div container for calculating the game size

This commit is contained in:
Paul Bottein 2021-01-27 12:38:57 +01:00
parent b7b2934106
commit b52c546a8c
2 changed files with 10 additions and 1 deletions

View File

@ -7,6 +7,15 @@ export class HtmlUtils {
throw new Error("Cannot find HTML element with id '"+id+"'"); throw new Error("Cannot find HTML element with id '"+id+"'");
} }
public static querySelectorOrFail<T extends HTMLElement>(selector: string): T {
const elem = document.querySelector(selector);
if (elem === null) {
throw new Error("Cannot find HTML element with selector '"+selector+"'");
}
// FIXME: does not check the type of the returned type
return elem as T;
}
public static removeElementByIdOrFail<T extends HTMLElement>(id: string): T { public static removeElementByIdOrFail<T extends HTMLElement>(id: string): T {
const elem = document.getElementById(id); const elem = document.getElementById(id);
if (HtmlUtils.isHtmlElement<T>(elem)) { if (HtmlUtils.isHtmlElement<T>(elem)) {

View File

@ -212,7 +212,7 @@ class LayoutManager {
* Tries to find the biggest available box of remaining space (this is a space where we can center the character) * Tries to find the biggest available box of remaining space (this is a space where we can center the character)
*/ */
public findBiggestAvailableArray(): {xStart: number, yStart: number, xEnd: number, yEnd: number} { public findBiggestAvailableArray(): {xStart: number, yStart: number, xEnd: number, yEnd: number} {
const game = HtmlUtils.getElementByIdOrFail<HTMLDivElement>('game'); const game = HtmlUtils.querySelectorOrFail<HTMLDivElement>('#game canvas');
if (this.mode === LayoutMode.VideoChat) { if (this.mode === LayoutMode.VideoChat) {
const children = document.querySelectorAll<HTMLDivElement>('div.chat-mode > div'); const children = document.querySelectorAll<HTMLDivElement>('div.chat-mode > div');
const htmlChildren = Array.from(children.values()); const htmlChildren = Array.from(children.values());