Row insertion implemented.
This commit is contained in:
parent
fa648ae730
commit
bd83449e79
|
@ -3,7 +3,7 @@ import TilorswiftFieldEnteredEvent from "./events/TilorswiftFieldEnteredEvent.js
|
|||
|
||||
export default class Field
|
||||
{
|
||||
constructor(tileset, index = 0)
|
||||
constructor(tileset, index = -1)
|
||||
{
|
||||
this.tileset = tileset;
|
||||
this.index = index;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -158,3 +158,9 @@ body {
|
|||
.field:hover .selection {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
/*
|
||||
tr:hover > td > .selection {
|
||||
opacity: 0.5;
|
||||
}
|
||||
*/
|
Loading…
Reference in New Issue