diff --git a/static/admin.js b/static/admin.js index b9c5626..86f675a 100644 --- a/static/admin.js +++ b/static/admin.js @@ -153,8 +153,11 @@ function scaleSpritePreview(source) { break; } } - tokenCX.value = Number(tokenWidth.value)/2; - tokenCY.value = Number(tokenHeight.value)/2; + if (!tokenCX.value || source) { + tokenCX.value = Number(tokenWidth.value)/2; + } if (!tokenCY.value || source) { + tokenCY.value = Number(tokenHeight.value)/2; + } drawTokenOrigin(); } } @@ -187,20 +190,26 @@ function drawTokenOrigin() { } } -function reinitializeSpritePreview() { +function reinitializeSpritePreview(existing = false) { const img = document.createElement("img"); img.src = tokenSpriteDropdown[tokenSpriteDropdown.selectedIndex].value; - const tokenNameParts = tokenSpriteDropdown[tokenSpriteDropdown.selectedIndex].text.split("."); - tokenNameParts.pop(); - tokenName.value = tokenNameParts.join("."); + if (!existing) { + const tokenNameParts = tokenSpriteDropdown[tokenSpriteDropdown.selectedIndex].text.split("."); + tokenNameParts.pop(); + tokenName.value = tokenNameParts.join("."); + } img.onload = () => { const w = img.naturalWidth; const h = img.naturalHeight; + if (!existing) { tokenWidth.value = w; tokenHeight.value = h; + tokenCX.value = "" + tokenCY.value = "" + } scaleSpritePreview(); } @@ -261,7 +270,7 @@ function previewExistingToken(id) { break; } } - reinitializeSpritePreview(); + reinitializeSpritePreview(true); } } @@ -500,7 +509,7 @@ function setTokenCreateFormVisible(v) { } createTokenForm.style.display = v ? "block" : "none"; tokenZone.style.display = v ? "none" : "block"; - reinitializeSpritePreview(); + previewZone.innerHTML = ""; } } diff --git a/static/index.html b/static/index.html index 2942138..f4cef00 100644 --- a/static/index.html +++ b/static/index.html @@ -146,13 +146,13 @@
- +