aboutsummaryrefslogtreecommitdiff
path: root/test-client/protocol.ts
blob: 3dfcc594ce45aba4c40dcce4c752fd98cb73f07a (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
    Hurry Curry! - a game about cooking
    Copyright (C) 2025 Hurry Curry! Contributors

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, version 3 of the License only.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.

*/
export type float = number
export type int = number
export type Vec2 = [float, float] // x, y (float)
export type IVec2 = [int, int] // 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: 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: 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: int,
}

export type PacketS =
    { type: "join", name: string, character: Character, class: PlayerClass } // Spawns a new character. The server replies with "joined". Dont send it to spectate.
    | { 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: 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: float } // Steps forward in replay.
    | { type: "ready" }
    | { type: "keepalive" }

export type PacketC =
    { 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: 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: 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: [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?: 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[] }
    | { type: "tutorial_ended", item: ItemIndex, player: PlayerID, success: boolean }
    | { type: "set_ingame", state: boolean, lobby: boolean } // Set to false when entering the game or switching maps
    | { type: "pause", state: boolean } // Set game paused so clients dont increment timers
    | { type: "debug" } & DebugEvent // Set game paused so clients dont increment timers
    | { type: "disconnect", reason: Message }

export interface Character {
    color: int,
    headwear: int,
    hairstyle: int
}

export type Menu =
    { menu: "score", data: Score }
    | { menu: "scoreboard", data: Scoreboard }
    | { menu: "book", data: Book }
    | { menu: "announce_start" }

export interface MessageTimeout {
    initial: float,
    remaining: float,
    pinned: boolean,
}

export interface Scoreboard {
    map: string,
    plays: int,
    best: ScoreboardEntry
}
export interface ScoreboardEntry {
    players: string[],
    score: Score
}

export interface Score {
    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: ItemIndex }
    | { tile: TileIndex }
    | { text: string }
    | { translation: { id: string, params: Message[] } }

export type ItemLocation =
    { player: [PlayerID, Hand] }
    | { 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, int][] }
    | { page_type: "text", title: Message, paragraphs: Message[] }
    | { page_type: "recipe", title: Message, description: Message, diagram: Diagram }

export interface Diagram {
    nodes: DiagramNode[]
    edges: DiagramEdge[]
}
export interface DiagramNode {
    position: Vec2,
    label: Message,
    style: NodeStyle
}
export interface DiagramEdge {
    src: int,
    dst: int,
}
export type NodeStyle =
    "intermediate_product"
    | "final_product"
    | "process_active"
    | "process_passive"
    | "process_instant"

export interface DebugEvent {
    key: string,
    color: [float, float, float]
    display: DebugEventDisplay
    timeout: float
}
export type DebugEventDisplay =
    { ty: "path", points: Vec2[] }
    | { ty: "label", pos: Vec2, text: string }