From 6a78f8f17f8c26351f256897b824e4c3966c972e Mon Sep 17 00:00:00 2001 From: core Date: Sun, 16 Apr 2023 13:15:43 -0400 Subject: [PATCH] fix --- client/play.html | 6 ++++++ client/src/gateway.ts | 7 +++++++ client/src/index.ts | 18 ++++++++++++------ client/static/play.css | 11 +++++++++++ client/static/root.css | 4 ++++ server/src/main.rs | 7 ++++++- 6 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 client/static/root.css diff --git a/client/play.html b/client/play.html index 7ce9d53d6d59c17d6e5fa93d7e7090bcae163c44..16df73a52f4bf13dae29b1a9a0a88c9cc4a66c85 100644 --- a/client/play.html +++ b/client/play.html @@ -10,5 +10,11 @@ + +
+

Position: NaN, NaN

+

Velocity: NaN

+

Relative to Moon: NaN, NaN

+
diff --git a/client/src/gateway.ts b/client/src/gateway.ts index f502392572d6a060b58e23843628e88434b33f7b..9636307fe96352ef4443a9e9f0826e10763575a4 100644 --- a/client/src/gateway.ts +++ b/client/src/gateway.ts @@ -130,6 +130,13 @@ export async function gateway_connect(gateway_url: string, username: string): Ga for (let i = 0; i < pkt.players.length; i++) { if (pkt.players[i].username == client.username) { + if (global.me !== null) { + let x_vel = (global.me.x - pkt.players[i].x) / (1 / 20); + let y_vel = (global.me.y - pkt.players[i].y) / (1 / 20); + let total_vel = Math.sqrt(x_vel * x_vel + y_vel * y_vel); + global.velocity = total_vel; + } + global.me = pkt.players[i]; } } diff --git a/client/src/index.ts b/client/src/index.ts index 368ec8fc83afed5545f92aae7013eda681cf7c8b..73fe541c3973472eb75343b52230e879e67f2844 100644 --- a/client/src/index.ts +++ b/client/src/index.ts @@ -1,6 +1,3 @@ -import * as PIXI from "pixi.js"; -import {Sprite} from "pixi.js"; - import {Logger, logSetup} from "./logger"; import {gateway_connect, GatewayClient} from "./gateway"; import {Player} from "./protocol/player"; @@ -20,7 +17,8 @@ export interface GlobalData { spritesheet_img: HTMLImageElement | null, spritesheet: object | null, context: CanvasRenderingContext2D, - keys: Keys + keys: Keys, + velocity: number } export interface Keys { @@ -44,7 +42,8 @@ export const global: GlobalData = { down: false, left: false, right: false - } + }, + velocity: 0 } async function client_main(server: string, username: string, texture_quality: string) { @@ -146,6 +145,11 @@ async function client_main(server: string, username: string, texture_quality: st // only translation will be to center our core module. global.context.translate(viewer_size_x / 2, viewer_size_y / 2); + if (global.me !== null) { + document.getElementById("pos").innerText = `Position: ${Math.trunc(global.me.x)}, ${Math.trunc(global.me.y)}`; + } + document.getElementById("vel").innerText = `Velocity: ${Math.trunc(global.velocity)}`; + for (let i = 0; i < global.planets.length; i++) { let planet = global.planets[i]; // @ts-ignore @@ -159,6 +163,8 @@ async function client_main(server: string, username: string, texture_quality: st (planet.y - planet.radius - global.me?.y!), // dy planet.radius * 2, // dw planet.radius * 2); // dh + + // todo: moon } for (let i = 0; i < global.players.length; i++) { @@ -224,4 +230,4 @@ function planet_type_to_tex_id(ty: PlanetType): string { return "earth.png" } return "unknown.png" -} +} \ No newline at end of file diff --git a/client/static/play.css b/client/static/play.css index 3f19f0a3a99f57ad26819fa77fa47966789f9517..35e508bb40b41c136f3a82ff23f1c1483a6a9e81 100644 --- a/client/static/play.css +++ b/client/static/play.css @@ -1,3 +1,5 @@ +@import "root.css"; + .renderbox { position: absolute; top: 0; @@ -7,4 +9,13 @@ body { margin: 0; padding: 0; +} + +.infobox { + position: absolute; + bottom: 0; + left: calc(50vw - 25%); + width: 50%; + background-color: var(--ui-bg-color); + padding: var(--ui-padding); } \ No newline at end of file diff --git a/client/static/root.css b/client/static/root.css new file mode 100644 index 0000000000000000000000000000000000000000..6f90db4b96ff5de67a25af8023ff58b7036083ca --- /dev/null +++ b/client/static/root.css @@ -0,0 +1,4 @@ +:root { + --ui-bg-color: gray; + --ui-padding: 5px; +} \ No newline at end of file diff --git a/server/src/main.rs b/server/src/main.rs index 3756d4eb3efcdaaf51615b59aa7ec38317e32ef9..0f75f408e83ace1da2b324d596fbd09993ed560a 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -83,7 +83,12 @@ async fn _handle_request(mut conn: TcpStream, remote_addr: SocketAddr, mgr: Clie info!("[{}] passing to client handler", remote_addr); //forward the stream to the sink to achieve echo - handle_client(mgr.clone(), physics_data.clone(), remote_addr, rx, ws_write, ws_read).await?; + match handle_client(mgr.clone(), physics_data.clone(), remote_addr, rx, ws_write, ws_read).await { + Ok(_) => (), + Err(e) => { + error!("error in client thread: {}", e); + } + } // clean up values left over {