@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.
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:66
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:130
playPackage function
async function playPackage(o: PlayOptions): Promise<Played>packages/player/src/index.ts:70
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:41
Played interface
interface Playedgame: Game | |
pkg: FerretPackage | |
world: Game['world'] | |
levels: LevelService | |
mount: PackageMount | |
code: CodeLoader | |
level: string | the level that was started |
stop(): void | |
dispose(): void |
packages/player/src/index.ts:52
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 |
packages/player/src/index.ts:12