From e0fddea3f712d7c602ebbecba40358879d4ffdc0 Mon Sep 17 00:00:00 2001 From: ghostlyzsh Date: Mon, 8 Apr 2024 22:32:48 -0500 Subject: [PATCH] ship editor loading fixed --- .../src/pages/ShipEditor.svelte | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/starkingdoms-client/src/pages/ShipEditor.svelte b/starkingdoms-client/src/pages/ShipEditor.svelte index 3f2ceecb778af1a03ea5d99bc2c98d53ac309206..c93f36dede7eabb8df935f0256e21a5424d8d08a 100644 --- a/starkingdoms-client/src/pages/ShipEditor.svelte +++ b/starkingdoms-client/src/pages/ShipEditor.svelte @@ -35,6 +35,9 @@ let grid_x = 0; let grid_y = 0; + let x_dir = [0, -1, 0, 1]; + let y_dir = [1, 0, -1, 0]; + let scale = 1.0; $: grid_size = 48 * scale; @@ -162,7 +165,7 @@ let img = textures.get(selected!)!; ctx.save(); ctx.translate(canvas_x + grid_size / 2, canvas_y + grid_size / 2); - ctx.rotate((rotation * Math.PI) / 2); + ctx.rotate(((rotation+2) * Math.PI) / 2); ctx.globalAlpha = 0.2; ctx.drawImage( img, @@ -208,7 +211,7 @@ ctx.save(); ctx.translate(canvas_x + grid_size / 2, canvas_y + grid_size / 2); - ctx.rotate((rotation * Math.PI) / 2); + ctx.rotate(((rotation+2) * Math.PI) / 2); ctx.drawImage( img, -grid_size / 2, @@ -251,6 +254,8 @@ let [type, children] = data; + console.log("(" + x + ", " + y + ") type:" + type + ", rot: " + rotation); + console.log(children); placePart(x, y, type, rotation); let existing_part_count = @@ -263,25 +268,27 @@ 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 + y_dir, children[0], (rotation + 2) % 4); + let rotation_next = (rotation + 2) % 4; + place(x + x_dir[rotation_next], y + y_dir[rotation_next], children[0], rotation_next); } if (children[1] !== null) { - place(x + x_dir, y, children[1], (rotation + 1) % 4); + let rotation_next = (rotation + 1) % 4; + place(x + x_dir[rotation_next], y + y_dir[rotation_next], children[1], rotation_next); } if (children[2] !== null) { - place(x, y - y_dir, children[2], rotation); + let rotation_next = (rotation + 0) % 4; + place(x + x_dir[rotation_next], y + y_dir[rotation_next], children[2], rotation_next); } if (children[3] !== null) { - place(x - x_dir, y, children[3], (rotation + 3) % 4); + let rotation_next = (rotation + 3) % 4; + place(x + x_dir[rotation_next], y + y_dir[rotation_next], children[3], rotation_next); } } function load_save_data(save: any) { grid = new Map(); - place(0, 0, [PartType.Hearty, save[0]], 0); + place(0, 0, [PartType.Hearty, save[0]], 2); } $: {