diff --git a/packages/framework/src/ui/GameUI.tsx b/packages/framework/src/ui/GameUI.tsx index d9e0161..412194f 100644 --- a/packages/framework/src/ui/GameUI.tsx +++ b/packages/framework/src/ui/GameUI.tsx @@ -1,14 +1,28 @@ +import type { JSX } from "preact"; + export interface GameUIOptions { - container: HTMLElement; - root: HTMLElement; + container: HTMLElement | string; + root: JSX.Element; } export class GameUI { private container: HTMLElement; - private root: HTMLElement; + private root: JSX.Element; constructor(options: GameUIOptions) { - this.container = options.container; + if (typeof options.container === "string") { + const existing = document.getElementById(options.container); + if (existing) { + this.container = existing; + } else { + const newContainer = document.createElement("div"); + newContainer.id = options.container; + document.body.appendChild(newContainer); + this.container = newContainer; + } + } else { + this.container = options.container; + } this.root = options.root; }