diff --git a/dev/assets/tiles/pathConversion.fish b/dev/assets/tiles/pathConversion.fish index 6bdcd6e9..ad33bce1 100755 --- a/dev/assets/tiles/pathConversion.fish +++ b/dev/assets/tiles/pathConversion.fish @@ -17,7 +17,7 @@ test -z "$tilesDir"; and set tilesDir "$SDIR/../../../tiles"; altPushd "$tilesDir"; -echo "Processing $tilesDir..."; +echo "Processing \"$tilesDir\"..."; find \ "$tilesDir" \ diff --git a/docs/Development.md b/docs/Development.md index e2ac0650..0b4091b1 100644 --- a/docs/Development.md +++ b/docs/Development.md @@ -160,7 +160,7 @@ - Common Commands: - Create a new migration: - - `rake db:new_migration name=(read)` + - `rake db:new_migration name=(read -P 'Migration Proper Name: ')` - Change name subshell to read `read | tr ' ' '_'` on Windows to prevent carriage return characters causing problems. - Then edit content with your features' details. - To apply your newest migration: @@ -267,7 +267,7 @@ ``` - Source: `dev/db/migrate/disabled/20230406031615_submap_add_tot_k_overworld_submaps.rb` - Names: - - Note: Try to keep migration files focused on specific tables. + - Note: The RoR AR Migrations guide may recommend trying to keep migrations focused on a specific table per file. - Format: - Database table, - action, diff --git a/javascript.txt b/javascript.txt index 0e1acd19..905ee6c2 100644 --- a/javascript.txt +++ b/javascript.txt @@ -35,6 +35,7 @@ scripts/controls/ZLayers.js scripts/controls/ZMobileHeaderBar.js scripts/controls/ZLayers.Bottom.js scripts/zmap.js +scripts/zmain.lib.js scripts/zmain.js scripts/util/debug.js scripts/widgets/CategoryButtonCompletedBlock.js diff --git a/scripts/util/ZConfig.js b/scripts/util/ZConfig.js index 642dab22..6821956c 100644 --- a/scripts/util/ZConfig.js +++ b/scripts/util/ZConfig.js @@ -20,11 +20,19 @@ ZConfig = { // Main config set-up with defaults +// Direct Settings // "exact", "focus" (ZU default) ZConfig.setConfig("categorySelectionMethod" , "focus" ); +ZConfig.setConfig("changelog" , 'false' ); +ZConfig.setConfig("collapsed" , 'false' ); +ZConfig.setConfig("errorTileUrl" , '' ); +ZConfig.setConfig("markerClusters" , 'false' ); +ZConfig.setConfig("showInfoControls" , 'false' ); ZConfig.setConfig("tilesBaseURL" , "https://zeldamaps.com/tiles/"); ZConfig.setConfig("tileAxisDirectories" , 'false' ); ZConfig.setConfig("tileZoomDirectories" , 'false' ); + +// Potentially Derived Settings ZConfig.setConfig("tileNameFormat" , ( (ZConfig.getConfig("tileAxisDirectories") == 'true') ? '{z}/{x}/{y}' @@ -32,7 +40,3 @@ ZConfig.setConfig("tileNameFormat" , ( ? '{z}/{x}_{y}' : '{z}_{x}_{y}' )); -ZConfig.setConfig("markerClusters" , 'false' ); -ZConfig.setConfig("showInfoControls" , 'false' ); -ZConfig.setConfig("collapsed" , 'false' ); -ZConfig.setConfig("errorTileUrl" , '' ); diff --git a/scripts/zmain.js b/scripts/zmain.js index e84ff0f6..e35f12f8 100644 --- a/scripts/zmain.js +++ b/scripts/zmain.js @@ -1,196 +1,13 @@ -// This script sets OSName variable as follows: -// "Windows" for all versions of Windows -// "MacOS" for all versions of Macintosh OS -// "Linux" for all versions of Linux -// "UNIX" for all other UNIX flavors -// "Unknown OS" indicates failure to detect the OS - -var OSName="Unknown OS"; -if (navigator.appVersion.indexOf("Win" )!=-1) OSName="Windows" ; -if (navigator.appVersion.indexOf("Mac" )!=-1) OSName="MacOS" ; -if (navigator.appVersion.indexOf("X11" )!=-1) OSName="UNIX" ; -if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux" ; - -function getUrlParam(vParam) { - - vParam = vParam.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); - - var regexS = "[\\?&]"+vParam+"=([^&#]*)"; - var regex = new RegExp(regexS); - var vResults = regex.exec(window.location.href); - - if (vResults == null) { - return ""; - } else { - return vResults[1]; - } - -}; - -function setCookie(cname, cvalue, exdays) { - if (exdays) { - var d = new Date(); - d.setTime(d.getTime() + (exdays*24*60*60*1000)); - var expires = "expires="+ d.toUTCString(); - } else { - var d = new Date(); - d.setTime(d.getTime() + (365*24*60*60*1000)); - var expires = "expires="+ d.toUTCString(); - - } - //console.log(expires); - - // Added explicity tag SameSite -> https://www.chromestatus.com/feature/5633521622188032. - document.cookie = cname + "=" + cvalue + ";" + expires + "; SameSite=Lax"; -} - -function getCookie(cname) { - var name = cname + "="; - var decodedCookie = decodeURIComponent(document.cookie); - var ca = decodedCookie.split(';'); - for(var i = 0; i 0) getMarkers(); - }); -}; - -function getUserInfo() { - $.getJSON("ajax.php?command=get_user_info", function(vResults) { - if(vResults.user) zMap.setUser(vResults.user); - updateAdState(); - checkChangelog(vResults.user); - }); -}; - -function checkChangelog(user) { - var lastSeemVersion = getCookie(seenChangelogVersionCookieName); - if (lastSeemVersion == null || lastSeemVersion == "") { - lastSeemVersion = '0.0.0'; - } - - new ChangelogHandler({ - user: user, - seenChangelogVersion: lastSeemVersion, - version: zMap.version - }); - -}; - -function hideLoginControls() { - var controlHeader = $(".leaflet-control-container .leaflet-control-layers-list .row-header") - $(".login-button", controlHeader).parent().hide(); - var searchBoxParent = $(".search-box", controlHeader).parent(); - searchBoxParent.removeClass("col-xs-8"); - searchBoxParent.addClass("col-xs-10"); -} - -function showLoginControls() { - var controlHeader = $(".leaflet-control-container .leaflet-control-layers-list .row-header") - $(".login-button", controlHeader).parent().show(); - var searchBoxParent = $(".search-box", controlHeader).parent(); - searchBoxParent.removeClass("col-xs-10"); - searchBoxParent.addClass("col-xs-8"); -} - -function getMarkers() { - $.getJSON("ajax.php?command=get_markers&game=" + gameId, function(vResults) { - zMap.buildMap(); - getUserInfo(); - zMap.addMarkers(vResults); - zMap.refreshMap(); - zMap.goToStart(); - zMap.goTo({ - map : getUrlParamValue('map' , null ) - , subMap : getUrlParamValue('subMap' , null ) - , marker : getUrlParamValue('marker' , null ) - , zoom : getUrlParamValue('zoom' , 4 ) - , hideOthers : getUrlParamValue('hideOthers', false ) - , hidePin : getUrlParamValue('hidePin' , false ) - }); - }); -}; - zMap = new ZMap(); var gameId = getUrlParam("game"); -// Get value of parameters -function getUrlParamValue(vParamName, vDefaultValue) { - var vParamName = getUrlParam(vParamName); - - if (vParamName == undefined || vParamName == "") { - return vDefaultValue; - } - if (vParamName == "false") { - return false; - } - if (vParamName == "true") { - return true; - } - return vParamName; -}; - -function globalKeyPressHandler(e) { - var evtobj = window.event? event : e - - if (evtobj.key == 'z' && ( - ((OSName != 'MacOS') && evtobj.ctrlKey) || - ((OSName == 'MacOS') && evtobj.metaKey) - )) { - zMap.undoMarkerComplete(); - } -} - $(document).on('keydown', globalKeyPressHandler); // Initial Load // Get map that we want to load (the game ID) $.getJSON( "ajax.php?command=get_container&game=" + gameId, - function(vResults){ + function(vResults) { // Should only get only one map $.each(vResults, function(i, vContainer) { vContainer.showMapControl = getUrlParamValue('showMapControl', vContainer.showMapControl); @@ -255,53 +72,3 @@ $.getJSON( }); }); - -function parseBounds(input) { - function error() { - zlogger.error("Map parameter is invalid: \"" + input + "\". Ignoring, and continuing to load the map with the default view."); - return false; - }; - - var bounds; - - // Try loading as JSON first. - try { - bounds = JSON.parse(input); - } catch(e) { - // Ignore and try other methods. - } - - // Try the CSV/CSL method next if it's not JSON. - if(!bounds) bounds = input.split(','); - if(!bounds) return error(); // We're fresh out of methods we're currently supporting. Error out and be happy (with the default view)! - - // Check if data is not in the format we expect, namely, 4 ordinate elements, or 2 pairs or 2 each. - if(bounds.length != 4 && bounds.length != 2) return error(); - - if(bounds.length == 4) { - bounds = [ - bounds.slice(0, 2), - bounds.slice(2, 4) - ]; - } - - bounds.forEach(function(point) { - point = point.map(parseFloat); - - // Check if the data is not in the format we expect, namely, containing any invalid number ordinate elements. - if(bounds && bounds.includes(NaN)) return error(); - - return point; - }); - - - return bounds; -}; - -function updateAdState() { - var authenticated = !!user; - var mobileAds = document.getElementById("mobileAds"); - if(mobileAds) $(mobileAds).toggleClass("hidden", (!mapControl.isMobile() || authenticated)); - var desktopAds = document.getElementById("desktopAds"); - if(desktopAds) $(desktopAds).toggleClass("hidden", (mapControl.isMobile() || authenticated)); -}; diff --git a/scripts/zmain.lib.js b/scripts/zmain.lib.js new file mode 100644 index 00000000..44b05c7d --- /dev/null +++ b/scripts/zmain.lib.js @@ -0,0 +1,233 @@ +// This script sets OSName variable as follows: +// "Windows" for all versions of Windows +// "MacOS" for all versions of Macintosh OS +// "Linux" for all versions of Linux +// "UNIX" for all other UNIX flavors +// "Unknown OS" indicates failure to detect the OS + +var OSName="Unknown OS"; +if (navigator.appVersion.indexOf("Win" )!=-1) OSName="Windows" ; +if (navigator.appVersion.indexOf("Mac" )!=-1) OSName="MacOS" ; +if (navigator.appVersion.indexOf("X11" )!=-1) OSName="UNIX" ; +if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux" ; + +function getUrlParam(vParam) { + + vParam = vParam.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); + + var regexS = "[\\?&]"+vParam+"=([^&#]*)"; + var regex = new RegExp(regexS); + var vResults = regex.exec(window.location.href); + + if (vResults == null) { + return ""; + } else { + return vResults[1]; + } + +}; + +function setCookie(cname, cvalue, exdays) { + if (exdays) { + var d = new Date(); + d.setTime(d.getTime() + (exdays*24*60*60*1000)); + var expires = "expires="+ d.toUTCString(); + } else { + var d = new Date(); + d.setTime(d.getTime() + (365*24*60*60*1000)); + var expires = "expires="+ d.toUTCString(); + + } + //console.log(expires); + + // Added explicity tag SameSite -> https://www.chromestatus.com/feature/5633521622188032. + document.cookie = cname + "=" + cvalue + ";" + expires + "; SameSite=Lax"; +} + +function getCookie(cname) { + var name = cname + "="; + var decodedCookie = decodeURIComponent(document.cookie); + var ca = decodedCookie.split(';'); + for(var i = 0; i 0) getMarkers(); + }); +}; + +function getUserInfo() { + $.getJSON("ajax.php?command=get_user_info", function(vResults) { + if(vResults.user) zMap.setUser(vResults.user); + updateAdState(); + if(ZConfig.getConfig("changelog") == 'true') + checkChangelog(vResults.user); + }); +}; + +function checkChangelog(user) { + var lastSeenVersion = getCookie(seenChangelogVersionCookieName); + if (lastSeenVersion == null || lastSeenVersion == "") { + lastSeenVersion = '0.0.0'; + } + + new ChangelogHandler({ + user: user, + seenChangelogVersion: lastSeenVersion, + version: zMap.version + }); + +}; + +function hideLoginControls() { + var controlHeader = $(".leaflet-control-container .leaflet-control-layers-list .row-header") + $(".login-button", controlHeader).parent().hide(); + var searchBoxParent = $(".search-box", controlHeader).parent(); + searchBoxParent.removeClass("col-xs-8"); + searchBoxParent.addClass("col-xs-10"); +} + +function showLoginControls() { + var controlHeader = $(".leaflet-control-container .leaflet-control-layers-list .row-header") + $(".login-button", controlHeader).parent().show(); + var searchBoxParent = $(".search-box", controlHeader).parent(); + searchBoxParent.removeClass("col-xs-10"); + searchBoxParent.addClass("col-xs-8"); +} + +function getMarkers() { + $.getJSON("ajax.php?command=get_markers&game=" + gameId, function(vResults) { + zMap.buildMap(); + getUserInfo(); + zMap.addMarkers(vResults); + zMap.refreshMap(); + zMap.goToStart(); + zMap.goTo({ + map : getUrlParamValue('map' , null ) + , subMap : getUrlParamValue('subMap' , null ) + , marker : getUrlParamValue('marker' , null ) + , zoom : getUrlParamValue('zoom' , 4 ) + , hideOthers : getUrlParamValue('hideOthers', false ) + , hidePin : getUrlParamValue('hidePin' , false ) + }); + }); +}; + +// Get value of parameters +function getUrlParamValue(vParamName, vDefaultValue) { + var vParamName = getUrlParam(vParamName); + + if (vParamName == undefined || vParamName == "") { + return vDefaultValue; + } + if (vParamName == "false") { + return false; + } + if (vParamName == "true") { + return true; + } + return vParamName; +}; + +function globalKeyPressHandler(e) { + var evtobj = window.event? event : e + + if (evtobj.key == 'z' && ( + ((OSName != 'MacOS') && evtobj.ctrlKey) || + ((OSName == 'MacOS') && evtobj.metaKey) + )) { + zMap.undoMarkerComplete(); + } +} + +function parseBounds(input) { + function error() { + zlogger.error("Map parameter is invalid: \"" + input + "\". Ignoring, and continuing to load the map with the default view."); + return false; + }; + + var bounds; + + // Try loading as JSON first. + try { + bounds = JSON.parse(input); + } catch(e) { + // Ignore and try other methods. + } + + // Try the CSV/CSL method next if it's not JSON. + if(!bounds) bounds = input.split(','); + if(!bounds) return error(); // We're fresh out of methods we're currently supporting. Error out and be happy (with the default view)! + + // Check if data is not in the format we expect, namely, 4 ordinate elements, or 2 pairs or 2 each. + if(bounds.length != 4 && bounds.length != 2) return error(); + + if(bounds.length == 4) { + bounds = [ + bounds.slice(0, 2), + bounds.slice(2, 4) + ]; + } + + bounds.forEach(function(point) { + point = point.map(parseFloat); + + // Check if the data is not in the format we expect, namely, containing any invalid number ordinate elements. + if(bounds && bounds.includes(NaN)) return error(); + + return point; + }); + + + return bounds; +}; + +function updateAdState() { + var authenticated = !!user; + var mobileAds = document.getElementById("mobileAds"); + if(mobileAds) $(mobileAds).toggleClass("hidden", (!mapControl.isMobile() || authenticated)); + var desktopAds = document.getElementById("desktopAds"); + if(desktopAds) $(desktopAds).toggleClass("hidden", (mapControl.isMobile() || authenticated)); +}; diff --git a/scripts/zmap.js b/scripts/zmap.js index a6c6fae5..79fb5a86 100644 --- a/scripts/zmap.js +++ b/scripts/zmap.js @@ -24,12 +24,12 @@ function ZMap() { this.markerIconSmall; this.markerIconMedium; - this.errorTileUrl = ZConfig.getConfig("errorTileUrl"); + this.errorTileUrl = ZConfig.getConfig("errorTileUrl" ); this.tileNameFormat = ZConfig.getConfig("tileNameFormat"); this.tilesBaseURL = ZConfig.getConfig("tilesBaseURL" ); - // @TODO: This is a WORKAROUND. Icon should be on the same folder as the tiled map itself. - // For now, since we don`t want to bother Matthew, we are creating a new folder in th ecode + // @TODO: This is a WORKAROUND. Icon should be in the same folder as the tiled map itself. + // For now, since we don`t want to bother Matthew, we are creating a new folder in the code // In the future, we need to move the icon.png of every map to the tiledmap and change defaultIconURL to defaultTilesURL this.defaultIconURL = 'images/icons/';