Skip to content

LocalSession beta ​

Class of @v12-engine/engine

ts
export declare class LocalSession implements GameSession

A 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 ​

ts
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 ​

ts
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 ​

ts
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 ​

ts
readonly cameras: readonly MapCamera[];

The map's named camera positions

camps ​

ts
camps(): readonly CampInfo[];

The camps as the player knows them (GameSession.camps, campsFor): worked out once a tick

can ​

ts
readonly can: SessionCan;

Its pace, saves of its world, the debug tools' view, and what a computer player's brain reads (SessionCan)

canPlace ​

ts
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 ​

ts
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 ​

ts
readonly debug: LocalDebug;

The debug tools over this session's world

dispose ​

ts
dispose(): void;

Stops the session's listeners and debug tools, and the world too when the session owns it

doodads ​

ts
readonly doodads: readonly MapDoodad[];

The map's scenery objects, which have no life at runtime

environment ​

ts
readonly environment?: MapEnvironment;

The map's look (sky, mist, light), when the world was made from a map that has one

failure ​

ts
get failure(): {
        message: string;
    } | null;

Why the game ended on an error, once it has (World.failure)

findPath ​

ts
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 ​

ts
fog(): FogState;

The seat's team's fog as cells, visible and explored

forComputer ​

ts
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 ​

ts
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 ​

ts
lanes(): readonly Lane[];

The lanes of the map, as the map shows them (GameSession.lanes)

lastSeq ​

ts
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 ​

ts
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 ​

ts
mines(): readonly MineInfo[];

Where the game's money is mined, as the map shows it, seen or not (GameSession.mines, minesFor)

observer ​

ts
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 ​

ts
readonly paths: readonly MapPath[];

The map's named paths

pendingEvents ​

ts
pendingEvents(): SessionEvent[];

What happened since the last snapshot, not yet given in one: a copy, for a computer's save

placeCells ​

ts
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 ​

ts
readonly playerId: PlayerId;

The player whose seat this is, from whose side the snapshots are taken

regions ​

ts
readonly regions: readonly MapRegion[];

The map's named regions

registry ​

ts
readonly registry: Registry;

The definitions of the game the world runs: unit types, abilities, orders and the rest

restoreEvents ​

ts
restoreEvents(events: readonly SessionEvent[]): void;

Takes back what pendingEvents gave, ahead of what has happened since: in a game loaded from a save

runUntil ​

ts
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 ​

ts
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 ​

ts
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 ​

ts
snapshot(): Snapshot;

Takes a snapshot of the world as the seat sees it now, without stepping

speed ​

ts
speed: number;

Simulation speed multiplier, 0 pauses. A debug control, a real server sets the pace itself

team ​

ts
get team(): number;

The player's team: theirs now, as the rules may move them to another (setTeam)

terrain ​

ts
readonly terrain: Terrain;

The ground of the world, for the client to draw and ask about

tickRate ​

ts
readonly tickRate: number;

Simulation ticks per second of the world

update ​

ts
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 ​

ts
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 ​

ts
readonly world: World;

For tools and tests. Clients have no business here, they go through the session