跳转到内容

PlatformAdapter

此内容尚不支持你的语言。

Defined in: platform/types.ts:361

readonly optional family?: "minigame"

Defined in: platform/types.ts:369

The capability family this platform belongs to, if any. Absent means the platform stands alone (web, node, native). Set by the mini-game family adapter — the single reason isMiniGame() needs no vendor list.


readonly name: PlatformName

Defined in: platform/types.ts:362

bindInputEvents(callbacks, target?): void

Defined in: platform/types.ts:412

InputEventCallbacks

unknown

void


clearStorage(prefix): void

Defined in: platform/types.ts:485

string

void


optional createAudioBackend(): PlatformAudioBackend

Defined in: platform/types.ts:427

Create the platform audio backend (WebAudio on web, the mini-game audio API on WeChat). Optional — a host with no audio device (headless node, the unshipped native shell) omits it and the audio system falls back to the silent Null backend, exactly like createVideoBackend.

PlatformAudioBackend


createCanvas(width, height): PlatformCanvas

Defined in: platform/types.ts:386

number

number

PlatformCanvas


createImage(): PlatformImage

Defined in: platform/types.ts:410

PlatformImage


optional createSocket(options): PlatformSocket

Defined in: platform/types.ts:461

Open a socket connection. Web → WebSocket, WeChat → wx.connectSocket, Node → a ws wrapper. Optional — platforms without networking (playable ads) omit it and createSocket() fails loud.

PlatformSocketOptions

PlatformSocket


optional createTextEditor(): PlatformTextEditor | null

Defined in: platform/types.ts:406

The OS text-editing surface for editable fields (see PlatformTextEditor). Optional — a host without one (a headless realm, the editor’s edit mode) renders fields but cannot type into them.

PlatformTextEditor | null


optional createVideoBackend(ctx): PlatformVideoBackend

Defined in: platform/types.ts:434

Create the platform video backend: HTMLVideoElement on web, the wasm software decoder (videodec side module) on WeChat. The choice is a static per-platform matrix — no runtime fallback chain. Optional — a platform without video (headless server) omits it and the video system uses the silent Null backend.

VideoBackendContext

PlatformVideoBackend


devicePixelRatio(): number

Defined in: platform/types.ts:480

number


fetch(url, options?): Promise<PlatformResponse>

Defined in: platform/types.ts:371

string

PlatformRequestOptions

Promise<PlatformResponse>


fileExists(path): Promise<boolean>

Defined in: platform/types.ts:377

string

Promise<boolean>


getStorageItem(key): string | null

Defined in: platform/types.ts:482

string

string | null


instantiateWasm(pathOrBuffer, imports): Promise<WasmInstantiateResult>

Defined in: platform/types.ts:381

string | ArrayBuffer

WebAssembly.Imports

Promise<WasmInstantiateResult>


optional language(): string

Defined in: platform/types.ts:478

The host’s UI language tag (‘zh-CN’, ‘en-US’, …). WeChat reports ‘zh_CN’-style tags — platformLanguage() normalizes underscores. Optional; web falls through to navigator.language.

string


loadImagePixels(path): Promise<ImageLoadResult>

Defined in: platform/types.ts:379

string

Promise<ImageLoadResult>


optional loadSubpackage(name): Promise<void>

Defined in: platform/types.ts:441

Download an on-demand asset subpackage by name and resolve when its files are available. WeChat → wx.loadSubpackage; platforms with no subpackage concept (web) omit it and lazy groups load directly from their URLs.

string

Promise<void>


now(): number

Defined in: platform/types.ts:408

number


optional onAppHide(callback): () => void

Defined in: platform/types.ts:473

() => void

() => void


optional onAppShow(callback): () => void

Defined in: platform/types.ts:472

App foreground/background signals, for platforms with no DOM visibility event. The native shell pushes them through its bridge; the Lifecycle plugin subscribes and auto-pauses on hide. Web/WeChat read visibility from their own globals (document/wx) and omit these. Each returns an unsubscribe.

() => void

() => void


optional onMemoryWarning(callback): () => void

Defined in: platform/types.ts:466

Subscribe to OS memory-pressure warnings; returns an unsubscribe. WeChat → wx.onMemoryWarning; platforms without a pressure signal (web) omit it. Residency caches subscribe to drop their evictable entries.

() => void

() => void


optional pollGamepads(): GamepadSnapshot[]

Defined in: platform/types.ts:421

Poll connected gamepads for this frame. Optional — platforms without gamepad support (WeChat, headless) omit it and the input plugin skips gamepad polling entirely.

GamepadSnapshot[]


optional rasterizeGlyph(request): PlatformGlyph | null

Defined in: platform/types.ts:399

Rasterize one glyph through the OS text stack, for a platform with no 2D canvas to draw it on. Synchronous: the dynamic glyph atlas fills cells during the frame it needs them.

Optional — a platform that has createCanvas omits it and the atlas uses the Canvas2D rasterizer (web, WeChat). Native implements it (the embedded-Dawn host has no DOM), and null means the font or the glyph was unavailable, which the atlas treats as “no cell” exactly as it does a canvas miss.

PlatformGlyphRequest

PlatformGlyph | null


optional readCacheFile(key): Promise<ArrayBuffer | null>

Defined in: platform/types.ts:455

Persistent content-addressed byte cache — the offline/disk primitive behind hot-update. key is an immutable content-addressed url (the asset’s <hash>.<ext> CDN url), so an entry NEVER goes stale and needs no invalidation. Hot-update writes each verified downloaded asset here; the http backend reads it first so updated assets stay available offline and skip the CDN roundtrip.

Optional — a platform with no local storage (web relies on the browser HTTP cache) omits BOTH; then platformReadCacheFile returns null (a miss → normal fetch) and platformWriteCacheFile is a no-op. Node (fs) and native (the shell’s on-disk store) implement them; WeChat may later back them with wx user storage.

string

Promise<ArrayBuffer | null>


readFile(path): Promise<ArrayBuffer>

Defined in: platform/types.ts:373

string

Promise<ArrayBuffer>


readTextFile(path): Promise<string>

Defined in: platform/types.ts:375

string

Promise<string>


removeStorageItem(key): void

Defined in: platform/types.ts:484

string

void


setStorageItem(key, value): void

Defined in: platform/types.ts:483

string

string

void


optional unbindInputEvents(): void

Defined in: platform/types.ts:416

Tear down the listeners bindInputEvents registered. Optional — a headless host that never binds input (node) omits it.

void


optional writeCacheFile(key, bytes): Promise<void>

Defined in: platform/types.ts:456

string

ArrayBuffer

Promise<void>