Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api-Like map save option #730

Merged
merged 5 commits into from
Jan 26, 2022
Merged

Api-Like map save option #730

merged 5 commits into from
Jan 26, 2022

Conversation

yldrefruz
Copy link
Contributor

Added a option for saving files that looks like a json api response. Can be used easily by programmers.

The result json can look like, this is just an example original output will be different. :

{
  "info":{
    "version": 1.71,
    "description" : "Api-Like Output From FMG",
    "creation-date": "2022-1-25",
    "seed": "155464654654",
    "mapID": 65651351351,
    "mapName" : "name"
  },
  "settings": {
    "distanceUnit": "km",
    "distanceScale": "2",
    "areaUnit": "square",
    "heightUnit": "m",
    "heightExponent": "2",
    "temperatureScale": "°C",
    "barSize": "2",
    "barLabel": "",
    "barBackOpacity": "0.2",
    "barBackColor": "#ffffff",
    "barPosX": "99",
    "barPosY": "99",
    "populationRate": 1000,
    "urbanization": 1,
    "mapSize": "57",
    "latitude": "45",
    "temperatureEquator": "27",
    "temperaturePole": "-2",
    "prec": "127",
    "options": {
      "pinNotes": false,
      "showMFCGMap": true,
      "winds": [
        225
      ],
      "stateLabelsMode": "auto",
      "year": 1882,
      "era": "Osazu Era",
      "eraShort": "OE",
      "military": [
        {
          "icon": "⚔️",
          "name": "infantry",
          "rural": 0.25,
          "urban": 0.2,
          "crew": 1,
          "power": 1,
          "type": "melee",
          "separate": 0
        }
      ]
    },
    "hideLabels": true,
    "stylePreset": "styleDefault",
    "rescaleLabels": true,
    "urbanDensity": 10
  },
  "coords": {
    "latT": 102.6,
    "latN": 55.2,
    "latS": -47.4,
    "lonT": 134,
    "lonW": -67,
    "lonE": 67
  },
  "notesData": [
    {
      "id": "regiment1-0",
      "name": "⚔️ 1st (Wusenlin) Regiment",
      "legend": "Regiment was formed in 1881 Osazu Era during the Rickinterian War. 1st (Wusenlin) Regiment is stationed in Wusenlin Commune. \r\n\r\nRegiment composition in 1882 OE:\r\n— infantry: 1312\r\n— archers: 672\r\n— cavalry: 378\r\n— artillery: 21."
    }],
  "pack": {
    "cells": {
      "h": [1],
      "f": [1],
      "t": [1],
      "s": [1],
      "biome": [1],
      "burg": [1],
      "culture": [1],
      "state": [1],
      "province": [1],
      "religion": [1],
      "area": [1],
      "pop": [1],
      "r": [1],
      "fl": [1],
      "conf": [1],
      "harbor": [1],
      "haven": [1],
      "road": [1],
      "crossroad": [1]
    },
    "features": [
      {
        "i" : 1,
        "land" : false,
        "border" : true,
        "type" : "ocean",
        "group" : "ocean",
        "cells" : 1662,
        "firstCell" : 0,
        "vertices" : [6790]
      }
    ],
    "cultures": [
      {
        "i": 0,
        "base": 1,
        "name": "Wildlands",
        "origin" : null,
        "shield" : "round",
        "center" : 2876,
        "code" : "Sl",
        "color"  : "#6e40aa",
        "expansionism" : 2,
        "type"   : "Nomadic",
        "area" : 1,
        "cells" : 1000,
        "rural" : 1,
        "urban" : 1,
        "removed" : false
      }
    ],

    "burgs" : [{
      "i" : 1,
      "name" : "name",
      "cell" : 1,
      "x": 1.50,
      "y": 1.50,
      "culture" : 1,
      "state" : 1,
      "feature" : 1,
      "population" : 1,
      "type" : "",
      "coa" : "coastring",
      "MFCG": 100,
      "link" : "linkof",
      "capital": 1,
      "port": 1,
      "citadel": 1,
      "plaza": 1,
      "shanty": 1,
      "temple" : 1,
      "walls": 1,
      "lock": 1,
      "removed": true
    }],

   "states": [{
     "i": 1,
     "name" : "",
     "form": "",
     "formName": "",
     "fullName": "",
     "color": "",
     "center": 1,
     "pole": [1,2],
     "culture": 1,
     "type": "",
     "expansionism": 1,
     "area": 1,
     "burgs": 1,
     "cells": 1,
     "rural": 1,
     "urban": 1,
     "neighbors": [1],
     "provinces": [1],
     "diplomacy": [""],
     "campaigns": [{
       "start": 1,
       "end": 2,
       "name": ""
     }],
     "alert": 1,
     "military": [
       {
         "i": 1,
         "a": 1,
         "cell": 1,
         "x": 1.4,
         "y": 1.4,
         "bx": 1.4,
         "by": 1.3,
         "u": {
           "infantry": 2,
           "archers": 3,
           "cavalry": 2,
           "artillery": 3
         },
         "n": 1,
         "name": "",
         "state": 2,
         "icon": ""
       }
     ],
     "coa" : "coastring",
     "removed": true
   }],
    "provinces": [
      {
        "i": 1,
        "name": "",
        "formName": "",
        "fullName": "",
        "color": "",
        "center": 1,
        "pole": [1],
        "area": 1,
        "burg":1,
        "burgs": [1],
        "cells": 1,
        "rural": 1,
        "urban": 1,
        "coa":"coastring",
        "removed": true

      }
    ],
    "religions": [{
      "i" : 1,
      "name": "",
      "type": "",
      "form": "",
      "deity": "",
      "color": "",
      "code": "",
      "origin" : 1,
      "center": 1,
      "culture": 1,
      "pole": [1],
      "expansionism": 1,
      "expansion": "",
      "area":1,
      "cells": 1,
      "rural": 1,
      "urban": 1,
      "removed": true
    }],
    "rivers": [{
      "i": 1,
      "name": "",
      "type": "",
      "source": 1,
      "mouth": 1,
      "parent": 2,
      "basin": 1,
      "cells":[1],
      "points": [[1]],
      "discharge": 1,
      "length": 1,
      "width": 1,
      "sourceWidth": 1
    }],
    "markers": [{
      "i" : 1,
      "icon": 1,
      "x": 1,
      "y": 1,
      "cell": 1,
      "type": "",
      "size": 2,
      "fill": "",
      "stroke": "",
      "pin": "",
      "pinned": true,
      "dx": 1,
      "dy": 1,
      "px": 1,
      "lock": true
    }]
  },
  "biomes": {
    "i": [1],
    "name" : [""],
    "color" : [""],
    "biomesMatrix": [[1]],
    "cost": [1],
    "habitability" : [1],
    "icons": [[""]],
    "iconsDensity": [1]
  },
  "notes": [{
    "i" : "",
    "name" : "",
    "legend": ""
  }],
  "nameBases": [{
    "i" : 1,
    "name": "",
    "b": "",
    "min": 1,
    "max": 1,
    "d": "",
    "m": 1
  }]
}

@Azgaar Azgaar self-requested a review January 25, 2022 19:47
@Azgaar
Copy link
Owner

Azgaar commented Jan 25, 2022

Hello. Look good!

I would prefer to have it as a separate js file and a part of Export UI (not Save). We already have export to GeoJSON (for some data), having a JSON will be a good options as well.
See also https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Data-model if you did not see it before.

Copy link
Owner

@Azgaar Azgaar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request to:

  1. Move UI to the Export dialog
  2. Move code to a separate file (e.g. export-json.js)

Moved json export to another file named export-json.js
@yldrefruz yldrefruz requested a review from Azgaar January 25, 2022 21:24
@yldrefruz
Copy link
Contributor Author

FMG has two meta-objects storing most of the map data:

grid contains map data before repacking
pack contains map data after repacking

I already read the data model and made the output file based on the data model. Since wiki page says pack contains repackaged data I made exporting based on pack data. Output file contains:

  • info
  • settings(because some population and other things are related this)
  • coords
  • notes
  • pack

But i am not sure about exporting cell data of pack because cell data is too big. Maybe we can export cell data as different file.

- all JSON : exports all json data.
- minimal JSON : exports json data without cells data.
- cells JSON : exports json data only with pack.cells data.
@Azgaar
Copy link
Owner

Azgaar commented Jan 26, 2022

Looks good, I would like to make minor UI changes after the merge.

@Azgaar Azgaar merged commit 503eabd into Azgaar:master Jan 26, 2022
@Azgaar
Copy link
Owner

Azgaar commented Jan 26, 2022

I have cleaned up the code and changed the output a bit. Please let me know if it works.

@yldrefruz
Copy link
Contributor Author

yldrefruz commented Jan 28, 2022

I test some json data with java with json-simple and it works really good. But i think there should be a export type for grid data. Because some graphical data depends on it.

Should app export graphical datas like that with json or some other file

@Azgaar
Copy link
Owner

Azgaar commented Jan 28, 2022

You can add it in another PR, I would be glad to review

sofronaspe pushed a commit to sofronaspe/Fantasy-Map-Generator that referenced this pull request Nov 22, 2022
* Added Save Option for Api-like json export.
Will be updated and set to a scheme

* Save Option for Api-like added

* Moved UI of json export to export dialog.
Moved json export to another file named export-json.js

* Added Seperated json export selections
- all JSON : exports all json data.
- minimal JSON : exports json data without cells data.
- cells JSON : exports json data only with pack.cells data.

* More Stable Cell Export...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants