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: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
7 changed files with 33 additions and 19 deletions

View file

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

View file

@ -146,13 +146,13 @@
</form> </form>
</details> </details>
<div id="lag" style="display:none;">lag...</div> <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> </nav>
</body> </body>
<script src="./leaflet.js?v=1.9.4" type="text/javascript"></script> <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="./util.js?v=0.2.1" type="text/javascript"></script>
<script src="./map.js?v=0.2.0" type="text/javascript"></script> <script src="./map.js?v=0.2.1" type="text/javascript"></script>
<script src="./socket.js?v=0.2.0" type="text/javascript"></script> <script src="./socket.js?v=0.2.1" type="text/javascript"></script>
<script src="./dice.js?v=0.2.0" type="text/javascript"></script> <script src="./dice.js?v=0.2.1" type="text/javascript"></script>
<script src="./admin.js?v=0.2.0" type="text/javascript"></script> <script src="./admin.js?v=0.2.1" type="text/javascript"></script>
</html> </html>

View file

@ -20,6 +20,7 @@ function initializeMap(mapImgUrl) {
if (init) { if (init) {
map.setView([0,0], 2); map.setView([0,0], 2);
} }
resizeMarkers();
} }
// this works but assumes the map is square (reasonable limitation I think) // 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 // the following few functions aren't socket related but they directly relate to the previous function
function initSpritePreviewById(id) { function initSpritePreviewById(id) {
const img = document.createElement("img");
const token = tokens.find(t=>t.t.id == id); const token = tokens.find(t=>t.t.id == id);
let img = null;
if (token && id) { if (token && id) {
img = document.createElement("img");
img.src = token.t.sprite; img.src = token.t.sprite;
secondaryPreviewIdInput.value = id; secondaryPreviewIdInput.value = id;
@ -102,8 +104,10 @@ function initSpritePreviewById(id) {
} }
dismissPreviewBtn.style.display = (token && id) ? "block" : "none"; dismissPreviewBtn.style.display = (token && id) ? "block" : "none";
secondaryPreviewZone.innerHTML = ""; secondaryPreviewZone.innerHTML = "";
if (img) {
secondaryPreviewZone.appendChild(img); secondaryPreviewZone.appendChild(img);
} }
}
function dismissPreview() { function dismissPreview() {
initSpritePreviewById(null); initSpritePreviewById(null);

View file

@ -15,6 +15,6 @@
<p><a href="/table">Get back to gaming...</a></p> <p><a href="/table">Get back to gaming...</a></p>
</main> </main>
</body> </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>
<html> <html>

View file

@ -23,5 +23,5 @@
{{end}} {{end}}
</main> </main>
</body> </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> </html>

View file

@ -19,5 +19,5 @@
{{end}} {{end}}
</main> </main>
</body> </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> </html>