Windows

View source

Stores the canvas registered for each window entity.

Windows is a world resource installed by WindowPlugin. Browser integration can register the canvas associated with each Window component. This resource stores those references; it does not create, append, resize, focus, or remove canvas elements itself.

Each entry is keyed by the exact value returned by EntityHandle#id. That packed EntityId includes an entity’s slot and generation, so an entity that replaces an older one in the same slot receives a different key. These methods do not check whether a handle is still live; they use its current id only. Delete entries during teardown and do not use a stale handle to access a canvas that has been closed.

WindowCommand uses this resource to find a canvas for a queued window operation. Read the shared resource with world.getResource(Windows) rather than creating one for each entity.

Examples

import { World } from '@wimaengine/ecs'
import { Windows } from '@wimaengine/window'

const world = new World()
world.setResource(new Windows())

const entity = world.spawn([])
const canvas = document.createElement('canvas')
const windows = world.getResource(Windows)

windows.setWindow(entity, canvas)
console.log(windows.getWindow(entity) === canvas) // true

windows.delete(entity)
console.log(windows.getWindow(entity)) // undefined

Constructor


constructor()

Methods


getWindow(entity: EntityHandle): HTMLCanvasElement

View source

Returns the canvas registered under an entity’s id.

This lookup does not query the world or verify that the entity is still alive. It returns undefined when no canvas is registered for the id.

Parameters

NameDescriptionDefault
entity——

Returns

The registered canvas, if any.

setWindow(entity: EntityHandle, window: HTMLCanvasElement): void

View source

Registers a canvas under an entity’s id.

Registering another canvas for the same id replaces the previous reference. This does not append the canvas to the document, change its dimensions, or focus it.

Parameters

NameDescriptionDefault
entity——
window——

delete(entity: EntityHandle): void

View source

Deletes the canvas registered under an entity’s id.

This only changes the resource map. It does not remove or modify the canvas element.

Parameters

NameDescriptionDefault
entity——