This commit is contained in:
Azgaar 2019-12-08 14:53:23 +03:00
parent d3486c5eee
commit 07bc3dee33
4 changed files with 58 additions and 36 deletions

View file

@ -1544,6 +1544,7 @@
</td> </td>
<td> <td>
<i data-tip="Show seed history to apply a previous seed" id="optionsMapHistory" class="icon-history"></i> <i data-tip="Show seed history to apply a previous seed" id="optionsMapHistory" class="icon-history"></i>
<i data-tip="Copy map seed as URL. It will produce the same map only if map was generated with default options" id="optionsCopySeed" class="icon-docs"></i>
</td> </td>
</tr> </tr>

View file

@ -11,24 +11,7 @@
cells = grid.cells, p = grid.points; cells = grid.cells, p = grid.points;
cells.h = new Uint8Array(grid.points.length); cells.h = new Uint8Array(grid.points.length);
const input = document.getElementById("templateInput"); switch (document.getElementById("templateInput").value) {
if (!locked("template")) {
const templates = {
"Volcano": 3,
"High Island": 22,
"Low Island": 9,
"Continents": 20,
"Archipelago": 25,
"Mediterranean":3,
"Peninsula": 3,
"Pangea": 5,
"Isthmus": 2,
"Atoll": 1,
"Shattered": 7};
input.value = rw(templates);
}
switch (input.value) {
case "Volcano": templateVolcano(); break; case "Volcano": templateVolcano(); break;
case "High Island": templateHighIsland(); break; case "High Island": templateHighIsland(); break;
case "Low Island": templateLowIsland(); break; case "Low Island": templateLowIsland(); break;

View file

@ -19,12 +19,12 @@ document.getElementById("dialogs").addEventListener("mousemove", showDataTip);
document.getElementById("optionsContainer").addEventListener("mousemove", showDataTip); document.getElementById("optionsContainer").addEventListener("mousemove", showDataTip);
document.getElementById("exitCustomization").addEventListener("mousemove", showDataTip); document.getElementById("exitCustomization").addEventListener("mousemove", showDataTip);
function tip(tip = "Tip is undefined", main, error, time) { function tip(tip = "Tip is undefined", main, type, time) {
tooltip.innerHTML = tip; tooltip.innerHTML = tip;
tooltip.style.background = "linear-gradient(0.1turn, #ffffff00, #5e5c5c80, #ffffff00)"; tooltip.style.background = "linear-gradient(0.1turn, #ffffff00, #5e5c5c80, #ffffff00)";
if (error === "error") tooltip.style.background = "linear-gradient(0.1turn, #ffffff00, #e11d1dcc, #ffffff00)"; else if (type === "error") tooltip.style.background = "linear-gradient(0.1turn, #ffffff00, #e11d1dcc, #ffffff00)"; else
if (error === "warn") tooltip.style.background = "linear-gradient(0.1turn, #ffffff00, #be5d08cc, #ffffff00)"; else if (type === "warn") tooltip.style.background = "linear-gradient(0.1turn, #ffffff00, #be5d08cc, #ffffff00)"; else
if (error === "success") tooltip.style.background = "linear-gradient(0.1turn, #ffffff00, #127912cc, #ffffff00)"; if (type === "success") tooltip.style.background = "linear-gradient(0.1turn, #ffffff00, #127912cc, #ffffff00)";
if (main) tooltip.dataset.main = tip; // set main tip if (main) tooltip.dataset.main = tip; // set main tip
if (time) setTimeout(tooltip.dataset.main = "", time); // clear main in some time if (time) setTimeout(tooltip.dataset.main = "", time); // clear main in some time

View file

@ -123,6 +123,7 @@ optionsContent.addEventListener("click", function(event) {
if (id === "toggleFullscreen") toggleFullscreen(); if (id === "toggleFullscreen") toggleFullscreen();
else if (id === "optionsSeedGenerate") generateMapWithSeed(); else if (id === "optionsSeedGenerate") generateMapWithSeed();
else if (id === "optionsMapHistory") showSeedHistoryDialog(); else if (id === "optionsMapHistory") showSeedHistoryDialog();
else if (id === "optionsCopySeed") copyMapURL();
else if (id === "zoomExtentDefault") restoreDefaultZoomExtent(); else if (id === "zoomExtentDefault") restoreDefaultZoomExtent();
}); });
@ -217,6 +218,16 @@ function restoreDefaultZoomExtent() {
zoom.scaleExtent([1, 20]).scaleTo(svg, 1); zoom.scaleExtent([1, 20]).scaleTo(svg, 1);
} }
function copyMapURL() {
const search = `?seed=${optionsSeed.value}&width=${graphWidth}&height=${graphHeight}`;
navigator.clipboard.writeText("https://azgaar.github.io/Fantasy-Map-Generator/"+search)
.then(() => {
tip("Map URL is copied to clipboard", false, "success", 3000);
window.history.pushState({}, null, search);
})
.catch(err => tip("Could not copy URL: "+err, false, "error", 5000));
}
function changeCellsDensity(value) { function changeCellsDensity(value) {
densityOutput.value = value * 10 + "K"; densityOutput.value = value * 10 + "K";
if (value > 5) densityOutput.style.color = "#b12117"; if (value > 5) densityOutput.style.color = "#b12117";
@ -275,7 +286,7 @@ function changeZoomExtent(value) {
zoom.scaleTo(svg, scale); zoom.scaleTo(svg, scale);
} }
// control sroted options // control stored options logic
function applyStoredOptions() { function applyStoredOptions() {
if (!localStorage.getItem("mapWidth") || !localStorage.getItem("mapHeight")) { if (!localStorage.getItem("mapWidth") || !localStorage.getItem("mapHeight")) {
mapWidthInput.value = window.innerWidth; mapWidthInput.value = window.innerWidth;
@ -305,37 +316,64 @@ function applyStoredOptions() {
if (localStorage.getItem("uiSize")) changeUIsize(localStorage.getItem("uiSize")); if (localStorage.getItem("uiSize")) changeUIsize(localStorage.getItem("uiSize"));
else changeUIsize(Math.max(Math.min(rn(mapWidthInput.value / 1280, 1), 2.5), 1)); else changeUIsize(Math.max(Math.min(rn(mapWidthInput.value / 1280, 1), 2.5), 1));
// search params overwrite stored and default options
const params = new URL(window.location.href).searchParams;
const width = +params.get("width");
const height = +params.get("height");
if (width) mapWidthInput.value = width;
if (height) mapHeightInput.value = height;
} }
// randomize options if randomization is allowed (not locked) // randomize options if randomization is allowed (not locked or default=1)
function randomizeOptions() { function randomizeOptions() {
Math.seedrandom(seed); // reset seed to initial one Math.seedrandom(seed); // reset seed to initial one
const randomize = new URL(window.location.href).searchParams.get("seed"); // ignore stored options if seed is provided
// 'Options' settings // 'Options' settings
if (!locked("regions")) regionsInput.value = regionsOutput.value = gauss(15, 3, 2, 30); if (randomize || !locked("template")) randomizeHeightmapTemplate();
if (!locked("provinces")) provincesInput.value = provincesOutput.value = gauss(40, 20, 20, 100); if (randomize || !locked("regions")) regionsInput.value = regionsOutput.value = gauss(15, 3, 2, 30);
if (!locked("manors")) {manorsInput.value = 1000; manorsOutput.value = "auto";} if (randomize || !locked("provinces")) provincesInput.value = provincesOutput.value = gauss(40, 20, 20, 100);
if (!locked("religions")) religionsInput.value = religionsOutput.value = gauss(5, 2, 2, 10); if (randomize || !locked("manors")) {manorsInput.value = 1000; manorsOutput.value = "auto";}
if (!locked("power")) powerInput.value = powerOutput.value = gauss(3, 2, 0, 10); if (randomize || !locked("religions")) religionsInput.value = religionsOutput.value = gauss(5, 2, 2, 10);
if (!locked("neutral")) neutralInput.value = neutralOutput.value = rn(1 + Math.random(), 1); if (randomize || !locked("power")) powerInput.value = powerOutput.value = gauss(3, 2, 0, 10);
if (!locked("cultures")) culturesInput.value = culturesOutput.value = gauss(12, 3, 5, 30); if (randomize || !locked("neutral")) neutralInput.value = neutralOutput.value = rn(1 + Math.random(), 1);
if (!locked("culturesSet")) randomizeCultureSet(); if (randomize || !locked("cultures")) culturesInput.value = culturesOutput.value = gauss(12, 3, 5, 30);
if (randomize || !locked("culturesSet")) randomizeCultureSet();
// 'Configure World' settings // 'Configure World' settings
if (!locked("prec")) precInput.value = precOutput.value = gauss(120, 20, 5, 500); if (randomize || !locked("prec")) precInput.value = precOutput.value = gauss(120, 20, 5, 500);
const tMax = +temperatureEquatorOutput.max, tMin = +temperatureEquatorOutput.min; // temperature extremes const tMax = +temperatureEquatorOutput.max, tMin = +temperatureEquatorOutput.min; // temperature extremes
if (!locked("temperatureEquator")) temperatureEquatorOutput.value = temperatureEquatorInput.value = rand(tMax-6, tMax); if (randomize || !locked("temperatureEquator")) temperatureEquatorOutput.value = temperatureEquatorInput.value = rand(tMax-6, tMax);
if (!locked("temperaturePole")) temperaturePoleOutput.value = temperaturePoleInput.value = rand(tMin, tMin+10); if (randomize || !locked("temperaturePole")) temperaturePoleOutput.value = temperaturePoleInput.value = rand(tMin, tMin+10);
// 'Units Editor' settings // 'Units Editor' settings
const US = navigator.language === "en-US"; const US = navigator.language === "en-US";
const UK = navigator.language === "en-GB"; const UK = navigator.language === "en-GB";
if (!locked("distanceScale")) distanceScaleOutput.value = distanceScaleInput.value = gauss(3, 1, 1, 5); if (randomize || !locked("distanceScale")) distanceScaleOutput.value = distanceScaleInput.value = gauss(3, 1, 1, 5);
if (!stored("distanceUnit")) distanceUnitInput.value = US || UK ? "mi" : "km"; if (!stored("distanceUnit")) distanceUnitInput.value = US || UK ? "mi" : "km";
if (!stored("heightUnit")) heightUnit.value = US || UK ? "ft" : "m"; if (!stored("heightUnit")) heightUnit.value = US || UK ? "ft" : "m";
if (!stored("temperatureScale")) temperatureScale.value = US ? "°F" : "°C"; if (!stored("temperatureScale")) temperatureScale.value = US ? "°F" : "°C";
} }
// select heightmap template pseudo-randomly
function randomizeHeightmapTemplate() {
const templates = {
"Volcano": 3,
"High Island": 22,
"Low Island": 9,
"Continents": 20,
"Archipelago": 25,
"Mediterranean":3,
"Peninsula": 3,
"Pangea": 5,
"Isthmus": 2,
"Atoll": 1,
"Shattered": 7
};
document.getElementById("templateInput").value = rw(templates);
}
// select culture set pseudo-randomly // select culture set pseudo-randomly
function randomizeCultureSet() { function randomizeCultureSet() {
const sets = { const sets = {