Documentation
¶
Overview ¶
Package tui renders a battle for a terminal.
Everything here is a pure function returning a string. Nothing reads input, writes output or holds state, which is what makes the rendering testable and keeps the client a renderer rather than a second copy of the rules.
The event lines are built from the event alone, never from the battle. That constraint is deliberate: if a line cannot be drawn from the log, the log is missing something, and a renderer that reaches into the engine to fill the gap is one that will drift from it.
Index ¶
- func Aims(fight *battle.Battle, option battle.Option, tags map[string]string, ...) string
- func Board(fight *battle.Battle, tags map[string]string) string
- func Detail(lang i18n.Lang, declared skill.Skill, shapes *pattern.Book, kinds *status.Book) string
- func DetailPassives(lang i18n.Lang, name string, held []passive.Passive, kinds *status.Book) string
- func DetailStatus(lang i18n.Lang, kind status.Kind) string
- func DetailStatuses(lang i18n.Lang, groups []status.Group) string
- func Effects(unit *battle.Unit) string
- func ElementCode(member element.Element) string
- func Extras(declared skill.Skill) string
- func HealthBar(current, max int64) string
- func Line(event battle.Event, tags, glosses map[string]string) string
- func Log(events []battle.Event, tags, glosses map[string]string) string
- func Menu(fight *battle.Battle, prompt *battle.Prompt, tags map[string]string) string
- func Names(units []*battle.Unit) map[string]string
- func NamesFromLog(events []battle.Event) map[string]string
- func Order(queue *atb.Queue, tags map[string]string, count int) string
- func Roster(lang i18n.Lang, fight *battle.Battle, tags map[string]string) string
- func RosterFor(lang i18n.Lang, fight *battle.Battle, tags map[string]string, width int, ...) string
- func RosterIsWide(width int) bool
- func RosterWide(lang i18n.Lang, fight *battle.Battle, tags map[string]string, ink ElementInk) string
- func Summary(events []battle.Event, tags map[string]string, names map[string]string) string
- func Tags(units []*battle.Unit) map[string]string
- func TagsFromLog(events []battle.Event) map[string]string
- type ElementInk
- type Tally
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Aims ¶
func Aims(fight *battle.Battle, option battle.Option, tags map[string]string, caster hex.Side) string
Aims lists the cells a chosen skill may be pointed at, with who is standing there and what the shape would catch.
caster is the half of the board the unit about to cast stands on, and it is the frame the shape's steps are read in — not the side the aim lands on. It is a parameter because this draws for whoever is being asked: a shape spreads away from its caster, so drawing an enemy's aim in the ally's frame would list cells the resolution does not touch. → package pattern's doc, TODO.md ENG-012.
func Detail ¶
Detail is a description as a block a prompt can print: the skill's name, then its sentences, indented under a rule.
The sentences themselves are i18n.Lang.Describe. This package holds only the framing, because the framing is what belongs to a screen: the menu above it is a table of figures, and a paragraph dropped into one without a break reads as another row that has lost its columns.
The language is a parameter rather than a constant even though the caller passes Vietnamese today. The rest of this package is English and stays that way until the whole battle screen is translated in one piece; this block is the one part read to *decide*, so it is worth being legible before the rest catches up, and the mixed screen is a stated cost. Making it a parameter is what keeps that a one-word decision rather than a rewrite.
func DetailPassives ¶
DetailPassives is the traits a unit is carrying, as one block. A unit with none says so rather than printing an empty frame, because a blank answer to a question the player asked reads as the tool failing to answer it.
The heading asks Lang for the name rather than reading passive.Passive.Name, and that is the same reading Detail gives a skill twelve lines above: a data name is authored once and in Vietnamese, so Lang.PassiveName answers nothing in English and the row is the id, which is the data's own name for itself. Reading the field raw put a Vietnamese word on an English screen — latent while the only caller hands this i18n.Vi, and a leak the day cmd/hexarena honours --lang, at which point trait headings would keep their names while the skill headings beside them dropped theirs.
The guard is the one all three blocks in this file use — non-empty, and not the id said twice. PassiveName has no fallback to the compiled tables, so only a name authored as its own id reaches the second half and nothing refuses one; a heading reading "blood_thirst · blood_thirst" is the same defect Detail's guard exists to prevent, and having the three agree by inspection is what this whole change is about.
func DetailStatus ¶
DetailStatus is one timed effect as a block a prompt can print, with the caveat under it.
The caveat is here rather than in the sentence, because it is true of every status and a reader asking about one is asking once: repeating "a trait may change this" fifteen times down a reference trains a reader to stop reading it.
func DetailStatuses ¶
DetailStatuses is the whole reference: every declared status under its category, and the caveat once at the foot.
Grouped rather than listed flat, because the grouping is the half a flat list cannot carry: a skill that strips a stat_debuff and a dot is unreadable to somebody who cannot see which statuses those two words cover.
func ElementCode ¶ added in v0.5.2
ElementCode is how the roster's element column names one element.
⚠️ **It is an id shortened, never a word translated**, and that is the whole reason it may be the same in both languages. internal/i18n's own doc comment keeps element ids as they are in Vietnamese and in English, because they are what an author types and what the data files store; the gloss table beside it puts the Vietnamese *next to* the id — `grass/electric <cỏ/điện>` — rather than instead of it, precisely so the id stays readable. A code is the same id with its tail cut off, so `gra` is still `grass` to a reader of either language, where a code derived from a translation would name a different word on each.
The column drew the names in full until this, and they cost fifteen cells to say what seven now say. What the colour adds is emphasis and never meaning: the goldens are recorded under NO_COLOR, so the code alone has to tell every element apart — which TestEveryElementDrawsItsOwnCodeWithNoColourAtAll holds.
A value the enum does not have is drawn whole rather than shortened. Nothing in the book can produce one, and the alternative is worse than an overlong cell: `element(12)` cut to three letters is `ele`, which is electric's code, so the unreadable case would quietly name a real element.
func Line ¶
Line renders one event, using nothing but the event.
glosses is data id -> display name, for the skill, status and trait ids the line prints — i18n.Lang.LogGlosses is what builds one. It is a caller-supplied map for exactly the reason tags and Summary's names are: the event lines are built from the event alone, so this package may not be handed books, a battle or a language, and a name is a fact about the reader rather than about what happened. **A nil or empty map reproduces the line byte for byte**, which is both what English is (a data id is shown as the data writes it) and what a replay drawn without books is, and it is the property the goldens hold.
Every occurrence is glossed rather than the first mention: a log is read in pieces, scrolled and frozen at a frame, so "the first mention" is a row a reader may never have on screen.
func Log ¶
Log renders a run of events. glosses is Line's, and a nil one renders exactly what this function rendered before there was a third parameter.
func Menu ¶
Menu lists what the acting unit may do. Unavailable options are shown with their reason rather than hidden, because a player deciding what to do needs to know a skill exists and is two turns away.
func Names ¶
Names maps unit ids to their display names, for a summary rendered from a log that carries ids rather than names.
func NamesFromLog ¶
NamesFromLog reads the display names out of a log's opening records, so a saved battle renders with the names it was fought under.
func Roster ¶
Roster lists every unit with its health, tempo and active effects.
The language is a parameter for the reason Detail's is: the column headings are words rather than ids, and a heading nobody can read is a column nobody can use. The rest of the table is ids and figures, which is why this was English for as long as it was.
⚠️ **The heading used to carry a rule as well as a label** — that an effect with no countdown beside it is permanent — and it does not any more. The rule itself has not gone: it is stated on the statuses catalogue, which is the screen a reader goes to when they want to know what an effect is and how long it lasts, and which both clients carry on their menu. → screen.StatusesScreen, i18n.StatusesNoCountdown.
This is the narrow table, and it is what the program promises to draw: every window at all is at least MinWidth, and this fits that. RosterWide is the same table with three more columns and is only offered where there is room for it.
func RosterFor ¶ added in v0.5.1
func RosterFor(lang i18n.Lang, fight *battle.Battle, tags map[string]string, width int, ink ElementInk) string
RosterFor draws whichever of the two a window of this width has room for.
It exists so that a caller holding a width does not write the comparison out itself — one declaration of the rule, as RosterIsWide's comment says.
func RosterIsWide ¶ added in v0.5.1
RosterIsWide reports whether a window this wide has room for the wide table.
⚠️ **This is the one declaration of that rule**, and every caller asks it rather than comparing a width to a number of its own. A second comparison is a second copy of an arithmetic that moves whenever a column does.
⚠️ **It must be asked at DRAW time, not when a battle is read.** A live screen takes its reading when a turn arrives, which on a ninety-second allowance can be a long while before the next one; a player who resizes in between would otherwise keep the layout chosen for a window they no longer have. That is why internal/screen renders both tables into its reading and picks here.
func RosterWide ¶ added in v0.5.1
func RosterWide(lang i18n.Lang, fight *battle.Battle, tags map[string]string, ink ElementInk) string
RosterWide is Roster with the three columns a player needs to decide who to hit first: the unit's element, its attack and its defence.
⚠️ **It is an addition and never a replacement.** The narrow table is what ships in a window at the floor, unchanged to the byte, because the three columns cost more room than the floor has: nothing here is cut to make space for them, so a reader of a narrow terminal loses nothing they had. What decides between the two is the window, and RosterIsWide is the whole of that rule.
The three sit **after** the tempo and before the effects, so the narrow row is this row's own prefix: the columns a reader already knows stay where they were and the new ones arrive in a block, rather than the whole table shifting.
The ink is how the element column is coloured, and a nil one draws it plain. → ElementInk for why this package takes a function rather than a palette.
Types ¶
type ElementInk ¶ added in v0.5.2
ElementInk draws one element's code in whatever ink its caller has.
⚠️ **A function rather than a palette, because this package may not have one.** internal/tui renders a battle as text and knows nothing about styles, terminals or lipgloss; the screen layer owns the palette and the one table of element colours in the program. Handing that table in as a *table* would make this package depend on the styling library, and re-deriving the colours here would be a second copy of a table whose entries were chosen with reasons. So the caller keeps the ink and this package keeps the table — the same division Detail already makes with a language it cannot know.
⚠️ **The ink is applied to the code alone and never to the padding**, which is what elementCell relies on to measure the column: the plain width of a cell has to be knowable without asking what the ink did to it.
type Tally ¶
type Tally struct {
ID string
Name string
Side hex.Side
Turns int
Dealt int64
Taken int64
Ticked int64
Healed int64
Hits int
Misses int
Walled int
Kills int
Fell bool
}
Tally is what one unit did and had done to it, counted from the event log.