NET FORGE DOCS

@netforge/kit-play API reference

Last updated Checked against @netforge/engine 0.2.0View as Markdown

Net Forge, the open-source multiplayer browser game engine built for AI coding agents, is published on npm under @netforge with source at github.com/netnetdev/net-forge.

Runs a game folder on your computer with play money: builds the template client with your src/game.ts and starts a local room host. The kit-play command and the same functions for scripts.

import { play, TEMPLATES } from "@netforge/kit-play";

Generated from packages/kit-play/src/index.ts by apps/forge-docs/scripts/api.mjs. Signatures are what the TypeScript compiler reports for the current source; long types are cut and say so.

KindCount
Functions10
Classes1
Constants5
Types10

Functions

check

function check(o: CheckOptions): Promise<CheckResult>;

Source: packages/kit-play/src/check.ts

namesModule

The names module: everything the template's names.ts exports, with these labels in place of its tables.

function namesModule(n: Names, templateNamesPath: string): string;

Source: packages/kit-play/src/names.ts

parseNames

Parses src/names.json; throws with the first problem.

function parseNames(text: string): Names;

Source: packages/kit-play/src/names.ts

play

function play(o: PlayOptions): Promise<Playing>;

Source: packages/kit-play/src/play.ts

readGameFolder

Reads and checks the game folder.

function readGameFolder(dir: string): GameFolder;

Source: packages/kit-play/src/play.ts

runKitPlayCli

The kit-play command: play (the default), test, new and templates.

function runKitPlayCli(argv: readonly string[], io: PlayCliIo): Promise<number>;

Source: packages/kit-play/src/cli.ts

runPlayCli

function runPlayCli(argv: readonly string[], io: PlayCliIo): Promise<number>;

Source: packages/kit-play/src/cli.ts

runTestCli

function runTestCli(argv: readonly string[], io: PlayCliIo): Promise<number>;

Source: packages/kit-play/src/cli.ts

summary

The report in a few lines.

function summary(r: CheckResult): string[];

Source: packages/kit-play/src/check.ts

templateFor

netnet.json's template field (the room template names are accepted too).

function templateFor(name: unknown): TemplateEntry | null;

Source: packages/kit-play/src/templates.ts

Classes

PlayError

class PlayError {
  constructor(message?: string);
}

Source: packages/kit-play/src/play.ts

Constants

ALLOWED_IMPORT

The only import a game module may make (the studio's rule, kept here so a game that plays locally plays in the studio).

const ALLOWED_IMPORT: "@netforge/engine";

Source: packages/kit-play/src/play.ts

COMMANDS_HELP

const COMMANDS_HELP: "kit-play: make, test and play Net Forge games on this computer with play money.\n\nUsage:\n  kit-play play [dir] [flags]       Build the game in dir (default: here) and play it. kit-play play --help for flags.\n  kit-play test [dir] [flags]       Compile src/game.ts and run the playtest bots, no browser.\n  kit-play check [dir] [flags]      The same, with the report as JSON on stdout.\n  kit-play new [folder] [flags]     Start a new game from a template (the same as npm create netforge).\n  kit-play templates [--json]       List the templates.\n\nkit-play [dir] without a command plays, as bef /* ... */;

Source: packages/kit-play/src/cli.ts

HELP

const HELP: "kit play: run a Net Forge game on this computer with play money.\n\nUsage: kit play [dir] [flags]     (inside the folder you downloaded from Net Forge)\n\n  --port <n>          Port for the page and the local room (default 4663).\n  --host <addr>       Interface to listen on (default 127.0.0.1, this computer only).\n                      Use 0.0.0.0 to let devices on your network join.\n  --players <n>       Browser tabs to open, one per local player (default 1).\n  --no-open           Print the link instead of opening a browser.\n  --library-url <u>   Load the asset library from this URL ins /* ... */;

Source: packages/kit-play/src/cli.ts

TEMPLATES

const TEMPLATES: Readonly<Record<TemplateId, TemplateEntry>>;

Source: packages/kit-play/src/templates.ts

TEST_HELP

const TEST_HELP: "kit-play test: compile src/game.ts as the play build does and run the playtest bots.\n\nUsage: kit-play test [dir] [flags]\n\n  --minutes <n>   Minutes of game time the bots play, at the template's own tick rate (default 1, up to 30).\n  --bots <n>      Bots playing (default: 2, or fewer when the template seats fewer).\n  --seed <n>      Random seed (default 1).\n  --json          Print the result as JSON on stdout.\n\nExits 0 when the game compiles and every playtest check passes, 1 otherwise.";

Source: packages/kit-play/src/cli.ts

Types

CheckOptions

interface CheckOptions {
  readonly dir: string;
  readonly minutes: number;
  readonly bots: number | null;
  readonly seed: number;
  readonly log: (s: string) => void;
}

Source: packages/kit-play/src/check.ts

CheckReport

What the engine's playtest reports (the fields this command reads; the rest pass through to --json).

interface CheckReport {
  readonly ticks: number;
  readonly bots: number;
  readonly kills: number;
  readonly deaths: number;
  readonly wave: number;
  readonly maxLevel: number;
  readonly earnEmitted: number;
  readonly earned: Readonly<Record<string, number>>;
  readonly softlock: boolean;
  readonly msPerTick: number;
  readonly rules?: { readonly template: string; readonly checks: readonly { readonly ok: boolean; readonly line: string }[]; readonly progress: number };
  readonly failed: readonly string[];
}

Source: packages/kit-play/src/check.ts

CheckResult

interface CheckResult {
  readonly ok: boolean;
  readonly template: string;
  readonly problems: readonly string[];
  readonly tickRate?: number;
  readonly report: CheckReport | null;
}

Source: packages/kit-play/src/check.ts

GameFolder

interface GameFolder {
  readonly dir: string;
  readonly template: TemplateEntry;
  readonly gameFile: string;
  readonly names: Names | null;
}

Source: packages/kit-play/src/play.ts

Names

interface Names {
  readonly title: string;
  readonly weapons: Readonly<Record<string, { readonly name: string; readonly line: string }>>;
  readonly upgrades: Readonly<Record<string, { readonly name: string; readonly line: string }>>;
  readonly enemies: Readonly<Record<string, string>>;
  readonly rules: Readonly<Record<string, string>>;
  readonly skus: Readonly<Record<string, string>>;
}

Source: packages/kit-play/src/names.ts

PlayCliIo

interface PlayCliIo {
  out(s: string): void;
  err(s: string): void;
  cwd: string;
}

Source: packages/kit-play/src/cli.ts

Playing

interface Playing {
  readonly url: string;
  readonly lan: readonly string[];
  close(): Promise<void>;
}

Source: packages/kit-play/src/play.ts

PlayOptions

interface PlayOptions {
  readonly dir: string;
  readonly port: number;
  readonly host: string;
  readonly open: boolean;
  readonly players: number;
  readonly libraryUrl: string | null;
  readonly log: (s: string) => void;
}

Source: packages/kit-play/src/play.ts

TemplateEntry

interface TemplateEntry {
  readonly id: TemplateId;
  readonly label: string;
  readonly pkg: string;
  readonly adapter: string;
  readonly manifest: { readonly fn: string; readonly field?: "manifest" };
  readonly seats: number;
  readonly aoi: LocalAoi;
}

Source: packages/kit-play/src/templates.ts

TemplateId

type TemplateId = "survivor" | "arena" | "tower-defense" | "dungeon" | "idle" | "platformer" | "cards" | "collector" | "racer" | "party";

Source: packages/kit-play/src/templates.ts