Mercurial > hg > batmud > maputils
changeset 2187:8d22266fde6f
Rename various javascript functions used in the maps.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 13 Oct 2019 00:11:10 +0300 |
parents | ac059b4d395a |
children | 75f59a7daa5e |
files | colormap.c util.js |
diffstat | 2 files changed, 34 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/colormap.c Sat Oct 12 23:00:55 2019 +0300 +++ b/colormap.c Sun Oct 13 00:11:10 2019 +0300 @@ -294,7 +294,7 @@ fprintf(outFile, "</head>\n" - "<body onLoad=\"jsGotoOnLoadPos();\">\n"); + "<body onLoad=\"mapOnLoad();\">\n"); if (!optPosGlue) { @@ -314,11 +314,11 @@ fprintf(outFile, "</div>\n" " <form>\n" - " <select id=\"slocation\" onChange=\"jsGotoPos();\" autofocus=\"autofocus\">\n" + " <select id=\"slocation\" onChange=\"mapGotoPos();\" autofocus=\"autofocus\">\n" "@LOCATIONS@\n" " </select>\n" " <br />\n" - " <input id=\"shide\" onClick=\"jsToggleLabels();\" type=\"checkbox\"%s><label for=\"shide\">Labels</label>\n" + " <input id=\"shide\" onClick=\"mapToggleLabels();\" type=\"checkbox\"%s><label for=\"shide\">Labels</label>\n" " <input id=\"sscroll\" type=\"checkbox\"%s><label for=\"sscroll\">Smooth scroll</label>\n" " </form>\n" "</div>\n",
--- a/util.js Sat Oct 12 23:00:55 2019 +0300 +++ b/util.js Sun Oct 13 00:11:10 2019 +0300 @@ -1,7 +1,7 @@ // // Positioning utility functions in JavaScript for BatMUD maps // Programmed by Matti 'ccr' Hamalainen <ccr@tnsp.org> -// (C) Copyright 2007-2017 Tecnic Software productions (TNSP) +// (C) Copyright 2007-2019 Tecnic Software productions (TNSP) // var currLoc = ""; @@ -10,7 +10,7 @@ var scrollIndex = 0.0; -function jsFindElemCoords(elem) +function mapFindElemCoords(elem) { var xc = yc = 0; if (elem.offsetParent) @@ -28,7 +28,7 @@ } -function jsGetWindowSize() +function mapGetWindowSize() { var winW = 0, winH = 0; if (typeof(window.innerWidth) == 'number') @@ -56,32 +56,32 @@ } -function jsClamp10(a) +function mapClamp10(a) { return (a < 0.0 ? 0.0 : (a > 1.0 ? 1.0 : a)); } -function jsSCurve(t) +function mapSCurve(t) { return (t * t * (3.0 - 2.0 * t)); } -function jsLerp(t, a, b) +function mapLerp(t, a, b) { return (a + t * (b - a)); } -function jsScrollToPos() +function mapScrollToPos() { if (scrollIndex <= 1.0) { - var dim = jsGetWindowSize(); - var n = jsSCurve(jsClamp10(scrollIndex)); - var px = jsLerp(n, scrollPos0[0], scrollPos1[0]); - var py = jsLerp(n, scrollPos0[1], scrollPos1[1]); + var dim = mapGetWindowSize(); + var n = mapSCurve(mapClamp10(scrollIndex)); + var px = mapLerp(n, scrollPos0[0], scrollPos1[0]); + var py = mapLerp(n, scrollPos0[1], scrollPos1[1]); window.scrollTo(px - (dim[0] / 2), py - (dim[1] / 2)); scrollIndex += 0.01; @@ -91,7 +91,7 @@ } -function jsSetActiveLocation(newLoc) +function mapSetActiveLocation(newLoc) { // Change CSS class state for prev/curr/new selected element if (currLoc) @@ -128,15 +128,15 @@ } -function jsSetPosToElem(nelem) +function mapSetPosToElem(nelem) { - var pos = jsFindElemCoords(nelem); - var dim = jsGetWindowSize(); + var pos = mapFindElemCoords(nelem); + var dim = mapGetWindowSize(); window.scrollTo(pos[0] - (dim[0] / 2), pos[1] - (dim[1] / 2)); } -function jsGotoPos() +function mapGotoPos() { var newLoc = document.getElementById("slocation").value; if (currLoc != newLoc) @@ -151,23 +151,30 @@ if (scrollTimerID != -1) clearInterval(scrollTimerID); - scrollPos0 = jsFindElemCoords(celem); - scrollPos1 = jsFindElemCoords(nelem); + scrollPos0 = mapFindElemCoords(celem); + scrollPos1 = mapFindElemCoords(nelem); scrollIndex = 0.0; - scrollTimerID = setInterval(jsScrollToPos, 10); + scrollTimerID = setInterval(mapScrollToPos, 10); } else - jsSetPosToElem(nelem); + mapSetPosToElem(nelem); - jsSetActiveLocation(newLoc); + mapSetActiveLocation(newLoc); currLoc = newLoc; } } } -function jsGotoOnLoadPos() +function mapToggleLabels() +{ + var vcl = document.all ? document.styleSheets[0].rules[0] : document.styleSheets[0].cssRules[0]; + vcl.style.visibility = document.getElementById("shide").checked ? "visible" : "hidden"; +} + + +function mapOnLoad() { var slink = window.location.href; var spos; @@ -177,16 +184,9 @@ var nelem = document.getElementById(eid); if (nelem) { - jsSetPosToElem(nelem); - jsSetActiveLocation(eid); + mapSetPosToElem(nelem); + mapSetActiveLocation(eid); currLoc = eid; } } } - - -function jsToggleLabels() -{ - var vcl = document.all ? document.styleSheets[0].rules[0] : document.styleSheets[0].cssRules[0]; - vcl.style.visibility = document.getElementById("shide").checked ? "visible" : "hidden"; -}