From 65d0484acf88896b35061feddbc802e34fbd4b61 Mon Sep 17 00:00:00 2001 From: ghostlyzsh Date: Mon, 1 Jan 2024 23:24:12 -0600 Subject: [PATCH] merge i guess --- Cargo.lock | 4 +-- starkingdoms-client/src/hub.ts | 56 +++++++++++++++++++++++++++++ starkingdoms-client/src/protocol.ts | 16 ++++++++- 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c639bab1cdc72902cd597b2d3728b4752fbe8f1d..d085655b729f76a52c2d45a43522a20481a5118d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1056,7 +1056,7 @@ dependencies = [ [[package]] name = "bevy_twite" version = "1.0.0" -source = "git+https://gitlab.com/ghostlyzsh/twite.git#4998e404fefe46bea91048fb492b89e74b2f9596" +source = "git+https://gitlab.com/ghostlyzsh/twite.git#d6f1b2a46b84048c239d8667f499977d9dc40e5b" dependencies = [ "bevy", "crossbeam-channel", @@ -3874,7 +3874,7 @@ dependencies = [ [[package]] name = "twite" version = "0.1.0" -source = "git+https://gitlab.com/ghostlyzsh/twite.git#4998e404fefe46bea91048fb492b89e74b2f9596" +source = "git+https://gitlab.com/ghostlyzsh/twite.git#d6f1b2a46b84048c239d8667f499977d9dc40e5b" dependencies = [ "base64 0.21.5", "rand", diff --git a/starkingdoms-client/src/hub.ts b/starkingdoms-client/src/hub.ts index 9b91944e081c6c2577e376335973b5ef22bbd4e0..569bc0af047486def50866db9e74bf2760b86f78 100644 --- a/starkingdoms-client/src/hub.ts +++ b/starkingdoms-client/src/hub.ts @@ -14,6 +14,7 @@ import { appendPacket } from "./packet_ui.ts"; import { global } from "./routes/ingame/main.ts"; import { startRender } from "./rendering.ts"; import { addMessage } from "./chat.ts"; +import {ButtonType} from "./protocol"; const logger = createDebug("hub"); @@ -105,6 +106,60 @@ export async function hub_connect( }; sendPacket(client, input_packet); }; + document.onmousedown = (e) => { + if (global.me !== null) { + let me_transform = global.parts_map.get(global.me?.part_id).transform; + let x = e.clientX - window.innerWidth / 2 + me_transform.x; + let y = e.clientY - window.innerHeight / 2 + me_transform.y; + + let button: ButtonType; + if (e.button == 0) { + button = ButtonType.Left; + } else if (e.button == 1) { + button = ButtonType.Middle; + } else if (e.button == 2) { + button = ButtonType.Right; + } + let packet: Packet = { + t: PacketType.PlayerMouseInput, + c: { + x: x, + y: y, + button: button!, + released: false, + }, + }; + sendPacket(client, packet); + console.log(packet); + } + } + document.onmouseup = (e) => { + if (global.me !== null) { + let me_transform = global.parts_map.get(global.me?.part_id).transform; + let x = e.clientX - window.innerWidth / 2 + me_transform.x; + let y = e.clientY - window.innerHeight / 2 + me_transform.y; + + let button: ButtonType; + if (e.button == 0) { + button = ButtonType.Left; + } else if (e.button == 1) { + button = ButtonType.Middle; + } else if (e.button == 2) { + button = ButtonType.Right; + } + let packet: Packet = { + t: PacketType.PlayerMouseInput, + c: { + x: x, + y: y, + button: button!, + released: true, + }, + }; + sendPacket(client, packet); + console.log(packet); + } + } document.getElementById("chatentry")!.onkeydown = (e) => { if (e.key === "Enter") { @@ -204,6 +259,7 @@ export async function hub_connect( ).toString(); } } + console.log(global.parts_map.size); } else if (packet.t == PacketType.PlayerLeave) { let p = packet.c; let username = global.players_map.get(p.id)!; diff --git a/starkingdoms-client/src/protocol.ts b/starkingdoms-client/src/protocol.ts index 5464a287c85aefb30a1c45e97bce6ba197ab4872..46a0439abf95b85c53ae96a2e89ccb8540908100 100644 --- a/starkingdoms-client/src/protocol.ts +++ b/starkingdoms-client/src/protocol.ts @@ -10,6 +10,11 @@ export enum PartType { Hearty = "Hearty", Cargo = "Cargo", } +export enum ButtonType { + Left = "Left", + Middle = "Middle", + Right = "Right", +} export interface Planet { planet_type: PlanetType; transform: ProtoTransform; @@ -39,6 +44,12 @@ export interface PlayerInputPacket { left: boolean; right: boolean; } +export interface PlayerMouseInputPacket { + x: number, + y: number, + released: boolean, + button: ButtonType, +} export interface PlayerListPacket { players: [number, string][]; } @@ -66,6 +77,7 @@ export enum PacketType { ClientLogin = "ClientLogin", SendMessage = "SendMessage", PlayerInput = "PlayerInput", + PlayerMouseInput = "PlayerMouseInput", // clientbound SpawnPlayer = "SpawnPlayer", PlayerList = "PlayerList", @@ -86,13 +98,15 @@ export interface Packet { | PlayerLeavePacket | SendMessagePacket | MessagePacket - | PlayerInputPacket; + | PlayerInputPacket + | PlayerMouseInputPacket; } export const SERVERBOUND = [ PacketType.ClientLogin, PacketType.SendMessage, PacketType.PlayerInput, + PacketType.PlayerMouseInput, ]; export const CLIENTBOUND = [ PacketType.SpawnPlayer,