@ferret/player
Classes
PlayError class
class PlayError extends ErrorWhat 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): voidInsert 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 LibraryContextWhat a game's install(ctx) is given: the library context, and the game around it.
game: Game | |
levels: LevelService | |
root: HTMLElement | the element that holds the game's UI (entry.ui is inserted here; a game may add its own) |
args: URLSearchParams | the 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 Playedgame: Game | |
pkg: FerretPackage | |
world: Game['world'] | |
levels: LevelService | |
mount: PackageMount | |
code: CodeLoader | |
level: string | the 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 PlayOptionscanvas: HTMLCanvasElement | |
source: PackageInput | FerretPackage | the package: a URL, bytes, a Blob, or an opened package |
fileName?: string | the file's name when the source has none (a Blob): .fex must be a game and .fprj a project |
tier?: QualityTier | the 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> | undefined | key ids whose signatures are trusted (the game's own code runs anyway: it is what the player was asked to play) |
level?: string | start here instead of entry.level |
ferret?: unknown | the engine's API for code that wants an object instead of imports (the old bundle). ES-module code needs none. |
origin?: boolean | does the package come from the player's own site? Then its code runs unsigned. Default true: the caller decides. |
onExit?: () => void | the game called platform.exit() (the player's exit event); without it exit does what the platform does |
root?: HTMLElement | the element for the game's UI (default: a new one over the canvas) |
args?: string | the tag's args as a query string |
onProgress?: (p: number) => void | called with 0..1 while the start level loads |
base?: string | where 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?: AssetStore | the store dependencies are fetched through (default: one with the persistent cache, if the browser has one) |
catalogPolicy?: (catalogUrl: string) => CatalogPolicy | how 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) => boolean | may 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