@lute-lang/player-web
v0.53.1
Published
The Lute web visual-novel player: PixiJS 8 renderer, Web Audio, screens and input over @lute-lang/player.
Readme
@lute-lang/player-web
The Lute 0.53 browser visual-novel player. It supplies PixiJS 8 rendering, Web Audio, screens, and keyboard/mouse/touch/gamepad input for the renderer-free @lute-lang/player core.
Install
bun add @lute-lang/[email protected] @lute-lang/[email protected] @lute-lang/[email protected] [email protected] @effect/[email protected] [email protected] @pixi/[email protected]
# npm install @lute-lang/[email protected] @lute-lang/[email protected] @lute-lang/[email protected] [email protected] @effect/[email protected] [email protected] @pixi/[email protected]The package requires exact [email protected] and @effect/[email protected] peers. Runtime and player packages are released in lockstep.
Minimal usage
Serve a lute compile --project bundle, the runtime wasm file, the bindings file, and its assets. Then mount into an element:
import { mountPlayer } from "@lute-lang/player-web"
const options = {
bindings: { url: "/player.bindings.yaml" },
bundleUrl: "/bundle/",
wasmUrl: "/wasm/lute_runtime_wasm_bg.wasm",
assetsUrl: "/assets/",
storageKey: "my-game"
} as const
const player = await mountPlayer(document.querySelector("#player")!, options)
await player.act({ type: "newGame" })
const view = await player.view()
// A player save can resume a fresh player:
const save = await player.snapshot()
await player.unmount()
const resumed = await mountPlayer(document.querySelector("#player")!, { ...options, snapshot: save.snapshot })
await resumed.restore(save)
// Later:
await resumed.unmount()mountPlayer returns Promise methods act, view, send, snapshot, restore, and unmount, plus the handle's session, program, and bundle values (session.current holds the state program's read-only queries take). The methods run the same Effects as the scoped LuteWeb.mount handle and reject with the Effect failure. The handle's bundle is the exact compiled bundle loaded by the player, so hosts can inspect artifacts without loading it again. MountOptions accepts the same seed/snapshot/session start union and cueFactory, linePacing, and autosave options as LutePlayer.make. Textures use a private Pixi asset manager; player-web does not initialize Pixi's global Assets.
When bindings define ui.ended, an ended state member selects a named ending screen. Player-web queries program.view(state) (the runtime's WorldView) at ended and selects a screen only when the entry at ui.ended.by is a { kind: "str", value } whose value screens maps; it displays that screen's title and text and loads its optional background through the private asset manager. An absent entry, another kind, an unmapped member or a failing query keeps the stock ending screen.
The stage is drawn in fixed layers, bottom to top: background, camera (actors), cg, video, dialogue, choice, overlay, transition. A ::cg covers the actors and stays under the dialogue window and UI.
The title screen's heading is the bound ui.title.text; without it the title draws no heading (never a placeholder name). Without ui.title.background the title has no backdrop, and without ui.title.music it plays no music.
Cue handling
- Names. The dialogue name plate and backlog rows show
speakerName, the cast display name from the bundle index (cast: { id: name }); name colours stay keyed by the speaker id. - Music.
PixiAudiohonoursAudioPlay.restart:restart: trueplays the file from its start; without it, the music file already playing only changes volume, fading overfade, and a different file crossfades. Audio plays only after a user gesture unlocks it; until then a musicplaywaits, and a later musicplayorstopsupersedes every earlier musicplaystill waiting (for the unlock, its file or the backend), which completes without starting (at once while it waits for the unlock; a backend play that resolves after it was superseded is stopped, never recorded). So a load before any gesture reaches its restored await at once, and the loaded stage's music (not the title music requested at mount) starts when audio unlocks. - Camera. The
cameralayer rests at alpha 1 with no mask. Atransitionwith a hiding effect (fade,dissolve,fadeOut,wipe*,slideLeft/slideRight,slideOut) hides the actors over the first half, applies the framing, and shows them over the second half; other effects apply the framing, then play. Every cue ends visible in its framing;cut,none, a zero duration and skip apply it at once; a started transition keeps playing after its batch ends (it runs in the player's scope); a later camera cue supersedes it, and so does skip when it starts while the cue still runs (a transition whose cue already ended finishes at normal speed); amovetakes precedence; a wipe sweeps the design stage, not the actors' span;restore(load, rollback) cancels running camera behaviours and rests the layer before applying the framing. - Custom vfx. A
StageCue.Vfxwhoseeffect.effectis"custom"(a project vfx bound as{ effect: custom }, or a vfx type with no binding) has no Pixi effect: the presenter plays nothing and logseffect.nameonce at debug level (PresenterOptions.debug, defaultconsole.debug). Render project effects with your ownPresenter.
Tests
bun run test # unit tests (node); real-runtime tests compile fixtures with the lute binary
bun run test:browser # Chromium (vitest browser mode, WebGL via SwiftShader); projects `browser` and `real` (test/browser/real, one file at a time)
bun run test:e2e # Playwright over `bun run demo`The suites build the CLI with cargo build -q -p lute-cli unless LUTE_BIN names a lute executable.
Player behaviour is tested against real runtime output, never a hand-written view, record or bundle:
- Node.
test/support/bundle.tscompiles a project (compileProject(name, dir, locales?),localesalute loc importbundle passed as--locale-bundle; output undernode_modules/.lute-test/); tests drive it with@lute-lang/runtime/bun(seetest/ui/ended.test.ts). - Browser. The
realproject (test/browser/real/, invitest.browser.config.ts) runs its files one at a time: its players animate on the per-frame clock (at most 0.1s a frame), so files rendering side by side on a few CPUs stretch every playthrough past its deadlines; the batch-end camera test reads the player's clock (pixi.frames), not wall time. Itstest/browser/globalSetup.tscompiles once the projects registered inrealProjects(globalSetup.ts:examples/player-demowith its Korean bundlelocales/bundle.json, and fixtures undertest/fixtures/; add new fixtures there) and provides its URLs (inject("luteProjects"); vite serves them through/@fs/).test/browser/support/real-player.tsmounts player-web withmountover that bundle and the packaged wasm runtime:mountProject(name, options?)(demo= examples/player-demo, others undertest/fixtures/) (a freshstorageKeyunless one is passed; mounting again with the same key afterclose()models a reload over the same storage),playUntil(player, stop, prefer?)plays with realPlayerActions (New game, idle menu, choices by preferred option id, advance),playReading(player, stop, prefer?)plays the same way but records every dialogue line and choice menu as drawn and advances a line only after reading it (each fails whenstopdoes not hold withinplaythroughMs, 300 s: the demo played to an ending takes about 1 min on a fast machine, over 2 min on a CI runner; a test makingcountsuch calls takesplaythroughTimeout(count)),buttonLabelled(container, label)finds a drawn button toactivate(), and assertions read what player-web drew:player.pixi.layers(the mounted Pixi stage from the internalpixiAppOf(element), not exported from the package),drawnTexts(container)andstagePixels(pixi, frame). Seetest/browser/real/.
API and guides
Source and releases: github.com/journeyWorker/lute.
