Skip to main content

Module grid_map

Module grid_map 

Source
Expand description

The .map text format of a grid map: a RON header, a --- line, then one character per tile, top row first.

(
    name: "Crossing",
    legend: { '.': "plain", 'T': "forest", '~': "water" },
    features: { (2, 0): Sign("Turn back") },
    look: (tiles: "indoor", light: "dusk"),
)
---
..T
~~.

The header has the map’s name, its legend (tile character → terrain id), its features and its look; the last two may be left out. A game says what a feature is (the MapFeature hook: its own serde type, written after the tile’s (x, y)), what a terrain id resolves to, and which tile looks there are (MapFormat). Every problem is reported together, each with its line and column.

The look is kept beside the tiles, for a skin to paint them by; the rules never need it. As a format (ADR-0007): MapText.

Structs§

GridMap
A map read from a .map file: its tiles and features, the legend it was written with (for printing it back) and its look.
Legend
A map’s legend: tile character → terrain id as written, and what each resolved to.
MapFormat
What a game’s maps may be: the tile looks there are, and how big a map may be. Build it with MapFormat::new (ADR-0039).
MapLook
How a map looks, as far as its file says: which pictures a skin that has pictures paints its terrain with, and in which light. A skin without them ignores it. Look data only: the rules never see it.
MapText
The .map format (map, .map) of a game’s maps, read as parse says: the game’s MapFormat, what a legend’s terrain id resolves to, and its features F.

Enums§

NoFeature
The feature of a game whose maps have none.

Constants§

DEFAULT_LIGHT
The light of a map that names none.
DEFAULT_TILES
The tile look of a map that names none.
SEPARATOR
The line separating the RON header from the tile rows.

Traits§

MapFeature
A game’s tile feature, as written in a map header after the tile’s (x, y) (a shop, a chest, a sign): the hook through which a game adds its own things to the format.

Functions§

column_number
1-based column number of 0-based char index i.
header_lines
The header lines of map source: every line before the separator (all of them if it has none).
header_position
1-based line and column of the first needle in the header lines.
legend_position
1-based line and column of legend entry c in the header lines: the quoted character if found, else the terrain id string, else the start.
line_number
1-based line number of 0-based line index i.
parse
Parses map source (errors attributed to file), resolving legend terrain ids with terrain. Reports every problem with its line and column.
print
Prints map in .map format: its look only if it isn’t the look of a map that names none. None if a tile’s terrain has no character in the legend. Parsing the text gives map back.