FERRETGame engine over Babylon.js
Ferret

@ferret/player

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:82

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:171

playPackage function

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

packages/player/src/index.ts:86

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:55

Played interface

interface Played
game: Game
pkg: FerretPackage
world: Game['world']
levels: LevelService
mount: PackageMount
code: CodeLoader
level: stringthe level that was started
dependencies: { id: string; version: string; url: string; catalog: string }[]the dependencies the player fetched from catalogs before the start
stop(): void
dispose(): void

packages/player/src/index.ts:66

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
base?: stringwhere the package was loaded from: its relative catalogs are read from here (default: the source when it is a URL, else the page). The editor plays a blob, so it passes the URL the project came from.
catalogs?: string[]more catalogs to look for dependencies in, after the package's own: absolute URLs, or relative to the page
store?: AssetStorethe store dependencies are fetched through (default: one with the persistent cache, if the browser has one)
catalogPolicy?: (catalogUrl: string) => CatalogPolicyhow a catalog is checked; default: unsigned is accepted from the page's own origin only, elsewhere a valid signature (from trusted when given)
dependencyOrigin?: (url: string) => booleanmay the code of a dependency loaded from this URL run unsigned? Default: when it comes from the page's own origin

packages/player/src/index.ts:13