aboutsummaryrefslogtreecommitdiff
path: root/test-client/protocol.ts
blob: d5605e379ee09b4acd532abdd2af87a419446a90 (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
29
export type Vec2 = [number, number] // x, y
export type PlayerID = number
export type ItemID = 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
}

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

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