mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
v1.3.3
This commit is contained in:
parent
79e9a12d99
commit
aab1b8eac6
12 changed files with 152 additions and 109 deletions
|
|
@ -281,46 +281,49 @@ function editBurg(id) {
|
|||
function openInMFCG(event) {
|
||||
const id = elSelected.attr("data-id");
|
||||
const burg = pack.burgs[id];
|
||||
const defSeed = seed + id.padStart(4, 0);
|
||||
const defSeed = +(seed + id.padStart(4, 0));
|
||||
if (isCtrlClick(event)) {
|
||||
const newSeed = prompt(`Please provide a Medieval Fantasy City Generator seed. `+
|
||||
`Seed should be a number. Default seed is FMG map seed + burg id padded to 4 chars with zeros (${defSeed}). `+
|
||||
`Please note that if seed is custom, "Overworld" button from MFCG will open a different map`, burg.MFCG || defSeed);
|
||||
if (newSeed) burg.MFCG = newSeed; else return;
|
||||
prompt(`Please provide a Medieval Fantasy City Generator seed. <br>
|
||||
Seed should be a number. Default seed is FMG map seed + burg id padded to 4 chars with zeros (${defSeed}). <br>
|
||||
Please note that if seed is custom, "Overworld" button from MFCG will open a different map`, {default:burg.MFCG||defSeed, step:1, min:1, max:1e13-1}, v => {
|
||||
burg.MFCG = v;
|
||||
openMFCG();
|
||||
});
|
||||
} else openMFCG();
|
||||
|
||||
function openMFCG() {
|
||||
const name = elSelected.text();
|
||||
const size = Math.max(Math.min(rn(burg.population), 65), 6);
|
||||
|
||||
const s = burg.MFCG || defSeed;
|
||||
const cell = burg.cell;
|
||||
const hub = +pack.cells.road[cell] > 50;
|
||||
const river = pack.cells.r[cell] ? 1 : 0;
|
||||
|
||||
const coast = +burg.port;
|
||||
const citadel = +burg.citadel;
|
||||
const walls = +burg.walls;
|
||||
const plaza = +burg.plaza;
|
||||
const temple = +burg.temple;
|
||||
const shanty = +burg.shanty;
|
||||
|
||||
const site = "http://fantasycities.watabou.ru/";
|
||||
const url = `${site}?name=${name}&size=${size}&seed=${s}&hub=${hub}&random=0&continuous=0&river=${river}&coast=${coast}&citadel=${citadel}&plaza=${plaza}&temple=${temple}&walls=${walls}&shantytown=${shanty}`;
|
||||
openURL(url);
|
||||
}
|
||||
|
||||
const name = elSelected.text();
|
||||
const size = Math.max(Math.min(rn(burg.population), 65), 6);
|
||||
|
||||
const s = burg.MFCG || defSeed;
|
||||
const cell = burg.cell;
|
||||
const hub = +pack.cells.road[cell] > 50;
|
||||
const river = pack.cells.r[cell] ? 1 : 0;
|
||||
|
||||
const coast = +burg.port;
|
||||
const citadel = +burg.citadel;
|
||||
const walls = +burg.walls;
|
||||
const plaza = +burg.plaza;
|
||||
const temple = +burg.temple;
|
||||
const shanty = +burg.shanty;
|
||||
|
||||
const url = `http://fantasycities.watabou.ru/?name=${name}&size=${size}&seed=${s}&hub=${hub}&random=0&continuous=0&river=${river}&coast=${coast}&citadel=${citadel}&plaza=${plaza}&temple=${temple}&walls=${walls}&shantytown=${shanty}`;
|
||||
openURL(url);
|
||||
}
|
||||
|
||||
function openInIAHG(event) {
|
||||
const id = elSelected.attr("data-id");
|
||||
const burg = pack.burgs[id];
|
||||
const defSeed = `${seed}-b${id}`;
|
||||
const id = elSelected.attr("data-id"), burg = pack.burgs[id], defSeed = `${seed}-b${id}`;
|
||||
const openIAHG = () => openURL("https://ironarachne.com/heraldry/" + (burg.IAHG || defSeed));
|
||||
|
||||
if (isCtrlClick(event)) {
|
||||
const newSeed = prompt(`Please provide an Iron Arachne Heraldry Generator seed. `+
|
||||
`Default seed is a combination of FMG map seed and burg id (${defSeed})`, burg.IAHG || defSeed);
|
||||
if (newSeed) burg.IAHG = newSeed; else return;
|
||||
}
|
||||
|
||||
const s = burg.IAHG || defSeed;
|
||||
openURL("https://ironarachne.com/heraldry/" + s);
|
||||
prompt(`Please provide an Iron Arachne Heraldry Generator seed. <br>Default seed is a combination of FMG map seed and burg id (${defSeed})`,
|
||||
{default:burg.IAHG || defSeed}, v => {
|
||||
if (v && v != defSeed) burg.IAHG = v;
|
||||
openIAHG();
|
||||
});
|
||||
} else openIAHG();
|
||||
}
|
||||
|
||||
function toggleRelocateBurg() {
|
||||
|
|
|
|||
|
|
@ -460,10 +460,10 @@ function editCultures() {
|
|||
}
|
||||
|
||||
function changeCode(d) {
|
||||
const code = prompt(`Please provide an abbreviation for culture: ${d.data.name}`, d.data.code);
|
||||
if (!code) return;
|
||||
pack.cultures[d.data.i].code = code;
|
||||
nodes.select("g[data-id='"+d.data.i+"']").select("text").text(code);
|
||||
prompt(`Please provide an abbreviation for culture: ${d.data.name}`, {default:d.data.code}, v => {
|
||||
pack.cultures[d.data.i].code = v;
|
||||
nodes.select("g[data-id='"+d.data.i+"']").select("text").text(v);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -711,12 +711,13 @@ function editHeightmap() {
|
|||
|
||||
function setRange(event) {
|
||||
if (event.target.value !== "interval") return;
|
||||
const interval = prompt("Set a height interval. E.g. '17-20'. Avoid space, use hyphen as a separator");
|
||||
if (!interval || interval === "") return;
|
||||
const opt = document.createElement("option");
|
||||
opt.value = opt.innerHTML = interval;
|
||||
event.target.add(opt);
|
||||
event.target.value = interval;
|
||||
|
||||
prompt("Set a height interval. Avoid space, use hyphen as a separator", {default:"17-20"}, v => {
|
||||
const opt = document.createElement("option");
|
||||
opt.value = opt.innerHTML = v;
|
||||
event.target.add(opt);
|
||||
event.target.value = v;
|
||||
});
|
||||
}
|
||||
|
||||
function selectTemplate(e) {
|
||||
|
|
|
|||
|
|
@ -76,14 +76,14 @@ function changePreset(preset) {
|
|||
}
|
||||
|
||||
function savePreset() {
|
||||
const preset = prompt("Please provide a preset name"); // preset name
|
||||
if (!preset) return;
|
||||
presets[preset] = Array.from(document.getElementById("mapLayers").querySelectorAll("li:not(.buttonoff)")).map(node => node.id).sort();
|
||||
layersPreset.add(new Option(preset, preset, false, true));
|
||||
localStorage.setItem("presets", JSON.stringify(presets));
|
||||
localStorage.setItem("preset", preset);
|
||||
removePresetButton.style.display = "inline-block";
|
||||
savePresetButton.style.display = "none";
|
||||
prompt("Please provide a preset name", {default:""}, preset => {
|
||||
presets[preset] = Array.from(document.getElementById("mapLayers").querySelectorAll("li:not(.buttonoff)")).map(node => node.id).sort();
|
||||
layersPreset.add(new Option(preset, preset, false, true));
|
||||
localStorage.setItem("presets", JSON.stringify(presets));
|
||||
localStorage.setItem("preset", preset);
|
||||
removePresetButton.style.display = "inline-block";
|
||||
savePresetButton.style.display = "none";
|
||||
});
|
||||
}
|
||||
|
||||
function removePreset() {
|
||||
|
|
|
|||
|
|
@ -193,15 +193,15 @@ function editProvinces() {
|
|||
|
||||
function provinceOpenCOA(event, p) {
|
||||
const defSeed = `${seed}-p${p}`;
|
||||
const openIAHG = () => openURL("https://ironarachne.com/heraldry/" + (pack.provinces[p].IAHG || defSeed));
|
||||
|
||||
if (isCtrlClick(event)) {
|
||||
const newSeed = prompt(`Please provide an Iron Arachne Heraldry Generator seed. `+
|
||||
`Default seed is a combination of FMG map seed and province id (${defSeed})`, pack.provinces[p].IAHG || defSeed);
|
||||
if (newSeed && newSeed != defSeed) pack.provinces[p].IAHG = newSeed; else return;
|
||||
}
|
||||
|
||||
const s = pack.provinces[p].IAHG || defSeed;
|
||||
openURL("https://ironarachne.com/heraldry/" + s);
|
||||
prompt(`Please provide an Iron Arachne Heraldry Generator seed. <br>Default seed is a combination of FMG map seed and province id (${defSeed})`,
|
||||
{default:pack.provinces[p].IAHG || defSeed}, v => {
|
||||
if (v && v != defSeed) pack.provinces[p].IAHG = v;
|
||||
openIAHG();
|
||||
});
|
||||
} else openIAHG();
|
||||
}
|
||||
|
||||
function capitalZoomIn(p) {
|
||||
|
|
|
|||
|
|
@ -450,10 +450,10 @@ function editReligions() {
|
|||
}
|
||||
|
||||
function changeCode(d) {
|
||||
const code = prompt(`Please provide an abbreviation for ${d.data.name}`, d.data.code);
|
||||
if (!code) return;
|
||||
pack.religions[d.data.i].code = code;
|
||||
nodes.select("g[data-id='"+d.data.i+"']").select("text").text(code);
|
||||
prompt(`Please provide an abbreviation for ${d.data.name}`, {default:d.data.code}, v => {
|
||||
pack.religions[d.data.i].code = v;
|
||||
nodes.select("g[data-id='"+d.data.i+"']").select("text").text(v);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -307,15 +307,15 @@ function editStates() {
|
|||
|
||||
function stateOpenCOA(event, state) {
|
||||
const defSeed = `${seed}-s${state}`;
|
||||
const openIAHG = () => openURL("https://ironarachne.com/heraldry/" + (pack.states[state].IAHG || defSeed));
|
||||
|
||||
if (isCtrlClick(event)) {
|
||||
const newSeed = prompt(`Please provide an Iron Arachne Heraldry Generator seed. `+
|
||||
`Default seed is a combination of FMG map seed and province id (${defSeed})`, pack.states[state].IAHG || defSeed);
|
||||
if (newSeed && newSeed != defSeed) pack.states[state].IAHG = newSeed; else return;
|
||||
}
|
||||
|
||||
const s = pack.states[state].IAHG || defSeed;
|
||||
openURL("https://ironarachne.com/heraldry/" + s);
|
||||
prompt(`Please provide an Iron Arachne Heraldry Generator seed. <br>Default seed is a combination of FMG map seed and state id (${defSeed})`,
|
||||
{default:pack.states[state].IAHG || defSeed}, v => {
|
||||
if (v && v != defSeed) pack.states[state].IAHG = v;
|
||||
openIAHG();
|
||||
});
|
||||
} else openIAHG();
|
||||
}
|
||||
|
||||
function changePopulation(state) {
|
||||
|
|
|
|||
|
|
@ -250,43 +250,39 @@ function regenerateMilitary() {
|
|||
}
|
||||
|
||||
function regenerateMarkers(event) {
|
||||
let number = gauss(1, .5, .3, 5, 2);
|
||||
|
||||
if (isCtrlClick(event)) {
|
||||
const numberManual = prompt("Please provide markers number multiplier", 1);
|
||||
if (numberManual === null || numberManual === "" || isNaN(+numberManual)) {
|
||||
tip("The number provided is invalid, please try again and provide a valid number", false, "error", 4000);
|
||||
return;
|
||||
}
|
||||
prompt("Please provide markers number multiplier", {default:1, step:.01, min:0, max:100}, v => {
|
||||
if (v === null || v === "" || isNaN(+v)) return;
|
||||
addNumberOfMarkers(Math.min(+v, 100));
|
||||
});
|
||||
} else addNumberOfMarkers(gauss(1, .5, .3, 5, 2));
|
||||
|
||||
number = Math.min(+numberManual, 100);
|
||||
function addNumberOfMarkers(number) {
|
||||
// remove existing markers and assigned notes
|
||||
markers.selectAll("use").each(function() {
|
||||
const index = notes.findIndex(n => n.id === this.id);
|
||||
if (index != -1) notes.splice(index, 1);
|
||||
}).remove();
|
||||
|
||||
addMarkers(number);
|
||||
if (!layerIsOn("toggleMarkers")) toggleMarkers();
|
||||
}
|
||||
|
||||
// remove existing markers and assigned notes
|
||||
markers.selectAll("use").each(function() {
|
||||
const index = notes.findIndex(n => n.id === this.id);
|
||||
if (index != -1) notes.splice(index, 1);
|
||||
}).remove();
|
||||
|
||||
addMarkers(number);
|
||||
}
|
||||
|
||||
function regenerateZones(event) {
|
||||
let number = gauss(1, .5, .6, 5, 2);
|
||||
|
||||
if (isCtrlClick(event)) {
|
||||
const numberManual = prompt("Please provide zones number multiplier", 1);
|
||||
if (numberManual === null || numberManual === "" || isNaN(+numberManual)) {
|
||||
tip("The number provided is invalid, please try again and provide a valid number", false, "error", 4000);
|
||||
return;
|
||||
}
|
||||
prompt("Please provide zones number multiplier", {default:1, step:.01, min:0, max:100}, v => {
|
||||
if (v === null || v === "" || isNaN(+v)) return;
|
||||
addNumberOfZones(Math.min(+v, 100));
|
||||
});
|
||||
} else addNumberOfZones(gauss(1, .5, .6, 5, 2));
|
||||
|
||||
number = Math.min(+numberManual, 100);
|
||||
function addNumberOfZones(number) {
|
||||
zones.selectAll("g").remove(); // remove existing zones
|
||||
addZones(number);
|
||||
if (document.getElementById("zonesEditorRefresh").offsetParent) zonesEditorRefresh.click();
|
||||
if (!layerIsOn("toggleZones")) toggleZones();
|
||||
}
|
||||
|
||||
zones.selectAll("g").remove(); // remove existing zones
|
||||
addZones(number);
|
||||
if (document.getElementById("zonesEditorRefresh").offsetParent) zonesEditorRefresh.click();
|
||||
}
|
||||
|
||||
function unpressClickToAddButton() {
|
||||
|
|
|
|||
|
|
@ -41,8 +41,13 @@ function editUnits() {
|
|||
|
||||
function changeDistanceUnit() {
|
||||
if (this.value === "custom_name") {
|
||||
const custom = prompt("Provide a custom name for distance unit");
|
||||
if (custom) this.options.add(new Option(custom, custom, false, true));
|
||||
prompt("Provide a custom name for a distance unit", {default:""}, custom => {
|
||||
this.options.add(new Option(custom, custom, false, true));
|
||||
lock("distanceUnit");
|
||||
drawScaleBar();
|
||||
calculateFriendlyGridSize();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
lock("distanceUnit");
|
||||
|
|
@ -69,9 +74,11 @@ function editUnits() {
|
|||
|
||||
function changeHeightUnit() {
|
||||
if (this.value === "custom_name") {
|
||||
const custom = prompt("Provide a custom name for height unit");
|
||||
if (custom) this.options.add(new Option(custom, custom, false, true));
|
||||
else this.value = "ft";
|
||||
prompt("Provide a custom name for a height unit", {default:""}, custom => {
|
||||
this.options.add(new Option(custom, custom, false, true));
|
||||
lock("heightUnit");
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
lock("heightUnit");
|
||||
|
|
|
|||
|
|
@ -608,5 +608,26 @@ function generateDate(from = 100, to = 1000) {
|
|||
return new Date(rand(from, to),rand(12),rand(31)).toLocaleDateString("en", {year:'numeric', month:'long', day:'numeric'});
|
||||
}
|
||||
|
||||
// prompt replacer (prompt does not work in Electron)
|
||||
window.prompt = function(dialogText = "Please provide an input", options = {default:1, step:.01, min:0, max:100}, callback) {
|
||||
if (options.default === undefined) {console.error("Prompt: options object does not have default value defined"); return;}
|
||||
const modal = document.getElementById("prompt");
|
||||
const input = modal.querySelector("#promptInput");
|
||||
modal.querySelector("#dialogText").innerHTML = dialogText;
|
||||
const type = typeof(options.default) === "number" ? "number" : "text";
|
||||
input.type = type;
|
||||
if (options.step !== undefined) input.step = options.step;
|
||||
if (options.min !== undefined) input.min = options.min;
|
||||
if (options.max !== undefined) input.max = options.max;
|
||||
input.placeholder = "type a " + type;
|
||||
input.value = options.default;
|
||||
modal.showModal();
|
||||
|
||||
modal.addEventListener("close", () => {
|
||||
if (callback && modal.returnValue === "yes") callback(input.value);
|
||||
input.value = modal.returnValue = "";
|
||||
}, {once: true});
|
||||
}
|
||||
|
||||
// localStorageDB
|
||||
!function(){function e(t,o){return n?void(n.transaction("s").objectStore("s").get(t).onsuccess=function(e){var t=e.target.result&&e.target.result.v||null;o(t)}):void setTimeout(function(){e(t,o)},100)}var t=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB;if(!t)return void console.error("indexDB not supported");var n,o={k:"",v:""},r=t.open("d2",1);r.onsuccess=function(e){n=this.result},r.onerror=function(e){console.error("indexedDB request error"),console.log(e)},r.onupgradeneeded=function(e){n=null;var t=e.target.result.createObjectStore("s",{keyPath:"k"});t.transaction.oncomplete=function(e){n=e.target.db}},window.ldb={get:e,set:function(e,t){o.k=e,o.v=t,n.transaction("s","readwrite").objectStore("s").put(o)}}}();
|
||||
Loading…
Add table
Add a link
Reference in a new issue