Documentation
¶
Overview ¶
Package game defines the plugin interface for puzzle games.
Index ¶
- Constants
- Variables
- func BorderChar(ch string, colors GridBorderColors, solved, highlight bool) string
- func ComposeGameView(title, primary string, secondary ...string) string
- func ComposeGameViewRows(title, primary string, rows ...SecondaryRow) string
- func ConflictBG() color.Color
- func ConflictFG() color.Color
- func CursorBG() color.Color
- func CursorFG() color.Color
- func CursorSolvedStyle() lipgloss.Style
- func CursorStyle() lipgloss.Style
- func DebugHeader(title string, rows [][2]string) string
- func DebugTable(heading string, headers []string, rows [][]string) string
- func DynamicGridBridgeOnCrosshairAxis(cursor Cursor, bridge DynamicGridBridge) bool
- func DynamicGridOrigin(termW, termH int, fullView, title, grid string) (x, y int)
- func DynamicGridScreenToCell(metrics DynamicGridMetrics, originX, originY, screenX, screenY int, ...) (col, row int, ok bool)
- func HBorderRow(w, cursorX, cellWidth int, left, right string, colors GridBorderColors, ...) string
- func HasPrintAdapter(gameType string) bool
- func IsNilPrintPayload(payload any) bool
- func NormalizeName(s string) string
- func RegisterPrintAdapter(adapter PrintAdapter)
- func RenderDynamicGrid(spec DynamicGridSpec) string
- func SameColor(left, right color.Color) bool
- func SolvedFG() color.Color
- func StatusBarStyle() lipgloss.Style
- func TitleBarView(gameName, modeName string, solved bool) string
- type BaseMode
- type CancellableSeededSpawner
- type CancellableSpawner
- type Category
- type Cursor
- type CursorKeyMap
- type Definition
- type DynamicGridBridge
- type DynamicGridBridgeKind
- type DynamicGridMetrics
- type DynamicGridSpec
- type Gamer
- type GridBorderColors
- type HelpToggleMsg
- type Mode
- type PrintAdapter
- type SecondaryRow
- type SeededSpawner
- type SpawnCompleteMsg
- type Spawner
Constants ¶
const ( CursorLeft = "\u25b8" // ▸ CursorRight = "\u25c2" // ◂ )
Bracket markers for cursor identification. These are prepended/appended to cell content so the cursor is identifiable independent of BG contrast.
const DynamicGridCellWidth = 3
Variables ¶
var DefaultCursorKeyMap = CursorKeyMap{ Up: key.NewBinding( key.WithKeys("k", "up", "w"), key.WithHelp("↑/w/k", "Up"), ), Down: key.NewBinding( key.WithKeys("j", "down", "s"), key.WithHelp("↓/s/j", "Down"), ), Left: key.NewBinding( key.WithKeys("h", "left", "a"), key.WithHelp("←/a/h", "Left"), ), Right: key.NewBinding( key.WithKeys("l", "right", "d"), key.WithHelp("→/d/l", "Right"), ), }
DefaultCursorKeyMap provides the standard cursor movement bindings.
Functions ¶
func BorderChar ¶ added in v1.4.0
func BorderChar(ch string, colors GridBorderColors, solved, highlight bool) string
BorderChar renders a single border character with optional crosshair highlighting.
func ComposeGameView ¶ added in v1.6.0
ComposeGameView joins title + primary content + optional secondary rows. Secondary rows are width-anchored to primary so long help/info text wraps instead of widening the full layout and shifting centered views.
func ComposeGameViewRows ¶ added in v1.6.0
func ComposeGameViewRows(title, primary string, rows ...SecondaryRow) string
ComposeGameViewRows joins title + primary content + optional secondary rows. Secondary rows are rendered at 150% of primary width to reduce wrapping. If variants are provided for a row, the row reserves the max wrapped height across the variants and current value to avoid height jitter.
func ConflictBG ¶ added in v1.4.0
func ConflictFG ¶ added in v1.4.0
func CursorSolvedStyle ¶ added in v1.3.0
CursorSolvedStyle highlights the cursor position on a solved grid.
func CursorStyle ¶ added in v1.4.0
CursorStyle highlights the cursor position with an accent background.
func DebugHeader ¶
DebugHeader returns the markdown heading and property table header for debug info. rows is a list of [key, value] pairs for the "Game State" table.
func DebugTable ¶
DebugTable returns a markdown table section with a heading and arbitrary columns. headers is the column names, rows is a list of row values.
func DynamicGridBridgeOnCrosshairAxis ¶ added in v1.8.0
func DynamicGridBridgeOnCrosshairAxis(cursor Cursor, bridge DynamicGridBridge) bool
DynamicGridBridgeOnCrosshairAxis reports whether a bridge should be tinted by a row/column crosshair for the given cursor position.
func DynamicGridOrigin ¶ added in v1.7.0
func DynamicGridScreenToCell ¶ added in v1.7.0
func DynamicGridScreenToCell( metrics DynamicGridMetrics, originX, originY, screenX, screenY int, includeSeparators bool, ) (col, row int, ok bool)
func HBorderRow ¶ added in v1.4.0
func HBorderRow(w, cursorX, cellWidth int, left, right string, colors GridBorderColors, solved bool) string
HBorderRow builds a horizontal border row (top or bottom) with per-column crosshair highlighting. cellWidth is the visual width of each cell.
func HasPrintAdapter ¶ added in v1.7.0
func IsNilPrintPayload ¶ added in v1.7.0
func NormalizeName ¶ added in v1.7.0
NormalizeName lowercases and replaces hyphens/underscores with spaces for fuzzy matching of CLI arguments to game names and aliases.
func RegisterPrintAdapter ¶ added in v1.7.0
func RegisterPrintAdapter(adapter PrintAdapter)
func RenderDynamicGrid ¶ added in v1.7.0
func RenderDynamicGrid(spec DynamicGridSpec) string
func SameColor ¶ added in v1.8.0
SameColor reports whether two colors resolve to identical RGBA values.
func StatusBarStyle ¶ added in v1.4.0
StatusBarStyle returns the shared style for the status/help bar below each puzzle grid.
func TitleBarView ¶
TitleBarView renders a title bar with the game name, mode name, and optional solved badge.
Types ¶
type BaseMode ¶
type BaseMode struct {
// contains filtered or unexported fields
}
BaseMode provides the common title/description fields and the three Mode-interface methods so that concrete mode structs can embed it instead of duplicating boilerplate.
func NewBaseMode ¶
func (BaseMode) Description ¶
func (BaseMode) FilterValue ¶
type CancellableSeededSpawner ¶ added in v1.6.0
type CancellableSeededSpawner interface {
SeededSpawner
SpawnSeededContext(ctx context.Context, rng *rand.Rand) (Gamer, error)
}
CancellableSeededSpawner optionally supports context-aware deterministic generation so callers can cancel long-running seeded spawn work.
type CancellableSpawner ¶ added in v1.6.0
CancellableSpawner optionally supports context-aware generation so callers can cancel long-running spawn work.
type Category ¶
type Category struct {
Name string
Desc string
Modes []list.Item
Help string // embedded help.md content rendered in "How to Play"
}
Category groups related game modes under a heading in the menu.
func (Category) Description ¶
func (Category) FilterValue ¶
type Cursor ¶
type Cursor struct {
X, Y int
}
func (*Cursor) Move ¶
func (c *Cursor) Move(keys CursorKeyMap, msg tea.KeyPressMsg, maxX, maxY int) bool
Move updates the cursor position based on the key message and bounds. Returns true if the cursor moved.
type CursorKeyMap ¶
CursorKeyMap defines the shared cursor movement key bindings.
type Definition ¶ added in v1.7.0
type Definition struct {
Name string
Description string
Aliases []string
Modes []list.Item
DailyModes []list.Item
Help string
Import func([]byte) (Gamer, error)
}
Definition is the package-level metadata for a puzzle game.
func (Definition) Category ¶ added in v1.7.0
func (d Definition) Category() Category
type DynamicGridBridge ¶ added in v1.7.0
type DynamicGridBridgeKind ¶ added in v1.7.0
type DynamicGridBridgeKind int
const ( DynamicGridBridgeVertical DynamicGridBridgeKind = iota DynamicGridBridgeHorizontal DynamicGridBridgeJunction )
type DynamicGridMetrics ¶ added in v1.7.0
type DynamicGridSpec ¶ added in v1.7.0
type DynamicGridSpec struct {
Width int
Height int
CellWidth int
Solved bool
Colors *GridBorderColors
Cell func(x, y int) string
ZoneAt func(x, y int) int
HasVerticalEdge func(x, y int) bool
HasHorizontalEdge func(x, y int) bool
VerticalBridgeWidth func(x int) int
HorizontalBridgeHeight func(y int) int
ZoneFill func(zone int) color.Color
BridgeFill func(bridge DynamicGridBridge) color.Color
BridgeForeground func(bridge DynamicGridBridge) color.Color
BridgeBold func(bridge DynamicGridBridge) bool
VerticalBridgeText func(x, y int) string
HorizontalBridgeText func(x, y int) string
}
type Gamer ¶
type Gamer interface {
GetDebugInfo() string
GetFullHelp() [][]key.Binding
GetSave() ([]byte, error)
IsSolved() bool
Reset() Gamer
SetTitle(string) Gamer
Init() tea.Cmd
View() string
Update(msg tea.Msg) (Gamer, tea.Cmd)
}
Gamer is the interface that an active game instance must implement.
type GridBorderColors ¶ added in v1.4.0
type GridBorderColors struct {
BorderFG color.Color
BackgroundBG color.Color
CrosshairBG color.Color
SolvedBorderFG color.Color
SolvedBG color.Color
}
GridBorderColors holds the color configuration for a grid border with crosshair and solved-state highlighting.
func DefaultBorderColors ¶ added in v1.5.0
func DefaultBorderColors() GridBorderColors
DefaultBorderColors returns border colors from the active theme.
type HelpToggleMsg ¶
type HelpToggleMsg struct{ Show bool }
HelpToggleMsg is sent from the root model to games when the user toggles the full help display with Ctrl+H.
type PrintAdapter ¶ added in v1.7.0
type PrintAdapter = pdfexport.PrintAdapter
func LookupPrintAdapter ¶ added in v1.7.0
func LookupPrintAdapter(gameType string) (PrintAdapter, bool)
type SecondaryRow ¶ added in v1.6.0
SecondaryRow defines one auxiliary row below the main game grid. Variants can be provided to reserve the tallest wrapped height up-front and avoid layout shift when row content changes.
func StableRow ¶ added in v1.6.0
func StableRow(current string, variants ...string) SecondaryRow
func StaticRow ¶ added in v1.6.0
func StaticRow(row string) SecondaryRow
type SeededSpawner ¶ added in v1.3.0
SeededSpawner creates a new game instance using a deterministic RNG. This enables reproducible puzzle generation for daily puzzles.
type SpawnCompleteMsg ¶ added in v1.3.0
SpawnCompleteMsg is sent when an async Spawn() call finishes.