M server/src/main.rs => server/src/main.rs +4 -2
@@ 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(),
});
}
M starkingdoms-client/src/globals.ts => starkingdoms-client/src/globals.ts +1 -0
@@ 21,6 21,7 @@ export interface GlobalData {
rendering: GlobalRendering | null;
saveEligible: boolean;
+ leaving: boolean;
}
export interface GlobalRendering {
M starkingdoms-client/src/hub.ts => starkingdoms-client/src/hub.ts +5 -1
@@ 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 = <EnergyUpdatePacket>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 {
M starkingdoms-client/src/pages/Play.svelte => starkingdoms-client/src/pages/Play.svelte +24 -1
@@ 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 @@
<table>
<thead>
<tr>
+ <th></th>
<th class="hud-d">Position</th>
<th class="hud-d">Velocity</th>
<th class="hud-d">Track Angle</th>
@@ 143,6 162,9 @@
</thead>
<tbody>
<tr>
+ <td id="leave">
+ <Button on:click={beam_out}>Beam out</Button>
+ </td>
<td id="pos">
<span id="pos-val-x" bind:this={x_pos}>--</span>
,
@@ 156,6 178,7 @@
</td>
</tr>
<tr>
+ <td></td>
<td class="hud-d"><strong>Energy:</strong></td>
<td
colspan="2"
M starkingdoms-client/src/pages/ShipEditor.svelte => starkingdoms-client/src/pages/ShipEditor.svelte +21 -0
@@ 203,6 203,7 @@
let confirm_reload_save = false;
let confirm_save = false;
+ let confirm_quit = false;
let part_counts: Map<PartType, { used: number; available: number }> =
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}
</Button>
+ <Button
+ on:click={quit_btn}
+ variant="danger"
+ style="min-width: 16em; margin-top: 5px;">
+ {#if confirm_quit}
+ Are you sure you want to quit without saving? (again to confirm, resets in 5s)
+ {:else}
+ Quit without Save
+ {/if}
+ </Button>
</Popup>
<canvas