From 37598994cb1cedb50b4f14770e2ccd1d4cf38286 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Sun, 6 Feb 2022 01:04:11 +0300 Subject: [PATCH] dissalow local run --- index.html | 17 +++++++++-------- main.js | 39 ++++++++++++++++++++++++++++++-------- modules/coa-generator.js | 2 +- modules/coa-renderer.js | 4 +++- modules/fonts.js | 29 ++++++++++++++++++---------- modules/load.js | 2 +- modules/save.js | 4 +--- modules/ui/stylePresets.js | 6 +++--- run_php_server.bat | 3 --- 9 files changed, 68 insertions(+), 38 deletions(-) delete mode 100644 run_php_server.bat diff --git a/index.html b/index.html index 41b1b1a8..d515b96d 100644 --- a/index.html +++ b/index.html @@ -19,7 +19,7 @@ body {margin: 0; font-size: 10px; overflow: hidden;} #map {position: absolute;} #initial {fill: none; stroke: black; pointer-events: none;} - #init-rose {animation: 20s infinite spin; opacity: .7; transform-origin: center;} + #init-rose {opacity: .7; transform-origin: center; opacity: .7; animation: 20s infinite spin;} @keyframes spin {0% {transform: rotate(0deg);} 100% {transform: rotate(359deg);}} #loading {opacity:1; font-size: 11px; color:#fff5da; text-align:center; text-shadow:0px 1px 4px #4c3a35; width:80%; max-width:600px; position:fixed; top:50%; left:50%; transform:translate(-50%, -50%); pointer-events:none;} #loading-text {font-size: 1.8em; margin: 0.2em 0 0 1em;} @@ -4399,17 +4399,17 @@ - - - + + + + - - + @@ -4430,7 +4430,6 @@ - @@ -4443,14 +4442,16 @@ - + + + diff --git a/main.js b/main.js index 3f449c2e..f153ba83 100644 --- a/main.js +++ b/main.js @@ -5,7 +5,7 @@ const version = "1.72"; // generator version document.title += " v" + version; -// Switches to disable/enable logging features +// switches to disable/enable logging features const PRODUCTION = location.hostname && location.hostname !== "localhost" && location.hostname !== "127.0.0.1"; const DEBUG = localStorage.getItem("debug"); const INFO = DEBUG || !PRODUCTION; @@ -172,14 +172,37 @@ landmass.append("rect").attr("x", 0).attr("y", 0).attr("width", graphWidth).attr oceanPattern.append("rect").attr("fill", "url(#oceanic)").attr("x", 0).attr("y", 0).attr("width", graphWidth).attr("height", graphHeight); oceanLayers.append("rect").attr("id", "oceanBase").attr("x", 0).attr("y", 0).attr("width", graphWidth).attr("height", graphHeight); -// remove loading screen -d3.select("#loading").transition().duration(4000).style("opacity", 0).remove(); -d3.select("#initial").transition().duration(4000).attr("opacity", 0).remove(); -d3.select("#optionsContainer").transition().duration(3000).style("opacity", 1); -d3.select("#tooltip").transition().duration(4000).style("opacity", 1); +if (!location.hostname) { + const wiki = "https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Run-FMG-locally"; + alertMessage.innerHTML = `Fantasy Map Generator cannot run serverless. + Follow the instructions on how you can easily run a local web-server`; + + $("#alert").dialog({ + resizable: false, + title: "Loading error", + width: "28em", + position: {my: "center center-4em", at: "center", of: "svg"}, + buttons: { + OK: function () { + $(this).dialog("close"); + } + } + }); + + d3.select("#loading-text").transition().duration(1000).style("opacity", 0); + d3.select("#init-rose").transition().duration(4000).style("opacity", 0); +} else { + checkLoadParameters(); + + // remove loading screen + d3.select("#loading").transition().duration(4000).style("opacity", 0).remove(); + d3.select("#initial").transition().duration(4000).attr("opacity", 0).remove(); + d3.select("#optionsContainer").transition().duration(3000).style("opacity", 1); + d3.select("#tooltip").transition().duration(4000).style("opacity", 1); +} // decide which map should be loaded or generated on page load -void (function checkLoadParameters() { +function checkLoadParameters() { const url = new URL(window.location.href); const params = url.searchParams; @@ -224,7 +247,7 @@ void (function checkLoadParameters() { WARN && console.warn("Generate random map"); generateMapOnLoad(); -})(); +} async function generateMapOnLoad() { await applyStyleOnLoad(); // apply previously selected default or custom style diff --git a/modules/coa-generator.js b/modules/coa-generator.js index 2856759d..9491cc0d 100644 --- a/modules/coa-generator.js +++ b/modules/coa-generator.js @@ -976,7 +976,7 @@ window.COA = (function () { if (emblemShape.value === "state" && state && pack.states[state].coa) return pack.states[state].coa.shield; if (pack.cultures[culture].shield) return pack.cultures[culture].shield; - console.error("Shield shape is not defined on culture level", pack.cultures[culture]); + ERROR && console.error("Shield shape is not defined on culture level", pack.cultures[culture]); return "heater"; }; diff --git a/modules/coa-renderer.js b/modules/coa-renderer.js index 5cc4ab40..8bb6b777 100644 --- a/modules/coa-renderer.js +++ b/modules/coa-renderer.js @@ -1938,7 +1938,9 @@ window.COArenderer = (function () { g.setAttribute("id", charge + "_" + id); return g.outerHTML; }) - .catch(err => console.error(err)); + .catch(err => { + ERROR && console.error(err); + }); return fetched; } diff --git a/modules/fonts.js b/modules/fonts.js index 6637e0f4..652ee524 100644 --- a/modules/fonts.js +++ b/modules/fonts.js @@ -14,12 +14,14 @@ const fonts = [ { family: "Almendra SC", src: "url(https://fonts.gstatic.com/s/almendrasc/v13/Iure6Yx284eebowr7hbyTaZOrLQ.woff2)", - unicodeRange: "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" + unicodeRange: + "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" }, { family: "Amatic SC", src: "url(https://fonts.gstatic.com/s/amaticsc/v11/TUZ3zwprpvBS1izr_vOMscGKfrUC.woff2)", - unicodeRange: "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" + unicodeRange: + "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" }, { family: "Architects Daughter", @@ -34,7 +36,8 @@ const fonts = [ { family: "Caesar Dressing", src: "url(https://fonts.gstatic.com/s/caesardressing/v6/yYLx0hLa3vawqtwdswbotmK4vrRHdrz7.woff2)", - unicodeRange: "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" + unicodeRange: + "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" }, { family: "Cinzel", @@ -49,7 +52,8 @@ const fonts = [ { family: "Fredericka the Great", src: "url(https://fonts.gstatic.com/s/frederickathegreat/v6/9Bt33CxNwt7aOctW2xjbCstzwVKsIBVV--Sjxbc.woff2)", - unicodeRange: "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" + unicodeRange: + "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" }, { family: "Gloria Hallelujah", @@ -74,12 +78,14 @@ const fonts = [ { family: "MedievalSharp", src: "url(https://fonts.gstatic.com/s/medievalsharp/v9/EvOJzAlL3oU5AQl2mP5KdgptMqhwMg.woff2)", - unicodeRange: "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" + unicodeRange: + "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" }, { family: "Metamorphous", src: "url(https://fonts.gstatic.com/s/metamorphous/v7/Wnz8HA03aAXcC39ZEX5y133EOyqs.woff2)", - unicodeRange: "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" + unicodeRange: + "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" }, { family: "Montez", @@ -89,7 +95,8 @@ const fonts = [ { family: "Nova Script", src: "url(https://fonts.gstatic.com/s/novascript/v10/7Au7p_IpkSWSTWaFWkumvlQKGFw.woff2)", - unicodeRange: "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" + unicodeRange: + "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" }, { family: "Orbitron", @@ -109,12 +116,14 @@ const fonts = [ { family: "Uncial Antiqua", src: "url(https://fonts.gstatic.com/s/uncialantiqua/v5/N0bM2S5WOex4OUbESzoESK-i-MfWQZQ.woff2)", - unicodeRange: "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" + unicodeRange: + "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" }, { family: "Underdog", src: "url(https://fonts.gstatic.com/s/underdog/v6/CHygV-jCElj7diMroWSlWV8.woff2)", - unicodeRange: "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" + unicodeRange: + "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" }, { family: "Yellowtail", @@ -243,7 +252,7 @@ async function addGoogleFont(family) { }) .catch(err => { tip(`Failed to load Google font ${family}`, true, "error", 4000); - console.error(err); + ERROR && console.error(err); }); } diff --git a/modules/load.js b/modules/load.js index 67596ba9..fec7f6d9 100644 --- a/modules/load.js +++ b/modules/load.js @@ -145,7 +145,7 @@ function parseLoadedResult(result) { const mapVersion = parseFloat(mapData[0].split("|")[0] || mapData[0]); return [mapData, mapVersion]; } catch (error) { - console.error(error); + ERROR && console.error(error); return [null, null]; } } diff --git a/modules/save.js b/modules/save.js index 52e1d30e..8e0a74e8 100644 --- a/modules/save.js +++ b/modules/save.js @@ -120,7 +120,6 @@ function getMapData() { return mapData; } - // Download .map file function dowloadMap() { if (customization) return tip("Map cannot be saved when edit mode is active, please exit the mode and retry", false, "error"); @@ -137,7 +136,6 @@ function dowloadMap() { window.URL.revokeObjectURL(URL); } - async function saveToDropbox() { if (customization) return tip("Map cannot be saved when edit mode is active, please exit the mode and retry", false, "error"); closeDialogs("#alert"); @@ -147,7 +145,7 @@ async function saveToDropbox() { await Cloud.providers.dropbox.save(filename, mapData); tip("Map is saved to your Dropbox", true, "success", 8000); } catch (msg) { - console.error(msg); + ERROR && console.error(msg); tip("Cannot save .map to your Dropbox", true, "error", 8000); } } diff --git a/modules/ui/stylePresets.js b/modules/ui/stylePresets.js index f9d59a5d..c08bdf90 100644 --- a/modules/ui/stylePresets.js +++ b/modules/ui/stylePresets.js @@ -31,13 +31,13 @@ async function getStylePreset(desiredPreset) { if (isCustom) { const storedStyleJSON = localStorage.getItem(desiredPreset); if (!storedStyleJSON) { - console.error(`Custom style ${desiredPreset} in not found in localStorage. Applying default style`); + ERROR && console.error(`Custom style ${desiredPreset} in not found in localStorage. Applying default style`); presetToLoad = "default"; } else { const isValid = JSON.isValid(storedStyleJSON); if (isValid) return [desiredPreset, JSON.parse(storedStyleJSON)]; - console.error(`Custom style ${desiredPreset} stored in localStorage is not valid. Applying default style`); + ERROR && console.error(`Custom style ${desiredPreset} stored in localStorage is not valid. Applying default style`); presetToLoad = "default"; } } @@ -50,7 +50,7 @@ async function fetchSystemPreset(preset) { const style = await fetch(`/styles/${preset}.json`) .then(res => res.json()) .catch(err => { - console.error("Error on loading style preset", preset, err); + ERROR && console.error("Error on loading style preset", preset, err); return null; }); diff --git a/run_php_server.bat b/run_php_server.bat deleted file mode 100644 index fe11833e..00000000 --- a/run_php_server.bat +++ /dev/null @@ -1,3 +0,0 @@ -start chrome.exe http://localhost:8000/ -@echo off -php -S localhost:8000 \ No newline at end of file