Artifact.fromAsciiDefinition constructor

Artifact.fromAsciiDefinition(
  1. List<String> template
)

Creates a Matrix from an ASCII representation.

template A list of strings where '#' represents true and any other character represents false.

Implementation

factory Artifact.fromAsciiDefinition(final List<String> template) {
  final int rows = template.length;
  final int cols = template[0].length;

  final Artifact artifact = Artifact(cols, rows);

  for (int y = 0; y < rows; y++) {
    for (int x = 0; x < cols; x++) {
      artifact.cellSet(x, y, template[y][x] == '#');
    }
  }
  return artifact;
}