palettepick

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: 8 Imported by: 0

Documentation

Overview

Package palettepick resolves which TA / TA: Kingdoms palette should be used to render a given GAF.

Total Annihilation ships a single global palette (palettes/palette.pal) and every GAF in the install renders against it. TA: Kingdoms reuses the GAF container format but splits the palette out by asset: interface GAFs ship alongside a same-name .pcx whose embedded 256-color table is the GAF's palette, while unit/feature GAFs use a side-specific palette (one of aramon / taros / veruna / zhon for the base game, plus aiden / creon from the Iron Plague expansion).

Resolve performs the lookup in the order kbot considers most reliable:

  1. Caller-supplied override path (e.g. from a UI selector or --palette flag).
  2. Same-name .pcx adjacent to the GAF (TAK's documented convention).
  3. Same-base-name .pal under palettes/ (covers oddities like palettes/<gafname>.pal).
  4. Side prefix heuristic on the GAF basename — ara*/tar*/ver*/zon*/aid*/cre* map to the four kingdoms + the two Iron Plague factions.
  5. palettes/palette.pal from the VFS (matches what TA shipped).
  6. The embedded TA palette as a last-resort fallback.

Resolve never returns a nil palette: it always at least surfaces the embedded fallback.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	// Path is the VFS path (empty for the embedded sentinel).
	Path string
	// Label is the short human-readable name.
	Label string
	// Source is the lookup category this candidate would be classified as.
	Source Source
}

Candidate is a labelled palette source the UI can offer to the user. It describes a palette without loading it.

func Candidates

func Candidates(vfs VFS, gafPath string) []Candidate

Candidates returns the full menu of palettes that make sense for gafPath: the auto-resolved default first, then every available palettes/*.{pal,pcx} the VFS exposes, ending with the embedded fallback. The list is suitable for populating a palette picker dropdown.

Auto-resolution failures don't propagate — if the auto pick errors out, it's simply omitted from the menu (the embedded sentinel is always present).

type Result

type Result struct {
	Palette *gaf.Palette
	Source  Source
	// Path is the VFS path the palette came from, or empty for the embedded
	// fallback. For SourceSidecarPCX it's the .pcx that supplied the palette;
	// for SourceSidePalette it's e.g. "palettes/aramon.pcx".
	Path string
	// Label is a short human-readable description suitable for surfacing in
	// the UI (e.g. "aramon", "actionbuttons.pcx", "palette.pal").
	Label string
}

Result captures the palette plus enough provenance for diagnostics, cache keys, and UI labels.

func Resolve

func Resolve(vfs VFS, gafPath, override string) (Result, error)

Resolve returns the palette that should be used to render gafPath. If override is non-empty it is loaded directly (and failures bubble up). A caller passing override == "" gets the documented auto-detection chain.

vfs may be nil — in that case auto-detection skips every VFS-based step and falls back to the embedded palette.

type Source

type Source string

Source identifies which lookup step produced the resolved palette. The strings are stable and short so they can be embedded in cache keys.

const (
	SourceOverride    Source = "override"
	SourceSidecarPCX  Source = "sidecar-pcx"
	SourceSidecarPAL  Source = "sidecar-pal"
	SourceSidePalette Source = "side"
	SourceGlobal      Source = "global"
	SourceEmbedded    Source = "embedded"
)

func (Source) String

func (s Source) String() string

String returns the Source as a stable identifier for cache keys / logs.

type VFS

type VFS interface {
	ReadFile(path string) ([]byte, error)
}

VFS is the subset of a virtual filesystem the resolver needs. Both the explorer/MCP VFS and a simple on-disk reader can satisfy it.

Jump to

Keyboard shortcuts

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