Walkable mask painting
This commit is contained in:
43
js/grid.js
43
js/grid.js
@@ -1,38 +1,20 @@
|
||||
import { Layer } from './layer.js';
|
||||
import { Mask } from './mask.js';
|
||||
export class Grid {
|
||||
constructor(prnt) {
|
||||
constructor(prnt, width, height, tileset, layers, masks) {
|
||||
this.layers = new Map();
|
||||
this.masks = new Map();
|
||||
this.prnt = prnt;
|
||||
this.prnt.style.display = 'grid';
|
||||
}
|
||||
set_size(x, y) {
|
||||
this.height = y;
|
||||
this.prnt.style.gridTemplateColumns = `repeat(${x}, 1fr)`;
|
||||
this.prnt.style.gridTemplateRows = `repeat(${y}, 1fr)`;
|
||||
}
|
||||
set_tileset(set) {
|
||||
this.tileset = set;
|
||||
this.prnt.style.backgroundImage = `url("images/${this.tileset}/land.svg")`;
|
||||
// TODO: Notify layers
|
||||
}
|
||||
set_layers(layers) {
|
||||
const newNames = new Set(layers);
|
||||
for (const name of newNames) {
|
||||
if (!this.layers.has(name)) {
|
||||
const layer = new Layer();
|
||||
layer.set_tileset(this.tileset);
|
||||
this.layers.set(name, layer);
|
||||
}
|
||||
this.prnt.style.gridTemplateColumns = `repeat(${width}, 1fr)`;
|
||||
this.prnt.style.gridTemplateRows = `repeat(${height}, 1fr)`;
|
||||
this.prnt.style.backgroundImage = `url("images/${tileset}/land.svg")`;
|
||||
for (let i = 0; i <= layers.length; i++) {
|
||||
const name = layers[i];
|
||||
this.layers.set(name, new Layer(i * height, tileset));
|
||||
}
|
||||
for (const name of this.layers.keys()) {
|
||||
if (!newNames.has(name)) {
|
||||
// TODO: Notify layer to tear down
|
||||
this.layers.delete(name);
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < layers.length; i++) {
|
||||
const layer = this.layers.get(layers[i]);
|
||||
layer.set_level(i * this.height);
|
||||
for (const name of masks) {
|
||||
this.masks.set(name, new Mask(width, height));
|
||||
}
|
||||
}
|
||||
add_tile(tile_factory, x, y) {
|
||||
@@ -41,6 +23,9 @@ export class Grid {
|
||||
tile.elem.style.gridColumnStart = `${x + 1}`;
|
||||
tile.elem.style.gridRowStart = `${y + 1}`;
|
||||
this.prnt.appendChild(tile.elem);
|
||||
for (const [name, mask] of tile.masks) {
|
||||
this.masks.get(name).update(x, y, mask);
|
||||
}
|
||||
return tile;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user