Palats / mapshot

Factorio mod to export maps as zoomable html
Apache License 2.0
77 stars 12 forks source link
factorio factorio-mod factorio-tool

Mapshot for Factorio

Mapshot generates zoomable screenshots of Factorio maps - example.

They can be created in 2 ways:

The generated zoomable screenshots can be explored through a web browser, using the CLI tool to serve them. As those mapshots are exported as static files (html, javascript, jpg), they can also be served through any HTTP server - see below.

Some simple layers are generated - currently it is possible to show train stations and map labels (chart tags).

Warning: Generation can take quite a while. Factorio UI will appear frozen during that time; this is normal.

See https://github.com/Palats/mapshot for more details.

Installing

The Factorio mod can be installed like any other mod from the Factorio UI.

The optional CLI is used for serving generated mapshots and generating mapshots from outside the game. The standalone binaries can be downloaded from https://github.com/Palats/mapshot/releases; then:

An externally maintained package for Arch is also available, thanks to Sharparam.

Creating a mapshot

In Factorio

In the Factorio console, run:

/mapshot <name>

It will create a website in the Factorio script output directory, in a subdirectory called mapshot/<name>/. If <name> is not specified, a name based on the seed and current tick will be generated (modding API does not gives access to savename, hence no good default naming).

With the CLI

To generate a mapshot:

./mapshot render <savename>

where savename is the name of the save you want to render. It will not modify the file - specifically, despite mod usage, it will not impact achievements for example. This will run Factorio to generate the mapshot - let it run, it will shut it down when finished. As with the regular mod, the output will be somewhere in the script-output directory.

This commands takes the list of mods to load from the current active list in Factorio config - not the list of mods which were used when the save was created. This can lead to inconsistent renders; see https://github.com/Palats/mapshot/issues/20.

If your Factorio data dir or binary location are not detected automatically, you can specify them with --factorio_datadir and --factorio_binary. You can also override the rendering parameters - see CLI help for the specific flag names.

Steam version of Factorio is not supported for now - see https://github.com/Palats/mapshot/issues/21 for more details. If you have only a Steam version, you can still get a standalone version on factorio.com by linking your Steam account.

Headless version of Factorio is not supported at all - it lacks the ability to render any image.

Parameters

You can tune parameters such as many layers to generate, their resolution and a few more details. Those parameters are:

Parameters:

Warning: the generation time & disk usage increases very quickly. At maximum resolution, it will take forever to generate and use up several gigabytes of space.

Headless server

NOTE: This is hacky and you need some familiarity with Linux; also, you are mostly on your own.

Mapshot requires a running Factorio with UI to do the rendering - this is a constraint of Factorio itself. On Linux, this means a X server must be available. On a Linux headless server, it is still possible to do renders using Xvfb.

On Ubuntu, Xvfb can be installed through apt-get install xvfb. Once you have it installed, you can create a mapshot by running the command through xvfb-run; for example:

xvfb-run ./mapshot render <savename>

It can be a bit fiddly with OpenGL; a few tips:

Serving the maps

The CLI can be used to serve the mapshots:

./mapshot serve

By default, it serves on port 8080 - thus accessible at http://localhost:8080 if it is running on your local machine. It serves all the mapshots available in the script-output directory of Factorio. Directory can be overriden using flag --factorio_scriptoutput. It provides a very basic list of available mapshots and refreshes this list every few seconds. (Note: it uses frontend code built into the binary. It ignores the frontend files such as index.html and Javascript files present next to the mapshots.)

The generated content has static frontend code generated next to the images. This means you can also serve the content through any HTTP server (e.g., python3 -m http.server 8080 from the script-output directory) or your favorite web file hosting.

The viewer has the following URL query parameters:

Generated content

Directory hierarchy

All content is generated in the Mapshot output directory. This directory is script-output/<prefix>, where:

Within that directory, a directory will be created per save:

Within a given <savename> directory, one subdirectory will be created everytime a mapshot is made. It is of the form d-<hash>, where the hash is computed based on many input to try to be as unique as possible. Those directories contain some more internal directories to organize the raw data.

Files

Currently no files are created in the Mapshot output directory itself.

In a <savename> directory, html and javascript files are created. It points to latest mapshot generated in that <savename> directory. Currently, accessing older mapshots require fiddling with ?path=xxx URL query parameter.

In a given mapshot directory (of the form d-<hash>), a mapshot.json file describes that specific render.

Caching

Generated html files are not meant to be cached, as they are potentially updated on each render. Javascript files can be cached as their name will change as needed. The thumbnail.png is used only as a favicon - while it might change in the future, it is not critical. Anything under a specific mapshot directory (d-<hash>) is immutable and can be cached indefinitely.

In practice, if adding a caching layer in front of ./mapshot serve, everything can be cached as most of the content URLs contain hashes. Exceptions:

Example

Visually, that gives something like that:

script-output/mapshot/  <--- output directory
  savename1/
    index.html
    main-1c3f7217.js
    thumbnail.png
    d-5bd8e540/
      mapshot.json
      s1zoom_0/ ...
      s1zoom_1/ ...
      ...
    d-a309ff22/
      ...
    ...
  savename2/
    ...
  map-ad765988/
    ...
  ...

Development

See DEVELOPMENT.md in the repository.