Skip to content

Game ​

Interface of @v12-engine/engine

ts
export interface Game<V = unknown>

A game: one object everything of it is registered on, which every host takes (createGame). Its rules are made from what it holds (toRules(), the module underneath that a server, a test and a worker run); its view is fetched as a page first needs it (view(() => import('./view')), toView()), so that the rules are read where nothing draws (a server, a test) without the client. Each method that registers a definition gives it back

export const game = createGame( id: 'td', name: 'Tower defense' ) export const archer = game.unit( id: 'archer', name: 'Archer', kind: 'unit', stats: health: 200 ) game.on(entityDied, (world, entity ) = … ) game.onStart((world, map ) = … ) game.maps(mapsFrom(import.meta.glob('./maps/*.vgmap.json', import: 'default' ))) game.view(() = import('./view'))

Members ​

ability ​

ts
ability<T extends AbilityDef>(def: T): T;

An ability (AbilityDef)

after ​

ts
after<K extends HookName>(hook: K, run: HookHandler<K>, options?: HandlerOptions): Game<V>;

A handler of a hook that runs after the engine's own (priority 1): one that reads or changes what they made of it

after ​

ts
after<T>(hook: HookKey<T>, run: (world: World, event: T) => void, options?: HandlerOptions): Game<V>;

A handler of a game's own hook (HookKey) that runs after the rest

area ​

ts
area<T extends AreaDef>(def: T): T;

A part of the map the rules watch (AreaDef)

before ​

ts
before<K extends HookName>(hook: K, run: HookHandler<K>, options?: HandlerOptions): Game<V>;

A handler of a hook that runs before the engine's own (priority -1): one that may say no (event.cancel())

before ​

ts
before<T>(hook: HookKey<T>, run: (world: World, event: T) => void, options?: HandlerOptions): Game<V>;

A handler of a game's own hook (HookKey) that runs before the rest

brain ​

ts
brain<T extends BrainDef>(def: T): T;

A brain of its computer players (defineBrain): the first given is what a seat that names none gets

buff ​

ts
buff<T extends BuffDef>(def: T): T;

A buff (BuffDef)

cellLayer ​

ts
cellLayer<T extends CellLayerDef>(def: T): T;

A layer of cells of its own (CellLayerDef)

check ​

ts
check(): Promise<RulesProblem[]>;

What does not fit: the rules against themselves (checkRules), ids given twice among what was registered (one takes the other's place unseen), and each map (fetched where it is lazy) against the rules: a type it places that no unit type is, a map of another game. A save or a map naming an id that nothing registered is what this finds before it is played

checkView ​

ts
readonly checkView: 'warn' | 'throw' | false;

What a page does about a view that does not fit the rules as it fetches it (GameInit.checkView)

command ​

ts
command<T extends CommandDef>(def: T): T;

A command of its own (defineCommand), or one in the place of a core one

component ​

ts
component<T extends Component<any, any>>(component: T): T;

State of its own (defineComponent), listed so that a world, a save and a snapshot find it

contentPacks ​

ts
readonly contentPacks: readonly string[];

Packs of content to play it with in a page, by URL (GameInit.contentPacks)

effect ​

ts
effect<T extends EffectType>(def: T): T;

A type of effect of its own (defineEffect), or one in the place of the engine's of its type

event ​

ts
event<T extends EventKey<any>>(key: T): T;

An event of its own (defineEvent), listed so that a world finds it

file ​

ts
file<T extends GameFileDef<any>>(def: T): T;

A file of its own data its rules read (defineGameFile)

formation ​

ts
formation<T extends FormationDef>(def: T): T;

A formation of its own (FormationDef)

hasView ​

ts
readonly hasView: boolean;

Whether a view was given (view): a game without one has rules alone, for a server or a test

id ​

ts
readonly id: string;

The game's id (Rules.id): what a save, a map, a replay and a server call it by

item ​

ts
item<T extends ItemDef>(def: T): T;

An item (ItemDef)

loadMap ​

ts
loadMap(name?: string): Promise<GameMap>;

A map of it by name (the first when left out), fetched where it is lazy, as a copy: a game changes nothing of the next one's

maps ​

ts
maps(maps: GameMaps): Game<V>;

Its maps by name, laid over those given before; the first is the one a game is on when nothing says which

mission ​

ts
mission(id: string, setup: (mission: Mission) => void): Mission;

A mission: its parts registered through setup with ids made of the game's and the mission's (Mission)

name ​

ts
readonly name: string;

What the player sees the game called (Rules.name)

on ​

ts
on<T>(event: EventKey<T>, run: (world: World, payload: T) => void, options?: HandlerOptions): Game<V>;

How the game reacts to an event, the engine's or its own: a listener (defineListener), its id made for it

onStart ​

ts
onStart(run: GameStart): Game<V>;

What the game does once a world is made, before anyone plays; each given runs, in order, before a mission's

order ​

ts
order<T extends OrderBehavior>(def: T): T;

An order type (OrderBehavior), or one in the place of a core one of its type

pack ​

ts
pack(pack: GamePack): Game<V>;

A part of the rules it opts into (GamePack: heroesPack()), before its own

prefab ​

ts
prefab<T extends PrefabDef>(def: T): T;

A group of things spawned as one (definePrefab)

race ​

ts
race<T extends RaceDef>(def: T): T;

A side players can play (RaceDef)

resource ​

ts
resource<T extends ResourceDef>(def: T): T;

What players have amounts of and pay with (ResourceDef)

sequence ​

ts
sequence<T extends SequenceDef<any>>(def: T): T;

A script of steps (defineSequence)

settings ​

ts
settings(settings: RuleSettingsInit): Game<V>;

Its numbers that are not about any one unit (RuleSettingsInit), laid over what was said before, group by group

stat ​

ts
stat<T extends StatDef>(def: T): T;

A stat of the game's own (StatDef)

system ​

ts
system<T extends SystemDef>(def: T): T;

A system of the game's own (SystemDef): after the core ones unless it says a phase; one named as a core one takes its place

targeting ​

ts
targeting<T extends Targeting>(def: T): T;

A way of aiming of its own (defineTargeting)

tile ​

ts
tile<T extends TileDef>(def: T): T;

What the ground can be painted with (TileDef), in order

timer ​

ts
timer<T extends TimerDef<any>>(def: T): T;

Something set to go off later (defineTimer)

toMaps ​

ts
toMaps(): GameMaps;

Its maps by name, as given (maps)

toRules ​

ts
toRules(): Rules;

The module underneath (Rules): what the hosts run. The same object each time; what is registered after it was made is put into it in place

toStart ​

ts
toStart(): GameStart | undefined;

Its start: the onStarts given, then the mission whose map the world was made from. None when it has neither

toView ​

ts
toView(): Promise<V>;

The view, fetched the first time it is asked for. Throws when none was given

tunable ​

ts
tunable<T extends TunableDef>(def: T): T;

A number of its rules to tune while it plays (defineTunable)

unit ​

ts
unit<T extends UnitTypeDef>(def: T): T;

A unit type (UnitTypeDef), building or resource alike

upgrade ​

ts
upgrade<T extends UpgradeDef>(def: T): T;

An upgrade (UpgradeDef)

view ​

ts
view(view: V | (() => Promise<unknown>)): Game<V>;

Its view (how it looks and sounds: the client's GameView), or what fetches it as a page first needs it: () => import('./view') (a module whose view or default is the view). Given so, nothing of the client is part of what imports the game, which a server and a test do