From 0b7145612e91f4448aa386b1021f6b79c3a6d420 Mon Sep 17 00:00:00 2001 From: ghostlyzsh Date: Mon, 8 Apr 2024 23:44:31 -0500 Subject: [PATCH] no, saving does not work, but now it does --- .../src/pages/ShipEditor.svelte | 50 +++++++++++++------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/starkingdoms-client/src/pages/ShipEditor.svelte b/starkingdoms-client/src/pages/ShipEditor.svelte index 795c5a923f279ba0456935742c1ff5cedfb22d96..f321c322c03d3a0aaff6544faa378e95eacc5036 100644 --- a/starkingdoms-client/src/pages/ShipEditor.svelte +++ b/starkingdoms-client/src/pages/ShipEditor.svelte @@ -325,18 +325,18 @@ }, 5000); } - function save_recursive(x: number, y: number , a_rotation: number) { + function save_recursive(x: number, y: number, a_rotation: number) { let [part_type, m_rotation] = grid.get(x)!.get(y)!; let rotation = a_rotation; let children = [null, null, null, null]; if (part_type == PartType.Hearty) { if (grid.get(x - 1)?.get(y)?.[1] == 1) { // left - children[1] = save_recursive(x - 1, y, 3); + children[3] = save_recursive(x - 1, y, 3); } if (grid.get(x + 1)?.get(y)?.[1] == 3) { // right - children[3] = save_recursive(x + 1, y, 1); + children[1] = save_recursive(x + 1, y, 1); } if (grid.get(x)?.get(y - 1)?.[1] == 2) { // up @@ -346,31 +346,53 @@ // down children[0] = save_recursive(x, y + 1, 2); } - return [ part_type, children ]; + return [part_type, children]; } else if ( part_type == PartType.Cargo || part_type == PartType.LandingThruster ) { - return [ part_type, children ]; + return [part_type, children]; } - let left_rotation = (rotation+1)%4; - if (grid.get(x + x_dir[left_rotation])?.get(y + y_dir[left_rotation])?.[1] == left_rotation) { + let left_rotation = (rotation + 1) % 4; + if ( + grid.get(x + x_dir[left_rotation])?.get(y + y_dir[left_rotation])?.[1] == + left_rotation + ) { // left - children[1] = save_recursive(x + x_dir[left_rotation], y + y_dir[left_rotation], left_rotation); + children[3] = save_recursive( + x + x_dir[left_rotation], + y + y_dir[left_rotation], + left_rotation, + ); } - let right_rotation = (rotation+3)%4; - if (grid.get(x + x_dir[right_rotation])?.get(y + y_dir[right_rotation])?.[1] == right_rotation) { + let right_rotation = (rotation + 3) % 4; + if ( + grid + .get(x + x_dir[right_rotation]) + ?.get(y + y_dir[right_rotation])?.[1] == right_rotation + ) { // right - children[3] = save_recursive(x + x_dir[right_rotation], y + y_dir[right_rotation], right_rotation); + children[1] = save_recursive( + x + x_dir[right_rotation], + y + y_dir[right_rotation], + right_rotation, + ); } /*if (grid.get(x)?.get(y - y_dir)?.[1] == rotation) { // down children[2] = save_recursive(x, y - y_dir); }*/ - let up_rotation = rotation; - if (grid.get(x+y_dir[up_rotation])?.get(y + y_dir[up_rotation])?.[1] == up_rotation) { + let up_rotation = (rotation+2)%4; + if ( + grid.get(x + x_dir[up_rotation])?.get(y + y_dir[up_rotation])?.[1] == + up_rotation + ) { // up - children[2] = save_recursive(x + x_dir[up_rotation], y + y_dir[up_rotation], up_rotation); + children[2] = save_recursive( + x + x_dir[up_rotation], + y + y_dir[up_rotation], + up_rotation, + ); } return [part_type, children];