diff --git a/README.md b/README.md index a56098ea4..f662ac3cf 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ -# Fantasy Map Generator - -Azgaar's _Fantasy Map Generator_. Based on [D3](https://d3js.org) Voronoi diagram rendered in svg. - -Project goal is a procedurally generated map for my *Medieval Dynasty* simulator. Map should be interactive, scalable, fast and plausible. There should be enough space to place at least 500 burgs within 7 countries. The imagined land area is about 1 million km2. - -[![alt tag](https://i0.wp.com/azgaar.files.wordpress.com/2017/03/80k-part.png)](https://azgaar.wordpress.com) - -Project is under development, check out the demo [here](https://azgaar.github.io/Fantasy-Map-Generator). Please refer to [the project wiki](https://github.com/Azgaar/Fantasy-Map-Generator/wiki) for guidance. Links to an older versions are listed in the [changelog](https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Changelog). - -Some details are covered in my blog [_Fantasy Maps for fun and glory_](https://azgaar.wordpress.com), you may also keep an eye on my [devboard](https://trello.com/b/7x832DG4/fantasy-map-generator). Comments and ideas are *highly* welcomed, kindly contact me via [email](mailto:maxganiev@yandex.ru). I would also like to see your completed or work in progress maps. For bug reports and change requests please use the project [issues page](https://github.com/Azgaar/Fantasy-Map-Generator/issues). - -_Inspiration:_ - -* Martin O'Leary's [_Generating fantasy maps_](https://mewo2.com/notes/terrain) - -* Amit Patel's [_Polygonal Map Generation for Games_](http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation) - -* Scott Turner's [_Here Dragons Abound_](https://heredragonsabound.blogspot.com) \ No newline at end of file +# Fantasy Map Generator + +Azgaar's _Fantasy Map Generator_. Based on [D3](https://d3js.org) Voronoi diagram rendered in svg. + +Project goal is a procedurally generated map for my *Medieval Dynasty* simulator. Map should be interactive, scalable, fast and plausible. Initial intend was to place at least 500 burgs within 7 cultural areas and imagined land area about 1 million km2. As of now all these parameters are customizable. + +[![alt tag](https://i0.wp.com/azgaar.files.wordpress.com/2017/03/80k-part.png)](https://azgaar.wordpress.com) + +Project is under development, check out the demo [here](https://azgaar.github.io/Fantasy-Map-Generator). Refer to [the project wiki](https://github.com/Azgaar/Fantasy-Map-Generator/wiki) for a quick guidance. The the previous versions see the [changelog](https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Changelog). If you find the Demo performance low, open the page in a smaller window and use the graph size = 1. + +Some details are covered in my blog [_Fantasy Maps for fun and glory_](https://azgaar.wordpress.com), you may also keep an eye on my [devboard](https://trello.com/b/7x832DG4/fantasy-map-generator). Comments and ideas are *highly* welcomed, kindly contact me via [email](mailto:maxganiev@yandex.ru). I would also like to see your completed or work in progress maps. For bug reports and change requests please use the project [issues page](https://github.com/Azgaar/Fantasy-Map-Generator/issues). + +_Inspiration:_ + +* Martin O'Leary's [_Generating fantasy maps_](https://mewo2.com/notes/terrain) + +* Amit Patel's [_Polygonal Map Generation for Games_](http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation) + +* Scott Turner's [_Here Dragons Abound_](https://heredragonsabound.blogspot.com) diff --git a/fonts.css b/fonts.css index 497822d78..c1cd22bc2 100644 --- a/fonts.css +++ b/fonts.css @@ -1,16 +1,16 @@ @font-face { - font-family: 'Architects Daughter'; + font-family: 'Amatic SC'; font-style: normal; - font-weight: 400; - src: local('Architects Daughter Regular'), local('ArchitectsDaughter-Regular'), url(https://fonts.gstatic.com/s/architectsdaughter/v8/RXTgOOQ9AAtaVOHxx0IUBM3t7GjCYufj5TXV5VnA2p8.woff2) format('woff2'); - unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215; + font-weight: 700; + src: local('Amatic SC Bold'), local('AmaticSC-Bold'), url(https://fonts.gstatic.com/s/amaticsc/v11/TUZ3zwprpvBS1izr_vOMscGKfrUC.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; } @font-face { - font-family: 'Bangers'; + font-family: 'Architects Daughter'; font-style: normal; font-weight: 400; - src: local('Bangers Regular'), local('Bangers-Regular'), url(https://fonts.gstatic.com/s/bangers/v10/yJQgrSMUoqRj-0SbnQsv4g.woff2) format('woff2'); + src: local('Architects Daughter Regular'), local('ArchitectsDaughter-Regular'), url(https://fonts.gstatic.com/s/architectsdaughter/v8/RXTgOOQ9AAtaVOHxx0IUBM3t7GjCYufj5TXV5VnA2p8.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215; } @@ -23,11 +23,11 @@ } @font-face { - font-family: 'Chewy'; + font-family: 'Caesar Dressing'; font-style: normal; font-weight: 400; - src: local('Chewy Regular'), local('Chewy-Regular'), url(https://fonts.gstatic.com/s/chewy/v9/rb3O4cUMVLYzfgbaJOdJHw.woff2) format('woff2'); - unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215; + src: local('Caesar Dressing'), local('CaesarDressing-Regular'), url(https://fonts.gstatic.com/s/caesardressing/v6/yYLx0hLa3vawqtwdswbotmK4vrRHdrz7.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; } @font-face { @@ -54,6 +54,14 @@ unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215; } +@font-face { + font-family: 'Fredericka the Great'; + font-style: normal; + font-weight: 400; + src: local('Fredericka the Great'), local('FrederickatheGreat'), url(https://fonts.gstatic.com/s/frederickathegreat/v6/9Bt33CxNwt7aOctW2xjbCstzwVKsIBVV--Sjxbc.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} + @font-face { font-family: 'Gloria Hallelujah'; font-style: normal; @@ -79,27 +87,27 @@ } @font-face { - font-family: 'Josefin Sans'; + font-family: 'Kaushan Script'; font-style: normal; font-weight: 400; - src: local('Josefin Sans Regular'), local('JosefinSans-Regular'), url(https://fonts.gstatic.com/s/josefinsans/v12/xgzbb53t8j-Mo-vYa23n5ugdm0LZdjqr5-oayXSOefg.woff2) format('woff2'); + src: local('Kaushan Script'), local('KaushanScript-Regular'), url(https://fonts.gstatic.com/s/kaushanscript/v6/qx1LSqts-NtiKcLw4N03IEd0sm1ffa_JvZxsF_BEwQk.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215; } @font-face { - font-family: 'Kaushan Script'; + font-family: 'MedievalSharp'; font-style: normal; font-weight: 400; - src: local('Kaushan Script'), local('KaushanScript-Regular'), url(https://fonts.gstatic.com/s/kaushanscript/v6/qx1LSqts-NtiKcLw4N03IEd0sm1ffa_JvZxsF_BEwQk.woff2) format('woff2'); - unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215; + src: local('MedievalSharp'), url(https://fonts.gstatic.com/s/medievalsharp/v9/EvOJzAlL3oU5AQl2mP5KdgptMqhwMg.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; } @font-face { - font-family: 'Lobster'; + font-family: 'Metamorphous'; font-style: normal; font-weight: 400; - src: local('Lobster Regular'), local('Lobster-Regular'), url(https://fonts.gstatic.com/s/lobster/v20/cycBf3mfbGkh66G5NhszPQ.woff2) format('woff2'); - unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215; + src: local('Metamorphous'), url(https://fonts.gstatic.com/s/metamorphous/v7/Wnz8HA03aAXcC39ZEX5y133EOyqs.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; } @font-face { @@ -110,6 +118,14 @@ unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215; } +@font-face { + font-family: 'Nova Script'; + font-style: normal; + font-weight: 400; + src: local('Nova Script Regular'), local('NovaScript-Regular'), url(https://fonts.gstatic.com/s/novascript/v10/7Au7p_IpkSWSTWaFWkumvlQKGFw.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} + @font-face { font-family: 'Orbitron'; font-style: normal; @@ -134,10 +150,26 @@ unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215; } +@font-face { + font-family: 'Uncial Antiqua'; + font-style: normal; + font-weight: 400; + src: local('Uncial Antiqua'), local('UncialAntiqua-Regular'), url(https://fonts.gstatic.com/s/uncialantiqua/v5/N0bM2S5WOex4OUbESzoESK-i-MfWQZQ.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} + +@font-face { + font-family: 'Underdog'; + font-style: normal; + font-weight: 400; + src: local('Underdog'), local('Underdog-Regular'), url(https://fonts.gstatic.com/s/underdog/v6/CHygV-jCElj7diMroWSlWV8.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} + @font-face { font-family: 'Yellowtail'; font-style: normal; font-weight: 400; src: local('Yellowtail Regular'), local('Yellowtail-Regular'), url(https://fonts.gstatic.com/s/yellowtail/v8/GcIHC9QEwVkrA19LJU1qlPk_vArhqVIZ0nv9q090hN8.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215; -} \ No newline at end of file +} diff --git a/index.css b/index.css index df03bf562..9a97d8c52 100644 Binary files a/index.css and b/index.css differ diff --git a/index.html b/index.html index 245167942..6c56f571f 100644 --- a/index.html +++ b/index.html @@ -1,40 +1,56 @@ + - Azgaar's Fantasy Map Generator Demo - - + + + Azgaar's Fantasy Map Generator Demo + + + + - + - + - - + + - - + + + - -
-

-

Loading...

-
- + + + + + + + + + + + @@ -42,9 +58,21 @@

- + + + + + + + + + + + + + - + @@ -52,9 +80,9 @@

- + - + @@ -102,9 +130,19 @@

- + + + + + +
+
Azgaar's
+
Fantasy Map Generator
+
v. 0.56b
+

LOADING...

+
@@ -128,22 +166,28 @@

- +

Displayed layers. Drag to move, click to toggle

-
+
  • Ocean
  • -
  • Landmass
  • +
  • Landmass
  • Heightmap
  • Grid
  • Overlay
  • Cultures
  • Routes
  • Rivers
  • -
  • Countries
  • +
  • Countries
  • Borders
  • Relief
  • Labels
  • Burgs
  • +
+
+ + + +
@@ -168,10 +212,12 @@

- + +
+
Ensure Overlay layer is active (see Layout tab)

Overlay type: 1 -
+

Filter:
@@ -235,15 +284,15 @@

Toggle filters:

- +

Generate new map to apply the options!

- + @@ -270,9 +319,9 @@

- + @@ -390,7 +439,7 @@

Click to add:

- - - + + +
-

Fantasy Map Generator is an online tool which produces a procedurally generated fantasy maps. You may either use an auto-generated maps or create you own map manually or with a help of templates or image converter. Check out the wiki for guidance.

-

This is a Demo version, project is still under development. For older versions see the changelog. Some details are covered in my blog. To track the current progress see the devboard.

-

Please report bugs and suggest new features here. You may also send me an email.

+

Fantasy Map Generator is an online tool which produces a procedurally generated fantasy maps. You may either use an auto-generated maps or create you own map manually or with a help of templates or image converter. Check out the wiki for guidance.

+

This is a Demo version, project is still under development. For older versions see the changelog. Some details are covered in my blog. To track the current progress see the devboard.

+

Please report bugs and suggest new features here. You may also send me an email.

- -
Map sizeMap size w: @@ -251,7 +300,7 @@

- +
Graph sizeGraph size - + 1 @@ -361,7 +410,7 @@

- +
`; + for (var i=0; i < data.length && i < manors.length; i++) { + const v = data[i]; + if (v === "" || v === undefined) {continue;} + if (v === manors[i].name) {continue;} + change.push({i, name: v}); + message += ``; + } + message += `
IdCurrent nameNew Name
${i}${manors[i].name}${v}
`; + alertMessage.innerHTML = message; + $("#alert").dialog({title: "Burgs bulk renaming", position: {my: "center", at: "center", of: "svg"}, + buttons: { + Cancel: function() {$(this).dialog("close");}, + Confirm: function() { + for (var i=0; i < change.length; i++) { + const id = change[i].i; + manors[id].name = change[i].name; + labels.select("#manorLabel"+id).text(change[i].name); + } + $(this).dialog("close"); + updateCountryEditors(); + } + } + }); + } + fileReader.readAsText(fileToLoad, "UTF-8"); + }); + + // just apply map size that was already set, apply graph size! function applyMapSize() { - mapWidth = +mapWidthInput.value; - mapHeight = +mapHeightInput.value; - svg.attr("width", mapWidth).attr("height", mapHeight); - canvas.width = mapWidth; - canvas.height = mapHeight; - } - - // change map size on manual size change or window resize + svgWidth = graphWidth = +mapWidthInput.value; + svgHeight = graphHeight = +mapHeightInput.value; + svg.attr("width", svgWidth).attr("height", svgHeight); + voronoi = d3.voronoi().extent([[0, 0], [graphWidth, graphHeight]]); + initView = [1, 0, 0]; + zoom.translateExtent([[0, 0], [graphWidth, graphHeight]]).scaleExtent([1, 20]).scaleTo(svg, 1); + viewbox.attr("transform", null); + ocean.selectAll("rect").attr("x", 0).attr("y", 0).attr("width", "100%").attr("height", "100%"); + } + + // change svg size on manual size change or window resize, do not change graph size function changeMapSize() { - mapWidth = +mapWidthInput.value; - mapHeight = +mapHeightInput.value; - svg.attr("width", mapWidth).attr("height", mapHeight); - if ($("body").hasClass("fullscreen")) { - localStorage.removeItem("screenSize"); - } else { - localStorage.setItem("screenSize", [mapWidth, mapHeight]); - } - voronoi = d3.voronoi().extent([[0, 0], [mapWidth, mapHeight]]); - oceanPattern.select("rect").attr("width", mapWidth).attr("height", mapHeight); - oceanLayers.select("rect").attr("width", mapWidth).attr("height", mapHeight); - scX = d3.scaleLinear().domain([0, mapWidth]).range([0, mapWidth]); - scY = d3.scaleLinear().domain([0, mapHeight]).range([0, mapHeight]); - lineGen = d3.line().x(function(d) {return scX(d.scX);}).y(function(d) {return scY(d.scY);}); - zoom.translateExtent([[0, 0], [mapWidth, mapHeight]]); + svgWidth = +mapWidthInput.value; + svgHeight = +mapHeightInput.value; + svg.attr("width", svgWidth).attr("height", svgHeight); + zoom.translateExtent([[0, 0], [svgWidth, svgHeight]]); + fitScaleBar(); + fitStatusBar(); + } + + // fit full-screen map if window is resized + $(window).resize(function(e) { + // trick to prevent resize on download bar opening + if (allowResize === false) {allowResize = true; return;} + mapWidthInput.value = window.innerWidth; + mapHeightInput.value = window.innerHeight; + changeMapSize(); + }); + + // fit ScaleBar to map size + function fitScaleBar() { if (d3.select("#scaleBar").size()) { var bbox = d3.select("#scaleBar").node().getBBox(); - var tr = [mapWidth - 10 - bbox.width, mapHeight - 10 - bbox.height]; + var tr = [svgWidth - 10 - bbox.width, svgHeight - 10 - bbox.height]; d3.select("#scaleBar").attr("transform", "translate(" + rn(tr[0]) + "," + rn(tr[1]) + ")"); - localStorage.removeItem("scaleBar"); + sessionStorage.removeItem("scaleBar"); } - $("#statusbar").css("top", mapHeight + 8); - if ($("body").hasClass("fullscreen")) {$("#statusbar").css("top", mapHeight - 20);} + } + + // fit Statusbar to map size + function fitStatusBar() { + var el = $("#statusbar"); + el.css("top", svgHeight - 20); + if (toggleStatusbar.checked) {el.show();} + } + + // restore initial style + function applyDefaultStyle() { + viewbox.on("touchmove mousemove", moved); + landmass.attr("opacity", 1).attr("fill", "#eef6fb"); + coastline.attr("opacity", .5).attr("stroke", "#1f3846").attr("stroke-width", .7).attr("filter", "url(#dropShadow)"); + regions.attr("opacity", .55); + stateBorders.attr("opacity", .8).attr("stroke", "#56566d").attr("stroke-width", .5).attr("stroke-dasharray", "1.2 1.5").attr("stroke-linecap", "butt"); + neutralBorders.attr("opacity", .8).attr("stroke", "#56566d").attr("stroke-width", .3).attr("stroke-dasharray", "1 1.5").attr("stroke-linecap", "butt"); + cults.attr("opacity", .6); + rivers.attr("opacity", 1).attr("fill", "#5d97bb"); + lakes.attr("opacity", 1).attr("fill", "#a6c1fd").attr("stroke", "#477794").attr("stroke-width", .3); + burgs.attr("opacity", 1).attr("fill", "#ffffff").attr("stroke", "#3e3e4b"); + roads.attr("opacity", .8).attr("stroke", "#d06324").attr("stroke-width", .4).attr("stroke-dasharray", "1 2").attr("stroke-linecap", "round"); + trails.attr("opacity", .8).attr("stroke", "#d06324").attr("stroke-width", .1).attr("stroke-dasharray", ".5 1").attr("stroke-linecap", "round"); + searoutes.attr("opacity", .8).attr("stroke", "#ffffff").attr("stroke-width", .2).attr("stroke-dasharray", "1 2").attr("stroke-linecap", "round"); + grid.attr("opacity", 1).attr("stroke", "#808080").attr("stroke-width", .1); + ruler.attr("opacity", 1).style("display", "none").attr("filter", "url(#dropShadow)"); + overlay.attr("opacity", .8).attr("stroke", "#808080").attr("stroke-width", .5); + ocean.select("#oceanBase").attr("opacity", 1).attr("fill", "#53679f"); + labels.attr("opacity", 1); + size = rn(8 - capitalsCount / 20); + if (size < 3) {size = 3;} + capitals.attr("fill", "#3e3e4b").attr("opacity", 1).attr("font-family", "Almendra SC").attr("data-font", "Almendra+SC").attr("font-size", size).attr("data-size", size); + towns.attr("fill", "#3e3e4b").attr("opacity", 1).attr("font-family", "Almendra SC").attr("data-font", "Almendra+SC").attr("font-size", 3).attr("data-size", 4); + size = rn(16 - capitalsCount / 6); + if (size < 6) {size = 6;} + countries.attr("fill", "#3e3e4b").attr("opacity", 1).attr("font-family", "Almendra SC").attr("data-font", "Almendra+SC").attr("font-size", size).attr("data-size", size); } // Options handlers $("input, select").on("input change", function() { var id = this.id; + if (id === "hideLabels") {invokeActiveZooming();} if (id === "styleElementSelect") { var sel = this.value; var el = viewbox.select("#"+sel); $("#styleInputs div").hide(); + // opacity + $("#styleOpacity, #styleFilter").css("display", "block"); + var opacity = el.attr("opacity") || 1; + styleOpacityInput.value = styleOpacityOutput.value = opacity; + // filter + if (sel == "oceanBase") {el = oceanLayers;} + styleFilterInput.value = el.attr("filter") || ""; if (sel === "rivers" || sel === "oceanBase" || sel === "lakes" || sel === "landmass" || sel === "burgs") { $("#styleFill").css("display", "inline-block"); styleFillInput.value = styleFillOutput.value = el.attr("fill"); @@ -5692,11 +6531,11 @@ function fantasyMap() { var id = this.id; var r = +id.replace("regionColor", ""); states[r].color = this.value; - regions.selectAll(".region"+r).attr("fill", this.value).attr("stroke", this.value); + regions.selectAll(".region"+r).attr("fill", this.value).attr("stroke", this.value); }); } - if (sel === "terrs") {$("#styleScheme").css("display", "block");} - if (sel === "heightmap") {$("#styleScheme").css("display", "block");} + if (sel === "terrs") {$("#styleScheme").css("display", "block");} + if (sel === "heightmap") {$("#styleScheme").css("display", "block");} if (sel === "cults") { $("#styleMultiple").css("display", "inline-block"); $("#styleMultiple input").remove(); @@ -5721,7 +6560,7 @@ function fantasyMap() { if (sel === "labels") { $("#styleFill, #styleFontSize").css("display", "inline-block"); styleFillInput.value = styleFillOutput.value = el.select("g").attr("fill"); - } + } if (sel === "burgs") { $("#styleSize").css("display", "block"); $("#styleStroke").css("display", "inline-block"); @@ -5730,13 +6569,6 @@ function fantasyMap() { if (sel === "overlay") { $("#styleOverlay").css("display", "block"); } - // opacity - $("#styleOpacity, #styleFilter").css("display", "block"); - var opacity = el.attr("opacity") || 1; - styleOpacityInput.value = styleOpacityOutput.value = opacity; - // filter - if (sel == "oceanBase") {el = oceanLayers;} - styleFilterInput.value = el.attr("filter") || ""; return; } if (id === "styleFillInput") { @@ -5782,6 +6614,7 @@ function fantasyMap() { if (sel == "oceanBase") {sel = "oceanLayers";} var el = svg.select("#"+sel); el.attr('filter', this.value); + invokeActiveZooming(); return; } if (id === "styleSchemeInput") { @@ -5802,8 +6635,16 @@ function fantasyMap() { toggleOverlay(); } } - if (id === "mapWidthInput" || id === "mapHeightInput") {changeMapSize();} - if (id === "sizeInput") {graphSize = sizeOutput.value = this.value;} + if (id === "mapWidthInput" || id === "mapHeightInput") { + changeMapSize(); + sessionStorage.setItem("screenSize", [+mapWidthInput.value, +mapHeightInput.value]); + } + if (id === "sizeInput") { + graphSize = sizeOutput.value = +this.value; + if (graphSize === 3) {sizeOutput.style.color = "red";} + if (graphSize === 2) {sizeOutput.style.color = "yellow";} + if (graphSize === 1) {sizeOutput.style.color = "green";} + } if (id === "randomizeInput") {randomizeOutput.innerHTML = +this.value ? "✓" : "✕";} if (id === "manorsInput") { if (randomizeInput.value === "1") { @@ -5816,7 +6657,7 @@ function fantasyMap() { if (randomizeInput.value === "1") { randomizeInput.value = 0; randomizeOutput.innerHTML = "✕"; - } + } capitalsCount = regionsOutput.value = this.value; var size = rn(6 - capitalsCount / 20); if (size < 3) {size = 3;} @@ -5886,16 +6727,21 @@ function fantasyMap() { $("#scaleBar").removeClass("hidden"); drawScaleBar(); } + if (id === "barLabel") { + $("#scaleBar").removeClass("hidden"); + drawScaleBar(); + } }); $("#rescaler").change(function() { var change = rn((+this.value - 5) / 10, 2); modifyHeights("all", change, 1); - mockHeightmap(); + updateHeightmap(); + updateHistory(); rescaler.value = 5; }); - $("#layoutPreset").on("change", function() { + $("#layoutPreset").on("change", function() { var preset = this.value; $("#mapLayers li").not("#toggleOcean, #toggleLandmass").addClass("buttonoff"); $("#toggleOcean, #toggleLandmass").removeClass("buttonoff"); @@ -5946,4 +6792,43 @@ function fantasyMap() { if (id === "customizeTab") {$("#customizeContent").show();} if (id === "aboutTab") {$("#aboutContent").show();} }); -} \ No newline at end of file + + // Pull request from @evyatron + // https://github.com/Azgaar/Fantasy-Map-Generator/pull/49 + function addDragToUpload() { + document.addEventListener('dragover', function(e) { + e.stopPropagation(); + e.preventDefault(); + $('#map-dragged').show(); + }); + + document.addEventListener('dragleave', function(e) { + $('#map-dragged').hide(); + }); + + document.addEventListener('drop', function(e) { + e.stopPropagation(); + e.preventDefault(); + $('#map-dragged').hide(); + // no files or more than one + if (e.dataTransfer.items == null || e.dataTransfer.items.length != 1) {return;} + var file = e.dataTransfer.items[0].getAsFile(); + // not a .map file + if (file.name.indexOf('.map') == -1) { + alertMessage.innerHTML = 'Please upload a .map file you have previously downloaded'; + $("#alert").dialog({ + resizable: false, title: "Invalid file format", + width: 400, buttons: { + Close: function() { $(this).dialog("close"); } + }, position: {my: "center", at: "center", of: "svg"} + }); + return; + } + // all good - show uploading text and load the map + $("#map-dragged > p").text("Uploading..."); + uploadFile(file, function onUploadFinish() { + $("#map-dragged > p").text("Drop to upload"); + }); + }); + } +}