@ferret/ferretic
Classes
FerreticError class
class FerreticError extends ErrorFerretic: the engine's language for playing a game by script (tests, checks, measured runs). BASIC to read: one statement a
line (or several with :), keywords in any case, no line numbers and no GOTO; structured IF / WHILE / DO / FOR / REPEAT / SUB /
FUNCTION, game time WAITs, the game's own input actions, what the game shows (positions, speeds, exposed values, events),
EXPECT / ASSERT, LOG / SAMPLE tables, PARALLEL branches and ON EVENT handlers. This file reads the text into a tree.
constructor(message: string, readonly line = 0, readonly col = 0) |
packages/ferretic/src/parse.ts:9
FerreticRun class
class FerreticRunOne run of a program. Call tick() after every fixed step of the game (and, while the game is paused, from time to time:
then no game time passes). done resolves with the report.
readonly program: Program | |
readonly report: FerreticReport | |
readonly done: Promise<FerreticReport> | |
constructor(readonly host: FerreticHost, source: string | Program, readonly opts: RunOptions = {}) | |
get running() | |
get isFinished() | |
shot(name: string): string | undefined | the pictures SHOT took, by name |
takeManualSteps(): number | |
now(): number | game seconds since the run began; the sum of fixed steps carries float noise (2 s is 1.999999999999993), taken off at a nanosecond |
start(): void | |
stop(): void | stop from outside (the command test.stop): the report says "stopped" |
tick(stepped = true): void | one fixed step of the game has passed (stepped), or the game is paused and nothing passed (stepped = false) |
*ev(e: Expr, scope: Scope): GenOf<Value> | |
rnd(): number | |
pos(v: Value, line: number): Vec | |
velocity(name: string, line: number): Vec | |
frameCount() | |
currentTask() | |
failures() |
packages/ferretic/src/run.ts:143
FerreticTest class
class FerreticTestreadonly program: Program | |
readonly runs: number | |
readonly done: Promise<FerreticTestReport> | |
run: FerreticRun | null | |
constructor(readonly host: FerreticHost, source: string, readonly opts: TestOptions = {}) | |
get index() | |
get finished() | |
tick(stepped = true): void | after every fixed step of the game (stepped), or now and then while it is paused |
stop(): void | |
reportOf(run?: number): FerreticReport | the full report of one run (1..n; default: the last that ran or the one running) |
report(): FerreticTestReport | the report so far (the last run's, with the runs before it) |
packages/ferretic/src/session.ts:14
Functions
bindFerretic function
function bindFerretic(world: World): FerreticBindingFerretic on a world: the commands test.*; returns the binding. Once per world.
packages/ferretic/src/bind.ts:101
checkFerretic function
function checkFerretic(source: string): { ok: boolean; error: { line: number; col: number; message: string } | null; routines: string[]; runs: number | null }Parse only: the problems with their lines, the SUBs and FUNCTIONs, RUNS.
packages/ferretic/src/run.ts:758
frameColour function
async function frameColour(dataUrl: string, reference?: string)the mean colour, the contrast (standard deviation of the luminance, 0..1) and, with a reference, how far the two frames are apart (mean absolute difference, 0..1)
packages/ferretic/src/probes.ts:154
makeProbes function
function makeProbes(world: World): ProbeSetpackages/ferretic/src/probes.ts:69
parseFerretic function
function parseFerretic(source: string): Programpackages/ferretic/src/parse.ts:130
tokenizeFerretic function
function tokenize(src: string): Tok[]packages/ferretic/src/parse.ts:36
Interfaces
FerreticBinding interface
interface FerreticBindingstart(source: string, opts?: { name?: string; runs?: number; timeout?: number; keepRunning?: boolean; seed?: number }): { id: string; test: FerreticTest } | start a test (any number may run at once); its done resolves with the report when it ends |
get(id?: string): { id: string; test: FerreticTest } | null | a test by id, or the last one started |
dispose(): void |
packages/ferretic/src/bind.ts:25
FerreticFailure interface
interface FerreticFailureline: number | |
code: string | |
message: string | |
time: number |
packages/ferretic/src/run.ts:53
FerreticHost interface
interface FerreticHostWhat the interpreter needs from the game. Everything is by name: entity id or name, or a scene node's name.
time(): number | the game's simulated time in seconds |
fixedStep(): number | the fixed step in seconds |
actions(): string[] | the game's input actions; press(action, null) lets go |
press(action: string, v: { x?: number; y?: number; down?: boolean } | null): void | |
actionValue(action: string): { down: boolean; x: number; y: number } | what an action reads now (the device and the injected value together) |
position(name: string): Vec | null | world position / rotation (degrees, x y z) of an entity or a node; null when there is none |
rotation(name: string): Vec | null | |
exposed(name: string): unknown | a value the game exposes (world.expose); throws when it does not |
prop(entity: string, path: string): unknown | a field of a component of an entity: path "Component.field.sub" |
on(event: string, fn: (payload: unknown) => void): () => void | listen to a game event; returns the function that stops listening |
command(name: string, args: Record<string, unknown>): unknown | Promise<unknown> | run an engine command |
screenshot?(): Promise<string> | a picture of what the player sees, as a data URL |
restart?(level?: string): Promise<void> | enter the level again (the current one when none is named) |
getTimeScale(): number | |
setTimeScale(s: number): void | |
isPaused(): boolean | |
setPaused(p: boolean): void | |
probes?: ProbeSet | the probes of the scene (view, count, ground, errors); a host without a scene has none |
packages/ferretic/src/run.ts:22
FerreticProgram interface
interface Programbody: Stmt[] | |
subs: Map<string, Routine> | |
runs: number | null | |
source: string |
packages/ferretic/src/parse.ts:127
FerreticReport interface
interface FerreticReportok: boolean | |
status: 'running' | 'passed' | 'failed' | 'error' | 'timeout' | 'stopped' | |
name?: string | |
time: number | game seconds from the start of the run, and fixed steps |
frames: number | |
realMs: number | |
expectations: { passed: number; failed: number } | |
failures: FerreticFailure[] | |
error: { line: number; code: string; message: string } | null | |
prints: { time: number; text: string }[] | |
log: Record<string, Value> | the last value LOGged under each name |
logRows: { time: number; name: string; value: Value }[] | |
samples: { columns: string[]; rows: Value[][]; total: number } | |
shots: { name: string; time: number }[] |
packages/ferretic/src/run.ts:54
FerreticRunOptions interface
interface RunOptionsname?: string | |
timeout?: number | game seconds the run may take, when its author wants a limit (the same as TIMEOUT at its start); none by default |
seed?: number |
packages/ferretic/src/run.ts:132
FerreticTestOptions interface
interface TestOptions extends RunOptionsruns?: number |
packages/ferretic/src/session.ts:12
FerreticTestReport interface
interface FerreticTestReport extends FerreticReportruns?: { run: number; status: FerreticReport['status']; time: number; failures: number; log: Record<string, Value> }[] | with RUNS n (or the option runs): each run's short result and, by LOG name, the last values of all runs |
summary?: { runs: number; passed: number; failed: number; log: Record<string, { min: number; mean: number; max: number; values: Value[] }> } |
packages/ferretic/src/session.ts:6
GroundProbe interface
interface GroundProbeonGround: boolean | the lowest point is within tolerance of what is under it (or sunk by no more than that) |
height: number | null | metres from the lowest point down to the first thing under it; negative when the point is inside it; null when nothing is above or below |
over: string | null | the name of that mesh |
packages/ferretic/src/probes.ts:28
ProbeSet interface
interface ProbeSetview(name: string): ViewProbe | |
count(what: string): number | |
ground(name: string, tolerance?: number): GroundProbe | |
errors(): string[] | |
dispose(): void |
packages/ferretic/src/probes.ts:36
ViewProbe interface
interface ViewProbeinView: boolean | inside the camera's frustum and at least one sample point of it is seen past everything else |
inFrustum: boolean | inside the frustum (whatever hides it) |
share: number | the share of the frame the thing's bounding box covers on the screen, 0..1 (a box that crosses the camera's plane is clipped to the frame) |
visible: number | the share of 9 sample points (centre and shrunk corners) that are in the frame and not hidden, 0..1 |
occludedBy: string | null | what hides most of the sample points (a mesh name), or null |
distance: number | distance from the camera to the centre of the box |
packages/ferretic/src/probes.ts:14
Constants
FERRETIC_FUNCTIONS const
const FERRETIC_FUNCTIONS: string[]packages/ferretic/src/run.ts:755
FERRETIC_REFERENCE const
const FERRETIC_REFERENCE: "FERRETIC: play the game by script. One statement a line (or several with \":\"), keywords in any case, ' starts a comment.\nThe program runs in the game's fixed step: it goes on until it WAITs, then game steps pass. Same game + same program = same presses at the same steps.\nNumbers may carry units: 0.3 s, 250 ms, 2 min, 90 deg, 1.5 rad (-> deg), 100 km/h (-> m/s), 5 m, 30 cm, 7000 rpm, 50 %.\n\n …The language in one page: what the command test.help returns (the skill ferret-ferretic says the same at length).
packages/ferretic/src/reference.ts:3