From c9c30806c8183ce5d52c4fd38b23f436c58a92c7 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Sat, 14 Sep 2019 19:45:11 +0300 Subject: [PATCH] v1.0.36 --- index.css | 9 +- modules/religions-generator.js | 4 +- modules/save-and-load.js | 181 +++++++++++++++++---------------- modules/ui/heightmap-editor.js | 3 +- modules/ui/options.js | 39 +------ modules/ui/tools.js | 5 +- 6 files changed, 106 insertions(+), 135 deletions(-) diff --git a/index.css b/index.css index 27f9c86c..457cc5f2 100644 --- a/index.css +++ b/index.css @@ -1854,6 +1854,11 @@ svg.button { margin: 10px 0; } +.pseudoLink { + cursor: pointer; + text-decoration: underline; +} + #info-line { font-size: .9em; color: gray; @@ -1971,7 +1976,7 @@ svg.button { .dontAsk { display: inline-block; - margin: 10px 0 0 7px; + margin: .9em 0 0 .6em; } #errorBox { @@ -1985,7 +1990,7 @@ svg.button { #debug { font-size: 1px; - opacity: 0.8; + opacity: .8; } @media print { diff --git a/modules/religions-generator.js b/modules/religions-generator.js index 3bcc595e..b0b52432 100644 --- a/modules/religions-generator.js +++ b/modules/religions-generator.js @@ -35,7 +35,7 @@ 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 = { "Shamanism":{"Beliefs":3, "Shamanism":2, "Spirits":1}, @@ -327,7 +327,7 @@ if (m === "Random + type") return [random() + " " + type(), "global"]; if (m === "Random + ism") return [trimVowels(random()) + "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 === "Culture + ism") return [trimVowels(culture()) + "ism", "culture"]; if (m === "Place + ian + type") return [place("adj") + " " + type(), "state"]; diff --git a/modules/save-and-load.js b/modules/save-and-load.js index f06fe5cd..29d65c67 100644 --- a/modules/save-and-load.js +++ b/modules/save-and-load.js @@ -155,7 +155,6 @@ function GFontToDataURI(url) { // prepare map data for saving function getMapData() { - if (customization) return false; console.time("createMapDataBlob"); return new Promise(resolve => { @@ -218,7 +217,7 @@ function getMapData() { // Download .map file async function saveMap() { 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 URL = window.URL.createObjectURL(blob); @@ -327,6 +326,92 @@ function getRiverPoints(node) { 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?
+ 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() { let data = "{ \"type\": \"FeatureCollection\", \"features\": [\n"; @@ -408,6 +493,11 @@ function uploadFile(file, callback) { function parseLoadedData(data) { try { + // exit customization + closeDialogs(); + customization = 0; + if (customizationMenu.offsetParent) styleTab.click(); + const reliefIcons = document.getElementById("defs-relief").innerHTML; // save relief icons 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?
- 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; } \ No newline at end of file diff --git a/modules/ui/heightmap-editor.js b/modules/ui/heightmap-editor.js index bb1b6cd0..67116613 100644 --- a/modules/ui/heightmap-editor.js +++ b/modules/ui/heightmap-editor.js @@ -13,11 +13,10 @@ function editHeightmap() {

Check out wiki for guidance.

-

Please save the map before edditing the heightmap!

`; +

Please save the map before edditing the heightmap!

`; $("#alert").dialog({resizable: false, title: "Edit Heightmap", width: "28em", buttons: { - Save: function() {saveMap();}, Erase: function() {enterHeightmapEditMode("erase");}, Keep: function() {enterHeightmapEditMode("keep");}, Risk: function() {enterHeightmapEditMode("risk");}, diff --git a/modules/ui/options.js b/modules/ui/options.js index afa297d1..569a58a5 100644 --- a/modules/ui/options.js +++ b/modules/ui/options.js @@ -1012,7 +1012,7 @@ document.getElementById("sticked").addEventListener("click", function(event) { function regeneratePrompt() { 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?
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() { if (loadDropdown.style.display === "block") {loadDropdown.style.display = "none"; return;} loadDropdown.style.display = "block"; @@ -1075,7 +1059,6 @@ function loadURL() { Load: function() { const value = mapURL.value; if (!pattern.test(value)) {tip("Please provide a valid URL", false, "error"); return;} - closeDialogs(); loadMapFromURL(value); $(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 document.getElementById("mapToLoad").addEventListener("change", function() { const fileToLoad = this.files[0]; diff --git a/modules/ui/tools.js b/modules/ui/tools.js index ec7feeb2..23a0ab10 100644 --- a/modules/ui/tools.js +++ b/modules/ui/tools.js @@ -30,14 +30,15 @@ toolsContent.addEventListener("click", function(event) { Proceed: function() {processFeatureRegeneration(button); $(this).dialog("close");}, Cancel: function() {$(this).dialog("close");} }, - create: function() { + open: function() { const pane = $(this).dialog("widget").find(".ui-dialog-buttonpane"); - $('').prependTo(pane); + $('').prependTo(pane); }, close: function() { const box = $(this).dialog("widget").find(".checkbox")[0]; if (!box) return; if (box.checked) sessionStorage.setItem("regenerateFeatureDontAsk", true); + $(this).dialog("destroy"); } }); }