diff options
| -rw-r--r-- | test-client/protocol.ts | 89 |
1 files changed, 46 insertions, 43 deletions
diff --git a/test-client/protocol.ts b/test-client/protocol.ts index 9223a103..b4189510 100644 --- a/test-client/protocol.ts +++ b/test-client/protocol.ts @@ -15,29 +15,32 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -export type Vec2 = [number, number] // x, y -export type PlayerID = number // opaque number to identify players. -export type ItemIndex = number // index used primarily for item_names in Gamedata -export type TileIndex = number // index used primarily for tile_names in Gamedata -export type Hand = number +export type Vec2 = [number, number] // x, y (float) +export type float = number +export type int = number +export type IVec2 = [number, number] // x, y (integer) +export type PlayerID = int // opaque number to identify players. +export type ItemIndex = int // index used primarily for item_names in Gamedata +export type TileIndex = int // index used primarily for tile_names in Gamedata +export type Hand = int export interface MapMetadata { name: string, - players: number, - difficulty: number, + players: int, + difficulty: int, } export interface Gamedata { current_map: string, item_names: string[], // Look-up table for ItemIndex tile_names: string[], // Look-up table for TileIndex - tile_collide: number[], // List of TileIndex that have collision - tile_placeable_items: { [key: string]: number[] }, // Map from TileIndex to list of ItemIndex which can be placed on that tile. Not set if not restricted - tile_placeable_any: number[], - tile_interactable_empty: number[], // List of TileIndex that have "crate recipes" + tile_collide: TileIndex[], // List of TileIndex that have collision + tile_placeable_items: { [key: string /*TileIndex*/]: ItemIndex[] }, // Map from TileIndex to list of ItemIndex which can be placed on that tile. Not set if not restricted + tile_placeable_any: TileIndex[], + tile_interactable_empty: TileIndex[], // List of TileIndex that have "crate recipes" maps: [string, MapMetadata][], // Metadata for most available maps bot_algos: string[], - hand_count: number, + hand_count: int, } export type PacketS = @@ -45,30 +48,30 @@ export type PacketS = | { type: "leave", player: PlayerID } // Despawns a character | { type: "idle", paused: boolean } // Indicates that this player is actively participating in the game right now. | { type: "movement", player: PlayerID, pos: Vec2, dir: Vec2, boost: boolean } - | { type: "interact", player: PlayerID, target?: ItemLocation, hand: number } // Interact with some tile. pos is a position when pressing and null when releasing interact button - | { type: "communicate", player: PlayerID, message?: Message, timeout?: number, pin?: boolean } // Sends a message + | { type: "interact", player: PlayerID, target?: ItemLocation, hand: Hand } // Interact with some tile. pos is a position when pressing and null when releasing interact button + | { type: "communicate", player: PlayerID, message?: Message, timeout?: float, pin?: boolean } // Sends a message | { type: "effect", player: PlayerID, name: string } // Sends an effect - | { type: "replay_tick", dt: number } // Steps forward in replay. + | { type: "replay_tick", dt: float } // Steps forward in replay. | { type: "ready" } | { type: "keepalive" } export type PacketC = - { type: "version", minor: number, major: number, supports_bincode?: boolean } // Sent once after connecting to ensure you client is compatible + { type: "version", minor: int, major: int, supports_bincode?: boolean } // Sent once after connecting to ensure you client is compatible | { type: "joined", id: PlayerID } // Informs you about the id of the character you spawned | { type: "data", data: Gamedata } // Game data was changed | { type: "add_player", id: PlayerID, name: string, position: Vec2, character: Character, class: PlayerClass } // Somebody else joined (or was already in the game) | { type: "remove_player", id: PlayerID } // Somebody left - | { type: "movement", player: PlayerID, pos: Vec2, rot: number, boost: boolean, dir: Vec2 } // Update the movement of a players (your own position is included here) + | { type: "movement", player: PlayerID, pos: Vec2, rot: float, boost: boolean, dir: Vec2 } // Update the movement of a players (your own position is included here) | { type: "movement_sync", player: PlayerID } // Your movement is difference on the server, you should update your position from a `position` packet | { type: "move_item", from: ItemLocation, to: ItemLocation } // Item moved | { type: "set_item", location: ItemLocation, item?: ItemIndex } // the item contained in a tile or player changed - | { type: "set_progress", item: ItemLocation, position: number, speed: number, warn: boolean, players: PlayerID[] } // An item is doing something. position goes from 0 to 1, speed unit is in 1 per second + | { type: "set_progress", item: ItemLocation, position: float, speed: float, warn: boolean, players: PlayerID[] } // An item is doing something. position goes from 0 to 1, speed unit is in 1 per second | { type: "clear_progress", item: ItemLocation } - | { type: "update_map", changes: [Vec2, number[]][] } // List of position-tiles-pairs of the map that changed + | { type: "update_map", changes: [IVec2, TileIndex[]][] } // List of position-tiles-pairs of the map that changed | { type: "communicate", player: PlayerID, message?: Message, timeout?: MessageTimeout } // A player wants to communicate something, message is null when cleared | { type: "effect2", location: ItemLocation, name: string } // Player sent an effect | { type: "server_message", message: Message, error: boolean } // Text message from the server - | { type: "server_hint", message?: Message, position?: Vec2, player: PlayerID } // Hint message from server with optional position. Message is unset to clear previous message + | { type: "server_hint", message?: Message, position?: IVec2, player: PlayerID } // Hint message from server with optional position. Message is unset to clear previous message | { type: "score" } & Score // Supplies information for score OSD | { type: "menu" } & Menu // Open a menu on the client-side | { type: "environment", effects: string[] } @@ -79,9 +82,9 @@ export type PacketC = | { type: "disconnect", reason: Message } export interface Character { - color: number, - headwear: number, - hairstyle: number + color: int, + headwear: int, + hairstyle: int } export type Menu = @@ -91,14 +94,14 @@ export type Menu = | { menu: "announce_start" } export interface MessageTimeout { - initial: number, - remaining: number, + initial: float, + remaining: float, pinned: boolean, } export interface Scoreboard { map: string, - plays: number, + plays: int, best: ScoreboardEntry } export interface ScoreboardEntry { @@ -107,33 +110,33 @@ export interface ScoreboardEntry { } export interface Score { - points: number, - demands_failed: number, - demands_completed: number, - time_remaining: number, - players: number, - active_recipes: number, - passive_recipes: number, - instant_recipes: number, - stars: number, + points: int, + demands_failed: int, + demands_completed: int, + time_remaining: float, + players: int, + active_recipes: int, + passive_recipes: int, + instant_recipes: int, + stars: int, } export type Message = - { item: number } - | { tile: number } + { item: ItemIndex } + | { tile: TileIndex } | { text: string } | { translation: { id: string, params: Message[] } } export type ItemLocation = { player: [PlayerID, Hand] } - | { tile: Vec2 } + | { tile: IVec2 } export type PlayerClass = "chef" | "bot" | "customer" | "tram" export interface Book { pages: BookPage[] } export type BookPage = { page_type: "cover" } - | { page_type: "contents", title: Message, table: [Message, number][] } + | { page_type: "contents", title: Message, table: [Message, int][] } | { page_type: "text", title: Message, paragraphs: Message[] } | { page_type: "recipe", title: Message, description: Message, diagram: Diagram } @@ -147,8 +150,8 @@ export interface DiagramNode { style: NodeStyle } export interface DiagramEdge { - src: number, - dst: number, + src: int, + dst: int, } export type NodeStyle = "intermediate_product" @@ -159,9 +162,9 @@ export type NodeStyle = export interface DebugEvent { key: string, - color: [number, number, number] + color: [float, float, float] display: DebugEventDisplay - timeout: number + timeout: float } export type DebugEventDisplay = { ty: "path", points: Vec2[] } |