This commit is contained in:
Azgaar 2019-09-14 19:45:11 +03:00
parent 0d88fd740e
commit c9c30806c8
6 changed files with 106 additions and 135 deletions

View file

@ -1854,6 +1854,11 @@ svg.button {
margin: 10px 0; margin: 10px 0;
} }
.pseudoLink {
cursor: pointer;
text-decoration: underline;
}
#info-line { #info-line {
font-size: .9em; font-size: .9em;
color: gray; color: gray;
@ -1971,7 +1976,7 @@ svg.button {
.dontAsk { .dontAsk {
display: inline-block; display: inline-block;
margin: 10px 0 0 7px; margin: .9em 0 0 .6em;
} }
#errorBox { #errorBox {
@ -1985,7 +1990,7 @@ svg.button {
#debug { #debug {
font-size: 1px; font-size: 1px;
opacity: 0.8; opacity: .8;
} }
@media print { @media print {

View file

@ -35,7 +35,7 @@
Heresy:{"Heresy":1} Heresy:{"Heresy":1}
}; };
const methods = {"Random + type":3, "Random + ism":1, "Supreme + ism":5, "Faith of + Supreme":3, "Place + ism":1, "Culture + ism":2, "Place + ian + type":6, "Culture + type":4}; const methods = {"Random + type":3, "Random + ism":1, "Supreme + ism":5, "Faith of + Supreme":5, "Place + ism":1, "Culture + ism":2, "Place + ian + type":6, "Culture + type":4};
const types = { const types = {
"Shamanism":{"Beliefs":3, "Shamanism":2, "Spirits":1}, "Shamanism":{"Beliefs":3, "Shamanism":2, "Spirits":1},
@ -327,7 +327,7 @@
if (m === "Random + type") return [random() + " " + type(), "global"]; if (m === "Random + type") return [random() + " " + type(), "global"];
if (m === "Random + ism") return [trimVowels(random()) + "ism", "global"]; if (m === "Random + ism") return [trimVowels(random()) + "ism", "global"];
if (m === "Supreme + ism" && deity) return [trimVowels(supreme()) + "ism", "global"]; if (m === "Supreme + ism" && deity) return [trimVowels(supreme()) + "ism", "global"];
if (m === "Faith of + Supreme" && deity) return ["Faith of " + supreme(), "global"]; if (m === "Faith of + Supreme" && deity) return [ra(['Faith', 'Way', 'Word']) + " of " + supreme(), "global"];
if (m === "Place + ism") return [place() + "ism", "state"]; if (m === "Place + ism") return [place() + "ism", "state"];
if (m === "Culture + ism") return [trimVowels(culture()) + "ism", "culture"]; if (m === "Culture + ism") return [trimVowels(culture()) + "ism", "culture"];
if (m === "Place + ian + type") return [place("adj") + " " + type(), "state"]; if (m === "Place + ian + type") return [place("adj") + " " + type(), "state"];

View file

@ -155,7 +155,6 @@ function GFontToDataURI(url) {
// prepare map data for saving // prepare map data for saving
function getMapData() { function getMapData() {
if (customization) return false;
console.time("createMapDataBlob"); console.time("createMapDataBlob");
return new Promise(resolve => { return new Promise(resolve => {
@ -218,7 +217,7 @@ function getMapData() {
// Download .map file // Download .map file
async function saveMap() { async function saveMap() {
if (customization) {tip("Map cannot be saved when edit mode is active, please exit the mode and retry", false, "error"); return;} if (customization) {tip("Map cannot be saved when edit mode is active, please exit the mode and retry", false, "error"); return;}
closeDialogs(); closeDialogs("#alert");
const blob = await getMapData(); const blob = await getMapData();
const URL = window.URL.createObjectURL(blob); const URL = window.URL.createObjectURL(blob);
@ -327,6 +326,92 @@ function getRiverPoints(node) {
return points; return points;
} }
async function quickSave() {
if (customization) {tip("Map cannot be saved when edit mode is active, please exit the mode and retry", false, "error"); return;}
const blob = await getMapData();
if (blob) ldb.set("lastMap", blob); // auto-save map
tip("Map is saved to browser memory", true, "success", 2000);
}
function quickLoad() {
ldb.get("lastMap", blob => {
if (blob) {
loadMapPrompt(blob);
} else {
tip("No map stored. Save map to storage first", true, "error", 2000);
console.error("No map stored");
}
});
}
function loadMapPrompt(blob) {
const workingTime = (Date.now() - last(mapHistory).created) / 60000; // minutes
if (workingTime < 5) {loadLastSavedMap(); return;}
alertMessage.innerHTML = `Are you sure you want to load saved map?<br>
All unsaved changes made to the current map will be lost`;
$("#alert").dialog({resizable: false, title: "Load saved map",
buttons: {
Cancel: function() {$(this).dialog("close");},
Load: function() {loadLastSavedMap(); $(this).dialog("close");}
}
});
function loadLastSavedMap() {
console.warn("Load last saved map");
try {
uploadFile(blob);
}
catch(error) {
console.error(error);
tip("Cannot load last saved map", true, "error", 2000);
}
}
}
const saveReminder = function() {
if (localStorage.getItem("noReminder")) return;
const message = ["Please don't forget to save your work as a .map file",
"Please remember to save work as a .map file",
"Saving in .map format will ensure your data won't be lost in case of issues",
"Safety is number one priority. Please save the map",
"Don't forget to save your map on a regular basis!",
"Just a gentle reminder for you to save the map",
"Please forget to save your progress (saving as .map is the best option)",
"Don't want to be reminded about need to save? Press CTRL+Q"];
saveReminder.reminder = setInterval(() => {
if (customization) return;
tip(ra(message), true, "warn", 2500);
}, 1e6);
saveReminder.status = 1;
}
saveReminder();
function toggleSaveReminder() {
if (saveReminder.status) {
tip("Save reminder is turned off. Press CTRL+Q again to re-initiate", true, "warn", 2000);
clearInterval(saveReminder.reminder);
localStorage.setItem("noReminder", true);
saveReminder.status = 0;
} else {
tip("Save reminder is turned on. Press CTRL+Q to turn off", true, "warn", 2000);
localStorage.removeItem("noReminder");
saveReminder();
}
}
function getFileName(dataType) {
const name = mapName.value;
const type = dataType ? dataType + " " : "";
const date = new Date();
const datFormatter = new Intl.DateTimeFormat("en", {month: "short", day: "numeric"});
const timeFormatter = new Intl.DateTimeFormat("ru", {hour: "numeric", minute: "numeric"});
const day = datFormatter.format(date).replace(" ", "");
const time = timeFormatter.format(date).replace(":", "-");
return name + " " + type + day + " " + time;
}
function saveGeoJSON_Cells() { function saveGeoJSON_Cells() {
let data = "{ \"type\": \"FeatureCollection\", \"features\": [\n"; let data = "{ \"type\": \"FeatureCollection\", \"features\": [\n";
@ -408,6 +493,11 @@ function uploadFile(file, callback) {
function parseLoadedData(data) { function parseLoadedData(data) {
try { try {
// exit customization
closeDialogs();
customization = 0;
if (customizationMenu.offsetParent) styleTab.click();
const reliefIcons = document.getElementById("defs-relief").innerHTML; // save relief icons const reliefIcons = document.getElementById("defs-relief").innerHTML; // save relief icons
const hatching = document.getElementById("hatching").cloneNode(true); // save hatching const hatching = document.getElementById("hatching").cloneNode(true); // save hatching
@ -732,91 +822,4 @@ function parseLoadedData(data) {
}); });
} }
}
async function quickSave() {
const blob = await getMapData();
if (blob) ldb.set("lastMap", blob); // auto-save map
tip("Map is saved to browser memory", true, "success", 2000);
}
function quickLoad() {
ldb.get("lastMap", blob => {
if (blob) {
loadMapPrompt(blob);
} else {
tip("No map stored. Save map to storage first", true, "error", 2000);
console.error("No map stored");
}
});
}
function loadMapPrompt(blob) {
const workingTime = (Date.now() - last(mapHistory).created) / 60000; // minutes
if (workingTime < 10) {loadLastSavedMap(); return;}
alertMessage.innerHTML = `Are you sure you want to load saved map?<br>
All unsaved changes made to the current map will be lost`;
$("#alert").dialog({resizable: false, title: "Load saved map",
buttons: {
Cancel: function() {$(this).dialog("close");},
Load: function() {loadLastSavedMap(); $(this).dialog("close");}
}
});
function loadLastSavedMap() {
console.warn("Load last saved map");
closeDialogs();
try {
uploadFile(blob);
}
catch(error) {
console.error(error);
tip("Cannot load last saved map", true, "error", 2000);
}
}
}
const saveReminder = function() {
if (localStorage.getItem("noReminder")) return;
const message = ["Please don't forget to save your work as a .map file",
"Please remember to save work as a .map file",
"Saving in .map format will ensure your data won't be lost in case of issues",
"Safety is number one priority. Please save the map",
"Don't forget to save your map on a regular basis!",
"Just a gentle reminder for you to save the map",
"Please forget to save your progress (saving as .map is the best option)",
"Don't want to be reminded about need to save? Press CTRL+Q"];
saveReminder.reminder = setInterval(() => {
if (customization) return;
tip(ra(message), true, "warn", 2500);
}, 1e6);
saveReminder.status = 1;
}
saveReminder();
function toggleSaveReminder() {
if (saveReminder.status) {
tip("Save reminder is turned off. Press CTRL+Q again to re-initiate", true, "warn", 2000);
clearInterval(saveReminder.reminder);
localStorage.setItem("noReminder", true);
saveReminder.status = 0;
} else {
tip("Save reminder is turned on. Press CTRL+Q to turn off", true, "warn", 2000);
localStorage.removeItem("noReminder");
saveReminder();
}
}
function getFileName(dataType) {
const name = mapName.value;
const type = dataType ? dataType + " " : "";
const date = new Date();
const datFormatter = new Intl.DateTimeFormat("en", {month: "short", day: "numeric"});
const timeFormatter = new Intl.DateTimeFormat("ru", {hour: "numeric", minute: "numeric"});
const day = datFormatter.format(date).replace(" ", "");
const time = timeFormatter.format(date).replace(":", "-");
return name + " " + type + day + " " + time;
} }

View file

@ -13,11 +13,10 @@ function editHeightmap() {
<p>Check out <a href="https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Heightmap-customization" target="_blank">wiki</a> for guidance.</p> <p>Check out <a href="https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Heightmap-customization" target="_blank">wiki</a> for guidance.</p>
<p>Please save the map before edditing the heightmap!</p>`; <p>Please <span class="pseudoLink" onclick=saveMap(); editHeightmap();>save the map</span> before edditing the heightmap!</p>`;
$("#alert").dialog({resizable: false, title: "Edit Heightmap", width: "28em", $("#alert").dialog({resizable: false, title: "Edit Heightmap", width: "28em",
buttons: { buttons: {
Save: function() {saveMap();},
Erase: function() {enterHeightmapEditMode("erase");}, Erase: function() {enterHeightmapEditMode("erase");},
Keep: function() {enterHeightmapEditMode("keep");}, Keep: function() {enterHeightmapEditMode("keep");},
Risk: function() {enterHeightmapEditMode("risk");}, Risk: function() {enterHeightmapEditMode("risk");},

View file

@ -1012,7 +1012,7 @@ document.getElementById("sticked").addEventListener("click", function(event) {
function regeneratePrompt() { function regeneratePrompt() {
const workingTime = (Date.now() - last(mapHistory).created) / 60000; // minutes const workingTime = (Date.now() - last(mapHistory).created) / 60000; // minutes
if (workingTime < 10) {regenerateMap(); return;} if (workingTime < 5) {regenerateMap(); return;}
alertMessage.innerHTML = `Are you sure you want to generate a new map?<br> alertMessage.innerHTML = `Are you sure you want to generate a new map?<br>
All unsaved changes made to the current map will be lost`; All unsaved changes made to the current map will be lost`;
@ -1043,22 +1043,6 @@ function toggleSavePane() {
} }
} }
// async function saveDropbox() {
// const filename = "fantasy_map_" + Date.now() + ".map";
// const options = {
// files: [{'url': '...', 'filename': 'fantasy_map.map'}],
// success: function () {alert("Success! Files saved to your Dropbox.")},
// progress: function (progress) {console.log(progress)},
// cancel: function (cancel) {console.log(cancel)},
// error: function (error) {console.log(error)}
// };
// // working file: "https://dl.dropbox.com/s/llg93mwyonyzdmu/test.map?dl=1";
// const dataBlob = await getMapData();
// const URL = window.URL.createObjectURL(dataBlob);
// Dropbox.save(URL, filename, options);
// }
function toggleLoadPane() { function toggleLoadPane() {
if (loadDropdown.style.display === "block") {loadDropdown.style.display = "none"; return;} if (loadDropdown.style.display === "block") {loadDropdown.style.display = "none"; return;}
loadDropdown.style.display = "block"; loadDropdown.style.display = "block";
@ -1075,7 +1059,6 @@ function loadURL() {
Load: function() { Load: function() {
const value = mapURL.value; const value = mapURL.value;
if (!pattern.test(value)) {tip("Please provide a valid URL", false, "error"); return;} if (!pattern.test(value)) {tip("Please provide a valid URL", false, "error"); return;}
closeDialogs();
loadMapFromURL(value); loadMapFromURL(value);
$(this).dialog("close"); $(this).dialog("close");
}, },
@ -1084,26 +1067,6 @@ function loadURL() {
}); });
} }
// function loadDropbox() {
// const options = {
// success: function(file) {send_files(file)},
// cancel: function() {},
// linkType: "preview",
// multiselect: false,
// extensions:['.map'],
// };
// Dropbox.choose(options);
// function send_files(file) {
// const subject = "Shared File Links";
// let body = "";
// for (let i=0; i < file.length; i++) {
// body += file[i].name + "\n" + file[i].link + "\n\n";
// }
// location.href = 'mailto:coworker@example.com?Subject=' + escape(subject) + '&body='+ escape(body),'200','200';
// }
// }
// load map // load map
document.getElementById("mapToLoad").addEventListener("change", function() { document.getElementById("mapToLoad").addEventListener("change", function() {
const fileToLoad = this.files[0]; const fileToLoad = this.files[0];

View file

@ -30,14 +30,15 @@ toolsContent.addEventListener("click", function(event) {
Proceed: function() {processFeatureRegeneration(button); $(this).dialog("close");}, Proceed: function() {processFeatureRegeneration(button); $(this).dialog("close");},
Cancel: function() {$(this).dialog("close");} Cancel: function() {$(this).dialog("close");}
}, },
create: function() { open: function() {
const pane = $(this).dialog("widget").find(".ui-dialog-buttonpane"); const pane = $(this).dialog("widget").find(".ui-dialog-buttonpane");
$('<input id="dontAsk" class="checkbox" type="checkbox"><label for="dontAsk" class="checkbox-label dontAsk"><i>do not ask again</i></label>').prependTo(pane); $('<span><input id="dontAsk" class="checkbox" type="checkbox"><label for="dontAsk" class="checkbox-label dontAsk"><i>do not ask again</i></label><span>').prependTo(pane);
}, },
close: function() { close: function() {
const box = $(this).dialog("widget").find(".checkbox")[0]; const box = $(this).dialog("widget").find(".checkbox")[0];
if (!box) return; if (!box) return;
if (box.checked) sessionStorage.setItem("regenerateFeatureDontAsk", true); if (box.checked) sessionStorage.setItem("regenerateFeatureDontAsk", true);
$(this).dialog("destroy");
} }
}); });
} }