Page 1 of 1

convert map exchange string to map generator settings

Posted: Tue Jun 04, 2019 8:58 pm
by trad_emark
Is it possible to generate the map-settings.json and map-gen-settings.json from map exchange string or directly in the gui?

I know I can start a new game and upload the save to the server, but I would prefer to "acquire" the settings anyway, for multiple reasons.
- It would help me to better understand which value is which.
- It would allow me to generate save with some values outside ranges available in the gui (I especially like to set negative time or pollution factors for biters evolution :D ) and to set some of the other properties that aren't available in the gui at all.

Thanks for any hints :D

Re: convert map exchange string to map generator settings

Posted: Thu Oct 03, 2019 12:39 am
by Casper042
Came to ask the same thing.

I would love to see either an in-game or a web based Exchange String to JSON converter.

For in-game, just have a JSON button on the normal Exchange String export screen perhaps.

Re: convert map exchange string to map generator settings

Posted: Thu Oct 03, 2019 8:57 am
by billbo99
I am not near my home PC, but I believe these commands would generate the data

/c game.write_file("map-settings.json", serpent.block(game.map_settings))
/c game.write_file("map-gen-settings.json", serpent.block(player.surface.map_gen_settings))

This will output to the "script-output" folder.

Re: convert map exchange string to map generator settings

Posted: Tue Feb 18, 2020 2:06 am
by IchibanDashi
I would also like to have this ability to output the map config files in JSON format from within Factorio. It would be helpful to be able to pass the config files to a server admin, instead of having to mess with save game files. Perhaps the server admin would like to tweak a few settings before spinning up the game?

I did try the commands that @billbo99 provided, but they didn't work. I'm not sure if it's because I'm running 0.18.6 or if it's something else.
This command doesn't give any errors:
/c game.write_file("map-settings.json", serpent.block(game.map_settings))
But, the contents of the file (and thus game.map_settings) are not what is expected:

Code: Select all

{
  __self = "userdata"
}
This command does give an error...
/c game.write_file("map-gen-settings.json", serpent.block(player.surface.map_gen_settings))
... as shown below:

Code: Select all

Cannot execute command. Error: (command):1:attempt to index global 'player' (a nil value)
I tried to do a little troubleshooting myself, but my knowledge of (Factorio's) Lua scripting is lacking.
For example: I can understand that the map settings would be in the game object, but why would the map generation settings be in player.surface?
Would it be foolish to presume that they might be stored in the same object?

Re: convert map exchange string to map generator settings

Posted: Tue Feb 18, 2020 2:38 am
by Squelch
Try this:

Code: Select all

/c game.write_file("my-map-settings.txt", serpent.block(game.parse_map_exchange_string(">>>eNpjYBBiYGYAgwZ7EOZgSc5PzIHxQJgrOb+gILVIN78oFVmYM 7moNCVVNz8TVXFqXmpupW5SYjGKYo7Movw8dBNYi0vy81BFSopSU 4uRRbhLixLzMktz0fUyMH6/sbyxoUWOAYT/1zMo/P8PwkDWA6BfQ JiBsQGiEigGA6zJOZlpaQwMCo5A7ASSZmRkrBZZ5/6waoo9I0SNn gOU8QEqciAJJuIJY/g54JRSgTFMkMwxBoPPSAyIpSVAK6CqOBwQD IhkC0iSkbH37dYF349dsGP8s/LjJd+kBHtGQ1eRdx+M1tkBJdlB/ mSCE7NmgsBOmFcYYGY+sIdK3bRnPHsGBN7YM7KCdIiACAcLIHHAm 5mBUYAPyFrQAyQUZBhgTrODGSPiwJgGBt9gPnkMY1y2R/cHMCBsQ IbLgYgTIAJsIdxljBCmQ78Do4M8TFYSoQSo34gB2Q0pCB+ehFl7G Ml+NIdgRgSyP9BEVBywRAMXyMIUOPGCGe4aYHheYIfxHOY7MILzE EjVF6AYIzPMkzCjILSAAzMDAgCTxWTGtfUAK4Wh8A==<<<")))
from here

Note the output will need a bit of adjustment to be fully preset compatible.

Re: convert map exchange string to map generator settings

Posted: Tue Feb 18, 2020 3:22 am
by IchibanDashi
I think I may have stumbled upon the answer:

Code: Select all

/c game.write_file("map-settings.json", serpent.block(game.parse_map_exchange_string(game.get_map_exchange_string())))
This basically gets the exchange string, runs it through the internal parser, runs it through the Serpent pretty printer, then outputs it all to the map-settings.json file in the script-output folder. (On Windows, this would be %APPDATA%\Factorio\script-output)
Both the map settings and the map gen settings get output to the same file (which might be fine, I think). [edit: I guess not]

Caveat: I haven't actually tested this on a headless server yet.
Also Caveat: This command will disable achievements. Save your game before you use this, if that's important to you.

EDIT: I should have refreshed the page before posting my answer. Thanks, Squelch, for that info. If I hadn't worked it out myself, I'm sure that would have pointed me in the right direction. Also good to know that the output isn't directly usable as the headless server config file. I'm sure a bit of comparison to the example config files will help clear that up!

Re: convert map exchange string to map generator settings

Posted: Tue Feb 18, 2020 4:37 am
by Squelch
IchibanDashi wrote:
Tue Feb 18, 2020 3:22 am
I think I may have stumbled upon the answer:
..

EDIT: I should have refreshed the page before posting my answer. Thanks, Squelch, for that info. If I hadn't worked it out myself, I'm sure that would have pointed me in the right direction. Also good to know that the output isn't directly usable as the headless server config file. I'm sure a bit of comparison to the example config files will help clear that up!
No problem, and as you may have noticed, I too struggled in the same way. In fact it was deja vu there for a moment, and I had to check that I was not in my own topic :D

There is also
table_to_json(data) you might want to use too.
ie.

Code: Select all

/c game.write_file("my-map-settings.json", serpent.block(game.table_to_json(game.parse_map_exchange_string(">>>eNpjYBBiYGYAgwZ7EOZgSc5PzIHxQJgrOb+gILVIN78oFVmYM 7moNCVVNz8TVXFqXmpupW5SYjGKYo7Movw8dBNYi0vy81BFSopSU 4uRRbhLixLzMktz0fUyMH6/sbyxoUWOAYT/1zMo/P8PwkDWA6BfQ JiBsQGiEigGA6zJOZlpaQwMCo5A7ASSZmRkrBZZ5/6waoo9I0SNn gOU8QEqciAJJuIJY/g54JRSgTFMkMwxBoPPSAyIpSVAK6CqOBwQD IhkC0iSkbH37dYF349dsGP8s/LjJd+kBHtGQ1eRdx+M1tkBJdlB/ mSCE7NmgsBOmFcYYGY+sIdK3bRnPHsGBN7YM7KCdIiACAcLIHHAm 5mBUYAPyFrQAyQUZBhgTrODGSPiwJgGBt9gPnkMY1y2R/cHMCBsQ IbLgYgTIAJsIdxljBCmQ78Do4M8TFYSoQSo34gB2Q0pCB+ehFl7G Ml+NIdgRgSyP9BEVBywRAMXyMIUOPGCGe4aYHheYIfxHOY7MILzE EjVF6AYIzPMkzCjILSAAzMDAgCTxWTGtfUAK4Wh8A==<<<"))))
Will output an unformatted .json that may help with the conversion.

Re: convert map exchange string to map generator settings

Posted: Sat Sep 26, 2020 6:43 pm
by larandar
For the record, since this is the result in google when trying to export map-settings.json for a server, here is a combination of what work:

Code: Select all

 /c game.write_file("map-settings.json", game.table_to_json(game.parse_map_exchange_string(game.get_map_exchange_string())))
 /c game.write_file("map-gen-settings.json", game.table_to_json(game.player.surface.map_gen_settings))
Ready to be copy-pasted by anyone (and surely older-me ;) )