From 0bdd9ed7b86fc39f154d762644de8483df0189bc Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 19 Feb 2025 18:13:41 +0100 Subject: fix testclient for single-handed games --- test-client/main.ts | 9 ++++++--- test-client/protocol.ts | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'test-client') diff --git a/test-client/main.ts b/test-client/main.ts index 4c1f28f0..946b933e 100644 --- a/test-client/main.ts +++ b/test-client/main.ts @@ -130,11 +130,14 @@ let last_server_sent_position: V2 = { x: 0, y: 0 } function get_item_location(loc: ItemLocation): PlayerData | TileData { if ("tile" in loc) return tiles.get(loc.tile.toString())! - if ("player" in loc) return players.get(loc.player)! + if ("player" in loc) return players.get(loc.player[0])! throw new Error("invalid item location"); } -function send(p: PacketS) { ws.send(JSON.stringify(p)) } +function send(p: PacketS) { + if (p.type != "movement") console.log("send", p); + ws.send(JSON.stringify(p)) +} function packet(p: PacketC) { if (!["movement", "update_map"].includes(p.type)) console.log(p); @@ -403,7 +406,7 @@ export function get_interact_target(): V2 | undefined { function set_interact(edge: boolean) { if (edge) interacting = get_interact_target() - if (interacting) send({ player: my_id, type: "interact", pos: edge ? [interacting.x, interacting.y] : undefined }) + if (interacting) send({ player: my_id, type: "interact", pos: edge ? [interacting.x, interacting.y] : undefined, hand: 0 }) if (!edge) interacting = undefined } diff --git a/test-client/protocol.ts b/test-client/protocol.ts index 787dfc15..a41c19d7 100644 --- a/test-client/protocol.ts +++ b/test-client/protocol.ts @@ -40,7 +40,7 @@ export type PacketS = { type: "join", name: string, character: number, class: PlayerClass } // Spawns a new character. The server replies with "joined". Dont send it to spectate. | { type: "leave", player: PlayerID } // Despawns a character | { type: "movement", player: PlayerID, pos: Vec2, dir: Vec2, boost: boolean } - | { type: "interact", player: PlayerID, pos?: Vec2 } // Interact with some tile. pos is a position when pressing and null when releasing interact button + | { type: "interact", player: PlayerID, pos?: Vec2, 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: "effect", player: PlayerID, name: string } // Sends an effect | { type: "replay_tick", dt: number } // Steps forward in replay. -- cgit v1.2.3-70-g09d2