~starkingdoms/starkingdoms

e0fddea3f712d7c602ebbecba40358879d4ffdc0 — ghostlyzsh 1 year, 8 months ago 3419bb3
ship editor loading fixed
1 files changed, 16 insertions(+), 9 deletions(-)

M starkingdoms-client/src/pages/ShipEditor.svelte
M starkingdoms-client/src/pages/ShipEditor.svelte => starkingdoms-client/src/pages/ShipEditor.svelte +16 -9
@@ 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);
  }

  $: {