fix tiling

This commit is contained in:
Azgaar 2021-06-24 23:34:27 +03:00
parent e923cf06c9
commit e767b1b54b
2 changed files with 10 additions and 6 deletions

View file

@ -106,8 +106,8 @@ async function saveTiles() {
const img = new Image(); const img = new Image();
img.src = url; img.src = url;
img.onload = function () { img.onload = function () {
for (let y = 0, i = 0; y < graphHeight; y += tileH) { for (let y = 0, i = 0; y + tileH <= graphHeight; y += tileH) {
for (let x = 0; x < graphWidth; x += tileW, i++) { for (let x = 0; x + tileW <= graphWidth; x += tileW, i++) {
ctx.drawImage(img, x, y, tileW, tileH, 0, 0, canvas.width, canvas.height); ctx.drawImage(img, x, y, tileW, tileH, 0, 0, canvas.width, canvas.height);
const name = `fmg_tile_${i}.png`; const name = `fmg_tile_${i}.png`;
canvas.toBlob(blob => { canvas.toBlob(blob => {

View file

@ -726,6 +726,7 @@ function openSaveTiles() {
updateTilesOptions(); updateTilesOptions();
const status = document.getElementById("tileStatus"); const status = document.getElementById("tileStatus");
status.innerHTML = ""; status.innerHTML = "";
let loading = null;
$("#saveTilesScreen").dialog({ $("#saveTilesScreen").dialog({
resizable: false, resizable: false,
@ -735,7 +736,7 @@ function openSaveTiles() {
Download: function () { Download: function () {
status.innerHTML = "Preparing for download..."; status.innerHTML = "Preparing for download...";
setTimeout(() => (status.innerHTML = "Downloading. It may take some time."), 1000); setTimeout(() => (status.innerHTML = "Downloading. It may take some time."), 1000);
const loading = setInterval(() => (status.innerHTML += "."), 1000); loading = setInterval(() => (status.innerHTML += "."), 1000);
saveTiles().then(() => { saveTiles().then(() => {
clearInterval(loading); clearInterval(loading);
status.innerHTML = `Done. Check file in "Downloads" (crtl + J)`; status.innerHTML = `Done. Check file in "Downloads" (crtl + J)`;
@ -746,7 +747,10 @@ function openSaveTiles() {
$(this).dialog("close"); $(this).dialog("close");
} }
}, },
close: () => debug.selectAll("*").remove() close: () => {
debug.selectAll("*").remove();
clearInterval(loading);
}
}); });
} }
@ -774,8 +778,8 @@ function updateTilesOptions() {
const labels = []; const labels = [];
const tileW = (graphWidth / tilesX) | 0; const tileW = (graphWidth / tilesX) | 0;
const tileH = (graphHeight / tilesY) | 0; const tileH = (graphHeight / tilesY) | 0;
for (let y = 0, i = 0; y < graphHeight; y += tileH) { for (let y = 0, i = 0; y + tileH <= graphHeight; y += tileH) {
for (let x = 0; x < graphWidth; x += tileW, i++) { for (let x = 0; x + tileW <= graphWidth; x += tileW, i++) {
rects.push(`<rect x=${x} y=${y} width=${tileW} height=${tileH} />`); rects.push(`<rect x=${x} y=${y} width=${tileW} height=${tileH} />`);
labels.push(`<text x=${x + tileW / 2} y=${y + tileH / 2}>${i}</text>`); labels.push(`<text x=${x + tileW / 2} y=${y + tileH / 2}>${i}</text>`);
} }