use ::java::data::dialog::Dialog
use ::java::util::text::Text

dispatch minecraft:storage["pipes:grid"] to struct data{
  cache?: struct{
    display?: Text,
    neighbour?: tile,
    processing_data?: [
      [tile]
    ],
    processing_data_cache?: [
      [tile]
    ],
    processing_tile?: tile,
    upset?: tile,
    warn?: tile,
    [any]: any
  },
  DFS?: [
    struct{
      current_tile?: tile,
      neighbour_tile?: [tile]
    }
  ],
  dialog?: struct{
    custom_menu?: Dialog,
    game?: Dialog,
    settings?: Dialog
  },
  generate?: struct{
    height?: int,
    seed?: int,
    width?: int
  },
  grid?: [
    [tile]
  ],
  macro?: struct{
    neighbour_x?: int,
    neighbour_y?: int,
    tile_index?: int,
    tile_x?: int,
    tile_y?: int,
    warn_x?: int,
    warn_y?: int
  },
  pop_tiles?: [tile],
  record?: struct{
    is_true?: Text,
    is_false?: Text,
    timer?: int[],
  },
  settings?: struct{
    record?: boolean,
    rotation_direction?: enum(string){
      clockwise = "clockwise",
      counterclockwise = "counterclockwise"
    },
    trigger?: boolean
  },
  stack?: [tile],
  style?: struct{
    flood?: #[id="font"] string,
    normal?: #[id="font"] string,
    source?: #[id="font"] string,
    warning?: #[id="font"] string
  },
}

dispatch minecraft:storage["pipes:prim"] to struct prim{
  alternative_side?: [alternative_side],
  cache?: struct{
    current?: alternative_side,
    neighbour?: alternative_side,
    tile_check: struct{
      current?: tile,
      neighbour?: tile
    }
  },
  debug?: any,
  macro?: struct{
    down?: int,
    left?: int,
    length_of_alternative_side?: int,
    neighbour_x?: int,
    neighbour_y?: int,
    random?: int,
    right?: int,
    up?: int,
    x?: int,
    y?: int
  }
}

struct tile{
  dfn?: int,
  index?: int,
  locked?: boolean,
  low?: int,
  parent?: int,
  parent_x?: int,
  parent_y?: int,
  side?: byte@0..1[] @ 4, // 依次为左、上、右、下四个方向，0为未连接，1为连接
  source?: boolean,
  state?: byte@0..3, // 0为无，1为灌水，2为警告，3为待访问
  visited?: boolean,
  x?: int,
  y?: int
}

struct alternative_side{
  side: byte@-1..1[] @ 2, // 左：[B;-1b,0b]，上：[B;0b,-1b]，右：[B;1b,0b]，下：[B;0b,1b]
  tile: int[] @ 2
}