From 5d4e9af56003298f41106a96bbb059b99ea0658f Mon Sep 17 00:00:00 2001 From: ghostlyzsh Date: Thu, 4 Apr 2024 18:34:38 -0500 Subject: [PATCH] beam out button --- server/src/main.rs | 6 +++-- starkingdoms-client/src/globals.ts | 1 + starkingdoms-client/src/hub.ts | 6 ++++- starkingdoms-client/src/pages/Play.svelte | 25 ++++++++++++++++++- .../src/pages/ShipEditor.svelte | 21 ++++++++++++++++ 5 files changed, 55 insertions(+), 4 deletions(-) diff --git a/server/src/main.rs b/server/src/main.rs index d8d86fc1f4915000e74f488b4aa734c8b2b3aedc..eb9f4e18809a10702b76ff1a3c0af252b799dfbc 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -660,7 +660,8 @@ fn on_message( } let mut player = player_query.get_mut(entity).unwrap().1; player.energy_capacity -= lost_energy_capacity; - player.energy = std::cmp::min(player.energy, player.energy_capacity); + player.energy = + std::cmp::min(player.energy, player.energy_capacity); break; } if attach_on_module_tree( @@ -748,7 +749,8 @@ fn on_message( payload: save_string, }; - event_queue.push(WsEvent::Broadcast { + event_queue.push(WsEvent::Send { + to: *from, message: packet.into(), }); } diff --git a/starkingdoms-client/src/globals.ts b/starkingdoms-client/src/globals.ts index d1ffd075bd9a2ae7d8020ccca7fbf6322d9623ff..cd668bccbd51916520bd3eca74d8fa83b6c06025 100644 --- a/starkingdoms-client/src/globals.ts +++ b/starkingdoms-client/src/globals.ts @@ -21,6 +21,7 @@ export interface GlobalData { rendering: GlobalRendering | null; saveEligible: boolean; + leaving: boolean; } export interface GlobalRendering { diff --git a/starkingdoms-client/src/hub.ts b/starkingdoms-client/src/hub.ts index de4f9ddeea327df18a5383533856e04123a5a608..03156b22f8f18701556a9d9486579079aabf2821 100644 --- a/starkingdoms-client/src/hub.ts +++ b/starkingdoms-client/src/hub.ts @@ -334,9 +334,13 @@ export async function hub_connect( ); window.localStorage.setItem("save", p.payload); chatbox.addMessage("server-message", "[Save] Game saved successfully!"); + + if (global.leaving) { + window.location.href = "/" + } } else if (packet.t == PacketType.EnergyUpdate) { let p = packet.c; - console.log(p.amount + "/" + p.max); + let percent_energy = p.amount / p.max; energy.style.width = energy_bar_max_width * percent_energy + "px"; } else { diff --git a/starkingdoms-client/src/pages/Play.svelte b/starkingdoms-client/src/pages/Play.svelte index 2dde85b6f07d571d15d16f401df827dc0cb99c8d..cd14c495bcc2be5243d6cb1a482689500267072a 100644 --- a/starkingdoms-client/src/pages/Play.svelte +++ b/starkingdoms-client/src/pages/Play.svelte @@ -2,7 +2,7 @@ import HeartIcon from "../icons/HeartIcon.svelte"; import createDebug from "debug"; - import { hub_connect } from "../hub.ts"; + import { hub_connect, sendPacket } from "../hub.ts"; import "../css/style.scss"; import "../css/themes/catppuccin-mocha.scss"; import { DEFAULT_CONFIG, loadConfig } from "../config.ts"; @@ -10,7 +10,9 @@ import { onMount } from "svelte"; import Popup from "../components/ui/Popup.svelte"; import Checkbox from "../components/ui/Checkbox.svelte"; + import Button from "../components/ui/Button.svelte"; import { global } from "../globals.ts"; + import { PacketType } from "../protocol.ts"; import * as PIXI from "pixi.js"; let config = DEFAULT_CONFIG; @@ -36,6 +38,22 @@ logger("Antialiasing is now", antialiasing ? "on" : "off"); }*/ + function beam_out() { + if (!global.saveEligible) { + chatbox.addMessage( + "server-message", + "[Save] Not eligible to beam out, please get closer to a planet" + ); + return; + } + let req_packet: Packet = { + t: PacketType.RequestSave, + c: {}, + }; + sendPacket(global.client!, req_packet); + global.leaving = true; + } + onMount(async () => { config = await loadConfig(); @@ -136,6 +154,7 @@ + @@ -143,6 +162,9 @@ + +
Position Velocity Track Angle
+ + -- , @@ -156,6 +178,7 @@
Energy: = new Map(); @@ -269,6 +270,16 @@ confirm_save = false; }, 5000); } + + function quit_btn() { + if (confirm_quit) { + window.location.href = "/"; + } + confirm_quit = !confirm_quit; + setTimeout(() => { + confirm_quit = false; + }, 5000); + } function toggle_select(type: PartType) { console.log(type); @@ -378,6 +389,16 @@ Save Changes {/if} +