Reverted formatting changes

This reverts commit 338ce17cb8.

Only small js fixes
This commit is contained in:
Brian Weasner 2018-08-14 16:06:25 -06:00
parent 338ce17cb8
commit 05bb3a2c50

110
script.js
View file

@ -190,8 +190,7 @@ function fantasyMap() {
<br><br><i>Join our <a href='https://www.reddit.com/r/FantasyMapGenerator/' target='_blank'>Reddit community</a> <br><br><i>Join our <a href='https://www.reddit.com/r/FantasyMapGenerator/' target='_blank'>Reddit community</a>
to share created maps, discuss the Generator, ask questions and propose new features.</i>`; to share created maps, discuss the Generator, ask questions and propose new features.</i>`;
$("#alert").dialog( $("#alert").dialog(
{ {resizable: false, title: "Fantasy Map Generator update", width: 280,
resizable: false, title: "Fantasy Map Generator update", width: 280,
buttons: { buttons: {
"Don't show again": function() { "Don't show again": function() {
localStorage.setItem("version", version); localStorage.setItem("version", version);
@ -467,10 +466,8 @@ function fantasyMap() {
const x = +debug.select(".tag").attr("cx"); const x = +debug.select(".tag").attr("cx");
const y = +debug.select(".tag").attr("cy"); const y = +debug.select(".tag").attr("cy");
if (line.size()) {line.attr("x1", x).attr("y1", y).attr("x2", point[0]).attr("y2", point[1]);} if (line.size()) {line.attr("x1", x).attr("y1", y).attr("x2", point[0]).attr("y2", point[1]);}
else { else {debug.insert("line", ":first-child").attr("class", "line")
debug.insert("line", ":first-child").attr("class", "line") .attr("x1", x).attr("y1", y).attr("x2", point[0]).attr("y2", point[1]);}
.attr("x1", x).attr("y1", y).attr("x2", point[0]).attr("y2", point[1]);
}
} else { } else {
line.remove(); line.remove();
} }
@ -994,7 +991,7 @@ function fantasyMap() {
for (let l = 0; start !== end && l < 1000; l++) { for (let l = 0; start !== end && l < 1000; l++) {
var min = 10000; // dummy value var min = 10000; // dummy value
cells[start].neighbors.forEach(function(e) { cells[start].neighbors.forEach(function(e) {
let diff = Math.hypot(cells[end].data[0] - cells[e].data[0], cells[end].data[1] - cells[e].data[1]); diff = Math.hypot(cells[end].data[0] - cells[e].data[0], cells[end].data[1] - cells[e].data[1]);
if (Math.random() > 0.8) {diff = diff / 2} if (Math.random() > 0.8) {diff = diff / 2}
if (diff < min) {min = diff; start = e;} if (diff < min) {min = diff; start = e;}
}); });
@ -2411,8 +2408,7 @@ function fantasyMap() {
$("#riverRemove").click(function() { $("#riverRemove").click(function() {
alertMessage.innerHTML = `Are you sure you want to remove the river?`; alertMessage.innerHTML = `Are you sure you want to remove the river?`;
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Remove river",
resizable: false, title: "Remove river",
buttons: { buttons: {
Remove: function() { Remove: function() {
$(this).dialog("close"); $(this).dialog("close");
@ -2678,8 +2674,7 @@ function fantasyMap() {
$("#routeRemove").click(function() { $("#routeRemove").click(function() {
alertMessage.innerHTML = `Are you sure you want to remove the route?`; alertMessage.innerHTML = `Are you sure you want to remove the route?`;
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Remove route",
resizable: false, title: "Remove route",
buttons: { buttons: {
Remove: function() { Remove: function() {
$(this).dialog("close"); $(this).dialog("close");
@ -2769,8 +2764,7 @@ function fantasyMap() {
} }
const message = "Are you sure you want to remove all '" + iconGroup.value + "' icons (" + count + ")?"; const message = "Are you sure you want to remove all '" + iconGroup.value + "' icons (" + count + ")?";
alertMessage.innerHTML = message; alertMessage.innerHTML = message;
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Remove icon group",
resizable: false, title: "Remove icon group",
buttons: { buttons: {
Remove: function() { Remove: function() {
$(this).dialog("close"); $(this).dialog("close");
@ -2816,8 +2810,7 @@ function fantasyMap() {
$("#iconRemove").click(function() { $("#iconRemove").click(function() {
alertMessage.innerHTML = `Are you sure you want to remove the icon?`; alertMessage.innerHTML = `Are you sure you want to remove the icon?`;
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Remove icon",
resizable: false, title: "Remove icon",
buttons: { buttons: {
Remove: function() { Remove: function() {
$(this).dialog("close"); $(this).dialog("close");
@ -2896,8 +2889,7 @@ function fantasyMap() {
} }
const message = "Are you sure you want to remove all '" + reliefGroup.value + "' icons (" + count + ")?"; const message = "Are you sure you want to remove all '" + reliefGroup.value + "' icons (" + count + ")?";
alertMessage.innerHTML = message; alertMessage.innerHTML = message;
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Remove all icons within group",
resizable: false, title: "Remove all icons within group",
buttons: { buttons: {
Remove: function() { Remove: function() {
$(this).dialog("close"); $(this).dialog("close");
@ -2911,8 +2903,7 @@ function fantasyMap() {
$("#reliefRemove").click(function() { $("#reliefRemove").click(function() {
alertMessage.innerHTML = `Are you sure you want to remove the icon?`; alertMessage.innerHTML = `Are you sure you want to remove the icon?`;
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Remove relief icon",
resizable: false, title: "Remove relief icon",
buttons: { buttons: {
Remove: function() { Remove: function() {
$(this).dialog("close"); $(this).dialog("close");
@ -3074,8 +3065,7 @@ function fantasyMap() {
var count = group.selectAll("*").size(); var count = group.selectAll("*").size();
const message = "Are you sure you want to remove all Burgs (" + count + ") of that group?"; const message = "Are you sure you want to remove all Burgs (" + count + ") of that group?";
alertMessage.innerHTML = message; alertMessage.innerHTML = message;
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Remove Burgs",
resizable: false, title: "Remove Burgs",
buttons: { buttons: {
Remove: function() { Remove: function() {
$(this).dialog("close"); $(this).dialog("close");
@ -3277,8 +3267,7 @@ function fantasyMap() {
$("#burgRemove").click(function() { $("#burgRemove").click(function() {
alertMessage.innerHTML = `Are you sure you want to remove the Burg?`; alertMessage.innerHTML = `Are you sure you want to remove the Burg?`;
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Remove Burg",
resizable: false, title: "Remove Burg",
buttons: { buttons: {
Remove: function() { Remove: function() {
$(this).dialog("close"); $(this).dialog("close");
@ -3446,11 +3435,9 @@ function fantasyMap() {
ruralPopulation += c.pop; ruralPopulation += c.pop;
area += cells[c.index].area; area += cells[c.index].area;
}); });
states.push({ states.push({i: states.length, color: "neutral", name: "Neutrals", capital: "neutral",
i: states.length, color: "neutral", name: "Neutrals", capital: "neutral",
cells: neutralCells.length, burgs, urbanPopulation: rn(urbanPopulation, 2), cells: neutralCells.length, burgs, urbanPopulation: rn(urbanPopulation, 2),
ruralPopulation: rn(ruralPopulation, 2), area: rn(area) ruralPopulation: rn(ruralPopulation, 2), area: rn(area)});
});
} }
} }
@ -5135,8 +5122,7 @@ function fantasyMap() {
var group = d3.select(elSelected.node().parentNode); var group = d3.select(elSelected.node().parentNode);
if (this.id == "editRemoveSingle") { if (this.id == "editRemoveSingle") {
alertMessage.innerHTML = "Are you sure you want to remove the label?"; alertMessage.innerHTML = "Are you sure you want to remove the label?";
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Remove label",
resizable: false, title: "Remove label",
buttons: { buttons: {
Remove: function() { Remove: function() {
$(this).dialog("close"); $(this).dialog("close");
@ -5157,8 +5143,7 @@ function fantasyMap() {
} }
var message = "Are you sure you want to remove all labels (" + count + ") of that group?"; var message = "Are you sure you want to remove all labels (" + count + ") of that group?";
alertMessage.innerHTML = message; alertMessage.innerHTML = message;
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Remove labels",
resizable: false, title: "Remove labels",
buttons: { buttons: {
Remove: function() { Remove: function() {
$(this).dialog("close"); $(this).dialog("close");
@ -5667,13 +5652,9 @@ function fantasyMap() {
of the Generator. Please note the Gennerator is still on demo and a lot of crusial changes are being made every month`; of the Generator. Please note the Gennerator is still on demo and a lot of crusial changes are being made every month`;
} }
alertMessage.innerHTML = message; alertMessage.innerHTML = message;
$("#alert").dialog({ $("#alert").dialog({title: "Warning", buttons: {OK: function() {
title: "Warning", buttons: {
OK: function () {
loadDataFromMap(data); loadDataFromMap(data);
} }}});
}
});
} else {loadDataFromMap(data);} } else {loadDataFromMap(data);}
if (mapVersion.length > 10) {console.error("Cannot load map"); return;} if (mapVersion.length > 10) {console.error("Cannot load map"); return;}
} }
@ -5725,8 +5706,7 @@ function fantasyMap() {
if (nWidth !== svgWidth || nHeight !== svgHeight) { if (nWidth !== svgWidth || nHeight !== svgHeight) {
alertMessage.innerHTML = `The loaded map has size ${nWidth} x ${nHeight} pixels, while the current canvas size is ${svgWidth} x ${svgHeight} pixels. alertMessage.innerHTML = `The loaded map has size ${nWidth} x ${nHeight} pixels, while the current canvas size is ${svgWidth} x ${svgHeight} pixels.
Click "Rescale" to fit the map to the current canvas size. Click "OK" to browse the map without rescaling`; Click "Rescale" to fit the map to the current canvas size. Click "OK" to browse the map without rescaling`;
$("#alert").dialog({ $("#alert").dialog({title: "Map size conflict",
title: "Map size conflict",
buttons: { buttons: {
Rescale: function() { Rescale: function() {
applyLoadedData(data); applyLoadedData(data);
@ -5960,9 +5940,9 @@ function fantasyMap() {
j0 = Math.max(j - 2, 0), j0 = Math.max(j - 2, 0),
i1 = Math.min(i + 3, gridWidth), i1 = Math.min(i + 3, gridWidth),
j1 = Math.min(j + 3, gridHeight); j1 = Math.min(j + 3, gridHeight);
for (let j = j0; j < j1; ++j) { for (j = j0; j < j1; ++j) {
var o = j * gridWidth; var o = j * gridWidth;
for (let i = i0; i < i1; ++i) { for (i = i0; i < i1; ++i) {
if (s = grid[o + i]) { if (s = grid[o + i]) {
var s, var s,
dx = s[0] - x, dx = s[0] - x,
@ -6070,8 +6050,7 @@ function fantasyMap() {
if ($("#options").css("display") === "none") { if ($("#options").css("display") === "none") {
$("#regenerate").show(); $("#regenerate").show();
$("#optionsTrigger").removeClass("glow"); $("#optionsTrigger").removeClass("glow");
} }}, function() {
}, function () {
$("#regenerate").hide(); $("#regenerate").hide();
}); });
@ -6282,8 +6261,7 @@ function fantasyMap() {
if (id === "burgNamesImport") {burgsListToLoad.click();} if (id === "burgNamesImport") {burgsListToLoad.click();}
if (id === "removeCountries") { if (id === "removeCountries") {
alertMessage.innerHTML = `Are you sure you want remove all countries?`; alertMessage.innerHTML = `Are you sure you want remove all countries?`;
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Remove countries",
resizable: false, title: "Remove countries",
buttons: { buttons: {
Cancel: function() {$(this).dialog("close");}, Cancel: function() {$(this).dialog("close");},
Remove: function() { Remove: function() {
@ -6310,8 +6288,7 @@ function fantasyMap() {
} }
if (id === "removeBurgs") { if (id === "removeBurgs") {
alertMessage.innerHTML = `Are you sure you want to remove all burgs associated with the country?`; alertMessage.innerHTML = `Are you sure you want to remove all burgs associated with the country?`;
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Remove associated burgs",
resizable: false, title: "Remove associated burgs",
buttons: { buttons: {
Cancel: function() {$(this).dialog("close");}, Cancel: function() {$(this).dialog("close");},
Remove: function() { Remove: function() {
@ -6400,8 +6377,7 @@ function fantasyMap() {
if (id === "removeAllRulers") { if (id === "removeAllRulers") {
if ($("#ruler > g").length < 1) {return;} if ($("#ruler > g").length < 1) {return;}
alertMessage.innerHTML = `Are you sure you want to remove all placed rulers?`; alertMessage.innerHTML = `Are you sure you want to remove all placed rulers?`;
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Remove all rulers",
resizable: false, title: "Remove all rulers",
buttons: { buttons: {
Remove: function() { Remove: function() {
$(this).dialog("close"); $(this).dialog("close");
@ -6415,8 +6391,7 @@ function fantasyMap() {
if (id === "editHeightmap") {$("#customizeHeightmap").slideToggle();} if (id === "editHeightmap") {$("#customizeHeightmap").slideToggle();}
if (id === "fromScratch") { if (id === "fromScratch") {
alertMessage.innerHTML = "Are you sure you want to clear the map? All progress will be lost"; alertMessage.innerHTML = "Are you sure you want to clear the map? All progress will be lost";
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Clear map",
resizable: false, title: "Clear map",
buttons: { buttons: {
Cancel: function() {$(this).dialog("close");}, Cancel: function() {$(this).dialog("close");},
Clear: function() { Clear: function() {
@ -6438,8 +6413,7 @@ function fantasyMap() {
message += "If you want to edit a map, it's better to clean up all the data except on heights. "; message += "If you want to edit a map, it's better to clean up all the data except on heights. ";
message += "You may also keep the data, but it can cause unexpected errors"; message += "You may also keep the data, but it can cause unexpected errors";
alertMessage.innerHTML = message; alertMessage.innerHTML = message;
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Edit Heightmap",
resizable: false, title: "Edit Heightmap",
buttons: { buttons: {
"Clean up": function() { "Clean up": function() {
editHeightmap("clean"); editHeightmap("clean");
@ -6551,8 +6525,7 @@ function fantasyMap() {
} }
if (id === "restoreStyle") { if (id === "restoreStyle") {
alertMessage.innerHTML = "Are you sure you want to restore default style?"; alertMessage.innerHTML = "Are you sure you want to restore default style?";
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Restore style",
resizable: false, title: "Restore style",
buttons: { buttons: {
Restore: function() { Restore: function() {
applyDefaultStyle(); applyDefaultStyle();
@ -6616,8 +6589,7 @@ function fantasyMap() {
if (customization === 1) { if (customization === 1) {
var message = "Are you sure you want to clear the map?"; var message = "Are you sure you want to clear the map?";
alertMessage.innerHTML = message; alertMessage.innerHTML = message;
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Clear map",
resizable: false, title: "Clear map",
buttons: { buttons: {
Clear: function() { Clear: function() {
$(this).dialog("close"); $(this).dialog("close");
@ -6671,8 +6643,7 @@ function fantasyMap() {
message += "Please ensure your browser does not block popups. "; message += "Please ensure your browser does not block popups. ";
message += "Please check browser settings and turn off adBlocker if it is enabled"; message += "Please check browser settings and turn off adBlocker if it is enabled";
alertMessage.innerHTML = message; alertMessage.innerHTML = message;
$("#alert").dialog({ $("#alert").dialog({title: "File saver. Please enable popups!",
title: "File saver. Please enable popups!",
buttons: { buttons: {
"Don't show again": function() { "Don't show again": function() {
localStorage.setItem("dns_allow_popup_message", true); localStorage.setItem("dns_allow_popup_message", true);
@ -6883,8 +6854,7 @@ function fantasyMap() {
var template = this.value; var template = this.value;
if (steps && changed === 1) { if (steps && changed === 1) {
alertMessage.innerHTML = "Are you sure you want to change the base template? All the changes will be lost."; alertMessage.innerHTML = "Are you sure you want to change the base template? All the changes will be lost.";
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Change Template",
resizable: false, title: "Change Template",
buttons: { buttons: {
Change: function() { Change: function() {
changeTemplate(template); changeTemplate(template);
@ -7082,8 +7052,7 @@ function fantasyMap() {
$("#imageConverter").dialog({ $("#imageConverter").dialog({
title: "Image to Heightmap Converter", title: "Image to Heightmap Converter",
minHeight: 30, width: 260, resizable: false, minHeight: 30, width: 260, resizable: false,
position: { my: "right top", at: "right-10 top+10", of: "svg" } position: {my: "right top", at: "right-10 top+10", of: "svg"}})
})
.on('dialogclose', function() {completeConvertion();}); .on('dialogclose', function() {completeConvertion();});
} }
@ -7563,15 +7532,13 @@ function fantasyMap() {
return; return;
} }
alertMessage.innerHTML = `Are you sure you want to remove the country?`; alertMessage.innerHTML = `Are you sure you want to remove the country?`;
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Remove country", buttons: {
resizable: false, title: "Remove country", buttons: {
Remove: function() { Remove: function() {
removeCountry(s); removeCountry(s);
$(this).dialog("close"); $(this).dialog("close");
}, },
Cancel: function() {$(this).dialog("close");} Cancel: function() {$(this).dialog("close");}
} }});
});
}); });
function removeCountry(s) { function removeCountry(s) {
@ -7737,8 +7704,7 @@ function fantasyMap() {
$("#burgsBody .icon-trash-empty").on("click", function() { $("#burgsBody .icon-trash-empty").on("click", function() {
alertMessage.innerHTML = `Are you sure you want to remove the burg?`; alertMessage.innerHTML = `Are you sure you want to remove the burg?`;
var b = +(this.parentNode.id).slice(5); var b = +(this.parentNode.id).slice(5);
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Remove burg",
resizable: false, title: "Remove burg",
buttons: { buttons: {
Remove: function() { Remove: function() {
$(this).dialog("close"); $(this).dialog("close");
@ -8256,8 +8222,7 @@ function fantasyMap() {
alertMessage.innerHTML = `Are you sure you want to restore the default namesbase? alertMessage.innerHTML = `Are you sure you want to restore the default namesbase?
All custom bases will be removed and default ones will be assigned to existing cultures. All custom bases will be removed and default ones will be assigned to existing cultures.
Meanwhile existing names will not be changed.`; Meanwhile existing names will not be changed.`;
$("#alert").dialog({ $("#alert").dialog({resizable: false, title: "Restore default data",
resizable: false, title: "Restore default data",
buttons: { buttons: {
Restore: function() { Restore: function() {
$(this).dialog("close"); $(this).dialog("close");
@ -8554,8 +8519,7 @@ function fantasyMap() {
} }
message += `</tr></table></div>`; message += `</tr></table></div>`;
alertMessage.innerHTML = message; alertMessage.innerHTML = message;
$("#alert").dialog({ $("#alert").dialog({title: "Burgs bulk renaming", position: {my: "center", at: "center", of: "svg"},
title: "Burgs bulk renaming", position: { my: "center", at: "center", of: "svg" },
buttons: { buttons: {
Cancel: function() {$(this).dialog("close");}, Cancel: function() {$(this).dialog("close");},
Confirm: function() { Confirm: function() {