Fixes for background tile widget

This commit is contained in:
Mal 2025-05-17 00:56:06 +02:00
parent fc990c12aa
commit 8d4bcf7c31
3 changed files with 6 additions and 2 deletions

View File

@ -77,7 +77,7 @@ export default class Field
{ {
const position = this.index >= -1 const position = this.index >= -1
? -this.index * this.tileset.getTileWidth() ? -this.index * this.tileset.getTileWidth()
: (this.index % this.tileset.background.tiles) * this.tileset.getTileWidth(); : ((this.index + 2) % this.tileset.background.tiles) * this.tileset.getTileWidth();
this.htmlElement.style.backgroundPositionX = String(position) + 'px'; this.htmlElement.style.backgroundPositionX = String(position) + 'px';
} }

View File

@ -141,6 +141,7 @@ export default class Tilorswift
} else { } else {
document.body.style.backgroundImage = 'none'; document.body.style.backgroundImage = 'none';
} }
this.map.innerHTML = ''; this.map.innerHTML = '';
this.map.appendChild(this.level.terrain.getElement()); this.map.appendChild(this.level.terrain.getElement());
this.tilesetPicker.reloadTileset(this.tileset); this.tilesetPicker.reloadTileset(this.tileset);

View File

@ -31,10 +31,13 @@ export default class BackgroundPickerWidget extends Widget
loadTileset() loadTileset()
{ {
if (this.tileset.background === null) { if (this.tileset.background === null) {
this.disable();
this.htmlElement.style.backgroundImage = 'none'; this.htmlElement.style.backgroundImage = 'none';
return; return;
} }
this.enable();
for (let t = -2; t >= -this.tileset.background.tiles - 1; t--) { for (let t = -2; t >= -this.tileset.background.tiles - 1; t--) {
console.log(t); console.log(t);
const button = new ButtonBackgroundTile(this.tileset, t); const button = new ButtonBackgroundTile(this.tileset, t);
@ -79,7 +82,7 @@ export default class BackgroundPickerWidget extends Widget
setTile(index) setTile(index)
{ {
this.htmlElement.style.backgroundPosition = String(-this.tileset.getTileWidth() * index) + 'px ' + String(this.tileset.getTileHeight()) + 'px'; this.htmlElement.style.backgroundPosition = String(((index + 2) % this.tileset.background.tiles) * this.tileset.getTileWidth()) + 'px ' + String(this.tileset.getTileHeight()) + 'px';
} }
getElement() getElement()