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 ¶
- func Highlight(svg []byte, provinces []string) ([]byte, error)
- func LoadSVG(_ EngineState) ([]byte, error)
- func Neighborhood(g Graph, territory string, n int) []string
- func Overlay(svg []byte, units map[string]Unit) ([]byte, error)
- func Render(_ EngineState) ([]byte, error)
- func RenderZoomed(state EngineState, svg []byte, provinces []string) ([]byte, error)
- func SVGToPNG(svg []byte) ([]byte, error)
- type EmptyGraph
- type EngineState
- type Graph
- type Unit
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Highlight ¶
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 ¶
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 ¶
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.
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 ¶
EngineState is the minimal engine interface needed for map rendering. engine.Engine satisfies this interface.