refactor: (setT|t)ileAt uses vector position

This commit is contained in:
cha0s 2019-05-27 18:13:09 -05:00
parent 6aec1875f7
commit 565bcc9300

View File

@ -58,12 +58,12 @@ export class Tiles extends decorate(class {}) {
return Rectangle.compose([0, 0], this.size);
}
setTileAt(x, y, tile) {
const oldTile = this.tileAt(x, y);
setTileAt(position, tile) {
const oldTile = this.tileAt(position);
if (oldTile === tile) {
return;
}
const index = y * this.width + x;
const index = position[1] * this.width + position[0];
if (index < 0 || index >= this.data.length) {
return;
}
@ -99,8 +99,8 @@ export class Tiles extends decorate(class {}) {
return slice;
}
tileAt(x, y) {
return this.data[y * this.width + x];
tileAt(position) {
return this.data[position[1] * this.width + position[0]];
}
toJSON() {