dipmap

package
v0.0.0-...-207b9fc Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package dipmap renders Diplomacy board images. It converts godip's SVG map assets to PNG and supports highlighting a neighbourhood of provinces around a target territory to radius n (BFS over godip's Graph.Edges()).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Highlight

func Highlight(svg []byte, provinces []string) ([]byte, error)

Highlight injects coloured copies of named provinces into the SVG's "highlights" layer (id="highlights"). Each province in the list receives a distinct colour from highlightPalette; colours cycle when the list is longer than the palette. Province names are matched case-insensitively against inkscape:label attributes. Provinces not found in the SVG are silently skipped. The original province elements are left unchanged.

func LoadSVG

func LoadSVG(_ EngineState) ([]byte, error)

LoadSVG returns the SVG map bytes from the embedded asset. It is used as the svgFn in bot.Dispatcher for the territory-zoom rendering path.

func Neighborhood

func Neighborhood(g Graph, territory string, n int) []string

Neighborhood returns all province names reachable within n hops from territory in g. n=0 returns only the territory itself; n=1 returns the territory plus all directly adjacent provinces; and so on. The result slice has no guaranteed order, but territory is always included.

func Overlay

func Overlay(svg []byte, units map[string]Unit) ([]byte, error)

Overlay activates the pre-placed unit placeholder glyphs in the SVG for each province in units. It sets fill to the nation colour and stroke to "#ffffff" on the matching <g id="unit-<province>-<type>"> element. Both attributes cascade to the child <rect> via SVG inheritance, making the coloured unit box visible. Hidden glyphs carry fill="none" stroke="none" so they are transparent; tdewolff/canvas ignores display:none.

Province names in units should use godip's lowercase convention (e.g. "vie", "stp/nc"). The "/" separator in coastal names is normalised to "-" to form the element ID (e.g. "unit-stp-nc-fleet").

Provinces not found in the SVG are logged to stderr and skipped silently. An empty units map returns the original SVG unchanged.

func Render

func Render(_ EngineState) ([]byte, error)

Render converts the classical SVG map to a PNG byte slice using the embedded map.svg with pre-placed unit placeholder glyphs.

func RenderZoomed

func RenderZoomed(state EngineState, svg []byte, provinces []string) ([]byte, error)

RenderZoomed renders a zoomed PNG of the given provinces from the highlighted SVG. It computes the union bounding box of the listed province shapes, adds 5% diagonal padding, rewrites the SVG viewBox to crop to that region, and rasterises at 800 px wide preserving aspect ratio. If provinces is empty the full canvas viewBox is used.

func SVGToPNG

func SVGToPNG(svg []byte) ([]byte, error)

SVGToPNG converts SVG bytes to a lossless PNG using tdewolff/canvas. The embedded LibreBaskerville-Bold font is registered on first call so that the SVG names layer renders with the correct typeface.

Types

type EmptyGraph

type EmptyGraph struct{}

EmptyGraph is a Graph with no edges; every province is isolated. It is used as a default when no real board graph is available.

func (EmptyGraph) Edges

func (EmptyGraph) Edges(_ string) []string

Edges returns nil for every territory.

type EngineState

type EngineState interface {
	Dump() ([]byte, error)
}

EngineState is the minimal engine interface needed for map rendering. engine.Engine satisfies this interface.

type Graph

type Graph interface {
	// Edges returns the names of all provinces directly adjacent to territory.
	Edges(territory string) []string
}

Graph is the adjacency interface used for BFS neighbourhood queries. Province names are the string keys returned by Edges.

type Unit

type Unit struct {
	Type   string
	Nation string
}

Unit describes a piece on the board: its type ("Army" or "Fleet") and the nation that controls it (e.g. "England").

Jump to

Keyboard shortcuts

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