Oliver level

This commit is contained in:
Ian Gulliver
2021-05-09 22:02:56 +00:00
parent 99aa50d5d3
commit 4651eeb335
9 changed files with 210 additions and 31 deletions

View File

@@ -27,6 +27,10 @@ export class Tile {
const mask = Array(width).fill(Array(height).fill(true));
return new Tile(name, width, height, mask);
}
static from_mask(name, mask_string) {
const mask = string_to_mask(mask_string);
return new Tile(name, mask.length, mask[0].length, mask);
}
get_mask() {
return __classPrivateFieldGet(this, _mask);
}
@@ -40,4 +44,22 @@ export class Tile {
}
}
_name = new WeakMap(), _width = new WeakMap(), _height = new WeakMap(), _mask = new WeakMap();
function string_to_mask(mask_string) {
// mask_string: '\n+++\n+++\n'
const rows = mask_string.trim().split('\n');
// rows: ['+++', '+++']
const mask = [];
for (let x = 0; x < rows[0].length; x++) {
mask[x] = Array(rows.length);
}
// mask: [ [ empty, empty ], [ empty, empty ], [ empty, empty ] ]
for (let y = 0; y < rows.length; y++) {
const row = rows[y];
for (let x = 0; x < row.length; x++) {
const cell = row[x];
mask[x][y] = (cell.toUpperCase() == 'X');
}
}
return mask;
}
//# sourceMappingURL=tile.js.map