fix token preview, copy; bump to v0.2.1

This commit is contained in:
Iris Lightshard 2023-07-17 22:26:31 -06:00
parent f1c56f63f1
commit 331150a0ff
Signed by: nilix
GPG key ID: 3B7FBC22144E6398
7 changed files with 33 additions and 19 deletions

View file

@ -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 = "";
}
}

View file

@ -146,13 +146,13 @@
</form>
</details>
<div id="lag" style="display:none;">lag...</div>
<div class="ui_win" id="felt_info"><a href="https://hacklab.nilfm.cc/felt">felt v0.2.0</a> (<a href="https://hacklab.nilfm.cc/felt/raw/main/LICENSE">license</a>) | built with <a href="https://leafletjs.com">leaflet</a> (<a href="https://hacklab.nilfm.cc/felt/raw/main/LEAFLET_LICENSE">license</a>) </div>
<div class="ui_win" id="felt_info"><a href="https://hacklab.nilfm.cc/felt">felt v0.2.1</a> (<a href="https://hacklab.nilfm.cc/felt/raw/main/LICENSE">license</a>) | built with <a href="https://leafletjs.com">leaflet</a> (<a href="https://hacklab.nilfm.cc/felt/raw/main/LEAFLET_LICENSE">license</a>) </div>
</nav>
</body>
<script src="./leaflet.js?v=1.9.4" type="text/javascript"></script>
<script src="./util.js?v=0.2.0" type="text/javascript"></script>
<script src="./map.js?v=0.2.0" type="text/javascript"></script>
<script src="./socket.js?v=0.2.0" type="text/javascript"></script>
<script src="./dice.js?v=0.2.0" type="text/javascript"></script>
<script src="./admin.js?v=0.2.0" type="text/javascript"></script>
<script src="./util.js?v=0.2.1" type="text/javascript"></script>
<script src="./map.js?v=0.2.1" type="text/javascript"></script>
<script src="./socket.js?v=0.2.1" type="text/javascript"></script>
<script src="./dice.js?v=0.2.1" type="text/javascript"></script>
<script src="./admin.js?v=0.2.1" type="text/javascript"></script>
</html>

View file

@ -20,6 +20,7 @@ function initializeMap(mapImgUrl) {
if (init) {
map.setView([0,0], 2);
}
resizeMarkers();
}
// this works but assumes the map is square (reasonable limitation I think)

View file

@ -88,10 +88,12 @@ function renderTokenSelect() {
// the following few functions aren't socket related but they directly relate to the previous function
function initSpritePreviewById(id) {
const img = document.createElement("img");
const token = tokens.find(t=>t.t.id == id);
let img = null;
if (token && id) {
img = document.createElement("img");
img.src = token.t.sprite;
secondaryPreviewIdInput.value = id;
@ -102,7 +104,9 @@ function initSpritePreviewById(id) {
}
dismissPreviewBtn.style.display = (token && id) ? "block" : "none";
secondaryPreviewZone.innerHTML = "";
secondaryPreviewZone.appendChild(img);
if (img) {
secondaryPreviewZone.appendChild(img);
}
}
function dismissPreview() {

View file

@ -15,6 +15,6 @@
<p><a href="/table">Get back to gaming...</a></p>
</main>
</body>
<script src="./util.js?v=0.2.0" type="text/javascript"></script>
<script src="./util.js?v=0.2.1" type="text/javascript"></script>
</html>
<html>

View file

@ -23,5 +23,5 @@
{{end}}
</main>
</body>
<script src="/table/util.js?v=0.2.0" type="text/javascript"></script>
<script src="/table/util.js?v=0.2.1" type="text/javascript"></script>
</html>

View file

@ -19,5 +19,5 @@
{{end}}
</main>
</body>
<script src="/table/util.js?v=0.2.0" type="text/javascript"></script>
<script src="/table/util.js?v=0.2.1" type="text/javascript"></script>
</html>