~starkingdoms/starkingdoms

0b7145612e91f4448aa386b1021f6b79c3a6d420 — ghostlyzsh 1 year, 8 months ago 83b9ddb
no, saving does not work, but now it does
1 files changed, 36 insertions(+), 14 deletions(-)

M starkingdoms-client/src/pages/ShipEditor.svelte
M starkingdoms-client/src/pages/ShipEditor.svelte => starkingdoms-client/src/pages/ShipEditor.svelte +36 -14
@@ 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];