This commit is contained in:
Azgaar 2020-04-04 00:18:29 +03:00
parent 79e9a12d99
commit aab1b8eac6
12 changed files with 152 additions and 109 deletions

View file

@ -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() {

View file

@ -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);
});
}
}

View file

@ -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) {

View file

@ -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() {

View file

@ -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) {

View file

@ -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);
});
}
}

View file

@ -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) {

View file

@ -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() {

View file

@ -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");