mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Tileset dialog for Tilorswift and fix for adding rows.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import Field from "./Field.js";
|
||||
import Tileset from "./Tileset.js";
|
||||
import TilorswiftEvent from "./events/TilorswiftEvent.js";
|
||||
import GraphicSet from "../../js/GraphicSet.js";
|
||||
|
||||
export default class Terrain
|
||||
{
|
||||
@@ -15,6 +16,7 @@ export default class Terrain
|
||||
this.targetTileX = undefined;
|
||||
this.targetTileY = undefined;
|
||||
this.backgroundColor = backgroundColor;
|
||||
this.backgroundImage = undefined;
|
||||
this.htmlElement = document.createElement('table');
|
||||
this.brushTileIndex = 0;
|
||||
|
||||
@@ -24,7 +26,6 @@ export default class Terrain
|
||||
init()
|
||||
{
|
||||
this.htmlElement.id = 'level';
|
||||
this.htmlElement.style.backgroundColor = this.backgroundColor;
|
||||
this.htmlElement.style.width = this.tileset.getTileWidth() * this.tilesX + 'px';
|
||||
this.htmlElement.style.height = this.tileset.getTileHeight() * this.tilesY + 'px';
|
||||
|
||||
@@ -65,6 +66,8 @@ export default class Terrain
|
||||
for (let q = 0; q < quantity; q++) {
|
||||
this._insertRow(index);
|
||||
this.tilesY++;
|
||||
this.entranceTileY = this.entranceTileY === undefined ? undefined : this.entranceTileY + 1;
|
||||
this.targetTileY = this.targetTileY === undefined ? undefined : this.targetTileY + 1;
|
||||
}
|
||||
|
||||
this.htmlElement.style.height = this.tileset.getTileHeight() * this.tilesY + 'px';
|
||||
@@ -82,11 +85,18 @@ export default class Terrain
|
||||
tr.appendChild(td);
|
||||
}
|
||||
|
||||
console.log(index);
|
||||
|
||||
if (index === undefined || index >= this.tilesY - 1) {
|
||||
this.fields.push(row);
|
||||
this.htmlElement.appendChild(tr);
|
||||
} else if (index === 0) {
|
||||
this.fields = [row].concat(this.fields);
|
||||
console.log(this.fields[0]);
|
||||
this.htmlElement.insertBefore(tr, this.htmlElement.childNodes[index]);
|
||||
} else {
|
||||
this.fields = this.fields.slice(0, index).concat(row).concat(this.fields.slice(index));
|
||||
this.fields = this.fields.slice(0, index).concat([row]).concat(this.fields.slice(index));
|
||||
console.log(this.fields[1]);
|
||||
this.htmlElement.insertBefore(tr, this.htmlElement.childNodes[index]);
|
||||
}
|
||||
}
|
||||
@@ -96,6 +106,8 @@ export default class Terrain
|
||||
for (let c = 0; c < quantity; c++) {
|
||||
this._insertColumn(index);
|
||||
this.tilesX++;
|
||||
this.entranceTileX = this.entranceTileX === undefined ? undefined : this.entranceTileX + 1;
|
||||
this.targetTileX = this.targetTileX === undefined ? undefined : this.targetTileX + 1;
|
||||
}
|
||||
|
||||
this.htmlElement.style.width = this.tileset.getTileWidth() * this.tilesX + 'px';
|
||||
@@ -175,11 +187,10 @@ export default class Terrain
|
||||
|
||||
static createFromJson(terrainData)
|
||||
{
|
||||
let imageTileset = new Image();
|
||||
imageTileset.src = terrainData.tileset;
|
||||
let graphicSet = GraphicSet[terrainData.tileset];
|
||||
|
||||
let tileset = new Tileset(imageTileset, terrainData.tiles, terrainData.scale);
|
||||
let terrain = new Terrain(tileset, terrainData.columns, terrainData.rows, terrainData.backgroundColor);
|
||||
let tileset = new Tileset(terrainData.tileset);
|
||||
let terrain = new Terrain(tileset, terrainData.columns, terrainData.rows, graphicSet.backgroundColor);
|
||||
|
||||
for (let y = 0; y < terrainData.rows; y++) {
|
||||
for (let x = 0; x < terrainData.columns; x++) {
|
||||
|
||||
Reference in New Issue
Block a user