~starkingdoms/starkingdoms

83b9ddb5426771bcf4025de317f6a1f53a1c28e6 — ghostlyzsh 1 year, 8 months ago f5ba856
saving fixed?
1 files changed, 25 insertions(+), 23 deletions(-)

M starkingdoms-client/src/pages/ShipEditor.svelte
M starkingdoms-client/src/pages/ShipEditor.svelte => starkingdoms-client/src/pages/ShipEditor.svelte +25 -23
@@ 254,8 254,8 @@

    let [type, children] = data;

    console.log("(" + x + ", " + y + ") type:" + type + ", rot: " + rotation);
    console.log(children);
    console.log(x_dir);
    console.log(y_dir);
    placePart(x, y, type, rotation);

    let existing_part_count =


@@ 325,50 325,52 @@
    }, 5000);
  }

  function save_recursive(x: number, y: number /*, a_rotation: number*/) {
    let [part_type, rotation] = grid.get(x)!.get(y)!;
  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];
    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 (part_type == PartType.Hearty) {
      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) {
      if (grid.get(x - 1)?.get(y)?.[1] == 1) {
        // left
        children[3] = save_recursive(x - 1, y, 3);
        children[1] = save_recursive(x - 1, y, 3);
      }
      if (grid.get(x + 1)?.get(y)?.[1] == 3) {
        // right
        children[3] = save_recursive(x + 1, y, 1);
      }
      if (grid.get(x)?.get(y - 1)?.[1] == 0) {
      if (grid.get(x)?.get(y - 1)?.[1] == 2) {
        // up
        children[2] = save_recursive(x, y - 1, 0);
      }
      if (grid.get(x)?.get(y + 1)?.[1] == 2) {
      if (grid.get(x)?.get(y + 1)?.[1] == 0) {
        // down
        children[0] = save_recursive(x, y + 1, 2);
      }
      return { part_type: part_type, children: children };
      return [ part_type, children ];
    } else if (
      part_type == PartType.Cargo ||
      part_type == PartType.LandingThruster
    ) {
      return { part_type: part_type, children: children };
      return [ part_type, children ];
    }
    if (grid.get(x + x_dir)?.get(y)?.[1] == (rotation + 3) % 4) {
    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[3] = save_recursive(x + x_dir, y, rotation + 3);
      children[1] = save_recursive(x + x_dir[left_rotation], y + y_dir[left_rotation], left_rotation);
    }
    if (grid.get(x - x_dir)?.get(y)?.[1] == (rotation + 1) % 4) {
    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[1] = save_recursive(x - x_dir, y, rotation + 1);
      children[3] = 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);
    }*/
    if (grid.get(x)?.get(y - y_dir)?.[1] == rotation) {
    let up_rotation = rotation;
    if (grid.get(x+y_dir[up_rotation])?.get(y + y_dir[up_rotation])?.[1] == up_rotation) {
      // up
      children[2] = save_recursive(x, y - y_dir, rotation);
      children[2] = save_recursive(x + x_dir[up_rotation], y + y_dir[up_rotation], up_rotation);
    }

    return [part_type, children];


@@ 377,7 379,7 @@
  async 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, 0).children;
      let children = save_recursive(0, 0, 0)[1];
      let unused_modules = [];
      for (let [part_type, value] of part_counts) {
        let unused = value.available - value.used;