Generate map images

Started by llamazing, September 14, 2019, 03:23:28 PM

Previous topic - Next topic
I revisited my script to generate images from a map .dat file. The original topic can be found here:
http://forum.solarus-games.org/index.php/topic,1122.0.html

Notable improvements:
*I adjusted the colors for a sleeker and more uniform appearance
*It now generate a composite image from all map layers
*It now exports an image file
*Can generate a "world" image of multiple maps linked by edge teletransporters
*Can generate individual images for all maps in a single operation

The image exported is a .ppm file, which has a very simple file format, but the file size is not optimal. The image can be converted to a .png using GIMP.

I experimented with a pure-lua library that generates png images, but it was slow and was actually generating the exact same sequence of bits, just with a different header (so there was no improvement in file size over the .ppm file). Maybe a better png library could be an option in the future.

Solarus crashes for me when trying to export an image of approximately 8000x8000 pixels or larger. I'm guessing this is some sort of memory limitation that is being exceeded (the outputted image would be over 100MB), but no error is given. The default SCALE_FACTOR is 8 (maps rendered at 1/8th original size), so this will probably not be an issue at this scale even when generating a world map image (unless you have a VERY big world map), just beware. I could possibly improve memory performance here by generating the image data one row at a time instead of doing the entire image at once if this becomes a problem.

Also note there are some bugs in Solarus v1.6 related to the drawing order (which are fixed in v1.6.2). I am not able to test in v1.6.2 right now, but the image might look slightly different.

https://gitlab.com/llamazing/solarus-scripts/blob/master/data/scripts/map_imager.lua
Usage:
Code (lua) Select

local map_imager = require"scripts/map_imager"
map_imager(map_id) --to generate one image for the specified map_id (string)
--equivalent to map_imager:export_map(map_id)
map_imager() --to generate images for ALL maps
--equivalent to map_imager:export_all()
map_imager:export_world_map(map_id) --to generate an image of the specified map_id (string) and any maps connected by edge teletransporters


When generating a world map image, it will also output coordinates of each map with 0,0 being the top-left corner. This could be useful if you need assistance in figuring out world coordinates of your maps.

Here is a world map generated from Ocean's Heart using "ballast_harbor/ballast_harbor" as the starting map (converted to png with GIMP):

I updated the script linked above to version 1.1.1.

Now there are warning messages when using export_world_map() if there are any overlapping maps or discontinuities are detected. These can be disabled respectively by setting IS_OVERLAP_WARNING and IS_DISCONNECT_WARNING to false at the beginning of the script.

I also added support for ignoring maps with an id matching a given pattern in the EXCLUDE_MAPS list.