M Cargo.lock => Cargo.lock +2 -2
@@ 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",
M starkingdoms-client/src/hub.ts => starkingdoms-client/src/hub.ts +56 -0
@@ 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 = <PlayerLeavePacket>packet.c;
let username = global.players_map.get(p.id)!;
M starkingdoms-client/src/protocol.ts => starkingdoms-client/src/protocol.ts +15 -1
@@ 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,