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

Add export-map script #1329

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
163 changes: 163 additions & 0 deletions docs/export-map.rst
Copy link
Member

Choose a reason for hiding this comment

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

could you move

  • export-map.lua -> devel/export-map.lua
  • docs/export-map.rst -> docs/devel/export-map.rst

to match other dev tools?

Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
export-map
==========

.. dfhack-tool::
:summary: Export fortress map tile data to a JSON file
Copy link
Member

Choose a reason for hiding this comment

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

short summaries need to end in a period. also, this tool should work just as well on an adventure map, so there's no need to restrict it to fortress maps

:tags: dev map
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
:tags: dev map
:tags: dev

Copy link
Member

Choose a reason for hiding this comment

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

dev tools generally do not carry any other tags to avoid confusing end users (regular players)


WARNING - This command will cause the game to freeze for minutes depending on
map size and options enabled.
Comment on lines +8 to +9
Copy link
Member

Choose a reason for hiding this comment

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

if the runtime for large maps is untenable, it probably would not be too hard to move the property scanning logic a Lua-accessible function of probe and just use Lua for the output formatting (which is a pain to do in C++).


Exports the fortress map tile data to a JSON file. (does not include items,
characters, buildings, etc.) Depending on options enabled, there will be a
Comment on lines +11 to +12
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Exports the fortress map tile data to a JSON file. (does not include items,
characters, buildings, etc.) Depending on options enabled, there will be a
Exports the fortress map tile data to a JSON file. The export does not include items,
characters, buildings, etc. Depending on options enabled, there will be a

``KEY`` table in the JSON with relevant [number ID] values that match a number
to their object type.

Usage
-----

::

export-map [include|exclude] [<options>]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
export-map [include|exclude] [<options>]
export-map
export-map (include|exclude) <options>

Copy link
Member

Choose a reason for hiding this comment

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

to better reflect that include/exclude is required when specifying options


Examples
--------

``export-map``
Exports the fortress map to JSON with ALL data included
Copy link
Member

Choose a reason for hiding this comment

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

Here and below: Exports -> Export. These are descriptions of what the command represents, not a description of what happens. Also, please end these sentences in a period.


``export-map include -m -s -v``
Exports the fortress map to JSON with only materials, shape, and variant
data included

``export-map exclude --variant --hidden --light``
Exports the fortress map to JSON with variant, hidden, and light data
excluded

Required
--------

When you are using options, you must include one of these settings.

``include``
Include only the data listed from options to the JSON (whitelist)

``exclude``
Exclude only the data listed from options to the JSON (blacklist)
Comment on lines +37 to +46
Copy link
Member

Choose a reason for hiding this comment

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

with the update to the Usage section, you can remove this section


Options
-------

``help``, ``--help``
Shows the help menu

Comment on lines +51 to +53
Copy link
Member

Choose a reason for hiding this comment

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

we generally don't document "help" options since the canonical way to get help is help devel/export-map

``-t``, ``--tiletype``
The tile material classification [number ID] (AIR/SOIL/STONE/RIVER/etc.)

``-s``, ``--shape``
The tile shape classification [number ID] (EMPTY/FLOOR/WALL/STAIR/etc.)

``-p``, ``--special``
The tile surface special properties for smoothness [number ID]
(NORMAL/SMOOTH/ROUGH/etc.) (used for engraving)

``-v``, ``--variant``
The specific variant of a tile that have visual variations [number] (like
grass tiles in ASCII mode)

``-h``, ``--hidden``
Whether tile is revealed or unrevealed [boolean]

``-l``, ``--light``
Whether tile is exposed to light [boolean]

``-b``, ``--subterranean``
Whether the tile is considered underground [boolean] (used to determine
crops that can be planted underground)

``-o``, ``--outside``
Whether the tile is considered “outside”. [boolean] (used by weather effects
to trigger on outside tiles)

``-a``, ``--aquifer``
Whether the tile is considered an aquifer [number ID] (NONE/LIGHT/HEAVY)

``-m``, ``--material``
The material inside the tile [number ID] (IRON/GRANITE/CLAY/
TOPAZOLITE/BLACK_OPAL/etc.) (will return nil if the tile is empty)

``-u``, ``--underworld``
Whether the underworld z-levels will be included

``-e``, ``--evilness``
Whether the evilness value will be included in MAP_SIZE table. This only
checks the value of the center map tile at ground level and will ignore
biomes at the edges of the map.

JSON DATA
Copy link
Member

Choose a reason for hiding this comment

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

What are the client requirements that led to this output format? The choices made here seem strange to me, and I could use some context.

---------

``ARGUMENT_OPTION_ORDER``
The order of the selected options for how data is arranged at a map position

Example 1:
``{"material": 1, "shape": 2, "hidden": 3}``

``map[z][y][x] = {material_data, shape_data, hidden_data}``

Example 2:
``{"variant": 3, "light": 1, "outside": 2, "aquifer": 4}``

``map[z][y][x] = {light_data, outside_data, variant_data, aquifer_data}``

``MAP_SIZE``
A table containing basic information about the map size for width, height,
depth. (x, y, z) The underworld_z_level is included if the underworld option
is enabled and the map depth (z) will be automatically adjusted.

``KEYS``
The tables containing the [number ID] values for different options.

``"SHAPE": {"-1": "NONE", "0": "EMPTY", "1": "FLOOR", "2": "BOULDERS",
"3": "PEBBLES", "4": "WALL", ..., "18": "ENDLESS_PIT"}``

``"PLANT": {"0": "SINGLE-GRAIN_WHEAT", "1": "TWO-GRAIN_WHEAT",
"2": "SOFT_WHEAT", "3": "HARD_WHEAT", "4": "SPELT", "5": "BARLEY", ...,
"224": "PALM"}``

``"AQUIFER": {"0": "NONE", "1": "LIGHT", "2": "HEAVY"}``

Note - when using the ``materials`` option, you need to pair the [number ID]
with the correct ``KEYS`` material table. Generally you use ``tiletype``
option as a helper to sort tiles into different material types. I would
recommend consulting ``tile-material.lua`` to see how materials are sorted.

``map``
JSON map data is arranged as: ``map[z][y][x] = {tile_data}``

JSON maps start at index [1]. (starts at map[1][1][1])
DF maps start at index [0]. (starts at map[0][0][0])

To translate an actual DF map position from the JSON map you need add +1 to
all x/y/z coordinates to get the correct tile position.

The ``ARGUMENT_OPTION_ORDER`` determines order of tile data. (see above)
I would recommend referencing the tile data like so:

``shape = json_data.map[z][x][y][json_data.ARGUMENT_OPTIONS_ORDER.shape]``

``light = json_data.map[z][x][y][json_data.ARGUMENT_OPTIONS_ORDER.light]``

Note - some of the bottom z-levels for hell do not have the same
width/height as the default map. So if your map is 190x190, the last hell
z-levels are gonna be like 90x90.

Instead of returning normal tile data like:

``map[0][90][90] = {tile_data}``

It will return nil instead:

``map[0][91][91] = nil``

So you need to account for this!
Loading