From 8d4bcf7c3134e59687a593f9cbb7e581292a45a8 Mon Sep 17 00:00:00 2001 From: Mal Date: Sat, 17 May 2025 00:56:06 +0200 Subject: [PATCH] Fixes for background tile widget --- tilorswift/js/Field.js | 2 +- tilorswift/js/Tilorswift.js | 1 + tilorswift/js/menu/BackgroundPickerWidget.js | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tilorswift/js/Field.js b/tilorswift/js/Field.js index 2ea8d4a..352ddc1 100644 --- a/tilorswift/js/Field.js +++ b/tilorswift/js/Field.js @@ -77,7 +77,7 @@ export default class Field { const position = this.index >= -1 ? -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'; } diff --git a/tilorswift/js/Tilorswift.js b/tilorswift/js/Tilorswift.js index 2e95b12..db399ae 100644 --- a/tilorswift/js/Tilorswift.js +++ b/tilorswift/js/Tilorswift.js @@ -141,6 +141,7 @@ export default class Tilorswift } else { document.body.style.backgroundImage = 'none'; } + this.map.innerHTML = ''; this.map.appendChild(this.level.terrain.getElement()); this.tilesetPicker.reloadTileset(this.tileset); diff --git a/tilorswift/js/menu/BackgroundPickerWidget.js b/tilorswift/js/menu/BackgroundPickerWidget.js index 4017116..d8f17f1 100644 --- a/tilorswift/js/menu/BackgroundPickerWidget.js +++ b/tilorswift/js/menu/BackgroundPickerWidget.js @@ -31,10 +31,13 @@ export default class BackgroundPickerWidget extends Widget loadTileset() { if (this.tileset.background === null) { + this.disable(); this.htmlElement.style.backgroundImage = 'none'; return; } + this.enable(); + for (let t = -2; t >= -this.tileset.background.tiles - 1; t--) { console.log(t); const button = new ButtonBackgroundTile(this.tileset, t); @@ -79,7 +82,7 @@ export default class BackgroundPickerWidget extends Widget 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()