diff --git a/index.css b/index.css index 12a67e67..f4e72beb 100644 --- a/index.css +++ b/index.css @@ -476,7 +476,6 @@ input[type="color"]::-webkit-color-swatch-wrapper { width: 100%; background-color: white; text-align: left; - height: 1.5em; } #optionsContent input[type="range"] { diff --git a/index.html b/index.html index e93fe534..896ff785 100644 --- a/index.html +++ b/index.html @@ -1581,7 +1581,7 @@ - + @@ -1594,6 +1594,20 @@ + + + + + Year and era + + + + + + + + + @@ -1685,7 +1699,7 @@ - + diff --git a/main.js b/main.js index 66258d8c..9dd78c21 100644 --- a/main.js +++ b/main.js @@ -102,7 +102,7 @@ legend.on("mousemove", () => tip("Drag to change the position. Click to hide the // main data variables let grid = {}; // initial grapg based on jittered square grid and data let pack = {}; // packed graph and data -let seed, mapHistory = [], elSelected, modules = {}, notes = []; +let seed, mapId, mapHistory = [], elSelected, modules = {}, notes = []; let customization = 0; // 0 - no; 1 = heightmap draw; 2 - states draw; 3 - add state/burg; 4 - cultures draw let biomesData = applyDefaultBiomesSystem(); @@ -121,11 +121,6 @@ let options = {}; // options object let mapCoordinates = {}; // map coordinates on globe options.winds = [225, 45, 225, 315, 135, 315]; // default wind directions -// woldbuilding options -options.year = rand(100, 2000); // current year -options.era = Names.getBaseShort(P(.7) ? 1 : rand(nameBases.length)) + " Era"; // current era name, global for all cultures -options.eraShort = options.era[0] + "E"; // short name for era - applyStoredOptions(); let graphWidth = +mapWidthInput.value, graphHeight = +mapHeightInput.value; // voronoi graph extention, cannot be changed arter generation let svgWidth = graphWidth, svgHeight = graphHeight; // svg canvas resolution, can be changed @@ -1699,18 +1694,20 @@ function showStatistics() { const template = templateInput.value; const templateRandom = locked("template") ? "" : "(random)"; const stats = ` Seed: ${seed} - Canvas size: ${graphWidth}x${graphHeight} - Template: ${template} ${templateRandom} - Points: ${grid.points.length} - Cells: ${pack.cells.i.length} - Map size: ${mapSizeOutput.value}% - States: ${pack.states.length-1} - Provinces: ${pack.provinces.length-1} - Burgs: ${pack.burgs.length-1} - Religions: ${pack.religions.length-1} - Culture set: ${culturesSet.selectedOptions[0].innerText} - Cultures: ${pack.cultures.length-1}`; - mapHistory.push({seed, width:graphWidth, height:graphHeight, template, created: Date.now()}); + Canvas size: ${graphWidth}x${graphHeight} + Template: ${template} ${templateRandom} + Points: ${grid.points.length} + Cells: ${pack.cells.i.length} + Map size: ${mapSizeOutput.value}% + States: ${pack.states.length-1} + Provinces: ${pack.provinces.length-1} + Burgs: ${pack.burgs.length-1} + Religions: ${pack.religions.length-1} + Culture set: ${culturesSet.selectedOptions[0].innerText} + Cultures: ${pack.cultures.length-1}`; + + mapId = Date.now(); // unique map id is it's creation date number + mapHistory.push({seed, width:graphWidth, height:graphHeight, template, created:mapId}); console.log(stats); } diff --git a/modules/save-and-load.js b/modules/save-and-load.js index 7aded690..8311d5f0 100644 --- a/modules/save-and-load.js +++ b/modules/save-and-load.js @@ -225,7 +225,7 @@ function getMapData() { const date = new Date(); const dateString = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate(); const license = "File can be loaded in azgaar.github.io/Fantasy-Map-Generator"; - const params = [version, license, dateString, seed, graphWidth, graphHeight].join("|"); + const params = [version, license, dateString, seed, graphWidth, graphHeight, mapId].join("|"); const settings = [distanceUnitInput.value, distanceScaleInput.value, areaUnit.value, heightUnit.value, heightExponentInput.value, temperatureScale.value, barSize.value, barLabel.value, barBackOpacity.value, barBackColor.value, @@ -586,6 +586,7 @@ function parseLoadedData(data) { if (params[3]) {seed = params[3]; optionsSeed.value = seed;} if (params[4]) graphWidth = +params[4]; if (params[5]) graphHeight = +params[5]; + mapId = params[6] ? +params[6] : Date.now(); }() console.group("Loaded Map " + seed); diff --git a/modules/ui/battle-screen.js b/modules/ui/battle-screen.js index f3e062f0..de9882f2 100644 --- a/modules/ui/battle-screen.js +++ b/modules/ui/battle-screen.js @@ -339,10 +339,7 @@ class Battle { cancelResults() { // move regiments back to initial positions - this.attackers.regiments.concat(this.defenders.regiments).forEach(r => { - Military.moveRegiment(r, r.px, r.py); - }); - + this.attackers.regiments.concat(this.defenders.regiments).forEach(r => Military.moveRegiment(r, r.px, r.py)); $("#battleScreen").dialog("close"); this.cleanData(); } diff --git a/modules/ui/options.js b/modules/ui/options.js index 477f5ffb..5fbef6a8 100644 --- a/modules/ui/options.js +++ b/modules/ui/options.js @@ -117,6 +117,7 @@ optionsContent.addEventListener("click", function(event) { else if (id === "optionsSeedGenerate") generateMapWithSeed(); else if (id === "optionsMapHistory") showSeedHistoryDialog(); else if (id === "optionsCopySeed") copyMapURL(); + else if (id === "optionsEraRegenerate") regenerateEra(); else if (id === "zoomExtentDefault") restoreDefaultZoomExtent(); else if (id === "translateExtent") toggleTranslateExtent(event.target); }); @@ -354,6 +355,9 @@ function randomizeOptions() { if (!stored("distanceUnit")) distanceUnitInput.value = US || UK ? "mi" : "km"; if (!stored("heightUnit")) heightUnit.value = US || UK ? "ft" : "m"; if (!stored("temperatureScale")) temperatureScale.value = US ? "°F" : "°C"; + + // World settings + generateEra(); } // select heightmap template pseudo-randomly @@ -389,6 +393,21 @@ function randomizeCultureSet() { changeCultureSet(); } +// generate current year and era name +function generateEra() { + if (!stored("year")) yearInput.value = rand(100, 2000); // current year + if (!stored("era")) eraInput.value = Names.getBaseShort(P(.7) ? 1 : rand(nameBases.length)) + " Era"; + options.year = yearInput.value; + options.era = eraInput.value; + options.eraShort = options.era.split(" ").map(w => w[0].toUpperCase()).join(""); // short name for era +} + +function regenerateEra() { + unlock("era"); + options.era = eraInput.value = Names.getBaseShort(P(.7) ? 1 : rand(nameBases.length)) + " Era"; + options.eraShort = options.era.split(" ").map(w => w[0].toUpperCase()).join(""); +} + // remove all saved data from LocalStorage and reload the page function restoreDefaultOptions() { localStorage.clear();