LocalSession beta
Class of @v12-engine/engine
export declare class LocalSession implements GameSessionA GameSession over a world in the same process: steps it from real time, takes a player's snapshots of it and sends their commands into it
Members
constructor
constructor(
world: World,
playerId: PlayerId,
options?: {
observer?: boolean;
debug?: boolean;
ownsWorld?: boolean;
forComputer?: boolean;
mostEffects?: number;
});Constructs a new instance of the LocalSession class
advance
advance(ticks?: number): void;Moves the game on by ticks at the next update, however fast it goes: a step of a paused game (speed 0), as an editor's Step does. Ticks asked for while it runs are taken on top of its pace
alpha
alpha: number;How far, 0..1, the time is between the last tick and the next, for the client to blend its drawing by; 1 when paused
cameras
readonly cameras: readonly MapCamera[];The map's named camera positions
camps
camps(): readonly CampInfo[];The camps as the player knows them (GameSession.camps, campsFor): worked out once a tick
can
readonly can: SessionCan;Its pace, saves of its world, the debug tools' view, and what a computer player's brain reads (SessionCan)
canPlace
canPlace(unitType: string, point: Vec2): boolean;Whether the player could place a building of this type at the point now, seen as their team sees the ground
checkpoint
checkpoint?: {
label: Message;
save: WorldSave;
};The label and save taken at the last tick that a checkpoint was asked for, for the game to be taken back to
debug
readonly debug: LocalDebug;The debug tools over this session's world
dispose
dispose(): void;Stops the session's listeners and debug tools, and the world too when the session owns it
doodads
readonly doodads: readonly MapDoodad[];The map's scenery objects, which have no life at runtime
environment
readonly environment?: MapEnvironment;The map's look (sky, mist, light), when the world was made from a map that has one
failure
get failure(): {
message: string;
} | null;Why the game ended on an error, once it has (World.failure)
findPath
findPath(from: Vec2, to: Vec2, flying?: boolean): Vec2[] | null;A path between two points on the ground, or in the air when flying; null when there is none
fog
fog(): FogState;The seat's team's fog as cells, visible and explored
forComputer
readonly forComputer: boolean;Whose seat is a computer player's (forComputer): its snapshots leave out projectiles, missiles, corpses, reveals and the events a brain never reads, and it listens for none of those, so twelve computers cost the world less
formationPlaces
formationPlaces(units: readonly (FormationUnit & {
readonly flying?: boolean;
})[], point: Vec2, facing?: number, formation?: string): Map<EntityId, Vec2>;Where a group would stand sent to a point in a formation, the rules' own pick when none is named (GameSession.formationPlaces)
lanes
lanes(): readonly Lane[];The lanes of the map, as the map shows them (GameSession.lanes)
lastSeq
lastSeq: number;The number of the last command sent: a computer's seat keeps it through a save, so the commands it sends after a load are numbered as they would have been
log
get log(): Logger;What the world says (World.log): a session in the page has it, and the client shows it with its own
mines
mines(): readonly MineInfo[];Where the game's money is mined, as the map shows it, seen or not (GameSession.mines, minesFor)
observer
readonly observer: boolean;Who only watches, and sees everything: every entity, the whole map, every player's resources and heroes. From playerId's side all the same (who is an ally, an enemy). For a server's watchers, whose commands go nowhere
paths
readonly paths: readonly MapPath[];The map's named paths
pendingEvents
pendingEvents(): SessionEvent[];What happened since the last snapshot, not yet given in one: a copy, for a computer's save
placeCells
placeCells(unitType: string, point: Vec2): readonly boolean[] | undefined;Which cells of a building's ground are in the way for the player: taken, or not explored by their team (placementCells)
playerId
readonly playerId: PlayerId;The player whose seat this is, from whose side the snapshots are taken
regions
readonly regions: readonly MapRegion[];The map's named regions
registry
readonly registry: Registry;The definitions of the game the world runs: unit types, abilities, orders and the rest
restoreEvents
restoreEvents(events: readonly SessionEvent[]): void;Takes back what pendingEvents gave, ahead of what has happened since: in a game loaded from a save
runUntil
runUntil(until: (world: World) => boolean, options?: {
most?: number;
deadline?: number;
}): {
ticks: number;
reached: boolean;
over: boolean;
};Runs the game on by itself, a tick at a time, as fast as the page can, until until holds of the world, most ticks have run, the game is over, or deadline (performance.now()'s) is past: what an editor's "Play to" does a slice a frame, its pace and advance aside. The ticks are the same ticks the game runs at its own pace, so the same game comes to the same moment. What happened in them is in the next snapshot (update), as after a slow frame. until is asked before the first tick too: what holds already runs none
save
save(): Promise<WorldSave>;A save of the world as it stands (saveWorld): at once, as a promise for what a session elsewhere answers later
send
send(command: PlayerCommand, seq?: number): number;Sends a command. seq is the sender's own number for it, for a host passing on what a remote player numbered
snapshot
snapshot(): Snapshot;Takes a snapshot of the world as the seat sees it now, without stepping
speed
speed: number;Simulation speed multiplier, 0 pauses. A debug control, a real server sets the pace itself
team
get team(): number;The player's team: theirs now, as the rules may move them to another (setTeam)
terrain
readonly terrain: Terrain;The ground of the world, for the client to draw and ask about
tickRate
readonly tickRate: number;Simulation ticks per second of the world
update
update(dt: number): Snapshot[];Adds dt real seconds (scaled by speed) and steps the world one tick for each tick's worth; returns a snapshot of how it stands after, or none when nothing happened
view
readonly view: SessionView;The seat's side of the world: whose it is, what they may know, what was told to them since the last snapshot
world
readonly world: World;For tools and tests. Clients have no business here, they go through the session