tntpreview

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package tntpreview composites the "preview" view of a Total Annihilation TNT map: the base tile-grid render with feature sprites painted on top and numbered start-position markers drawn from the sister .ota.

It is shared between the kbot CLI (kbot tnt preview) and the MCP server (tnt_preview tool). All inputs are explicit parameters — the package has no global state and reads no on-disk paths directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// SchemaIndex picks which schema's StartPos entries get drawn (0-based).
	// Values out of range fall back to schema 0 — the historical default,
	// equivalent to the CLI / MCP behaviour before the per-schema selector
	// existed.
	SchemaIndex int
}

Options tunes Compose. The zero value is the previous default: Schema 0, auto-resolved sister .ota.

type StartPos

type StartPos struct {
	Number int
	X, Y   int
}

StartPos holds one player start position in map pixel coordinates.

func ExtractStartPositions

func ExtractStartPositions(otaText string) []StartPos

ExtractStartPositions pulls Schema 0's StartPos entries — kept for callers that don't care which schema they get. Equivalent to ExtractStartPositionsForSchema(otaText, 0).

func ExtractStartPositionsForSchema

func ExtractStartPositionsForSchema(otaText string, schemaIndex int) []StartPos

ExtractStartPositionsForSchema pulls the StartPos entries out of an .ota's GlobalHeader / Schema <n> / specials section. When the requested schema doesn't exist (or the .ota's schema list is empty), returns nil — drawing zero markers is the right behaviour rather than silently falling back to a different schema's positions.

type Stats

type Stats struct {
	SpritesPainted int
	SpritesMissing int
	StartPositions int
	HasSisterOTA   bool
}

Stats summarises what the preview compositor did so callers can surface counts to users / MCP results.

func Compose

func Compose(base *image.RGBA, m *tnt.Map, features []tnt.Feature, vfs *filesystem.VirtualFileSystem, spritePalette *gaf.Palette, tntBasename, otaText string) (Stats, error)

Compose paints feature sprites and start position markers onto base using the default Options (Schema 0). Retained for callers that don't care about which schema they get.

func ComposeTAK

func ComposeTAK(base *image.RGBA, m *tnt.Map, features []tnt.Feature, vfs *filesystem.VirtualFileSystem, spritePalette *gaf.Palette) (Stats, error)

ComposeTAK paints TA: Kingdoms feature sprites onto base, which must be the map's full-resolution terrain render (see tnt.Map.RenderTAKTerrain). Each placement carries a full-resolution terrain pixel (its DataUnit cell scaled by 16), so the sprite is anchored at that coordinate using the GAF frame's hotspot (falling back to bottom-centre when the frame carries no origin).

vfs resolves feature TDFs (features/**.tdf) and their GAFs (anims/*.gaf); spritePalette is the map's per-kingdom feature palette used to decode frames. Placements are walked in grid (top-to-bottom) order so nearer features paint over farther ones.

func ComposeWith

func ComposeWith(base *image.RGBA, m *tnt.Map, features []tnt.Feature, vfs *filesystem.VirtualFileSystem, spritePalette *gaf.Palette, tntBasename, otaText string, opts Options) (Stats, error)

ComposeWith paints feature sprites and start position markers onto base using the supplied Options.

vfs is required for sprite resolution. When otaText is empty, the sister .ota is looked up in vfs by tntBasename (the filename without extension). spritePalette is used to decode GAF frames.

Jump to

Keyboard shortcuts

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