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
|
/*
Undercooked - a game about cooking
Copyright 2024 metamuffin
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 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
tile_collide: boolean[], // Look-up table for TileIndex to check tile collision with players
tile_interact: boolean[], // Look-up table for TileIndex to check if a tile is interactable
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: "communicate", message?: Message } // Send a message
| { type: "collide", player: PlayerID, force: Vec2 } // Apply force to another player as a result of a collision
export type PacketC =
{ type: "init", id: PlayerID } // You just connected. This is your id for this session.
| { type: "data", data: Gamedata } // Game data was changed
| { type: "add_player", id: PlayerID, name: string, 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: "set_tile_item", tile: Vec2, item?: ItemIndex } // A tile changed its item
| { type: "set_player_item", player: PlayerID, item?: ItemIndex } // A player changed their item
| { type: "set_active", tile: Vec2, progress?: number, warn: boolean } // A tile is doing something. progress goes from 0 to 1, then null when finished
| { type: "update_map", tile: Vec2, kind: TileIndex | null, neighbors: [TileIndex | null] } // A map tile was changed
| { type: "communicate", player: PlayerID, message?: Message } // A player wants to communicate something, message is null when cleared
| { type: "score", points: number, demands_failed: number, demands_completed: number, } // Supplies information for score OSD
| { type: "set_ingame", state: boolean } // Set to false when entering the game or switching maps
| { type: "error", message?: Message } // Your client did something wrong.
export type Message =
{ item: number }
| { text: string }
| { effect: string }
|