11"use strict" ;
22
3- // functions to save the project to a file
3+ // functions to save the whole .map project
44async function saveMap ( method ) {
55 if ( customization ) return tip ( "Map cannot be saved in EDIT mode, please complete the edit and retry" , false , "error" ) ;
66 closeDialogs ( "#alert" ) ;
@@ -9,7 +9,7 @@ async function saveMap(method) {
99 const mapData = prepareMapData ( ) ;
1010 const filename = getFileName ( ) + ".map" ;
1111
12- saveToStorage ( mapData , method === "storage" ) ; // any method saves to indexedDB
12+ if ( method === "storage" ) saveToStorage ( mapData , true ) ;
1313 if ( method === "machine" ) saveToMachine ( mapData , filename ) ;
1414 if ( method === "dropbox" ) saveToDropbox ( mapData , filename ) ;
1515 } catch ( error ) {
@@ -32,13 +32,12 @@ async function saveMap(method) {
3232 $ ( this ) . dialog ( "close" ) ;
3333 }
3434 } ,
35- position : { my : "center" , at : "center" , of : "svg" }
35+ position : { my : "center" , at : "center" , of : "svg" }
3636 } ) ;
3737 }
3838}
3939
4040function prepareMapData ( ) {
41-
4241 const date = new Date ( ) ;
4342 const dateString = date . getFullYear ( ) + "-" + ( date . getMonth ( ) + 1 ) + "-" + date . getDate ( ) ;
4443 const license = "File can be loaded in azgaar.github.io/Fantasy-Map-Generator" ;
@@ -90,8 +89,8 @@ function prepareMapData() {
9089
9190 const serializedSVG = new XMLSerializer ( ) . serializeToString ( cloneEl ) ;
9291
93- const { spacing, cellsX, cellsY, boundary, points, features, cellsDesired } = grid ;
94- const gridGeneral = JSON . stringify ( { spacing, cellsX, cellsY, boundary, points, features, cellsDesired } ) ;
92+ const { spacing, cellsX, cellsY, boundary, points, features, cellsDesired} = grid ;
93+ const gridGeneral = JSON . stringify ( { spacing, cellsX, cellsY, boundary, points, features, cellsDesired} ) ;
9594 const packFeatures = JSON . stringify ( pack . features ) ;
9695 const cultures = JSON . stringify ( pack . cultures ) ;
9796 const states = JSON . stringify ( pack . states ) ;
@@ -165,14 +164,14 @@ function prepareMapData() {
165164
166165// save map file to indexedDB
167166async function saveToStorage ( mapData , showTip = false ) {
168- const blob = new Blob ( [ mapData ] , { type : "text/plain" } ) ;
167+ const blob = new Blob ( [ mapData ] , { type : "text/plain" } ) ;
169168 await ldb . set ( "lastMap" , blob ) ;
170169 showTip && tip ( "Map is saved to the browser storage" , false , "success" ) ;
171170}
172171
173172// download map file
174173function saveToMachine ( mapData , filename ) {
175- const blob = new Blob ( [ mapData ] , { type : "text/plain" } ) ;
174+ const blob = new Blob ( [ mapData ] , { type : "text/plain" } ) ;
176175 const URL = window . URL . createObjectURL ( blob ) ;
177176
178177 const link = document . createElement ( "a" ) ;
0 commit comments