Game
Interface of @v12-engine/engine
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
ability<T extends AbilityDef>(def: T): T;An ability (AbilityDef)
after
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
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
area<T extends AreaDef>(def: T): T;A part of the map the rules watch (AreaDef)
before
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
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
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
buff<T extends BuffDef>(def: T): T;A buff (BuffDef)
cellLayer
cellLayer<T extends CellLayerDef>(def: T): T;A layer of cells of its own (CellLayerDef)
check
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
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
command<T extends CommandDef>(def: T): T;A command of its own (defineCommand), or one in the place of a core one
component
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
readonly contentPacks: readonly string[];Packs of content to play it with in a page, by URL (GameInit.contentPacks)
effect
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
event<T extends EventKey<any>>(key: T): T;An event of its own (defineEvent), listed so that a world finds it
file
file<T extends GameFileDef<any>>(def: T): T;A file of its own data its rules read (defineGameFile)
formation
formation<T extends FormationDef>(def: T): T;A formation of its own (FormationDef)
hasView
readonly hasView: boolean;Whether a view was given (view): a game without one has rules alone, for a server or a test
id
readonly id: string;The game's id (Rules.id): what a save, a map, a replay and a server call it by
item
item<T extends ItemDef>(def: T): T;An item (ItemDef)
loadMap
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
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
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
readonly name: string;What the player sees the game called (Rules.name)
on
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
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
order<T extends OrderBehavior>(def: T): T;An order type (OrderBehavior), or one in the place of a core one of its type
pack
pack(pack: GamePack): Game<V>;A part of the rules it opts into (GamePack: heroesPack()), before its own
prefab
prefab<T extends PrefabDef>(def: T): T;A group of things spawned as one (definePrefab)
race
race<T extends RaceDef>(def: T): T;A side players can play (RaceDef)
resource
resource<T extends ResourceDef>(def: T): T;What players have amounts of and pay with (ResourceDef)
sequence
sequence<T extends SequenceDef<any>>(def: T): T;A script of steps (defineSequence)
settings
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
stat<T extends StatDef>(def: T): T;A stat of the game's own (StatDef)
system
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
targeting<T extends Targeting>(def: T): T;A way of aiming of its own (defineTargeting)
tile
tile<T extends TileDef>(def: T): T;What the ground can be painted with (TileDef), in order
timer
timer<T extends TimerDef<any>>(def: T): T;Something set to go off later (defineTimer)
toMaps
toMaps(): GameMaps;Its maps by name, as given (maps)
toRules
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
toStart(): GameStart | undefined;Its start: the onStarts given, then the mission whose map the world was made from. None when it has neither
toView
toView(): Promise<V>;The view, fetched the first time it is asked for. Throws when none was given
tunable
tunable<T extends TunableDef>(def: T): T;A number of its rules to tune while it plays (defineTunable)
unit
unit<T extends UnitTypeDef>(def: T): T;A unit type (UnitTypeDef), building or resource alike
upgrade
upgrade<T extends UpgradeDef>(def: T): T;An upgrade (UpgradeDef)
view
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