mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
UI for adding rows and columns.
This commit is contained in:
@@ -27,7 +27,7 @@ export default class Terrain
|
||||
this.htmlElement.style.height = this.tileset.getTileHeight() * this.tilesY + 'px';
|
||||
|
||||
for (let r = 0; r < this.tilesY; r++) {
|
||||
this.insertRow();
|
||||
this._insertRow();
|
||||
}
|
||||
|
||||
window.addEventListener(
|
||||
@@ -48,15 +48,17 @@ export default class Terrain
|
||||
return this.tileset;
|
||||
}
|
||||
|
||||
addRows(quantity, index)
|
||||
addRows(index, quantity = 1)
|
||||
{
|
||||
for (let q = 0; q < quantity; q++) {
|
||||
this.insertRow(index);
|
||||
this._insertRow(index);
|
||||
this.tilesY++;
|
||||
}
|
||||
|
||||
this.htmlElement.style.height = this.tileset.getTileHeight() * this.tilesY + 'px';
|
||||
}
|
||||
|
||||
insertRow(index = undefined)
|
||||
_insertRow(index = undefined)
|
||||
{
|
||||
let row = [];
|
||||
let tr = document.createElement('tr');
|
||||
@@ -77,6 +79,32 @@ export default class Terrain
|
||||
}
|
||||
}
|
||||
|
||||
addColumns(index, quantity = 1)
|
||||
{
|
||||
for (let c = 0; c < quantity; c++) {
|
||||
this._insertColumn(index);
|
||||
this.tilesX++;
|
||||
}
|
||||
|
||||
this.htmlElement.style.width = this.tileset.getTileWidth() * this.tilesX + 'px';
|
||||
}
|
||||
|
||||
_insertColumn(index = undefined)
|
||||
{
|
||||
if (index === undefined || index > this.tilesX - 1) {
|
||||
index = this.tilesX;
|
||||
}
|
||||
|
||||
for (let y = 0; y < this.tilesY; y++) {
|
||||
let field = new Field(this.tileset);
|
||||
this.fields[y] = this.fields[y].slice(0, index).concat(field).concat(this.fields[y].slice(index));
|
||||
|
||||
let htmlRow = this.htmlElement.childNodes[y];
|
||||
htmlRow.insertBefore(field.getElement(), htmlRow.childNodes[index]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
setFieldIndex(x, y, index)
|
||||
{
|
||||
this.fields[y][x].setIndex(index);
|
||||
|
||||
Reference in New Issue
Block a user