mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Row insertion implemented.
This commit is contained in:
@@ -27,18 +27,7 @@ export default class Terrain
|
||||
this.htmlElement.style.height = this.tileset.getTileHeight() * this.tilesY + 'px';
|
||||
|
||||
for (let r = 0; r < this.tilesY; r++) {
|
||||
let row = [];
|
||||
let tr = document.createElement('tr');
|
||||
|
||||
for (let col = 0; col < this.tilesX; col++) {
|
||||
let field = new Field(this.tileset);
|
||||
let td = field.getElement();
|
||||
row.push(field);
|
||||
tr.appendChild(td);
|
||||
}
|
||||
|
||||
this.fields.push(row);
|
||||
this.htmlElement.appendChild(tr);
|
||||
this.insertRow();
|
||||
}
|
||||
|
||||
window.addEventListener(
|
||||
@@ -59,6 +48,35 @@ export default class Terrain
|
||||
return this.tileset;
|
||||
}
|
||||
|
||||
addRows(quantity, index)
|
||||
{
|
||||
for (let q = 0; q < quantity; q++) {
|
||||
this.insertRow(index);
|
||||
this.tilesY++;
|
||||
}
|
||||
}
|
||||
|
||||
insertRow(index = undefined)
|
||||
{
|
||||
let row = [];
|
||||
let tr = document.createElement('tr');
|
||||
|
||||
for (let col = 0; col < this.tilesX; col++) {
|
||||
let field = new Field(this.tileset);
|
||||
let td = field.getElement();
|
||||
row.push(field);
|
||||
tr.appendChild(td);
|
||||
}
|
||||
|
||||
if (index === undefined || index >= this.tilesY - 1) {
|
||||
this.fields.push(row);
|
||||
this.htmlElement.appendChild(tr);
|
||||
} else {
|
||||
this.fields = this.fields.slice(0, index).concat(row).concat(this.fields.slice(index));
|
||||
this.htmlElement.insertBefore(tr, this.htmlElement.childNodes[index]);
|
||||
}
|
||||
}
|
||||
|
||||
setFieldIndex(x, y, index)
|
||||
{
|
||||
this.fields[y][x].setIndex(index);
|
||||
|
||||
Reference in New Issue
Block a user