From 5365ecc9d91bd4171dcc44d49584b329183947f2 Mon Sep 17 00:00:00 2001 From: ghostlyzsh Date: Sun, 7 Apr 2024 00:36:47 -0500 Subject: [PATCH] fixed some ship editor loading and saving issues --- server/src/main.rs | 3 - starkingdoms-client/src/hub.ts | 6 +- .../src/pages/ShipEditor.svelte | 69 +++++++++++++------ 3 files changed, 54 insertions(+), 24 deletions(-) diff --git a/server/src/main.rs b/server/src/main.rs index 1c3189d22ca958c7f70ca6e5ffe6d1d59bc93b03..937c48618e36bb311e0c3bab980047584b28df0f 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1655,10 +1655,8 @@ fn save_eligibility( let player = player_query.get(player_entity).unwrap(); if !player.save_eligibility { if player_eligibilities.contains_key(&player_entity) { - println!("here"); player_eligibilities.remove(&player_entity); } - println!("heretrue"); player_eligibilities.insert(player_entity, true); } } else { @@ -1673,7 +1671,6 @@ fn save_eligibility( && !(player_eligibilities.contains_key(&other) && *player_eligibilities.get(&other).unwrap()) { - println!("herefalse"); player.save_eligibility = false; player_eligibilities.insert(other, false); } diff --git a/starkingdoms-client/src/hub.ts b/starkingdoms-client/src/hub.ts index dcd99178c4ae918cc0cfa36cb775d0dcbe01ef47..9c7e9d27d535f97dba0b89a1c434e96887fb70f7 100644 --- a/starkingdoms-client/src/hub.ts +++ b/starkingdoms-client/src/hub.ts @@ -71,11 +71,15 @@ export async function hub_connect( }; global.client = client; + let save = window.localStorage.getItem("save"); + if (save !== null) { + save = save.trim(); + } let packet: Packet = { t: PacketType.ClientLogin, c: { username, - save: window.localStorage.getItem("save"), + save, jwt: window.localStorage.getItem("stk-token"), }, }; diff --git a/starkingdoms-client/src/pages/ShipEditor.svelte b/starkingdoms-client/src/pages/ShipEditor.svelte index e58c7e6d70ce2e14f2422768f0024d9af55a9875..33970600072067592d0fb2fc2c31c2f8fbe33507 100644 --- a/starkingdoms-client/src/pages/ShipEditor.svelte +++ b/starkingdoms-client/src/pages/ShipEditor.svelte @@ -263,17 +263,19 @@ available: existing_part_count.available + 1, }); + let x_dir = Math.round(Math.cos((rotation+1)*Math.PI/2)); + let y_dir = Math.round(Math.sin((rotation+1)*Math.PI/2)); if (children[0] !== null) { - place(x, y + 1, children[0], (rotation + 2) % 4); + place(x, y + y_dir, children[0], (rotation + 2) % 4); } if (children[1] !== null) { - place(x + 1, y, children[1], (rotation + 1) % 4); + place(x + x_dir, y, children[1], (rotation + 1) % 4); } if (children[2] !== null) { - place(x, y - 1, children[2], rotation); + place(x, y - y_dir, children[2], rotation); } if (children[3] !== null) { - place(x - 1, y, children[3], (rotation + 3) % 4); + place(x - x_dir, y, children[3], (rotation + 3) % 4); } } @@ -296,31 +298,58 @@ }, 5000); } - function save_recursive(x: number, y: number) { + function save_recursive(x: number, y: number/*, a_rotation: number*/) { let [part_type, rotation] = grid.get(x)!.get(y)!; let children = [null, null, null, null]; + let x_dir = Math.round(Math.cos((rotation+1)*Math.PI/2)); + let y_dir = Math.round(Math.sin((rotation+1)*Math.PI/2)); + console.log(x_dir + ", " + y_dir + "(" + rotation + ")"); + console.log(grid.get(x)?.get(y + y_dir)); if (part_type == PartType.Hearty) { - if (grid.get(x+1)?.get(y)?.[1] == 1) { // right - children[1] = save_recursive(x+1, y); - } - if (grid.get(x-1)?.get(y)?.[1] == 3) { // left - children[3] = save_recursive(x-1, y); - } - if (grid.get(x)?.get(y-1)?.[1] == 0) { // up - children[2] = save_recursive(x, y-1); - } - if (grid.get(x)?.get(y+1)?.[1] == 2) { // down - children[0] = save_recursive(x, y+1); - } - } else if (part_type == PartType.Cargo) {} + if (grid.get(x + 1)?.get(y)?.[1] == 1) { + // right + children[1] = save_recursive(x + 1, y, 1); + } + if (grid.get(x - 1)?.get(y)?.[1] == 3) { + // left + children[3] = save_recursive(x - 1, y, 3); + } + if (grid.get(x)?.get(y - 1)?.[1] == 0) { + // up + children[2] = save_recursive(x, y - 1, 0); + } + if (grid.get(x)?.get(y + 1)?.[1] == 2) { + // down + children[0] = save_recursive(x, y + 1, 2); + } + return { part_type: part_type, children: children }; + } else if (part_type == PartType.Cargo || part_type == PartType.LandingThruster) { + return { part_type: part_type, children: children }; + } + if (grid.get(x + x_dir)?.get(y)?.[1] == (rotation+3)%4) { + // left + children[3] = save_recursive(x + x_dir, y, rotation+3); + } + if (grid.get(x - x_dir)?.get(y)?.[1] == (rotation+1)%4) { + // right + children[1] = save_recursive(x - x_dir, y, rotation+1); + } + /*if (grid.get(x)?.get(y - y_dir)?.[1] == rotation) { + // down + children[2] = save_recursive(x, y - y_dir); + }*/ + if (grid.get(x)?.get(y - y_dir)?.[1] == rotation) { + // up + children[0] = save_recursive(x, y - y_dir, rotation); + } - return {part_type: part_type, children: children}; + return { part_type: part_type, children: children }; } function save_btn() { if (confirm_save) { // todo: @ghostly you need to turn this back into a savefile and then call pack_partial on it - let children = save_recursive(0, 0).children; + let children = save_recursive(0, 0, 0).children; let unused_modules = []; for (let [part_type, value] of part_counts) { let unused = value.available - value.used;