summaryrefslogtreecommitdiff
path: root/test-client/protocol.ts
blob: 31f61d19bc9c5d58d10add5909f79e06feaf7942 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
export type Vec2 = [number, number] // x, y
export type PlayerID = number
export type ItemIndex = number
export type TileIndex = number

export interface Gamedata {
    item_names: string[], // Look-up table for ItemIndex
    tile_names: string[], // Look-up table for TileIndex
    spawn: Vec2, // Where players spawn when they join.
}

export type PacketS =
    { type: "join", name: string, character: number } // You join, sent as first packet.
    | { type: "position", pos: Vec2, rot: number } // Update your position and rotation in radians (0 is -y)
    | { type: "interact", pos: Vec2, edge: boolean } // Interact with some tile. edge is true when pressing and false when releasing interact button
    | { type: "collide", player: PlayerID, force: Vec2 } // Apply force to another player as a result of a collision

export type PacketC =
    { type: "init", id: PlayerID, data: Gamedata } // You joined
    | { type: "add_player", id: PlayerID, name: string, item?: ItemIndex, position: Vec2, character: number } // Somebody else joined (or was already in the game)
    | { type: "remove_player", id: PlayerID }  // Somebody left
    | { type: "position", player: PlayerID, pos: Vec2, rot: number } // Update the position of a players (your own position is included here)
    | { type: "take_item", tile: Vec2, player: PlayerID }  // An item was taken from a tile
    | { type: "put_item", tile: Vec2, player: PlayerID } // An item was put on a tile
    | { type: "produce_item", tile: Vec2, item: ItemIndex } // A tile generated a new item
    | { type: "consume_item", tile: Vec2 } // A tile removed an item
    | { type: "set_active", tile: Vec2, progress?: number } // A tile is doing something. progress goes from 0 to 1, then null when finished
    | { type: "update_map", pos: Vec2, tile: TileIndex } // A map tile was changed