WindowPlugin

View source

ExtendsPlugin

Adds ECS window support to an App.

WindowPlugin adds a Windows resource to the app’s default world and provides typed window, keyboard, pointer, and file events such as WindowMove, KeyDown, PointerDown, and FileDrop. The window state types, including WindowRequest, Window, MainWindow, and Windows, are available to persistence-facing features.

By default, the plugin creates one primary-window entity with a Window initialized from primaryWindowOptions and a MainWindow marker. An optional browser integration layer can connect Window components to browser HTMLCanvasElement instances and keep the associated Windows resource in sync. Set initPrimaryWindow to false when your code will create and manage window entities itself; the resource, events, and persistence-facing support remain available.

The plugin requires CorePlugin and ReflectPlugin. When initPrimaryWindow is enabled, it also requires CommandsPlugin. These dependencies are checked by the app and are not installed automatically.

Examples

import { App } from '@wimaengine/app'
import { CommandsPlugin } from '@wimaengine/command'
import { CorePlugin } from '@wimaengine/core'
import { ReflectPlugin } from '@wimaengine/reflect'
import { WindowPlugin } from '@wimaengine/window'

new App()
  .registerPlugin(new ReflectPlugin())
  .registerPlugin(new CorePlugin())
  .registerPlugin(new CommandsPlugin())
  .registerPlugin(new WindowPlugin({
    primaryWindowOptions: {
      selector: '#game',
      width: 1280,
      height: 720
    }
  }))
  .run()

Constructor


constructor(options?: WindowPluginOptions)

View source

Creates the window plugin configuration.

The default configuration creates a primary window entity. Set initPrimaryWindow to false when your code manages its own window entities.

Parameters

NameDescriptionDefault
options?

Primary-window options.

{}

Properties


readonlyinitPrimaryWindow: boolean

View source

Whether the plugin creates the default primary-window entity.

When true, the plugin creates one entity with Window and MainWindow. When false, the application is responsible for creating and managing its own window entities.

readonlyprimaryWindowOptions: WindowOptions

View source

Options forwarded to the primary entity’s Window component.

These options are used only when initPrimaryWindow is true.

Methods


register(app: App): void

View source

Configures an App with the window layer.

Adds a Windows resource to the app’s default world and registers typed window movement and resize, keyboard, pointer, and file drag/drop events, including WindowMove, WindowResize, KeyDown, PointerMove, and FileDrop. It also makes WindowRequest, Window, MainWindow, and Windows available to persistence-facing features.

When initPrimaryWindow is enabled, the plugin creates one primary-window entity with Window and MainWindow, using primaryWindowOptions. When it is disabled, no default primary-window entity is created and your code can create its own window entities. A browser integration layer can connect those entities to browser canvases.

Parameters

NameDescriptionDefault
app——

requires(): TypeId[]

View source

Lists the plugin type IDs required by this configuration.

The returned IDs always include CorePlugin and ReflectPlugin. When initPrimaryWindow is true, the list also includes CommandsPlugin for the default primary-window entity.

Returns

Required plugin type IDs.