clone method

dynamic clone()

Get a clone of this grid. @return {Grid} Cloned grid.

Implementation

clone() {
  var i, j,

  width = this.width,
  height = this.height,
  thisNodes = this.nodes,

  newGrid = new Grid(width, height),
  newNodes = new List.filled(height, new List<Node?>.filled(width, null)),
  row;

  for (i = 0; i < height; ++i) {
    newNodes[i] = new List.filled(width, null);
    for (j = 0; j < width; ++j) {
      newNodes[i][j] = new Node(j, i, thisNodes[i][j].walkable);
    }
  }

  newGrid.nodes = newNodes;

  return newGrid;
}