FERRETGame engine over Babylon.js
Ferret

@ferret/player

Playing a game package: playPackage takes a .fex (or a .fprj, for the viewer), checks it, builds the game from its game block, mounts its levels, runs its code against the engine modules th…

Playing a game package: playPackage takes a .fex (or a .fprj, for the viewer), checks it, builds the game from its game block, mounts its levels, runs its code against the engine modules the page has loaded, and starts at entry.level. The player page (stage P3) wraps this in the <ferret-player> element; a test calls it directly.

6 exports · source in packages/player/src

Classes

PlayError class

class PlayError extends Error

What is wrong with a package that cannot be played, in one message with the path of the first problem.

constructor(message: string, readonly path = '/')

packages/player/src/index.ts:66

Functions

insertUi function

function insertUi(root: HTMLElement, html: string): void

Insert a game's UI fragment. It runs no scripts of its own: script elements, inline handlers and javascript: links are dropped.

packages/player/src/index.ts:130

playPackage function

async function playPackage(o: PlayOptions): Promise<Played>

packages/player/src/index.ts:70

Interfaces

GameContext interface

interface GameContext extends LibraryContext

What a game's install(ctx) is given: the library context, and the game around it.

game: Game
levels: LevelService
root: HTMLElementthe element that holds the game's UI (entry.ui is inserted here; a game may add its own)
args: URLSearchParamsthe tag's args; a game never reads location
tier: 'desktop' | 'mobile' | 'low'the content tier the player chose

packages/player/src/index.ts:41

Played interface

interface Played
game: Game
pkg: FerretPackage
world: Game['world']
levels: LevelService
mount: PackageMount
code: CodeLoader
level: stringthe level that was started
stop(): void
dispose(): void

packages/player/src/index.ts:52

PlayOptions interface

interface PlayOptions
canvas: HTMLCanvasElement
source: PackageInput | FerretPackagethe package: a URL, bytes, a Blob, or an opened package
fileName?: stringthe file's name when the source has none (a Blob): .fex must be a game and .fprj a project
tier?: QualityTierthe render quality (default: the platform's choice)
contentTier?: 'desktop' | 'mobile' | 'low'the content tier: the game's tiers folder for it replaces the root's files (default desktop)
trusted?: () => Iterable<string> | undefinedkey ids whose signatures are trusted (the game's own code runs anyway: it is what the player was asked to play)
level?: stringstart here instead of entry.level
ferret?: unknownthe engine's API for code that wants an object instead of imports (the old bundle). ES-module code needs none.
origin?: booleandoes the package come from the player's own site? Then its code runs unsigned. Default true: the caller decides.
onExit?: () => voidthe game called platform.exit() (the player's exit event); without it exit does what the platform does
root?: HTMLElementthe element for the game's UI (default: a new one over the canvas)
args?: stringthe tag's args as a query string
onProgress?: (p: number) => voidcalled with 0..1 while the start level loads

packages/player/src/index.ts:12