map2wxx

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

map2wxx

map2wxx is a map converter: it reads a hex map written by hmz2map and writes it as a Worldographer map (.wxx), using the wxx reader and writer. It isn't part of the campaign-map pipeline; it only consumes the map.

The map is decoded with hmz2map's own Go types, so the schema is hmz2map's. map2wxx reads nothing else: not the heightmap, the climate file, or the rivers file.

Status

The converter is being built in small steps:

  1. Colored blank hexes (v0.1.0): every hex is Worldographer's Blank terrain, with its background colored as map2png fills it. This checks the geometry.
  2. Rivers (v0.2.0): lines along hex edges (see Rivers), built with wxx's NewEdgePath (wxx#155).
  3. Terrain, as Worldographer tile types. Not yet written.

Usage

go run ./cmd/map2wxx [flags] <map.json>

Flags:

  • -output <file> is the .wxx file to write. Required.
  • -app <version> is the Worldographer application version to write, such as 2.07. The default, current, is the newest version wxx writes (xmlio.CurrentApp(), 2.08 with wxx v0.50.0-beta); -h shows which version that is. A version wxx doesn't write is an error.
  • -wetlands-as-land treats hexes with a marshes, swamps, or mangroves surface as land for rivers, as in map2png. The default is off: they count as water, so no river is drawn along their sides.
  • -version prints the version.

The command prints the time taken by each phase, the map size, the application version it wrote, and the river edges and paths it drew.

map2wxx has no border option: it converts whatever map it is given. For a map with a deep-ocean border, give it the map from hmz2map -border.

Input

The input must have schema_version 1 (hmz2map.SchemaVersion) and layout "flat-top, 0-based, odd columns down" (hmz2map.Layout); any other value is an error. It must be at least 2 × 2 (the smallest map wxx makes) and list columns × rows hexes, ordered by row, then column, with col and row matching each position. A landform, surface, biome, or depth outside the terrain model is an error, since it has no color. map2wxx doesn't otherwise validate the map; hmz2map did.

Output

The map is built with xmlio.NewMap, so it carries the defaults the chosen application version writes for File > New World/Kingdom map: flat projection, WORLD view level, the grid and numbering, the map key, and the eight map layers.

Geometry

The map is COLUMNS: flat-top hexes with odd columns pushed down half a hex, which is hmz2map's layout. So no coordinates are converted: hex (col, row) is tile [col][row], and Worldographer's column and row numbers are hmz2map's. A columns × rows map is columns tiles wide and rows tiles high.

Hexes

Every tile's terrain is Blank, the only entry in the terrain table. Its custom background color (@bgColor) is map2png.FillColor of the hex, with each 8-bit component divided by 255; alpha is 1.

Rivers

Rivers are built from the hexes' rivers lists as paths along hex edges, and each path is written as a Worldographer line.

Edges. map2wxx draws the same edges as map2png, by the same rules (see map2png's README):

  • Each edge is taken once, from the hex that lists it as its n, ne, or se side, or as its s, sw, or nw side when the hex across is off the map.
  • An edge is drawn only if neither of its hexes is wet: a salt-water or fresh-water landform, or a marshes, swamps, or mangroves surface. So no river runs along a coast or a lake shore. A neighbor off the map is not wet.
  • An edge runs from its upstream vertex to its downstream one, the hex's flow corner, which must be one of the side's two corners.

Paths. Edges are joined into paths, each of one size class:

  • An edge continues the path of an edge flowing into its upstream vertex when that edge is the same size and has the largest drainage of the edges flowing in there. Ties go to the edge listed first.
  • Every other edge starts a new path. So at a confluence the main stem runs through and the tributary ends, and a path breaks where a river changes size class (the next one starts at the same vertex).
  • Two edges flowing out of one vertex is an error: rivers don't split.

Drawing. Each path is one line, made by wxx's NewEdgePath through the path's corners, on the Above Terrain layer, above the tiles whose background colors show the terrain, as lines drawn in the app are. NewEdgePath checks that each pair of corners next to each other is the two ends of one hex edge. Lines are wxx's default color, opaque blue, with no fill. Its width comes from its size class, but for now every size gets the width of a line drawn in the app (strokeWidth 0.05), until rivers display as expected. Mouths like map2png's are left out.

A vertex is named by one of the hexes that share it: a column, a row, and one of that hex's corners. The tool compares vertices by position, so the three names a vertex can have are the same vertex.

On the Panama map, 4,093 edges are drawn (2,724 streams, 1,225 rivers, 144 great rivers), matching map2png, with 358 skipped along shores and 153 with no land; they make 548 paths (411 streams, 116 rivers, 21 great rivers), with 235 confluences.

Testing

go test ./...

The tests check that every pair of hexes hmz2map calls neighbors is one hex apart on Worldographer's grid, that every tile is Blank with its map2png color after a write and a read in each version wxx writes, that bad input and an unsupported -app are errors, that the hexes sharing a corner name the same vertex, that shore and water edges are skipped, and that paths run through confluences and break at size changes.

License

MIT; see LICENSE.

Documentation

Overview

Package map2wxx converts an hmz2map hex map into a Worldographer map.

Index

Constants

View Source
const AppCurrent = "current"

AppCurrent is the -app value that names the newest application version wxx writes (xmlio.CurrentApp).

View Source
const RiverLayer = "Above Terrain"

RiverLayer is the map layer rivers are drawn on: above the tiles, whose background colors show the terrain, as Worldographer's own lines are.

Variables

This section is empty.

Functions

func Check

func Check(m *hmz2map.Map) error

Check returns an error if m is not a map map2wxx can convert: the wrong schema version or layout, or a hex list that doesn't match the map's size.

func CheckApp

func CheckApp(app string) error

CheckApp returns an error if wxx doesn't write application version app.

func ResolveApp

func ResolveApp(app string) string

ResolveApp returns the application version an -app value names: app itself, or xmlio.CurrentApp() for AppCurrent. Whether wxx writes that version is checked by Convert.

func RiverWidth added in v0.2.0

func RiverWidth(size hmz2map.RiverSize) (float64, error)

RiverWidth returns the stroke width of a river of the given size, in the units of a shape's @strokeWidth. Every size is drawn at the width of a line drawn in the app (0.05) until rivers display as expected; the size is passed through so widths can differ later without changing the paths.

func Rivers added in v0.2.0

func Rivers(m *hmz2map.Map, wetlandsAsLand bool) ([]RiverPath, RiverReport, error)

Rivers returns m's rivers as paths, with a report of what was drawn.

func Version

func Version() semver.Version

Types

type Options added in v0.2.0

type Options struct {
	// App is the application version whose new-map defaults are used: a
	// registered version such as "2.08" (see ResolveApp).
	App string
	// WetlandsAsLand treats marshes, swamps, and mangroves as land for
	// rivers, as map2png's -wetlands-as-land does.
	WetlandsAsLand bool
}

Options configures Convert.

type RiverEdge added in v0.2.0

type RiverEdge struct {
	From, To    Vertex
	DrainageKm2 float64
	Size        hmz2map.RiverSize
}

RiverEdge is a hex side that a river is drawn along, from its upstream vertex to its downstream one.

func RiverEdges added in v0.2.0

func RiverEdges(m *hmz2map.Map, wetlandsAsLand bool, rep *RiverReport) ([]RiverEdge, error)

RiverEdges returns the river edges to draw, as map2png draws them: each edge once, and only between two land hexes (or a land hex and the map's edge), so no river runs along a coast or lake shore.

An edge is taken from the hex that owns it, by its n, ne, or se side, or by its s, sw, or nw side when the hex across is off the map.

type RiverPath added in v0.2.0

type RiverPath struct {
	Size     hmz2map.RiverSize
	Vertices []Vertex
}

RiverPath is a run of edges of one size class, drawn as one shape. Vertices are in flow order; a path of n edges has n + 1 vertices.

func RiverPaths added in v0.2.0

func RiverPaths(edges []RiverEdge, rep *RiverReport) ([]RiverPath, error)

RiverPaths joins edges into paths. An edge continues the path of the edge flowing into its upstream vertex when that edge is the same size and is the largest (by drainage) of the edges flowing in there; every other edge starts a path. So a tributary ends where it joins, the main stem runs through, and a path breaks where the size class changes.

It is an error for two edges to flow out of one vertex: rivers don't split.

type RiverReport added in v0.2.0

type RiverReport struct {
	Edges       map[hmz2map.RiverSize]int // edges drawn, by size
	ShoreEdges  int                       // skipped: a wet hex on one side, land on the other
	WaterEdges  int                       // skipped: no land on either side
	Paths       map[hmz2map.RiverSize]int // paths, by size
	Confluences int                       // vertices where two or more drawn edges flow in
}

RiverReport counts what RiverEdges and RiverPaths did.

func Convert

func Convert(m *hmz2map.Map, opt Options) (*wxx.Map_t, RiverReport, error)

Convert returns m as a Worldographer map with the new-map defaults of application version opt.App, with a report of the rivers drawn.

The Worldographer map is COLUMNS, which is hmz2map's odd-q layout: hex (col, row) is tile [col][row]. Every tile is Blank, with its background colored as map2png fills the hex. Each river path (see Rivers) is a line along hex edges on RiverLayer, RiverWidth wide.

type Vertex added in v0.2.0

type Vertex struct {
	Col, Row int
	Corner   hmz2map.Corner
}

Vertex is a hex corner, named by one of the (up to three) hexes that share it. The hex may be off the map.

Directories

Path Synopsis
cmd
map2wxx command
Command map2wxx converts an hmz2map hex map into a Worldographer map.
Command map2wxx converts an hmz2map hex map into a Worldographer map.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL