Documentation
¶
Overview ¶
Package screen is what every full-screen view in this repository's terminal clients needs, and none of what any one of them decides.
Two clients draw the same reference screens — the authoring tool (`cmd/hexforge-tui`) and the game client (`cmd/hexarena-tui`), which exists now and is what all of this was for — so what lives here is the screens themselves plus everything they are drawn out of: the palette, the floor a window has to clear, the row-drawing helpers every pane is built from, the six read-only references (the affinity chart and its rings, the elements, statuses, species, builds and traits listings) with their cursors and their keystrokes, the two describers, the multi-select, the skill listing and the form over it, the squad builder, the works catalogue with the add-a-work form over it — the seventh and last of the catalogues the game client offers — the played battle, which is the screen it needs most, and the **ban and pick**, which is the first screen here that only one client draws.
⚠️ **The ban and pick is the one screen whose vocabulary is declared twice, and it is here anyway.** A drafting room's reading holds a wire.Seat, a wire.DraftStep and a draft.Pick, and this package may not see any of the three — so DraftLive is declared here and the client maps into it, exactly as PlayLive is. What that bought is a screen with a **data column** held by two goldens rather than one; what it costs is a second spelling of the step, held by a walk in cmd/hexarena-tui. → draft.go's own head, which carries the three options and what each costs, and TestNoScreenImportsTheProtocol, which is the first mechanical statement of the import rule this package's whole shape rests on.
⚠️ **Not every screen here is read-only any more.** The skill listing writes `skills.json`, the squad builder writes `squads.json` and the works catalogue writes `origins.json`, all three through internal/forge, which is the one part of the module allowed to touch a real file. Nothing in this package opens one itself, and the golden under testdata is built from values for that reason: it loads the shipped books straight out of ../seed/data, with no temp copy anywhere near the bytes.
⚠️ **And the three that write only offer to when the client in front can.** Context.Authoring is that answer and it is consulted in one place per screen, so the keystrokes and the footer cannot disagree about what is on offer — a game client draws all three of these catalogues and authors none of them. See Context.Authoring for why nought is the read-only reading.
What it still excludes is everything a *client* decides. A screen is handed a Context, which holds nothing the client owns, and answers a keystroke with an Action — what it wants — so it never names a view, a menu entry or a way back: see action.go for why that vocabulary is six Kinds and no more, and for the two fields that grew instead of a seventh. The frame around a body, which screen it is showing and where Back goes are the client's, and a screen here may not ask.
⚠️ **And it may not see the protocol, which is now a TEST rather than three doc comments.** internal/wire, internal/draft, internal/socket and internal/room are refused by TestNoScreenImportsTheProtocol, an AST walk over this directory including its own test files. That rule is what the whole shape of this package rests on — it is why i18n.Lang.Refusal and i18n.Lang.Seat take a **name**, why PlayLive and DraftLive are declared here and mapped by the client, and why the lobby's three screens live in cmd/hexarena-tui — and until the ban and pick arrived nothing checked it.
It reads no environment and takes no decision from one. `Plain` answers whether colour would be noise, and the **binary** is what hands it the three inputs — reading `os.Getenv` is the binary's business, and a package two clients share may not have an opinion about which of them is running.
Index ¶
- Constants
- func Bar(barWidth int, value, limit int64) string
- func BudgetLine(c Context, budget forge.Budget) string
- func ChosenForm(character cast.Character, level int, chosen string) string
- func Clamp(value, low, high int) int
- func Clip(text string, room int) string
- func FieldValueRoom(width, labelWidth, spent int) int
- func FormArms(character cast.Character, level int) []progression.Stage
- func FormRow(c Context, character cast.Character, level int, chosen string) string
- func FormationSlots() []hex.Offset
- func IndexOf(values []string, want string) int
- func IsSaveKey(message tea.KeyPressMsg) bool
- func Marked(sentence string, names []string, mark func(string) string) string
- func NewInput(plain bool) textinput.Model
- func NextForm(character cast.Character, level int, chosen string) string
- func NumberField(plain bool, placeholder string) *textinput.Model
- func NumberKey(message tea.KeyPressMsg) bool
- func OptionRefusal(c Context, option battle.Option) string
- func Pad(text string, width int) string
- func PasteDigits(field *textinput.Model, text string) tea.Cmd
- func PasteInto(field *textinput.Model, text string) tea.Cmd
- func PasteText(text string) string
- func Plain(noColour, term, goos string) bool
- func PlayBodyRoom(height int) int
- func RankLabel(c Context, slot hex.Offset) string
- func SaveKeyLabel() string
- func SkillFieldHelp(c Context, field int) string
- func SkillFieldLabel(c Context, field int) string
- func SkillLabelWidth(c Context) int
- func SkillLines(c Context, declared skill.Skill) []string
- func TraitRoom(c Context) int
- func TraitSentences(c Context, one passive.Passive) []string
- func Window(total, cursor, room int) (from, to int)
- func WrapWords(text string, room int) []string
- type Action
- type ArrangeScreen
- func (a ArrangeScreen) Attach(_ Context, live DraftLive) ArrangeScreen
- func (a ArrangeScreen) InHand() (DraftPick, bool)
- func (a ArrangeScreen) Picks() []DraftPick
- func (a ArrangeScreen) Placing() bool
- func (a ArrangeScreen) Squad() placement.Squad
- func (a ArrangeScreen) Update(_ Context, message tea.KeyPressMsg) (ArrangeScreen, DraftResult)
- func (a ArrangeScreen) View(c Context) (string, string)
- func (a ArrangeScreen) Waiting() bool
- func (a ArrangeScreen) Whole() bool
- type BlurbScreen
- type BonusesScreen
- type BrowseScreen
- func (b BrowseScreen) CycleForm() BrowseScreen
- func (b BrowseScreen) Detail(c Context, character cast.Character) string
- func (b BrowseScreen) FilterID() string
- func (b BrowseScreen) FilterName(c Context) string
- func (b BrowseScreen) Refresh(lib *forge.Library) BrowseScreen
- func (b BrowseScreen) Rows() []cast.Character
- func (b BrowseScreen) Subject() Subject
- func (b BrowseScreen) Update(_ Context, message tea.KeyPressMsg) (BrowseScreen, Action)
- func (b BrowseScreen) View(c Context) (string, string)
- type BuildRow
- type BuildsScreen
- type ChartScreen
- type Context
- func (c Context) Continued(format string, args ...any) string
- func (c Context) DetailLabelWidth() int
- func (c Context) Footer(authoring, reading i18n.Key) string
- func (c Context) Label(name, format string, args ...any) string
- func (c Context) LabelAt(name string, width int, format string, args ...any) string
- func (c Context) PlayerSquad(id string) bool
- func (c Context) Text(key i18n.Key, args ...any) string
- func (c Context) UsableWidth() int
- func (c Context) Wrapped(name string, width int, value string) string
- func (c Context) WrappedIn(name string, width int, style lipgloss.Style, value string) string
- type DraftDecision
- type DraftField
- type DraftLive
- type DraftPick
- type DraftPickInto
- type DraftResult
- type DraftScreen
- func (d DraftScreen) Attach(_ Context, live DraftLive) DraftScreen
- func (d DraftScreen) Character() (cast.Character, bool)
- func (d DraftScreen) Choosing() bool
- func (d DraftScreen) Chosen() (string, bool)
- func (d DraftScreen) Deciding() bool
- func (d DraftScreen) FormChoices() []string
- func (d DraftScreen) Left() int
- func (d DraftScreen) OpenPassives() *PickState
- func (d DraftScreen) OpenSkills() *PickState
- func (d DraftScreen) Picked(_ Context, into any, answer PickAnswer) (DraftScreen, Action)
- func (d DraftScreen) Update(c Context, message tea.KeyPressMsg) (DraftScreen, DraftResult)
- func (d DraftScreen) View(c Context) (string, string)
- type DraftStep
- type ElementsScreen
- type Kind
- type OriginsScreen
- func (o OriginsScreen) Confirmed(c Context, _ any) (OriginsScreen, Action)
- func (o OriginsScreen) Paste(_ Context, text string) (OriginsScreen, tea.Cmd)
- func (o OriginsScreen) Refresh(c Context) OriginsScreen
- func (o OriginsScreen) ResetForm(c Context) OriginsScreen
- func (o OriginsScreen) Update(c Context, message tea.KeyPressMsg) (OriginsScreen, Action, tea.Cmd)
- func (o OriginsScreen) View(c Context) (string, string)
- type Palette
- type PassivesScreen
- type PickAnswer
- type PickKind
- type PickOption
- type PickResult
- type PickState
- func (p *PickState) Describes() bool
- func (p *PickState) Detail(c Context, id string) string
- func (p *PickState) Group() string
- func (p *PickState) IDColumn() int
- func (p *PickState) NextFilter()
- func (p *PickState) Paste(_ Context, text string) tea.Cmd
- func (p *PickState) Raise() *PickState
- func (p *PickState) Room(c Context) int
- func (p *PickState) Toggle()
- func (p *PickState) Update(_ Context, message tea.KeyPressMsg) (*PickState, PickResult)
- func (p *PickState) View(c Context) (string, string)
- func (p *PickState) Visible() []PickOption
- type PlayAnswer
- type PlayClock
- type PlayClockSeat
- type PlayLive
- type PlayScreen
- func (p PlayScreen) Attach(c Context, live PlayLive) PlayScreen
- func (p PlayScreen) Choices(c Context) string
- func (p PlayScreen) LogRows(c Context) []string
- func (p PlayScreen) Move(by int) PlayScreen
- func (p PlayScreen) Open(c Context, home, away placement.Squad) PlayScreen
- func (p PlayScreen) OptionWidth() int
- func (p PlayScreen) Subject() Subject
- func (p PlayScreen) Update(c Context, message tea.KeyPressMsg) (PlayScreen, Action)
- func (p PlayScreen) View(c Context) (string, string)
- func (p PlayScreen) Wrote(c Context) []string
- type PreviewScreen
- type SkillsPick
- type SkillsScreen
- func (s SkillsScreen) Confirmed(c Context, _ any) (SkillsScreen, Action)
- func (s SkillsScreen) DamageRow(c Context, labelWidth int) string
- func (s SkillsScreen) Draft(c Context) forge.SkillDraft
- func (s SkillsScreen) FieldValue(c Context, field, labelWidth int) string
- func (s SkillsScreen) FormInFront() bool
- func (s SkillsScreen) OpenAllowlist(c Context, field int) *PickState
- func (s SkillsScreen) OpenStatuses(c Context) *PickState
- func (s SkillsScreen) Paste(_ Context, text string) (SkillsScreen, tea.Cmd)
- func (s SkillsScreen) Picked(c Context, into any, answer PickAnswer) (SkillsScreen, Action)
- func (s SkillsScreen) Prefill(c Context, current skill.Skill) SkillsScreen
- func (s SkillsScreen) Refresh(c Context) SkillsScreen
- func (s SkillsScreen) ResetForm(c Context) SkillsScreen
- func (s SkillsScreen) Rows() []skill.Skill
- func (s SkillsScreen) Selected() (skill.Skill, bool)
- func (s SkillsScreen) Subject() Subject
- func (s SkillsScreen) Update(c Context, message tea.KeyPressMsg) (SkillsScreen, Action, tea.Cmd)
- func (s SkillsScreen) View(c Context) (string, string)
- type SpeciesScreen
- type SquadMode
- type SquadsAsk
- type SquadsAskKind
- type SquadsPick
- type SquadsScreen
- func (s SquadsScreen) Begin() SquadsScreen
- func (s SquadsScreen) Character() (cast.Character, bool)
- func (s SquadsScreen) Commit() SquadsScreen
- func (s SquadsScreen) Confirmed(c Context, about any) (SquadsScreen, Action)
- func (s SquadsScreen) Dirty() bool
- func (s SquadsScreen) EditUnit(index int) SquadsScreen
- func (s SquadsScreen) Form() string
- func (s SquadsScreen) Open(squad placement.Squad) SquadsScreen
- func (s SquadsScreen) OpenPassives() *PickState
- func (s SquadsScreen) OpenSkills() *PickState
- func (s SquadsScreen) Paste(_ Context, text string) (SquadsScreen, tea.Cmd)
- func (s SquadsScreen) Picked(_ Context, into any, answer PickAnswer) (SquadsScreen, Action)
- func (s SquadsScreen) Refresh(c Context) SquadsScreen
- func (s SquadsScreen) Refuse(slots int, chosen []string, kind string, available []string, insist bool) error
- func (s SquadsScreen) Save(c Context) SquadsScreen
- func (s SquadsScreen) StageChoices() []string
- func (s SquadsScreen) Update(c Context, message tea.KeyPressMsg) (SquadsScreen, Action, tea.Cmd)
- func (s SquadsScreen) View(c Context) (string, string)
- type StatusRow
- type StatusesScreen
- type Subject
- type SubjectKind
- type Target
Constants ¶
const ( OriginFieldID = iota OriginFieldTitle OriginFieldMedium OriginFieldYear OriginFieldNote OriginFieldCount )
The fields of the add-a-work form.
Exported for the reason the skill form's own field constants are: a client's fixture reaches a field the way a keystroke does, and a test cannot follow a screen across a package boundary.
const ( PlayMarkerWidth = 2 PlayOptionGap = 2 )
The two fixed columns a row spends before its summary: the cursor marker, and the gap between the id column and whatever follows it.
const ( MinWidth = 120 MinHeight = 24 )
The smallest window the screens fit in.
Below this the program says so rather than drawing a layout that overlaps itself: a corrupted screen looks like a bug in the tool, and the author is left unable to tell whether the character they are looking at is the one they typed.
The width was 72 while this client was English only, and moved to 80 when Vietnamese arrived: it runs a fifth to a third longer for the same sentence, and the busiest footers — six chords on the form, the level and filter keys on the browser — landed just past 72 once the language chord was added. That is where 80 came from, and it is not where 120 comes from, so the argument is rewritten rather than extended: 80 was the other number a terminal has always had, and 120 is a number the measurement asked for.
**The measurement.** Every screen in everyScreen rendered at 200x60 in both languages, and the widest line the width sweep actually constrains — free text and data columns are exempt, being the two things that have no length the program can promise. Of the 92 screen/language pairs, **34 sit at 76–79 cells** of the 79 the old floor left, 29 more at 70–75, 17 at 60–69 and 12 below 60. A third of the client is pressed flat against the ceiling, and several of those lines landing on 78 and 79 *exactly* is the fingerprint of wording trimmed to fit rather than wording that happened to end there.
**What is pinned is almost entirely footers** — rows of key chords, e.g. `space pick · ↑/↓ move · ? describes · enter done · esc back · ctrl+l tiếng Việt` at exactly 79 — plus the menu's detail column and the skill form's damage reading. ⚠️ **A footer cannot be given room any other way.** It is catalog wording, so the prose/data split does not reach it: measuring one against the window instead of the floor would cut it again on an 80-column terminal, which is the failure this sweep exists to prevent. The floor is therefore the only lever for this class, which is why widening the data cells bought it nothing — measured across #173 and #175, **35 pairs were packed against the ceiling before those two changes and 34 after**.
⚠️ **The cost, stated rather than buried: a terminal narrower than 120 no longer draws this program at all.** That is a real loss, accepted because the alternative was trimming the wording a third time. It is also the smaller half of the tool: `hexforge` needs no room and does everything this front-end does, which is what viewTooSmall already points at.
TestEveryWordingFitsTheMinimumWidth measures the catalog against this constant in both languages, so it cannot rot quietly. ⚠️ Raising the floor **loosens** that sweep, and deliberately: the promise changed, so every existing line passing trivially is the new promise being kept rather than a test going vacuous. What it does not loosen is the vertical budgets — prose wraps at this number, so a screen reserving rows for a wrapped block has to **measure** the wrap rather than count it, which is what speciesRoom and passivesRoom do.
const ( SkillFieldID = iota SkillFieldName SkillFieldFlavour SkillFieldElement SkillFieldTarget SkillFieldRange SkillFieldShape SkillFieldPower SkillFieldStrikes SkillFieldAccuracy SkillFieldCooldown SkillFieldInflicts SkillFieldOnItself SkillFieldPierce // Beside pierce, so the form reads in the order the file is written in. SkillFieldCrit SkillFieldRestores SkillFieldDrains SkillFieldKeptForElements SkillFieldKeptForRoles SkillFieldKeptForCharacters SkillFieldKeptForSpecies SkillFieldKeptForOrigins SkillFieldCount )
The fields of the new-skill form, in the order they are walked.
Exported because both a raise site and a client's own fixtures name one: the picker a list field opens carries the field it fills, and cmd/hexforge-tui builds the form's states by hand for its width sweep. A fixture cannot follow a screen across a package boundary.
Nine core fields, the display name, the statuses it inflicts (both sides), and the three allowlists. What is deliberately absent is requires, self_requires, self_gradient, strips, scaling and summons: each is a composite worth several questions of its own, and a form that asked a dozen more would be worse than an edit to skills.json. They survive a save untouched — see skill.Skill.MarshalJSON.
⚠️ This list was written down in three places (here, forge.resolveOnto, and TestTheShippedSkillBookSurvivesBeingWritten) and every copy was wrong the same way: each named self_applies, which this form *does* ask about, and none named self_requires or summons, which it does not. Corrected when self_gradient joined them. A list restated three times drifts three times; if it drifts again, derive it.
The name sits second because that is where it is authored: a skill and the name it is called by are one thought, which is also why the name is a field on skill.Skill and not a translations file beside the book.
const ( SquadUnitCharacter = iota SquadUnitLevel SquadUnitStage SquadUnitSlot SquadUnitSkills SquadUnitPassives // SquadUnitFieldCount is how many fields a member has, which is what the // cursor wraps against. SquadUnitFieldCount )
The fields of one unit, in the order they are asked.
Character first because everything under it is read against the character: the level bounds the forms, the form bounds the learnset, and the kit is chosen out of that. Slot last of the settled facts because it is the only one that says nothing about the unit itself — where it stands is a fact about the squad.
const ( BudgetBarWidth = 24 StatBarWidth = 12 )
How wide the two meters are drawn. Both are fixed rather than proportional to the window: a meter that changes width as the terminal is resized cannot be compared against the one drawn a moment ago.
const ChoiceFormat = "< %s > %s"
ChoiceFormat is how a chooser draws: the value between arrows, then where it sits in the list.
It is a constant because the art chooser measures its own room from it. A second copy of the decoration would drift from the one being drawn, and the measurement would then be of a row nobody sees.
It lives here rather than beside either form for the reason Pad and Clip do: the skill form moved into this package and the character form did not, so a copy on each side of the boundary is two spellings of one row.
const DraftStepCount = int(DraftStepTimeout) + 1
DraftStepCount is how many DraftStep values are declared, DraftStepNone included.
⚠️ It exists so a client can prove its mapping is **total in both directions** — every step the protocol declares reaches one of these, and every one of these is reached by some step. A one-way walk would pass on a value nothing ever produces, which is a screen arm that can never be drawn, and this repository has recorded the mirror-image failure (a target with no screen) five times.
const Ellipsis = "…"
Ellipsis marks a line that did not fit. One rune rather than three dots, so that its cell count is its character count, which is the unit every column in these clients is measured in.
const FilterLimit = 32
FilterLimit is how many letters the typed filter takes.
A bound rather than a free-running field, and it is what keeps the filter row inside the window by construction: the wording around the query is thirty-one cells at its longest, so a query this long cannot reach the seventy-nine the floor leaves. Nothing an author would type comes near it — the longest shipped skill name is well under half of it — so the limit is a guard rather than a constraint, and the row clips as well, because a guard nothing measures is a guard that has already stopped working.
const KindCount = int(Answer) + 1
KindCount is how many Kind values are declared, Stay included.
⚠️ **It exists because the two kinds above are new and a client that silently ignored one would swallow a keystroke.** That is the shape this repository has now recorded five times in TODO.md and measured four more — a target with no screen, a subject kind with no applier, a pick destination with no landing, a screen slipping out of everyScreen — and each time the fix was to walk a count rather than a list somebody remembered to write.
⚠️ **And a count is the smaller half.** It proves a kind is *handled*; it cannot prove it is handled *right*, which #207, #214, #216 and #218 each measured again. Every kind therefore has a behaviour test that presses the real key beside its entry in the walk.
const PlayLogWanted = 8
PlayLogWanted is how many rendered rows the log asks the budget for.
It is what the player has to read: what happened since they last chose. A screen that grew a line per event would push the board off the top by the third turn, which is why the section asks for a few rows rather than for all of them.
⚠️ **It is a floor of intent and no longer a ceiling**, and it was the ceiling that was the defect. `playFit` clamped the log's allotment to this number, so the body grew 20 → 42 rows between a 120x24 window and an 80x80 one and the log stood still at eight — a tall terminal bought the history nothing. The log now takes whatever rows nobody above it in the priority claimed, and this is only what it asks for **first**, which is what still makes "everything fits" a question with an answer: a window that gives the log its eight rows is a window with nothing missing, and one that gives it forty is the same window with room to spare.
⚠️ **It is not a floor in the priority**, and it cannot become one. The log is last precisely because it is history rather than state, so a guaranteed eight rows would have to be taken off the roster, the board or the order line — and every drop height in CLAUDE.md would move. Growing the log may only ever spend rows nobody else claimed.
⚠️ **Rendered rows, not events**, and it used to be events. The two are not the same number: tui.Line opens a turn with a blank row of its own, so one event arrives as two rows, and eight events measured **eleven rows** in a battle a few turns deep.
Renamed off playLogLines because the number no longer says how many lines the screen keeps — it says how many it asks for.
const PlayTurnLimit = 4000
PlayTurnLimit is where a battle is abandoned, and it is cmd/hexarena's number deliberately: a battle this screen calls endless and a battle the game calls endless have to be the same battle.
const Ramp = " .:-=+*#%@"
Ramp is the monochrome drawing's alphabet, lightest to heaviest. Inverted against luminance, so dark ink reads as a heavy character on a light terminal and a pale one on a dark terminal — the shape is the same either way.
Exported because a client's own test tells a row of drawn art from a row of wording by its alphabet, and an alphabet written down twice is two alphabets: a character added here and not there turns a picture row into a wording row and quietly stops that test measuring anything.
const SubjectKindCount = int(SquadSubject) + 1
SubjectKindCount is how many SubjectKind values are declared, NoSubject included.
⚠️ It exists for the reason TargetCount does: a client can prove its applier is **total**. A kind nothing applies makes a raise hand the describer nothing and draw an empty screen, and a test that walks the kinds somebody remembered to list cannot see the one they forgot. Walk the count.
const TargetCount = int(Fight) + 1
TargetCount is how many Target values are declared, NoTarget included.
⚠️ It exists so a client can prove its map is **total**. A Target with no entry makes a raise silently do nothing — the same shape as a screen slipping out of everyScreen, which this repository has now recorded five times — and a test that walks the values somebody remembered to list cannot see the one they forgot. Walk the count.
const TraitIndent = 4
TraitIndent is how far the sentences sit under the trait they belong to. Four rather than two, so a wrapped line is still visibly part of the trait above it and not the start of the next one.
It is here rather than beside one of its readers because there are three of them in two packages now — the traits listing and the chart in this package, and the description screen still in cmd/hexforge-tui — and an indent written down twice is two paragraphs that stop lining up.
Variables ¶
This section is empty.
Functions ¶
func Bar ¶
Bar draws a proportion in characters, never in colour alone.
The caller prints the numbers next to it. A value over its limit fills the whole bar and is marked with a '!' so that "full" and "too much" are not the same picture — being over the budget is the single thing an author most needs to notice, and a bar that saturates silently hides exactly that.
func BudgetLine ¶
BudgetLine is the joint health-and-defence bound drawn as a meter and as numbers. The numbers are what makes it readable without colour, and being over the bound is said in words in both languages, because it is the state rather than the styling.
Exported because the new-character form draws the same row and has not moved: a second copy would be a second answer to what "over the bound" looks like.
func ChosenForm ¶
ChosenForm is the form these views resolve a character in: progression.Furthest on a line that does not fork, and otherwise the arm chosen with the form key.
⚠️ **It settles the choice on every read rather than storing a settled one.** The cursor and the level both move under a chosen name — walking to another character, or below the level the fork opens at, leaves a name that is not on the list any more — and a stale name reaches Resolve as a form the line does not answer to. Deriving it means the two can never disagree; SquadsScreen settles the same hazard by writing the field back, which it has to do because its value is saved and this one is not.
The fallback is the **first** arm, which is a pick — and the reason it is not the silent pick StageAt refuses is that FormRow draws it. A chooser has to open on something; what it may not do is open on something unnamed.
func Clamp ¶
Clamp keeps an index or a level inside its range, and returns the low bound when the range is empty.
func Clip ¶
Clip shortens a line to a number of cells and **says that it did**, keeping the front, which is where the id, the label and the first half of a sentence are.
Shortened rather than wrapped, for the reason frame clips: a wrapped row pushes every row under it down by one, which is how the footer leaves the bottom of the screen.
⚠️ **Escape-aware and marking at once, which is a pair neither of the two tools this replaced could manage.** `lipgloss`'s `MaxWidth` steps over an escape sequence correctly and cuts **silently**. This function's own previous body appended the mark but sliced `[]rune`, and on a styled line that peels the terminating `\x1b[m` off the end one rune at a time — measured, not argued: a bold red ten-cell line cut to nine came back `"\x1b[1;31mabcdefgh…"`, the right width, the right letters, and **no reset**, so the colour bled down the rest of the screen. Every caller then passed unstyled text, so nothing showed it; frame's lines are styled, so making frame call the old body would have shipped the bleed on the first cut header. `ansi.Truncate` is measured in cells, steps over escape sequences rather than through them, and re-closes whatever the cut left open.
⚠️ **The mark is only added when the line is genuinely longer than the room.** A line that fills the room exactly comes back byte for byte unchanged — the early return below is that promise written down, and it is the whole off-by-one risk of marking at all: an ellipsis on a line that fitted claims a tail that was never there and spends a cell of real content to claim it. `ansi.Truncate` makes the same distinction on its own; the early return keeps it from mattering which of the two is doing so, and keeps an uncut line identical to what `MaxWidth` produced before this change.
The mark itself is `Ellipsis`, the one already declared for the art row — a second declaration would be a second thing to keep in step, and the whole client is measured in cells that are also characters.
It lives here rather than beside its first caller for the reason `Pad` does. It began as the picker's private helper for one refusal row and is now the one rule the whole client cuts by, so a second copy of "shorten and mark" is exactly what having it beside `Pad` and `LabelAt` exists to stop.
func FieldValueRoom ¶
FieldValueRoom is what a form row has left for the one part of it that has no length of its own — the chances beside the inflicts field, the ids in an allowlist, the kit and the species on the character form — once the marker, the label column, the fixed part of the value and the two-space gap before whatever follows have been paid for.
One declaration for **both forms**, because the skill form and the character form draw the identical row — `marker + Pad(label, width) + " " + value` — and each had written the arithmetic out for itself. All four copies were one cell over, in the same direction, and the two that were found first were fixed while the two in form.go were not; a second copy is a second thing to fix twice. The window's last column is left empty for the reason frame leaves it: a line filling a terminal's final cell wraps on some of them, and one wrapped line pushes the footer off the bottom.
The width is handed in rather than read off MinWidth, and that is what keeps the single declaration honest: a row that spends this on **data** — the chances, an allowlist of ids, a chosen kit — passes UsableWidth(), which is the window when there is one, while a row spending it on wording would pass MinWidth. All four callers today are data and all four pass the window, but picking a side inside the function would make the next caller either wrong or a second copy of the arithmetic, which is exactly what this exists to have stopped.
func FormArms ¶
func FormArms(character cast.Character, level int) []progression.Stage
FormArms is the grown ends of a character's line at a level: one form on a line that does not fork, one per arm on a line that does.
A level outside the line, or a character whose line covers nothing there, is no arms rather than an error: every caller here is drawing a screen, and the refusal a reader needs to see is the one Resolve gives with the level in it, not a second one from a chooser.
func FormRow ¶
FormRow is the line naming which arm is in force, ready to write into a body: indented, styled and newline-terminated, or **empty** when the character has no fork at this level.
Empty rather than a row saying "one form" is the whole of the promise a linear line is unchanged, so every caller writes the result unconditionally and lets this decide.
It is one self-contained line in all three views rather than a labelled row in the browser and a bare one in the other two. The detail pane's label column is for facts about the character, and this is a control: the same reason SquadsScreen draws its held-back note as an unaligned line under the rows it belongs to.
func FormationSlots ¶
FormationSlots is every cell of one side's formation, front column first: a squad is read from the rank that meets the enemy backwards, because that is the order an attack arrives in.
func IndexOf ¶
IndexOf is where a value sits in a chooser's list, and nought when it is not in one at all.
Exported because a client's own fixtures set a chooser by name — a shape, an element — and an index written out by hand would be a second reading of the book's order.
func IsSaveKey ¶
func IsSaveKey(message tea.KeyPressMsg) bool
IsSaveKey reports whether a keystroke asks for the work to be written.
One declaration for all three forms — the skill form here, the character form and the origins form in cmd/hexforge-tui — for the reason a passed turn's reason lives in one place: three screens matching on their own spelling of the same intent is three chances for one of them to be missed when a fourth keystroke is added, and the one that gets missed is the one nobody presses in a test.
func Marked ¶
Marked is one sentence of a trait's description with the status names in it picked out.
Word by word rather than name by name, because the caller wraps what comes back: a style spanning two words survives strings.Fields only until the wrap puts the words on different lines, and then the first line carries an escape sequence the second one closes. Marking each word whole keeps every word self-contained however the line breaks.
Longest first, so a name that begins another name cannot take its opening. The marker is a parameter rather than a style read off a Context, which is what makes this testable: the tests run with NO_COLOR set, so every style is the identity and a test asserting on the palette's own would be asserting that nothing happened.
func NewInput ¶
NewInput is a text field dressed the way these clients draw them.
Two decisions, and both are here rather than at the call sites so that a fifth field cannot be born looking different from the other four.
func NextForm ¶
NextForm is the arm after the one in force, wrapping round, and is what the form key writes back.
A character with nothing to choose hands the choice back untouched rather than clearing it: the key is live on every character because the screens are one screen, and a reader who has chosen Politoed, walked past a linear character and walked back should find Politoed still in front.
func NumberField ¶
NumberField is the chance field the status picker carries: a text field that takes digits and nothing else.
It takes the terminal's answer as a parameter for the reason NewInput does: this package reads no environment, so the binary asks and hands the answer down.
Narrow on purpose. A picker's other keys are space, the arrows, k, j, enter and escape, so letters have to stay out of the field or moving the cursor would type into it — and the field holds a figure in parts per thousand, which is four digits at most.
The default is the *placeholder* rather than the value, and that was measured rather than chosen: a four-digit default in a field with a four-character limit is a field that refuses the next keystroke, so the first thing an author has to do is delete an answer they did not give. Empty with the default shown means typing works immediately and pressing enter without typing still writes it — forge.AddApplications reads a blank chance as the default, so the two front-ends cannot disagree about what nothing means.
func NumberKey ¶
func NumberKey(message tea.KeyPressMsg) bool
NumberKey reports whether a keystroke belongs in a number field: a digit, or one of the keys that edit or move within one.
The filter is here rather than on the field's own Validate, and that is not a preference. bubbles' Validate does not refuse a keystroke — it takes the value and records an error beside it — so a letter typed at a "numeric" field sits in the field looking accepted, and only a caller reading Err would ever know. It was written the other way first and a test found the letters in the field. Refusing the key is what makes the field numeric. A keystroke is read through Code and Text rather than through a key type, because bubbletea v2 has none: an editing key is a named Code, and a printable one carries the characters it produced in Text. Text is empty whenever a modifier is held, which is what keeps ctrl+1 out of the field without a second check for it.
func OptionRefusal ¶
OptionRefusal is why an option cannot be taken, in the reader's own language.
**One place, and it is exported so that it stays one.** battle.Option carries a Reason of its own and every renderer in this repository used to print it, but that sentence is built inside internal/core, which may not import internal/i18n — so it is English wherever it is drawn, including on a Vietnamese screen. What the engine hands over instead is the enum and the three counts behind the sentence, and turning those back into words is a switch: a switch copied into the next client is the second answer that drifts, so there is one here and callers ask it.
⚠️ **A greyed row with a cooldown of nought is what this is really for.** While every refusal was a cooldown the row explained itself — it said three and the reader waited three — and an untranslated countdown is a small thing. A skill gated on the caster's own reserve has no cooldown to count down, so the row was a skill the reader could see, could not use, and was told nothing about. The fuel wording carries all three of its facts for that reason: how much is wanted, of what, and how much is actually held.
The status is named through its **gloss** — the Vietnamese name the reference screens and the battle log put beside a data id — falling back to the id, which is what English gets and what an unglossed status gets in either language. That fallback is this package's rule for every data id it draws and not a special case here.
An option blocked for a reason this does not know keeps the engine's own sentence. That is the honest degrade: English is worse than Vietnamese and both are better than a blank column where the reason was.
func Pad ¶
Pad widens a string to a column.
fmt's own %-*s counts runes, which is the right unit here — every letter this client draws, Vietnamese included, is one terminal cell wide, and TestEveryWordingIsOneCellPerLetter is what keeps that true. What fmt cannot do is ignore a style's escape codes, so padding happens before styling everywhere in this package.
func PasteDigits ¶
PasteDigits is PasteInto for a number field, which the level and the chance are.
⚠️ **A paste that is not all digits is refused whole rather than stripped.** Refused, because these two fields' typed path is NumberKey-gated and a paste is the only other way in: a field that took letters from one route and refused them from the other would be numeric only by accident, and the value would sit there looking accepted while strconv.Atoi quietly ignored it — which is exactly the failure NumberKey's own comment records having been written the other way round first. Whole, because stripping "1,200" down to "1200" would enter a number nobody pasted, and a level that silently became something else is worse than a keystroke that did nothing.
An empty paste is refused too: there is nothing in it to be a digit.
⚠️ **A nil answer does not mean refused.** It carries PasteInto's nil for the reason written there, so the two are indistinguishable and a caller that has to tell them apart reads the field's value either side. Both callers do.
func PasteInto ¶
PasteInto is the one place a pasted string reaches a text field.
It hands the field the same message a terminal delivers, which is what keeps the two routes — the terminal's own bracketed paste and the ctrl+v this program answers itself — landing on identical code. The command that comes back is the cursor's blink and has to be returned for the reason every three-return Update in this package returns one.
⚠️ **A newline becomes a space, and a tab too — measured, not assumed.** textinput sanitises what it inserts through a rune sanitizer built with ReplaceNewlines(" ") and ReplaceTabs(" "), so `"7QK4M2XZ9BTF\n"` lands as thirteen characters ending in a space and `"…\r\n"` as fourteen ending in two, while an escape or any other control character is dropped and invalid UTF-8 is discarded. Nothing here re-does that work: a caller that needs a clean value trims it where the value is read, which is what joinScreen.submit has always done and why its comment already says a pasted code arrives with a newline more often than not. The behaviour is pinned by TestATextFieldTurnsANewlineInAPasteIntoASpace so a bubbles upgrade that changed it would say so here rather than in a room code that would not decode.
⚠️ **The command is NOT a signal that anything was pasted, and reading it as one is a mistake this shipped with for one commit.** It is the cursor's blink, and a field on a plain terminal has no virtual cursor — NewInput turns it off under NO_COLOR — so a paste that landed perfectly well hands back **nil** on every machine the suite runs on. A caller that needs to know whether the value moved compares the value, which is what every arm calling this does.
func PasteText ¶
PasteText is a pasted string made fit for a field that is **not** a textinput — which in this package is the skill listing's typed filter, a plain string with a backspace for the reasons SkillsScreen.Query records.
⚠️ **It is the same rule bubbles applies and is held to it by a test rather than by this comment.** A second sanitiser is a second answer to "what does a pasted newline become", and the two would drift the first time either moved; TestTheFilterSanitisesAPasteExactlyAsATextFieldDoes feeds the same strings to this and to a real textinput and holds the answers equal, so a bubbles upgrade that changed the rule fails here instead of leaving one field behaving unlike every other.
func Plain ¶
Plain reports whether colour would be noise rather than help, with its three inputs handed in, so both answers can be tested from either sort of machine. `runtime.GOOS` cannot be faked, and the whole of what is written down below is a difference between two platforms.
⚠️ **An unset TERM is "dumb" only away from Windows.** TERM is terminfo's convention and cmd.exe, PowerShell and Windows Terminal set none at all — so reading its absence as a dumb terminal left every Windows terminal drawing plain text, with no cursor in any text field, while macOS and Linux (where TERM is always set) never reached the branch and nothing looked wrong. The rendering library draws the same line for the same reason: `colorprofile`'s own `isDumb` is `(!ok && runtime.GOOS != "windows") || term == dumbTerm`, and it reports TrueColor for a Windows 10 build 14931 or later. So this is not a guess about what those terminals can do — it is the same answer the thing that writes the escape codes has already given, and the palette's rule is only worth having if the two agree.
func PlayBodyRoom ¶
PlayBodyRoom is how many rows the body may write before frame cuts it.
frame gives the whole screen c.Height - 2 rows, spends the first two on the header and the blank under it, and puts the footer below whatever padding is left — so the body's own purse is four rows short of the window. Reading it off frame's arithmetic rather than writing the number down is the point: a second copy of "how many rows are there" is how a screen comes to disagree with the frame drawn around it.
func RankLabel ¶
RankLabel is what to call the rank a cell stands in, and empty for a cell that is on no formation — a slot a hand-edited file put off the grid draws its coordinate alone rather than borrowing a rank it is not in.
func SaveKeyLabel ¶
func SaveKeyLabel() string
SaveKeyLabel is what a footer calls the save key.
It is ctrl+s on every platform, including the one where ⌘S also works, and that is a rendering decision rather than a change of heart about ⌘S. ⌘ is East-Asian-Ambiguous width: lipgloss measures it as one cell, a good many terminals draw it as two, and the glyph then lands on top of whatever follows it — "⌘S" is drawn as the two characters overlapping, which is worse than not naming the key at all. Nothing inside a program can find out which of the two its terminal will do.
Spacing it apart does not help, because the extra cell has to come from somewhere: the English character-form footer is 73 cells without the label, the smallest window is 80, and the last cell of a row is left empty so that writing it cannot wrap the line. Six cells for the label, and any spelling that names both keys in ASCII needs more than six.
So the footer names the keystroke it can always deliver and always draw, and ⌘S is a Mac habit that turns out to work — MenuNote says so on the way in, and the README says why it might not. What the footer must never do is promise ⌘S alone, which is the one thing Terminal.app cannot keep.
func SkillFieldHelp ¶
SkillFieldHelp is the line describing the field the cursor is on: what it means, and an answer that would be valid.
One entry per field, and the array is indexed by the field constant for the same reason SkillFieldLabel's is — a field added without a help line is a blank line rather than a build failure, so TestEveryFieldOfTheSkillFormHasHelp walks every field and reads the screen.
It replaced a static footnote about parts per thousand. That footnote was true of two fields out of fourteen and drawn whichever field had the cursor, which is why it explained nothing about the fields nobody could guess: what a shape covers, what syntax the statuses take, what an empty allowlist means.
func SkillFieldLabel ¶
SkillFieldLabel is what each row of the form is called.
Exported with SkillFieldHelp and SkillLabelWidth for the reason the field constants are: a client's width sweep measures every row of this form in both languages, and a fixture cannot follow a screen across a package boundary.
func SkillLabelWidth ¶
SkillLabelWidth is the column the field names sit in, measured from the labels themselves rather than declared: the longest is "cooldown" in one language and "để dành cho mẫu" in the other.
func SkillLines ¶
SkillLines is what a skill does, one line per sentence and already marked.
A function rather than the second copy it was about to become: the authoring tool's kit picker reads the skill under its own cursor and this screen reads the one it was handed, which is the same paragraph asked for from two places. A second copy of the marking is a second thing that can decide a name is worth pointing out — and the comment above this screen already refused to write a second copy of a framing for the same reason.
Exported because that second caller is in another package now. It takes a Context and a declared skill and reads nothing else, so it is as much this package's as the screen that draws it.
func TraitRoom ¶
TraitRoom is how many lines of sentences fit: the window, less the two the heading takes and the one the position line does.
The authoring tool's picker shares it rather than counting again, which is why it is exported. The two spend their lines on the same four things in the same order, so two counts would be two answers to one question — and the one that was wrong would be the one that let the frame cut the line saying there is more to read.
The position line is counted whether or not it is drawn. Counting it only when it appears would make the answer one line taller the moment it fits, which is the shape of loop that flickers between two layouts on a window exactly at the boundary.
func TraitSentences ¶
TraitSentences is one trait's description, wrapped and indented under whatever named it above.
Split off the loop above rather than duplicated into the authoring tool's picker, which reads a trait under a cursor of its own and carries the name in its heading instead of in the body: what the two share is the measure and the indent, and those are exactly the parts a second copy would be free to disagree about. Exported for that caller, which is in another package now.
func Window ¶
Window is the slice of a list to draw, keeping the cursor inside it.
It scrolls by the least it can: the window only moves when the cursor would leave it, so stepping back and forth across one boundary does not make the whole list jump about.
Types ¶
type Action ¶
type Action struct {
Kind Kind
Target Target
// Subject is what the raise is about, and the zero value is a raise about
// nothing.
//
// ⚠️ Applying it is the **client's** job, and that is the point rather than a
// division of labour. The traits listing used to reach into the statuses
// screen's own state and move its cursor — the only cross-screen read among
// the six, and the one thing a screen could not have carried with it into a
// package that knows nothing about which other screens exist. A raise names
// what it wants and asks nobody where it lives.
//
// ⚠️ It replaced a bare `Focus string`, which was the same mechanism with one
// case in it, and the case was undeclared: a Focus at any target but the
// statuses reference made the client's applier answer "not found", and a
// declined raise is silent by design — so a raise carrying a subject to the
// wrong screen looked exactly like a reader who had not pressed the key. The
// kinds are counted now, for the reason TargetCount is counted.
Subject Subject
// Question is the wording an Ask puts to the reader, and is a key rather
// than a sentence so that switching language with one pending redraws it.
Question i18n.Key
// About is what an Ask is about, and the package never reads it.
//
// The squad builder is why it exists and it was predicted here before that
// screen arrived: one screen, **two** questions — discard the squad in hand,
// and delete the saved one under the catalogue's cursor — told apart by
// which they are about rather than by what mode the screen happens to be in.
// The delete also needs a value the screen does not hold: the id that was
// under the cursor when `d` was pressed. Reading either back when the answer
// arrives would work, because a pending question freezes every other key,
// and that is a subtle invariant to rest a file deletion on for nothing.
//
// ⚠️ **An opaque `any`, exactly as PickState.Into is, and for the same
// reason.** What a question is about is the *asking screen's* own
// vocabulary — SquadsAsk here, and whatever a client's own unmoved screens
// use over there — so this field carries it from the screen that asked to
// that screen's own Confirmed without anything in between learning what it
// means. The client's only job is to keep it while the question is up.
//
// ⚠️ **Subject above is NOT the carrier and may not become one.** Its Kind is
// the closed list of things a *raise* may land on, counted by
// SubjectKindCount and held total by a client's raise applier — so an ask
// kind added there would demand a raise applier for a kind no raise carries.
// That was measured in #214's step, where the answer was a client-local
// guardSubject; this field is that answer moved to where the asking screen
// can reach it. The two are not interchangeable: SquadSubject below is
// carried by a **raise** and is applied by a raise applier, and the two
// questions here are carried by an **Ask** and are read by nobody but the
// screen that asked.
About any
// Picker is the list a Pick wants put in front, built by the screen and
// owned by the client.
//
// ⚠️ **A pointer, and it stays one.** The client keeps a `*PickState` and
// *that* pointer is its presence flag — nil is no picker — so a value here
// would be a second shape for one thing and would break
// (*PickState).Toggle, which mutates in place. The screen says *open this*;
// the client owns *while it is open*, because the client is the only thing
// with a field to keep one in and the only thing that knows what closing one
// costs.
//
// It is handed over **unraised**: the screen builds the literal and the
// client calls Raise, which is exactly the division the ten raise sites
// already had when they all lived in one binary.
Picker *PickState
// Answer is the decision an Answer carries, and it is the pair
// battle.Chooser returns rather than a vocabulary of this package's own.
Answer PlayAnswer
}
Action is what a screen asks for once it has read a keystroke: it says what it wants and leaves what that means to whichever client is in front.
A screen used to write the answer itself — `m.screen = screenMenu` — and `screen` is one client's own enum, so a screen that named a menu entry could only ever live in the client that had that menu. Two clients draw these screens and the second one's menu is a different menu, which is why the naming moved out rather than being shared: a shared enum would be one client's menu declared where the other one could read it.
**The vocabulary was measured rather than invented.** Over the six screens this arrived for — the affinity chart, the elements listing, the statuses and traits references, the species listing and the build catalogue — every key does exactly one of three things: it quits, it goes back one step, or it raises another reference. Two of them raise (the elements listing opens the chart with `g`, the traits listing opens the statuses reference with `?`, landing it on the status the trait just named) and the other four do not. So there were four Kinds, and a fifth would have been a claim that a screen wanted something none of those six wanted.
**Two screens later it does.** The skill form is the first moved screen with something to lose, so it asks before throwing it away, and the first with lists to fill in, so it opens a picker over itself. Neither could be said in the four: an Ask is not a Raise (nothing is being navigated to — the question is drawn over whatever is in front and the reader comes straight back), and a Pick is not one either (the picker is not a screen a client names, it is a state the screen built and handed over). So there are six, and the count below is what stops the seventh arriving unhandled.
**A screen later, the count still holds and two of the fields grew.** The squad builder is the third moved screen with keys the four could not say, and neither of them needed a Kind: it asks **two** questions rather than one, so an Ask had to be able to say which (About, below), and it raises a screen the client is keeping, so Target gained a name for a view this package will never draw. Both are the vocabulary widening rather than the grammar.
type ArrangeScreen ¶ added in v0.2.0
type ArrangeScreen struct {
// Live is the reading in hand, replaced whole on every Attach. It is the draft
// screen's own reading — see the head of this file for why there is no second
// one.
Live DraftLive
// Arranging says a reading has been handed over at all. Nought is a screen
// nothing has attached to, which draws nothing rather than an empty formation.
Arranging bool
// Cursor is the cell enter would place on, in **authoring** coordinates: column
// 0 is this side's own back column and column 2 the one that meets the other
// half, which is what FormationSlots and hex.Place are both written in.
//
// ⚠️ **It never rests on a cell already taken**, which is the squad builder's
// own answer to the same question: a chooser that stops on an occupied cell is
// a chooser that can be left in a state the save has to refuse, so the movement
// steps over one instead of letting a later refusal explain it.
Cursor hex.Offset
// Slots is the cell each pick stands on, in pick order — `Slots[i]` is the cell
// for `Picks()[i]`, which is exactly what draft.Arrange takes.
Slots []hex.Offset
// Sent is this screen having handed its arrangement over, and it is **local
// state that gates nothing**.
//
// ⚠️ **Nothing on any reading can say this, which is the finding rather than a
// shortcut.** The record takes both arrangements in **one** step — the first to
// arrive is deliberately not recorded, because appending it would be showing it
// to the other player — so a client that has arranged sees exactly what it saw
// before: its own seat still owed, and no message at all until the phase
// closes. Without this the send is a keystroke after which nothing on the screen
// changes, for up to a whole allowance, which reads as a program that has hung.
//
// ⚠️ **It is not the "already answered" memo step 5a refused, and the
// difference is that it stops nothing.** That memo would have gated the send,
// and the retry-on-refusal loop is the only thing that ever gets a decision the
// room turned away through — so the keys stay live here, the footer goes on
// naming them, and a refusal drawn beside this line is an arrangement to send
// again. → i18n.ArrangeSent, and draw.DraftLive.Waiting, which is the same
// gap one phase earlier.
Sent bool
// Err is what placement.Squad.Validate said about the arrangement as it stands,
// and it is what blocks the send.
//
// ⚠️ **That function is the single legality rule and its words are kept.** It
// already refuses an empty squad, more than five, a blank or duplicated id, a
// cell off the 3x3 and two units on one cell, so nothing here restates any of
// them — and a refusal drawn here is the answer the room would give rather than
// a guess at it. Blocking rather than sending is the loadout's own reason: a
// refused draft decision is left open and re-sent, so an illegal one is an
// unbounded hot loop.
Err error
}
ArrangeScreen is one side placing its drafted picks: the whole board, this side's picks in pick order, and the cell each has been put on.
⚠️ **The cells are filled in pick order and the pick in hand is the first without one**, which is what makes Slots a plain prefix rather than a slice with holes in it. hex.Offset's zero value is a **real cell** — draft.Squads carries the same warning — so a slot standing for "not placed yet" would be a legal looking answer, and an absence has to be declared rather than detected. What it costs is that a player who wants to move the second pick takes the third back first; what it buys is that there is no second state to get wrong.
func NewArrangeScreen ¶ added in v0.2.0
func NewArrangeScreen() ArrangeScreen
NewArrangeScreen is the screen before a reading has been handed to it.
func (ArrangeScreen) Attach ¶ added in v0.2.0
func (a ArrangeScreen) Attach(_ Context, live DraftLive) ArrangeScreen
Attach points this screen at a drafting room.
It is called on every redraw, like every other Attach here, so it is cheap and idempotent. The one thing it resets is the arrangement itself, and only when the picks it was built for have changed: a cell belongs to the pick it was chosen for, so carrying cells into another set of picks would be an arrangement about somebody else.
func (ArrangeScreen) InHand ¶ added in v0.2.0
func (a ArrangeScreen) InHand() (DraftPick, bool)
InHand is the pick waiting for a cell, and whether there is one.
func (ArrangeScreen) Picks ¶ added in v0.2.0
func (a ArrangeScreen) Picks() []DraftPick
Picks is this reader's own side's picks, in the order they were taken — which is the order draft.Arrange reads the cells in.
func (ArrangeScreen) Placing ¶ added in v0.2.0
func (a ArrangeScreen) Placing() bool
Placing reports whether there is an arrangement for this reader to take: the phase is open and this side has not answered it.
⚠️ **It is Live.Yours and never `OnTurn == You`.** The phase has two decisions open at once, so the reading reports no seat on turn and this reader may still be one of the two being asked — which is draft.Draft.Turn's own note about never widening for it. Yours goes false the moment this side's arrangement is recorded, which is what makes Sent below a state rather than a flag of this screen's own.
func (ArrangeScreen) Squad ¶ added in v0.2.0
func (a ArrangeScreen) Squad() placement.Squad
Squad is the arrangement as the value the legality rule is asked about, and it is the same shape draft.squadAt builds: the unit id is the character id, because a draft's pool is exclusive and every pick is therefore a different character.
⚠️ **The level is progression.LevelCap and is not read off the reading**, which is DraftPick's own decision: every drafted unit fights at the cap, so a level on the screen would be a number a reader wonders about — and Validate does ask for one.
func (ArrangeScreen) Update ¶ added in v0.2.0
func (a ArrangeScreen) Update(_ Context, message tea.KeyPressMsg) (ArrangeScreen, DraftResult)
Update reads one keystroke.
func (ArrangeScreen) View ¶ added in v0.2.0
func (a ArrangeScreen) View(c Context) (string, string)
View draws the screen and its footer.
func (ArrangeScreen) Waiting ¶ added in v0.2.0
func (a ArrangeScreen) Waiting() bool
Waiting reports that there is nothing left for this reader to do: either the arrangement has gone, or the phase has closed and the board has not arrived yet — which is the one frame between the record taking both arrangements and the wire.Start that follows it.
It is what makes the screen say **why** it is waiting. The phase is simultaneous and secret by design, so a screen that only said it was waiting would read as a match that had stalled.
func (ArrangeScreen) Whole ¶ added in v0.2.0
func (a ArrangeScreen) Whole() bool
Whole reports every pick having a cell, which is the one state the send is offered in.
type BlurbScreen ¶
type BlurbScreen struct {
// Subject is what is being described, handed over by whichever screen raised
// it. The zero value describes nothing, and draws the same line an empty
// listing does.
Subject Subject
// Scroll is how far down the trait sentences have been walked, and it is
// **not** the cursor this screen refuses to keep.
//
// The difference is what the two can disagree about. A cursor of its own
// could point at a different character than the browser behind it, so the
// screen would describe one thing and the screen behind would show another.
// A scroll offset selects nothing: it is which lines of the answer are
// visible, and the answer is still the browser's. Every key that changes
// *what* is being described resets it, so it cannot survive into a shorter
// answer and leave a reader looking at nothing.
//
// Five traits at the level cap wrap to more lines than a 120-by-24 window
// holds, which is the floor rather than an unusual case.
// Letting the frame cut it would mean the one screen built for reading a
// trait cannot finish reading one.
Scroll int
}
BlurbScreen shows what the thing under the cursor behind it does, in the sentences a player reads rather than in the figures an author types.
It closes the loop the authoring tool was missing: every other row on the form says what a field *is*, and none of them said what the skill would sound like once somebody had to decide whether to use it. An author tuning a bonus from 1000 to 700 could see the damage move and not that "doubles" had become "amplifies a bit".
Three screens raise it, and it is still one screen ¶
The skill listing raises it for the skill under its cursor. The cast browser raises it for the traits the character under *its* cursor carries at the level it is sitting on — which is the same failure one layer over: an author moving virulence from 300 to 200 watched the table's "+30%" change and never read the sentence, because DescribePassive had exactly one caller and it was the battle prompt.
The played battle raises it for the option under its cursor, which is the same question a third time and the one place it is asked by a *player* rather than by an author: the compact line beside each option is what four of them can be compared on, and this is the long form of whichever one is in front. It shares the listing's rendering exactly — SkillLines — so a description read while choosing and the same description read while authoring cannot differ.
⚠️ Nothing here touches the battle. The played battle is the one screen holding something its client's model does not copy, so raising this and leaving it again must step no turn: the option is named on the way in, the skill is looked up in the library, and going back puts the previous screen up rather than re-entering it — which would rebuild the battle from its seed and throw the played half away.
A second screen would have been a second copy of the framing, the footer and the escape. So this one branches on what it was handed instead.
It is handed its subject rather than reaching for one ¶
⚠️ **This used to read the three screens that raise it** — the browser's level eight times, the skill listing's cursor five, the browser's cursor five, and the played battle four ways — which is a screen that could not live here and could not be drawn by a client whose screens are different ones. The raiser pushes a Subject and this describes it: the id of the skill or the character, where it sat in the list it came out of, and the level a character is being read at.
It keeps **no cursor and no level of its own**, and the push is what keeps that true rather than a second copy of it: every key that moves the listing behind re-pushes, so the two cannot disagree about what is in front and walking either here walks it there. A description of a character the author is not looking at is worse than none.
⚠️ **Where the raiser came from is deliberately not here.** Going back is the client's question — its own screens are the only answer to it — so a client carries that beside this value rather than in it. See Action.Back for why a screen in this package may not name its own way out.
type BonusesScreen ¶ added in v0.2.0
type BonusesScreen struct {
Rows []composition.Bonus
// Cursor indexes Rows. Every row is a bonus — there are no headings here,
// unlike the statuses listing, because the thing a heading would group by is
// the scope and the scope is already a column.
Cursor int
}
BonusesScreen is the reference for what a squad is paid for what it shares: every declared threshold, who receives it and what reaching it grants.
It exists because a composition bonus is the one thing in the game a player cannot find out by looking at the board. A skill is on a unit's list, a trait is on its character, a status is on the roster line — but a bonus is a property of the *squad that was brought*, decided before the first turn, and the only trace of it afterwards is a permanent buff that looks exactly like a trait's. Without this screen the way to learn that fielding two of an element is worth anything is to read bonuses.json.
Read-only, like the statuses and elements listings and for the same reason: a rung is balance rather than content, so adding one is a change to every squad that could reach it and belongs in a diff rather than behind a form.
func NewBonusesScreen ¶ added in v0.2.0
func NewBonusesScreen(lib *forge.Library) BonusesScreen
NewBonusesScreen is the reference filled from a library, ready to draw.
func (BonusesScreen) Refresh ¶ added in v0.2.0
func (s BonusesScreen) Refresh(lib *forge.Library) BonusesScreen
Refresh re-reads the book, keeping the cursor inside it.
func (BonusesScreen) Update ¶ added in v0.2.0
func (s BonusesScreen) Update(_ Context, message tea.KeyPressMsg) (BonusesScreen, Action)
Update reads one keystroke: the cursor moves, or the reader leaves.
type BrowseScreen ¶
type BrowseScreen struct {
Characters []cast.Character
// Origins is the catalogued work ids, and Filter indexes them from one.
// Zero is the filter that hides nothing, and it is a number rather than a
// name in the list because its name is a translated word while every other
// entry is an id that is the same in every language.
Origins []string
Filter int
Cursor int
Level int
// Form is the arm of a forking evolution line the reader has asked for, by
// stage name, and empty is "whatever the level resolves to".
//
// ⚠️ **It is read through ChosenForm and never straight**, because the cursor
// and the level both move under it: a name chosen on one character means
// nothing on the next, and below the level a fork opens at it means nothing
// on the same one. Kept rather than settled on every key for the reason it is
// kept at all — a reader who chose an arm, walked away and walked back should
// find it still in front.
Form string
}
BrowseScreen is the authored cast, filtered by origin, with one character resolved beside it.
The level is the reason this screen is worth having over `hexforge cast`: a character is a curve rather than a stat line, and walking the level with the arrow keys is how the shape of that curve — and where it starts costing the budget — becomes visible.
⚠️ **It is the first moved screen that raises another one about a subject**, which is why it could move at all. Its whole coupling to a client was three writes of that client's own screen enum — esc to the menu, `p` to the art preview, `?` to the description — and Action already has the vocabulary for all three: Back, and two Raises naming Preview and Blurb. Nothing here asks where any of them lives.
func NewBrowseScreen ¶
func NewBrowseScreen(lib *forge.Library) BrowseScreen
NewBrowseScreen is the cast listing filled from a library, opened at the level cap — the far end of every curve, which is where a character is comparable with another one.
func (BrowseScreen) CycleForm ¶
func (b BrowseScreen) CycleForm() BrowseScreen
CycleForm steps to the next arm of the fork the character under the cursor has at the level being walked, and does nothing on a line that does not fork.
Exported because the key that walks it is answered in three places: here, and in each client while one of the two describers is in front — the same arrangement the level already has, and for the same reason. A describer keeps no cursor and no level, so what a key pressed over it moves is the browser behind it, and the clients own that because they own which screen is in front.
func (BrowseScreen) Detail ¶
func (b BrowseScreen) Detail(c Context, character cast.Character) string
Detail is one character resolved at the chosen level.
Exported because the character it draws is a parameter rather than the row under the cursor: the tests that measure a form's art and a trait's gate walk the level over one named character, and reaching that through the listing would be measuring the cursor instead.
func (BrowseScreen) FilterID ¶
func (b BrowseScreen) FilterID() string
FilterID is the work in force, or empty when every work is shown.
func (BrowseScreen) FilterName ¶
func (b BrowseScreen) FilterName(c Context) string
FilterName is what the filter is called on screen: an id, or the translated word for "everything".
func (BrowseScreen) Refresh ¶
func (b BrowseScreen) Refresh(lib *forge.Library) BrowseScreen
Refresh re-reads the library, keeping the level and clamping the cursor — entering the screen after a write should show the new character rather than a stale list.
func (BrowseScreen) Rows ¶
func (b BrowseScreen) Rows() []cast.Character
Rows is the characters the current filter leaves visible.
func (BrowseScreen) Subject ¶
func (b BrowseScreen) Subject() Subject
Subject is what the two describers raised from here are about: the character under the cursor, read at the level being walked.
Built here rather than in either describer because this screen is the one that knows what its list holds — the filter decides which characters are in it, so the position on the row is a fact about this screen and not about the cast.
A filter that has left nothing gives a subject with Of at nought, which is how a raiser says there is nothing to describe without the describer reaching back to count. The level is carried either way: it is still the level being walked.
func (BrowseScreen) Update ¶
func (b BrowseScreen) Update(_ Context, message tea.KeyPressMsg) (BrowseScreen, Action)
Update reads one keystroke: the cursor and the level walk, the origin filter cycles, one of the two describers is raised about the row under the cursor, or the reader leaves.
type BuildRow ¶
type BuildRow struct {
Character cast.Character
// built is the build the row draws, and its absence is what makes the row a
// heading.
Built cast.Build
Heading bool
// empty marks a heading whose character has no build, which is what puts the
// note about it on the heading's own row.
//
// On its own row it was scrollable away from the character it was about: at the
// floor the first thing on screen was "no build written for this one yet" with
// the name of the character it meant one row above the top of the window. A
// note that can be separated from its subject is a note that says nothing, so
// it rides on the row that names the subject and the pair cannot come apart.
Empty bool
}
BuildRow is one line of the listing: a character opening its own group, or one of that character's builds.
The character is on every row, including the build rows, because a build names its character and a row that had to look one up would be a second index into the cast.
Headings are rows rather than something drawn between them, for the reason the status reference files its categories the same way: the listing scrolls, and a heading computed while rendering falls off the top of the window and leaves the rows under it with nothing saying whose they are.
type BuildsScreen ¶
type BuildsScreen struct {
Rows []BuildRow
// cursor indexes rows and is always on a build. Nothing is learnt by selecting
// a heading or the note under one, and a cursor that could land on either
// would make the pane below blink out for a keystroke.
Cursor int
}
BuildsScreen is the authored late-game builds, grouped by character, with the loadout of the one under the cursor spelled out below.
It is the answer to a question the rest of the tool cannot reach. A character screen shows a *learnset* — nine skills and five traits by the cap — and a placement spends four slots and one, so what the browser draws is everything a character could be rather than anything it is. Until the catalogue existed the only kit this repository could name was "the first four declared", which is the order the file happens to list and not a decision anybody made.
Read-only, like the status and trait references. A build is authored in builds.json against a character's learnset, and the loadout it picks changes what a battle measures — so it belongs in a diff, and this screen exists to be read.
func NewBuildsScreen ¶
func NewBuildsScreen(lib *forge.Library) BuildsScreen
NewBuildsScreen is the catalogue filled from a library, ready to draw.
func (BuildsScreen) Refresh ¶
func (b BuildsScreen) Refresh(lib *forge.Library) BuildsScreen
Refresh re-reads the catalogue, keeping the cursor where the list allows.
It walks the *cast* and asks each character for its builds, rather than walking the catalogue and grouping what it finds. The two differ in exactly one place and it is the place that matters: a character nobody has written a direction for is in the cast and in no build, so walking the catalogue would leave it off the screen entirely — the reader would be told the cast is shorter than it is, and the character most worth noticing is the one with nothing written for it.
func (BuildsScreen) Update ¶
func (b BuildsScreen) Update(_ Context, message tea.KeyPressMsg) (BuildsScreen, Action)
Update reads one keystroke: the cursor steps over the character headings, or the reader leaves.
type ChartScreen ¶
type ChartScreen struct{}
ChartScreen is the affinity chart drawn as the rings it was declared in.
The elements listing answers "what does fire lose to" one element at a time, which is the question somebody has with a skill in front of them. This answers the other one: what is the *shape*. Eleven rows of two strengths and two weaknesses is twenty-two facts to hold; three rings and a pair is four, and the rings are what the chart was written as — see the package doc on internal/core/element, which draws them the same way for the same reason.
A screen of its own rather than a block under the listing. Both halves want the height: the listing is eleven rows plus a description, the rings are five blocks plus their rates, and a window at the floor cannot hold the two. It is raised from the listing, the way the description screen is raised from the skills listing, because that is where a reader is when the question occurs to them.
No cursor. Nothing here is selected — the whole point is that it is read at once, and a cursor would invite a keystroke that has nothing to do.
func (ChartScreen) Update ¶
func (s ChartScreen) Update(_ Context, message tea.KeyPressMsg) (ChartScreen, Action)
Update reads one keystroke and says what the reader asked for. It quits, it goes back, or it does nothing: the chart has no cursor to move.
func (ChartScreen) View ¶
func (s ChartScreen) View(c Context) (string, string)
View draws the chart's body and its footer, in the language the Context is in.
Every block is generated from the chart the library holds, so the picture cannot disagree with the book — see chartBlocks for why that is the whole licence for drawing a picture at all.
type Context ¶
type Context struct {
Lib *forge.Library
Lang i18n.Lang
Style Palette
Width, Height int
// Authoring says whether the client in front can carry out a change to the
// data, and it is the one field here that is about the client rather than
// about the drawing.
//
// ⚠️ **It does not break the promise above, and the distinction is worth
// being exact about.** The paragraph over this type says a screen may not be
// told *which* client is asking, and it still may not: this says what the
// client in front is *able to do about a keystroke*, which is a capability
// and not an identity. Three screens here author — the skill listing writes
// `skills.json`, the works catalogue writes `origins.json`, the squad builder
// writes `squads.json` — and a game client offers none of that, so those
// three need an answer to one question and none of them may ask who is
// holding it.
//
// ⚠️ **Nought is the read-only reading, and that is deliberate rather than
// alphabetical.** The safe half of this flag has to be the one a forgotten
// declaration falls into, and here the safe half is *fewer* keys: a
// read-only client that quietly authored would write the author's files off
// a key its footer never named, while a tool that quietly stopped authoring
// loses `a`, `e`, `n`, `d` and `enter` — which the suites over these screens
// press by name. So the tool that can author declares it; the client that
// cannot has nothing to declare and therefore nothing to forget.
//
// ⚠️ **Which suite is the net was measured, and "the authoring client's own"
// is false for one of the three screens.** Inverting one guard at a time
// (`c.Authoring` → `!c.Authoring`) and counting failing tests:
//
// skills.go's `a` internal/screen 4 · cmd/hexarena-tui 2 · cmd/hexforge-tui 0
// squads.go's `n` internal/screen 10 · cmd/hexarena-tui 2 · cmd/hexforge-tui reddens
//
// The nought is `everyScreen` in cmd/hexforge-tui setting `SkillsScreen.Adding`
// **by hand** rather than pressing `a`, so nothing in that package drives that
// key at all. So the authoring half of these guards is held **here** — in this
// package's own suite — and the read-only half in cmd/hexarena-tui's, and
// neither client's suite alone covers both.
//
// ⚠️ **Both halves are measured, in the client that has the most to lose.**
// cmd/hexarena-tui presses every authoring key on every screen it draws and
// asserts nothing happened, and checks that no footer it draws names one of
// them — because a key announced on a screen that ignores it is worse than
// one nobody was told about, which is the rule picker.go states and the one
// this flag has to keep on three footers at once.
Authoring bool
// Player is the sides out of the player's **own** squad file, which is a
// different file from the game's and the only one a player may write in. It
// is what a client brings rather than something read from Lib — a Library is
// one data directory, and a player's file is not one: forge.Load wants the
// cast, the skills and the origins beside the squads, and a player has none
// of those. → forge.PlayerSquads.
//
// Two things read it, and only these two. forge.SquadsOffered lays it over
// Lib.Squads() to make the list a player picks from, which SquadsScreen does
// on every Refresh; and PlayerSquad below answers which of the merged rows
// came out of it, which is how a row says whose side it is.
//
// ⚠️ **Nil is the game-only reading, for exactly the reason Authoring's
// nought is the read-only one.** The safe half of a field a client may forget
// to declare has to be the half that changes nothing, and here that is a
// catalogue holding only what shipped. cmd/hexforge-tui therefore declares
// nothing: the authoring tool edits the game's data and a player's file is
// none of its business, which is the same sentence forge/player.go's head
// states pointing the other way.
Player []placement.Squad
}
Context is what a screen draws with: the books, the language, the palette and the window.
It is a value, copied per draw, and holds nothing a screen owns — no cursor, no mode, no pending question. That is what makes it shareable: a client keeps its own model and hands one of these down, so the helpers below cannot be told anything about which client is asking — only, since Authoring arrived, what the one in front is able to carry out.
func (Context) Continued ¶
Continued draws a row that carries on from the one above it: no name of its own, and its value under the same column as that row's.
The kit's Vietnamese names are what this exists for. Five skills glossed inline would be five brackets on one row, which does not fit the floor, so they go underneath in the same order instead — and they only line up with the ids above them if they are placed by the same measurement.
func (Context) DetailLabelWidth ¶
DetailLabelWidth is the column every detail pane's row name sits in, measured from the widest name being drawn in the language in front. The extra column is the gap, so the widest label is still followed by a space.
It was a constant 11, and that is what went wrong: a constant is one number for two languages, so it is only ever right for both by luck. The luck ran out on two labels at once — "effective hp" is 12 cells and "nguồn tham khảo" is 15 — and a label past its column pushes that one row's value right of every other row's, which is the same misalignment the form's summary rows had before formLabelWidth measured itself. Measure, do not raise the constant: raising it would waste the difference in whichever language is shorter, and leave the next reworded label to break it again.
func (Context) Footer ¶
Footer picks between a screen's two footers: the one naming the keys that author and the one naming only the keys a reader has.
⚠️ **It exists so the choice is made in one place rather than three.** The keys and the footer are two halves of one decision, and a screen that guarded the keys and drew the old footer would announce `a thêm` on a listing that ignores `a` — which is the failure picker.go's own comment names: *"A key announced on a screen that ignores it is worse than one nobody was told about."* A screen ignoring a keystroke is a reader wondering whether they pressed it; a footer naming that keystroke is the program promising something it does not do.
Neither wording takes an argument, and that is a property of the three footers this switches rather than of the idea: every authoring key on them is a bare letter, so the two spellings differ by whole clauses and not by a blank. A footer needing one is the site to widen this.
func (Context) Label ¶
Label draws a "name value" row the way every detail pane in this program does, so the panes line up with each other.
func (Context) LabelAt ¶
LabelAt is Label in a caller-chosen column.
The new-character form sizes its own column from the widest field name it is drawing, which differs per language ("archetype" is 9 cells, "mẫu vai trò" is 11), so its summary rows have to be told that width rather than assume the detail panes' one. They used to assume it, and the budget and carry lines sat a cell out of line with the stats directly above them — the wrong way in English and the wrong way in Vietnamese, in opposite directions.
func (Context) PlayerSquad ¶ added in v0.2.0
PlayerSquad reports whether the side of this id came out of the player's own file rather than out of the game's data.
⚠️ **It is asked by id rather than by row, and that is only sound because forge.SquadsOffered makes ids unique.** Two rows under one id would make this answer about whichever of them the merge happened to keep, which is the same ambiguity that would already have made the row a player pointed at and the side they fielded two different squads.
What it is for is the visible half of the collision rule: a player's side wins the id it shares with a shipped one, and a substitution nobody can see would be the silent collision that rule may not be. So a marked row is not decoration — it is how a player tells which of the two `s01`s is about to take the field.
func (Context) UsableWidth ¶
UsableWidth is what a row may spend: the window when there is one, and the floor before the first size message arrives.
func (Context) Wrapped ¶
Wrapped is Label for a value with no bound on its length: it fills the row and carries on underneath, aligned with where the value started.
Clipping was wrong for these in two ways at once. It cut at MinWidth, which is the *floor* a window has to clear rather than a ceiling on what one may use, so a hundred-cell terminal was being told it had seventy-nine. And a kit of nine ids or a paragraph of biography is longer than any terminal, so widening alone would not have saved it — the tail has to go somewhere, and a row below is where a reader looks for it.
The rows this draws are variable in number, so it belongs only on a pane that can afford that. The form counts its rows to scroll them and must not use it.
func (Context) WrappedIn ¶
WrappedIn is Wrapped with a style, applied one line at a time.
One line at a time matters. Styling the whole block instead treats it as a box: lipgloss pads every line out to the width of the widest and swallows the trailing newline, so the row after it was appended to the end of a field of spaces and disappeared. The dim reading lost its dimness and the art row lost its existence, from one Render around the wrong thing.
⚠️ **A wrapped row spends UsableWidth() - 1, and the cell it gives up is the window's last one.** LabelAt draws `marker + Pad(name, width) + " " + value`, so what is left for the value is the window less its final column, less the marker, less the label column and less the gap after it — the same terms FieldValueRoom spends and in the same order, without the two this row has not got (a fixed part of the value, and a gap before whatever follows it).
The final column is left empty for the reason frame leaves it: a line filling a terminal's final cell wraps on some of them, and one wrapped line pushes the footer off the bottom. This spent `- 2 - width - 1` until then and filled it — measured at the floor, browse's biography row came to exactly 120 of the 120 there are — which made it the fifth copy of the off-by-one FieldValueRoom's own comment records fixing in four other places, rather than a decision. The clip below is measured off the corrected room too, so the narrow case gives up the same cell the wrapped one does.
⚠️ **The bound is on the room and not on the drawn line, because WrapWords has an exception this cannot close**: a word longer than the room takes a line of its own and overflows it rather than being cut, so a value holding one still reaches the last column, and the frame is what answers for that. It is out of reach on shipped data — the longest token any recorded screen draws is 38 cells against a room of 99 at the floor — and narrowing the room by one adds no case to it, since a word that overflowed the wider room overflowed the narrower one already. TestAWrappedRowLeavesTheWindowsLastColumnEmpty is what holds it.
type DraftDecision ¶ added in v0.2.0
type DraftDecision struct {
Step DraftStep
// Character is the id banned or picked, and **empty on a ban is the skip** —
// a slot spent on nobody, with no third state and no flag beside it.
Character string
Stage string
Skills []string
Passives []string
// Slots is one side's whole arrangement, in **pick order**: `Slots[i]` is the
// cell for that side's i-th pick, which is what draft.Arrange takes and the
// only order it can be read in.
//
// ⚠️ **A side arranges in one call rather than a cell at a time**, which is
// why this is a list on one decision and not one decision per unit: the phase
// is simultaneous and secret, so a cell-by-cell stream would need the same
// buffer and would additionally hand a peer a partial arrangement to be told
// about. Empty on every other step. → ArrangeScreen, and wire.DraftDecision.
Slots []hex.Offset
}
DraftDecision is a draft decision as this screen took it.
⚠️ **A shape of its own for the reason DraftLive is one**, and the same walk holds it: the client maps this into a wire.DraftDecision, and its Step has to be one of the five the protocol declares.
⚠️ **The form is what was NAMED and never what it resolved to.** An empty Stage is progression.Furthest — "the furthest the level cap reaches" — which is what a line that does not fork means, and the resolution is the room's and the mirror's to compute. A decision carrying a resolved form would be a second statement of something both peers already work out, which is the one place two peers can disagree. → wire.DraftDecision.Stage.
type DraftField ¶ added in v0.2.0
type DraftField uint8
DraftField is which row of the loadout has the cursor.
⚠️ **Four rows for three fields, and the fourth is why `enter` needs no explaining.** On every other screen in this program enter means "do what is under the cursor", and on a loadout there are two things it could mean: open the list on this row, or send the whole decision. Making the send a **row** keeps one meaning for one key and lets the footer name it once — where a key that meant two things would need a footer explaining which, and a footer that explains a key is a key nobody has understood.
const ( // DraftForm is the form the pick will field, a chooser walked with the // arrows. DraftForm DraftField = iota // DraftKit and DraftTrait each open a list. DraftKit DraftTrait // DraftSend is the row that takes the decision. DraftSend // DraftFieldCount is how many rows there are, and is what the cursor wraps // against. DraftFieldCount )
type DraftLive ¶ added in v0.2.0
type DraftLive struct {
// Pool is every character the draft may ban and pick, **in the cast book's
// own declaration order**.
//
// ⚠️ **Do not sort it, and do not sort it here either.** draft.NewPool's
// comment carries the argument: five other listings in this repository are in
// declaration order — the browser, the builds screen, `hexforge list`, the
// squad builder's chooser and the restriction picker — so a draft screen that
// sorted would lay the cast out differently from every screen the player has
// just come from. ⚠️ The shipped cast happens to be in id order today, so
// sorting it would be a no-op and a test taken against the shipped books
// would measure nothing.
//
// It is **handed in** rather than read off Context.Lib, and that is the same
// decision PlayScreen.Home/Away is: the pool is a parameter of the draft. The
// client builds it with draft.NewPool over the **embedded** cast — the one the
// data digest at the gate promises both peers share — where Context.Lib is
// whatever --data pointed at, which may differ and would then offer a
// character the room refuses.
Pool []cast.Character
// Candidates is what the **open** decision may choose from, by id, in the
// pool's own order — draft.Draft.Candidates' answer, unchanged.
//
// ⚠️ It is what may be chosen and **not** what is left in the pool. A loadout
// chooses a form and a kit rather than a character, so this is empty during
// one while nineteen characters are still nobody's; what is left is derived
// from Bans and Picks instead, which is right in every state.
Candidates []string
// Picks and Bans are both sides' decisions, indexed by Seats.
Picks [2][]DraftPick
// Bans is the characters each side took out, in the order they were taken. A
// **skipped** ban is nowhere in it, because a skip names nobody. →
// draft.Draft.Bans.
Bans [2][]string
// Seats are the two seats in the order Picks and Bans are indexed, and the
// order is **handed in rather than declared here**: which of the two the room
// hands out first is the protocol's business, and a screen re-deriving it
// would be a fourth copy of three lines internal/draft, internal/room and
// internal/socket each already keep for their own stated reasons.
//
// They are names for the reason PlayLive.Refusal is one: a seat is only ever
// worded, through i18n.Lang.Seat, and never branched on.
Seats [2]string
// You is this reader's own seat and OnTurn the seat whose decision is due,
// empty when none is.
//
// ⚠️ **A You that names neither seat reads as neither side's**, and that is
// the safe half rather than an accident: every mark on the pool then says the
// *opponent* took it. The other way round, a forgotten seat would tell a
// player they had banned characters they never touched.
You string
OnTurn string
// Step is which kind of decision is due, DraftStepNone when none is.
Step DraftStep
// Yours is the open decision being **this** reader's to take, which is
// socket.DraftSight.Asked exactly.
//
// ⚠️ **It is not `OnTurn == You` and must not be replaced by it.** The arrange
// phase has two decisions open at once, so the reading reports no seat on turn
// and this reader may still be one of the two being asked — which is
// draft.Draft.Turn's own note about never widening for it.
Yours bool
// Subject is the character a loadout is owed for: the pick one decision
// earlier, which the reading derives rather than storing. Empty on every
// other step.
Subject string
// Recorded is how many decisions the draft has recorded, and it is the whole
// of how this screen knows a draft has begun at all. → Waiting, and
// socket.DraftDue.Recorded, which is the same number used as an answer's
// routing key.
Recorded int
// Units and BanSlots are the format's two numbers: how many characters a
// side picks, and how many it may ban.
//
// ⚠️ **Handed in, from draft.PicksPerSide and draft.BansPerSide, and never
// worked out here.** Those are the single declarations of both, and the
// arithmetic over them has moved three times in two days — a screen carrying
// its own copy would be a number that silently stopped being right. Note what
// is *not* here: how many candidates the last pick sees. That is
// `draft.Slack + 1` and this screen never needs it, because "there is only
// one left" is a fact about the list in hand. → OnlyOne.
Units int
BanSlots int
// Arranging is the arrange phase being open, and Cancelled the draft having
// been abandoned — which today happens for exactly one reason, an allowance
// running out.
Arranging bool
Cancelled bool
// Refusal is the **name** of the latest protocol refusal this client has been
// sent, empty when there has been none. → PlayScreen.LiveRefusal for why it
// is a name and never a typed value.
Refusal string
// Clock is what is left of the open decision's allowance on both sides,
// **handed in already counted**.
//
// ⚠️ **It is PlayClock and not a second countdown type.** A draft's allowance
// and a battle's are one number the room carries and one transport counts
// down, and PlayClock's whole argument — that this package reads no clock and
// is handed two counts of seconds — is about the boundary rather than about a
// battle. A DraftClock would be a second declaration of the same idea and a
// second pair of wordings for one row.
Clock PlayClock
}
DraftLive is a drafting room as one reading of it, and it is the draft's twin of PlayLive.
⚠️ **It is a value taken under the mirror's read lock and it does not outlive the call.** Unlike PlayLive it holds no pointer at all — a draft's state is the pool, the picks and whose decision is due, which is exactly what this carries, so there is no computation a renderer has to be handed an engine for. → socket.DraftSight, which says why Sight.Fight beside it is the one deliberate exception.
func (DraftLive) OnlyOne ¶ added in v0.2.0
OnlyOne is the character the open decision has no choice about, and whether there is one.
⚠️ **The rule is the list in hand and never a figure.** With every ban spent the final pick of a draft sees exactly `draft.Slack + 1` candidates, and that expression has answered 1, 2 and 4 within two days as the pool moved from sixteen characters to nineteen — so a screen holding the count, or a test asserting it, is a number that stops being true without anything saying so. Asking whether the list has one entry is the same question with nothing written down, and it is right for every step and every format.
A draft whose decision has one candidate must **say so** rather than present a list of one: the two look identical on screen and only one of them is a choice.
func (DraftLive) Waiting ¶ added in v0.2.0
Waiting reports that the draft has recorded nothing, which is the state a player has to be told about.
⚠️ **It cannot mean "the room is not full", and that is the finding rather than a weakness of this reading.** A room that drafts sends **nothing at all** when its second seat is taken — internal/room's bothTaken answers no message, and an empty wire.Drafted is refused by design — so from a client's side a draft with an empty record is either a room still waiting for its second player or a room that filled a moment ago and has been asked nothing, and the two are indistinguishable on the wire.
What is *not* indistinguishable is what a decision costs in each. Before the second seat is taken the room refuses a decision (draftOpen asks both seats taken) and the refusal leaves the decision open, so the client re-sends — five refusals were measured before the second client arrived — and what a real player, whose chooser blocks on a keystroke rather than spinning, gets instead is a ban that was **thrown away**. So this is drawn whenever the record is empty and the wording says what is true of both readings. → i18n.DraftNotBegun, and TODO.md § step 5a, which carries the protocol gap and the two candidate fixes for it, neither of which is a client fix.
type DraftPick ¶ added in v0.2.0
type DraftPick struct {
Character string
// Stage is the form this pick fields, **as resolved** — empty until the
// loadout has been taken.
Stage string
// Skills and Passives are the loadout. Both are empty while the pick's
// second decision is still open, which is a state the reading reports rather
// than one to detect: a pick with no skills is a character out of the pool
// whose loadout has not been chosen.
Skills []string
Passives []string
}
DraftPick is one side's pick as this screen draws it: the character, the form it will field and the kit it will bring.
It carries no level, unlike draft.Pick, and that is deliberate rather than an omission: every drafted unit fights at progression.LevelCap and nothing on this screen draws a level, so a field holding one would be a number a reader wonders about. → draft.Pick.Level, which is where the constant is argued for.
type DraftPickInto ¶ added in v0.2.0
type DraftPickInto uint8
DraftPickInto is where one of the loadout's two lists lands, in the shape SquadsPick already has: a destination names a field of *this* screen, so it is declared beside it. → PickState.Into.
const ( // DraftPickNothing is the zero value: a destination that names no field. DraftPickNothing DraftPickInto = iota // DraftPickKit is the skills a drafted unit brings, and DraftPickTrait the // one trait it holds. DraftPickKit DraftPickTrait // DraftPickIntoCount is the count a client's dispatch is held total against. DraftPickIntoCount )
type DraftResult ¶ added in v0.2.0
type DraftResult struct {
// Action is what the screen wants the client to do next — a Back, or a Pick
// putting one of the loadout's two lists in front.
Action Action
// Decided reports a decision having been taken, and Decision is it.
//
// ⚠️ Carried **beside** the decision rather than read off it, for
// PickResult.Answered's own reason: a zero Decision is a legal-looking value
// (a skipped ban names nobody), so absence has to be declared rather than
// detected.
Decided bool
Decision DraftDecision
}
DraftResult is what a keystroke did to the draft screen, beside the screen itself.
⚠️ **The pair is not (itself, Action), and the reason is PickResult's exactly: an Action cannot carry an answer.** A draft decision is a step, a character, a form, four skills and a trait; Action holds a Kind, a Target and a Subject, and a Subject is one id — so a loadout would have to be encoded into a field built to name one thing, which is the shape this repository has twice paid for.
⚠️ **And Kind did not grow an eighth value, which was the alternative.** draw.Answer is *"a decision this screen has taken on a battle it does not drive"* and reusing it for a draft would be a second vocabulary inside one field; a Kind of its own would bill cmd/hexforge-tui for an arm about a screen it does not draw and can never reach. A result type is the answer the picker already established for the same problem.
type DraftScreen ¶ added in v0.2.0
type DraftScreen struct {
// Live is the reading in hand, replaced whole on every Attach.
Live DraftLive
// Drafting says a reading has been handed over at all. Nought is a screen
// nothing has attached to, which draws nothing rather than an empty draft.
Drafting bool
// Cursor indexes Live.Candidates, so it can only ever point at something the
// open decision may actually name.
//
// ⚠️ **It indexes the candidates and not the pool rows**, which is what makes
// a character already gone unselectable by construction rather than by a
// refusal at the keystroke. The pool is drawn whole; the marker is put on the
// row whose id the cursor names.
Cursor int
// Field is which row of the loadout has the cursor, and Stage, Skills and
// Passives are the loadout under construction — this screen's own state,
// which nothing on the wire has yet been told about.
Field DraftField
Stage string
Skills []string
Passives []string
// Err is what cast.ChooseFrom said about the kit as it was chosen, and it is
// what blocks the send. → the file comment on why blocking is not politeness.
Err error
}
DraftScreen is the ban and pick: the pool with what is gone marked, both sides' picks, whose decision is due, and the loadout that finishes a pick.
It is drawn by cmd/hexarena-tui alone today — cmd/hexforge-tui has no room to join — and it lives here anyway, for the reason at the head of this file: it is a data column, and a data column held by one golden rather than two is a column whose width nothing measures on the client that stops drawing it.
func NewDraftScreen ¶ added in v0.2.0
func NewDraftScreen() DraftScreen
NewDraftScreen is the screen before a reading has been handed to it.
func (DraftScreen) Attach ¶ added in v0.2.0
func (d DraftScreen) Attach(_ Context, live DraftLive) DraftScreen
Attach points this screen at a drafting room.
It is called on **every** redraw rather than only when something changed — the client reads its mirror under a lock and hands over whatever it found — so it is cheap and idempotent, exactly as PlayScreen.Attach is. Unlike that one it is idempotent about everything, because a draft has no event cursor: the whole state arrives on every reading.
What it keeps and what it throws away:
- The cursor follows the **character** rather than the row. The candidate list shrinks under a reader — the opponent bans while they are walking it — and every row below the one that went moves up by one, so a kept index is a cursor that jumps to a neighbour every time the other player decides anything. When the character under the cursor is the one that went, the row number is kept, which lands on whatever is now next.
- The **loadout is thrown away when the pick it is owed for changes**, which is the one thing here that resets. A form and a kit belong to the character they were chosen for, so carrying them into the next pick would offer skills the new character has never learned — and cast.ChooseLoadout would refuse them, one decision later, with the reader unable to see why.
func (DraftScreen) Character ¶ added in v0.2.0
func (d DraftScreen) Character() (cast.Character, bool)
Character is the pool entry the loadout is being chosen for, and whether the pool holds one.
⚠️ **Read off the pool and never off Context.Lib**, which is the same rule DraftLive.Pool is handed in under: the legality of a kit has to be judged against the cast the *room* is drafting from, and --data may point at another one. A subject the pool does not hold is a reading nothing can act on, which the editor says rather than guessing at.
func (DraftScreen) Choosing ¶ added in v0.2.0
func (d DraftScreen) Choosing() bool
Choosing reports whether the loadout editor is in front rather than the pool: a loadout is due and it is this reader's.
A loadout the **other** player owes draws the pool, because that is what there is to look at while they choose — and because nothing about their form and kit is public until the decision is recorded.
func (DraftScreen) Chosen ¶ added in v0.2.0
func (d DraftScreen) Chosen() (string, bool)
Chosen is the character under the cursor, and whether there is one.
func (DraftScreen) Deciding ¶ added in v0.2.0
func (d DraftScreen) Deciding() bool
Deciding reports whether there is a decision on the pool for this reader to take, which is what decides whether enter does anything and which footer is drawn.
func (DraftScreen) FormChoices ¶ added in v0.2.0
func (d DraftScreen) FormChoices() []string
FormChoices is the forms this pick may field: the empty string, which is "the furthest the cap reaches", and then every arm the line offers by name.
It is the squad builder's StageChoices over a drafted pick, and the empty first entry is there for the same reason: a line that does not fork has one end and naming it would be a decision nobody has to take, while a line that forks has to be told which arm. A character the pool does not hold offers nothing.
func (DraftScreen) Left ¶ added in v0.2.0
func (d DraftScreen) Left() int
Left is how many of the pool nobody has taken.
⚠️ **Derived from the marks and not from the candidate list**, and the difference is a whole decision: Candidates is what the *open* decision may choose from, which is empty during a loadout — so a count taken off it would tell a player nought characters were left while nineteen were still nobody's.
func (DraftScreen) OpenPassives ¶ added in v0.2.0
func (d DraftScreen) OpenPassives() *PickState
func (DraftScreen) OpenSkills ¶ added in v0.2.0
func (d DraftScreen) OpenSkills() *PickState
OpenSkills and OpenPassives are the loadout's two lists.
⚠️ **They are PickState, which is the whole reason this screen needed no list of its own.** The multi-select already is "several out of a list, keeping the order", the squad builder's two are the prior art, and the two hints and the two slot counts below are that screen's — because a drafted loadout and a saved member's are the same question asked of the same books.
The options are the **learnset**, so no row can carry a refusal, which is why each names its own hint rather than taking the picker's default.
Nil is a pick the pool does not hold, or a form that does not resolve: there is no learnset to offer, and the key that raises the list declines rather than putting an empty one in front.
func (DraftScreen) Picked ¶ added in v0.2.0
func (d DraftScreen) Picked(_ Context, into any, answer PickAnswer) (DraftScreen, Action)
Picked is what the loadout's two lists write back, judged by the rule the send uses.
⚠️ **The destination arrives as an `any`** — see SkillsScreen.Picked for why there is more than one destination vocabulary to tell apart — and a destination this screen does not own is left alone rather than guessed at.
⚠️ **The refusal is taken here as well as at the send, which is the point.** An author picking five skills for four slots should be told at the list rather than at the decision: the picker's own Slots cap stops an over-full answer being *built*, and this is the rule underneath it, asked through the same call the room will make.
func (DraftScreen) Update ¶ added in v0.2.0
func (d DraftScreen) Update(c Context, message tea.KeyPressMsg) (DraftScreen, DraftResult)
Update reads one keystroke.
type DraftStep ¶ added in v0.2.0
type DraftStep uint8
DraftStep is which kind of decision a draft is asking for, in this package's own vocabulary.
⚠️ **It is an enum and not a name, and that is the one place this file departs from PlayLive.Refusal's precedent on purpose.** A refusal is only ever *worded* — it crosses as a string and goes straight to i18n.Lang.Refusal — and so does a seat here, for the same reason. A step is **branched on**: a ban, a pick and a loadout draw different lines, offer different keys and name different footers. Branching on an unchecked string would mean writing the protocol's own spellings out as literals in this package, where nothing would notice them drifting: "ban" is one short word with no space in it, so TestNoScreenHoldsItsOwnWording would pass on all five.
The zero value is nothing due, which is the safe half a forgotten declaration falls into: a screen that quietly went to DraftStepNone draws no decision, where one that quietly went to DraftStepBan would offer a ban nobody asked for.
const ( // DraftStepNone is no decision due: between decisions, before the first, on // a draft that is over and during the arrange phase, which is asked about // through DraftLive.Arranging because two decisions are open at once. DraftStepNone DraftStep = iota // DraftStepBan is a side taking a character out of the pool for the match, and // it is optional — a ban that names nobody is a slot spent on nobody, which // is the skip. DraftStepBan // DraftStepPick is a side taking a character for itself, the first of the two // decisions a pick is made of. DraftStepPick // DraftStepLoadout is the second: the form, the skills and the trait the // character just picked will field. DraftStepLoadout // DraftStepArrange is a side putting its picks on its own formation. This screen // draws that the phase is **open** and nothing else about it; the formation // is the arrange screen's. DraftStepArrange // DraftStepTimeout is nobody's decision: an allowance having run out, which // cancels the whole draft. It is in the vocabulary because the protocol's is, // and a mapper that had nowhere to put it would be a mapper with a hole. DraftStepTimeout )
type ElementsScreen ¶
type ElementsScreen struct {
Cursor int
}
ElementsScreen is the affinity chart: the eleven elements, and for the one under the cursor, what it beats, what beats it, and at what rate.
It is the reference the tool was missing hardest. Every other listing prints an element somewhere — a skill's own element, a character's affinity, the "hệ grass" in a restriction — and the chart those ids resolve against was readable only in elements.json, which spells it as three cycles and a mutual pair rather than as "what does fire lose to". That is the one table every damage figure in the game passes through, so it is the one an author is most often guessing at.
Read-only, like the status and trait references. The chart is balance in its purest form: adding an edge changes every battle at once, and the three multipliers are the game's whole scale. That belongs in a diff.
The rows are element.All() rather than anything read off the library, because the elements are a Go enum: the chart may say nothing about a member — neutral is inert on purpose — but it cannot invent a twelfth one, and a listing built from the edges would silently drop the element that has none.
func (ElementsScreen) Update ¶
func (s ElementsScreen) Update(_ Context, message tea.KeyPressMsg) (ElementsScreen, Action)
Update reads one keystroke: the cursor moves, the chart is raised, or the reader leaves.
type Kind ¶
type Kind uint8
Kind is what a screen wants done.
const ( // Stay is the zero value, and that is load-bearing rather than tidy: a // screen handed a key it has nothing to do about returns an Action it never // filled in, and the client does nothing with it. A "do nothing" that had to // be spelled out is one keystroke handler away from being forgotten, and a // forgotten one would fall into whichever Kind sat at nought. Stay Kind = iota // Back is one step towards wherever the reader came from, and the client is // what remembers where that was. // // ⚠️ A screen may not name its own way back even when it has only one // raiser. The chart's did — it went to the elements listing by name, on the // true and fragile ground that nothing else raises it — and a screen that // spells out the one door it has today is a screen that is wrong the day it // has two, in a client it was not written for. Back // Quit ends the session. // // An action rather than a tea.Cmd, and that is not ceremony: it lets the // client decide what quitting means. The authoring tool ends there; a game // client with a battle half played may well want to ask first, and a screen // that returned the command itself would have taken that decision away from // it. Quit // Raise opens another screen, named by Target and about whatever Subject // names. Raise // Ask puts a confirmation to the reader, worded by Question, and leaves the // screen where it is. // // ⚠️ **Not a Raise, and the difference is not bookkeeping.** A raise names a // Target — one of a closed list of *screens* — and the client remembers // where it came from so Back can return. A question is drawn over whatever // is already in front, takes one keystroke, and hands the answer back to the // screen that asked through that screen's own Confirmed. There is nothing to // name and nowhere to go back to, so a Target would have to be invented for // a screen a client does not have. Ask // Pick puts the list in Picker in front, over whatever raised it. // // ⚠️ **Also not a Raise**, for a sharper reason: a Target is a *request* the // client turns into one of its own screens, and a picker is not one of them. // It is a value this package built, holding the rows, the cursor and the // destination the answer belongs to, and the client's only job is to keep it // while it is open. There is no map from Pick to anything. Pick // Answer is a decision this screen has taken on a battle it does **not** // drive: a live PlayScreen, whose engine belongs to a socket.Mirror and // whose turns are the server's to apply. // // ⚠️ **It is the seventh Kind because none of the six can say it.** Nothing // is navigated to (not Raise), nothing is asked (not Ask), no list is opened // (not Pick), and Stay would swallow it. // // ⚠️ **Carrying it as a field under Stay was considered and refused**, even // though that is exactly the Picker precedent one type up. The difference is // what a dropped one looks like: a dropped Picker opens no list, which a // reader sees at once, while a dropped Answer looks precisely like a turn // nobody has got round to resolving yet — the opponent is thinking, or the // engine is between turns. Swallowing the one keystroke a battle is about, // invisibly, is the failure KindCount exists to make loud, so it gets a // Kind and both clients owe it an arm. cmd/hexforge-tui's is one line // saying it draws PlayScreen in local mode only. Answer )
type OriginsScreen ¶
type OriginsScreen struct {
Origins []cast.Origin
Counts map[string]int
Cursor int
// Adding is whether the form is in front of the catalog.
Adding bool
// Inputs is every typed field of the form, indexed by the OriginField
// constants above.
//
// ⚠️ **A slice, so two copies of this screen SHARE it**, exactly as the skill
// form's own Inputs do and with the same caveat: every other field is copied
// when the screen is and these text fields are not. It is moved as it is,
// deliberately — the behaviour is relied on today and changing it is a
// measurement of its own rather than a side effect of a move.
Inputs []textinput.Model
MediumIndex int
Field int
Touched bool
Err error
// Added is the last work written, kept as what it was rather than as the
// line announcing it, so a language switch redraws the announcement.
Added *cast.Origin
}
OriginsScreen is the catalog of works the cast is borrowed from, and the form that adds one.
A work has to exist before a character can name it, so this screen is the other half of the new-character form rather than a listing for its own sake: an author who finds the origin they want missing can add it and go straight back without leaving the program.
It is the **seventh and last** of the catalogues a game client will offer, and the cleanest of the moves: it kept no cursor of anybody else's, raised nothing and read no other screen's state, so the whole of what it named of its client was one way back and one question. The way back is a Back and the question is an Ask carrying no subject — this screen names nothing, so it passes nil where the squad builder passes a SquadsAsk.
func NewOriginsScreen ¶
func NewOriginsScreen(c Context) OriginsScreen
NewOriginsScreen is the catalog filled from a library, with an empty form behind it.
⚠️ **It takes a Context rather than a library**, which is the one signature this move had to change, and the reason is the one NewSkillsScreen carries: the form dresses text fields, NewInput wants to know whether colour would be noise, this package may not read an environment, and Palette already holds the answer the binary was handed.
func (OriginsScreen) Confirmed ¶
func (o OriginsScreen) Confirmed(c Context, _ any) (OriginsScreen, Action)
Confirmed throws the half-typed work away and closes the form, which is the whole of what the question above offered.
It stays on this screen — the listing behind the form is where the reader was — so the action is the zero one, Stay.
⚠️ **What the question was about arrives as an `any` and is ignored.** This screen asks one question and it is about the screen itself, so there is nothing to tell apart; the parameter is here so the shape matches every other Confirmed a client dispatch is held total over.
func (OriginsScreen) Paste ¶
func (o OriginsScreen) Paste(_ Context, text string) (OriginsScreen, tea.Cmd)
Paste puts a pasted string where a typed one would go, and nowhere when the keyboard is not on a field. → paste.go for the one rule pasteTarget is.
The bookkeeping is updateForm's, on the same condition: a paste that changed the field is an edit, so it makes the form dirty and clears the last refusal, and a paste that changed nothing — refused for length, or empty — leaves both alone.
func (OriginsScreen) Refresh ¶
func (o OriginsScreen) Refresh(c Context) OriginsScreen
Refresh re-reads the catalog and the count of characters borrowed from each work, clamping the cursor: entering the screen after a write should show the new row rather than a stale list.
func (OriginsScreen) ResetForm ¶
func (o OriginsScreen) ResetForm(c Context) OriginsScreen
ResetForm empties every field of the add-a-work form and puts the keyboard back on the first of them.
func (OriginsScreen) Update ¶
func (o OriginsScreen) Update(c Context, message tea.KeyPressMsg) (OriginsScreen, Action, tea.Cmd)
Update routes a keystroke on the catalog or on the form over it, and says what the client owes it.
⚠️ **Three returns rather than two, and the third is a tea.Cmd** — the same arrangement, for the same measured reason, as draw.SkillsScreen.Update. This screen has text fields, and a bubbles textinput answers an Update with a command (the cursor's blink) which has to come out or the field loses its cursor. It is not a field on Action, deliberately: an Action is a comparable value a screen returns and a test writes out as a literal, and a func field would take that away from every screen to serve two.
type Palette ¶
type Palette struct {
Title lipgloss.Style
Heading lipgloss.Style
Label lipgloss.Style
Dim lipgloss.Style
Good lipgloss.Style
Bad lipgloss.Style
Selected lipgloss.Style
// Emphasis marks a data name inside the program's own prose. Bold and no
// colour, because it is standing in a sentence rather than in a column, and
// a coloured word mid-paragraph reads as a link to somewhere the terminal
// cannot take you.
Emphasis lipgloss.Style
// Plain is what NewPalette was told about the terminal in front, kept so a
// screen that draws something other than styled text can ask.
//
// ⚠️ It is a **remembered answer, never a second one**: this package reads no
// environment, so the binary asks Plain and hands the result to NewPalette,
// and this field is that same bool. The art preview needs it because its
// monochrome path is a *different drawing* rather than the coloured one with
// the escape codes taken out — a ramp of weights instead of half blocks — so
// it cannot get the answer by rendering through a style and finding nothing
// happened.
Plain bool
// Elements is one style per element, indexed by the enum.
//
// It is the one place in this program where colour is *about* the data
// rather than about the layout, and it still is not information: the chart
// screen names every element in words and draws every relation with an
// arrow, so the colours only make a ring easier to follow with the eye. Take
// them away and the same screen says the same thing — which is the test the
// palette's rule really is.
//
// An array rather than a map: it is indexed by an enum whose Count is fixed
// and checked, and a map would let an element go unstyled without anything
// saying so.
Elements [element.Count]lipgloss.Style
}
Palette is every style the screens draw with.
Colour is decoration and never information. A missing file says "MISSING", a kit an affinity cannot carry says which skill it cannot carry, a selected row carries a "> " marker, and a bar prints the numbers beside it — so the whole program reads on a monochrome terminal, through a screen reader, and in a terminal recording that lost its escape codes. That is not politeness: the one thing this client exists to show is whether a character is legal, and an answer nobody can read is not an answer.
func NewPalette ¶
NewPalette picks the styles for the terminal in front of it.
NO_COLOR and a dumb TERM both mean "write plain text". The check is explicit rather than left to the rendering library so that the behaviour is this program's own, testable, and does not change under it when a dependency revises its own idea of when colour is welcome.
⚠️ The answer is **handed in** rather than read: the environment belongs to the binary, and two clients share this package. The caller asks `Plain` and passes what it said.
func (Palette) Element ¶
Element is the style one element is drawn in, or plain for an id the enum does not have — which nothing in the book can produce, and is written down rather than left to panic on the day something does.
func (Palette) ElementInk ¶ added in v0.5.2
func (p Palette) ElementInk() tui.ElementInk
ElementInk is the roster's element column drawn in the colours above.
⚠️ **It is the whole of the wiring, and it exists so that there is one of it.** internal/tui draws the table and has no palette; this package has the palette and may not restate the table. So the renderer asks for one cell's ink and gets it from `Element` — the same array the chart screen and the matchup marks read — rather than from a second list of colours chosen again here. A second list would agree on the day it was written and drift on the first day somebody decided ground should be brown.
Under NO_COLOR every style in the palette is the identity, so this returns the code untouched and the goldens stay plain without a case of their own. That is also the property the column rests on: the code carries the meaning and the colour only reinforces it. A method rather than a function so that a caller holding a palette cannot draw the table without one: `tui.RosterWide(…, nil)` is legal and plain, and the thing that should never happen is the *client* passing it.
type PassivesScreen ¶
type PassivesScreen struct {
Passives []passive.Passive
// carriers is keyed by trait id and read by key only; nothing ranges over it
// into an ordered output, so it cannot reach a rendered line out of order.
Carriers map[string]string
Cursor int
}
PassivesScreen is the declared traits, with what each one does under the cursor.
It answers a different question from the one the cast browser's `?` answers, which is why both exist. That one asks "what is this character carrying" and is filtered by a level; this one asks "what traits are there", which is the question somebody has before they know which character to look at — and the one nothing in the tool could answer, because a trait was only ever reachable through a character that already had it.
The column that earns its place is **who carries it**. A trait has no restriction mechanism at all, so "who may carry this" is everybody and answers nothing; who actually *does* is the fact worth a column, and a trait nobody learns is a trait that cannot reach a battle. That is not an error — a catalog may be written before the cast that fills it — but it is the sort of thing a listing is for.
Read-only, like the status reference and unlike the skills listing. A trait carries modifier terms and shares of damage, which is balance rather than content: adding one changes what every character holding it does, and that belongs in a diff rather than behind a form. Nothing in either front-end authors a trait today.
func NewPassivesScreen ¶
func NewPassivesScreen(lib *forge.Library) PassivesScreen
NewPassivesScreen is the listing filled from a library, ready to draw.
func (PassivesScreen) Refresh ¶
func (p PassivesScreen) Refresh(lib *forge.Library) PassivesScreen
Refresh re-reads the declared traits and who carries each, keeping the cursor inside the book.
func (PassivesScreen) Update ¶
func (p PassivesScreen) Update(_ Context, message tea.KeyPressMsg) (PassivesScreen, Action)
Update reads one keystroke: the cursor moves, the statuses reference is raised on the status this trait names, or the reader leaves.
type PickAnswer ¶
type PickAnswer struct {
// Chosen is in the order it was picked, because for a kit that order *is*
// the kit.
Chosen []string
// Typed is the extra field's answer, empty for a picker that has none.
Typed string
}
PickAnswer is what a picker hands back: what was chosen, and the one thing that was typed beside the list.
A struct rather than two parameters so that the pickers with nothing to type are not written as though they had ignored something — and so that a sixth picker needing a second answer does not change four call sites.
type PickKind ¶
type PickKind int
PickKind is what a picker is choosing.
const ( // PickSkills is the kit, whose rows say who may carry each skill. PickSkills PickKind = iota // PickElements, PickArchetypes, PickCharacters, PickSpecies and PickOrigins // are a restriction's five allowlists, whose rows are ids and their // Vietnamese names. PickElements PickArchetypes PickCharacters // PickSpecies is one of the two whose name comes out of a data file rather // than a compiled gloss, because a species is authored with its name beside // it -- the same arrangement a passive has. PickSpecies // PickOrigins is the second of those, and for the same reason: an origin is // authored with its title beside it in origins.json. PickOrigins // PickStatuses is what a skill inflicts, whose rows carry each status's own // facts — how long it lasts, how far it stacks, whether it ticks — because // choosing between "mire" and "expose" on the ids alone is not choosing. PickStatuses // PickPassives is the trait a placement keeps, and it exists because the // squad builder was raising its trait picker as PickSkills: the rows were // trait ids and the detail looked each one up in the skill book, so every // row on that screen drew "unknown skill" in red where its detail belonged. // A kind of its own rather than a lookup that tries both books, for the // reason every other kind here is one — what a row *is* decides how it // reads, and a detail guessing at that is a detail that can guess wrong. PickPassives )
type PickOption ¶
type PickOption struct {
ID string
Refusal error
// Group is what a filter narrows the list by, empty for a picker with none.
//
// One string per row rather than a predicate per filter, because the only
// thing a filter has to do here is answer "is this row in the group in
// front" — and a row carrying its own group means the filtering is the same
// code whatever the group turns out to be.
Group string
}
PickOption is one row: an id, and why the carrier may not take it.
The refusal is an error value rather than a sentence, and it is the same value forge.CheckSkill hands the write. A picker that decided availability for itself would be a second copy of the rule, and the copy would be the one an author trusted.
func CharacterOptions ¶
func CharacterOptions(lib *forge.Library) []PickOption
CharacterOptions is the authored cast as rows, each carrying the work it was borrowed from so the list can be narrowed by it.
The order is the cast book's own, which is what the browser lists too, and the group is the character's origin — the same axis the browser filters on, so an author filtering here is filtering by the thing they already filter by there.
⚠️ **A held-back character is offered here, and that is not an oversight — do not "finish the job" by filtering cast.Character.Hidden out of this list.** The squad builder honours the flag because it is choosing *who fights*, and a character held back is one an author has taken out of that choice. This list answers a different question: which characters is this skill kept for, written into `restrict.characters`. Hiding a row here would make an existing restriction naming that character **unauthorable** — a skill whose allowlist already names it could not be re-saved with the name it has, and there is no second way in, because the field is a picker and nothing else writes it. The two lists share a shape and share nothing else.
func IDOptions ¶
func IDOptions(ids []string) []PickOption
IDOptions is a plain list of ids, for the three allowlists.
func KitOptions ¶
func KitOptions(lib *forge.Library, who forge.Carrier) []PickOption
KitOptions is the skill book as rows, each carrying whether this character may take it and why not.
Every skill is listed, including the ones this character cannot take. That is the point: a kit is chosen against a book an author is still learning, and a row saying "kept for the bulwark role" teaches something a missing row does not.
func StatusOptions ¶
func StatusOptions(lib *forge.Library) []PickOption
StatusOptions is the status book as rows.
Every status is offered and none can be refused: a skill may inflict anything the book declares, so there is no carrier to check against and no row that carries a mark. What each row carries instead is the status's own facts, which is the thing an id does not say.
type PickResult ¶
type PickResult struct {
// Answered reports the list came down on enter rather than on esc, which is
// the difference between a finished pick and an abandoned one.
//
// ⚠️ It is carried **beside** Into rather than read off it. A picker with no
// destination is legal — a state built by hand carries none — so a nil Into
// means "this answer lands nowhere", which is a different sentence from
// "there was no answer", and the two would be one field otherwise. Absence
// declared, never detected: the rule the log's follow flag and the queue's
// pending reading are both written under.
Answered bool
// Into is the destination the picker was raised with, handed straight back
// and never looked at. See PickState.Into.
Into any
// Answer is what was chosen and what was typed, and is only filled in when
// Answered.
Answer PickAnswer
// Cmd is whatever the field under the list asked for — a cursor blink, on
// the one picker in five that has a field at all.
//
// ⚠️ **A tea.Cmd here is the one thing no other screen in this package
// returns**, and it is unavoidable rather than a widening of the vocabulary:
// bubbles' textinput answers an Update with a command, and dropping it would
// leave the chance field with no cursor. Everything else a keystroke wants is
// still said in data.
Cmd tea.Cmd
}
PickResult is what a keystroke did to a picker, beside the picker itself.
⚠️ **The pair is not (itself, Action), which every other screen here answers with, and the reason is that an Action cannot carry an answer.** A closed picker hands back a set of ids and one typed string; Action holds a Kind, a Target and a Subject, and a Subject is one id — so a kit of four would have to be encoded into a field built to name one thing, which is the shape this repository has twice paid for. The two are not even the same question: an Action says *what a screen wants a client to do next*, and none of the ten destinations wants anything done — a pick fills in a field and leaves the reader in front of the form they were filling. So there is no Action here at all, and there is a result type instead.
The **picker** is the other half of the pair and is returned rather than carried in here, because the pointer is the presence flag: nil is the list coming down, which is what esc and enter both do.
type PickState ¶
type PickState struct {
Title i18n.Key
Hint i18n.Key
Kind PickKind
Options []PickOption
// Chosen is the answer, in the order it was chosen, because for a kit that
// order *is* the kit.
Chosen []string
// Slots is how many the answer may hold, and **nought is uncapped**.
//
// Uncapped is what every picker but two is, so nought is the honest default
// rather than a flag beside a number: the five restriction allowlists take
// as many ids as an author cares to name, the status picker likewise, and
// the character form's kit picker is bounded by the write rather than by a
// count. The two the squad builder raises are the exception, because a
// placement spends exactly cast.SkillSlots and cast.TraitSlots.
//
// It is enforced in Toggle rather than only where the answer lands, so an
// answer past the limit cannot be built at all — the refusal used to arrive
// after enter, by which time the author had picked six and had to reopen the
// list to give two back.
Slots int
Cursor int
// Typed is the one answer collected beside the list, and Label names it.
// Both are absent for the pickers that choose ids and nothing else.
Typed *textinput.Model
Label i18n.Key
// Groups are the values f narrows the list by, and Filter indexes them from
// one — zero is the filter that hides nothing, exactly as the cast browser's
// own filter is numbered, and for the same reason: its name is a translated
// word while every entry in the list is an id that reads the same in either
// language.
//
// Empty for a picker with nothing to narrow. The list a filter is worth
// having on is the one that grows with the cast, which is the characters.
Groups []string
Filter int
// Reading is whether the description of the row under the cursor is in
// front of the list, and Scroll is how far down that description has been
// walked.
//
// A state of the picker rather than a screen, and that is forced rather than
// preferred: the picker is drawn over whichever screen raised it and takes
// keys before any screen does, so a description reached by switching screens
// would be a screen the picker went on swallowing the keys of. It is the
// same reading BlurbScreen gives, from the one place a kit is actually
// chosen — an author picking four of nine wants to know what the fifth does
// *there*, not on the listing two screens away.
//
// Scroll is not a second cursor, for the reason BlurbScreen's is not: it
// selects nothing, it is which lines of one answer are visible, and every
// key that changes *which* row is described resets it so it cannot survive
// into a shorter answer and leave a reader looking at nothing.
//
// ⚠️ **Measured: no shipped description reaches it.** BlurbScreen scrolls
// because it draws all five of a character's traits at once, which is some
// thirty lines against the seventeen an 120-by-24 window leaves;
// one row is at most three, in either language, across every shipped skill
// and trait. So this is the guard and not a live path — kept because a trait
// is allowed six sentences and the room falls to three in a small window, and
// because dropping it would leave the one screen built for reading a
// description unable to finish reading one the day somebody writes a long
// one. What that costs is two cases; what the answer being clamped where it
// is *read* buys is that an offset past a short answer still draws it.
Reading bool
Scroll int
// Into is where the answer lands when the list is closed with enter, and
// **this package never looks at it**: it is stored, carried through the
// keystroke that closes the list, and handed straight back on the result.
//
// ⚠️ **It is deliberately opaque, and that is what let the picker move.** A
// destination names one field of one *client's* screen — the kit on that
// client's character form, the fifth allowlist on its skill form — so it is
// that client's vocabulary and cannot be declared here. Carrying it as `any`
// is the same arrangement the unsaved-changes guard already has, where the
// question records the client's own screen enum and nothing in the question
// reads it. The client is the only thing that knows what a value here means,
// and the only thing entitled to interpret one.
//
// ⚠️ **It used to be an `apply func(model, PickAnswer) model`**, and that
// closure is what kept this screen in one binary: a callback naming `model`
// names one client, so a screen holding one is a screen written for the
// client it was written in. Measured before it was replaced — there were
// **ten** of them, in three files, and every one wrote the answer into one
// named field of its own screen and then set a flag or two beside it. That
// is a destination, and a destination is data.
//
// A nil Into is a picker whose answer goes nowhere, which is what a state
// built by hand carries: enter closes the list and writes nothing.
Into any
}
PickState is a picker while it is open.
func (*PickState) Describes ¶
Describes reports whether the row under the cursor has a description behind it, which is what decides whether ? is offered at all.
Two of the eight kinds, and the division is which books hold a describer a player would read: a skill has Describe and a trait has DescribePassive. An element, a role, a character, a species and an origin have none — a row there is an id and its name, which is already the whole of what could be said.
A status has one and is deliberately left out. Its rows already carry the facts a description would derive, its picker spends the keys under the list on a chance field, and Lang.DescribeStatus has a reference screen of its own that reaches every status rather than only the ones a skill happens to inflict.
func (*PickState) Detail ¶
Detail is what a row says about its option, beyond the id.
For a skill that is who may carry it, in the same words the listing and a refusal use. For the three allowlists it is the id's Vietnamese name, which is nothing at all in English — there, an id is shown as the data writes it, and detailColumn drops the whole column rather than drawing a row of blanks.
⚠️ It is exported for the client's width sweep, which enumerates this column over every row of whichever picker a screen is holding open. That sweep calls this rather than rebuilding one, deliberately: a second reading would have to know the eight kinds apart, and a data column enumerated by a copy of the thing that draws it goes quietly wrong the day a ninth is added.
func (*PickState) IDColumn ¶
IDColumn is the column the ids sit in, measured from the ids being drawn.
func (*PickState) NextFilter ¶
func (p *PickState) NextFilter()
NextFilter steps the filter on, wrapping through "everything".
The key and the cycle are the cast browser's, deliberately: an author who has filtered the cast once should not have a second interaction to learn for the same job on a list of the same things.
func (*PickState) Paste ¶
Paste puts a pasted string into the one field a picker can have.
Three things have to hold and each is one of Update's own: there is a field at all — four pickers in five have none — it has the keyboard, and no description is in front of the list. ⚠️ **Reading is the load-bearing one.** A description takes every key before the switch is reached, so a paste that ignored it would be the one input that reached the list from behind a screen drawn over it.
A nil receiver does nothing, because "there is no picker up" is a state a client's paste route asks this in.
PasteDigits rather than PasteInto: that field is the chance, its typed path is gated on NumberKey, and a paste is the only other way into it. → paste.go.
func (*PickState) Raise ¶
Raise settles the defaults a raiser did not fill in and hands the picker back ready to be put in front. Nothing is applied until it is closed with enter.
It returns the same pointer it was given rather than a value, because the pointer **is** the presence flag: a client stores it, branches on it not being nil to decide whether a picker is up, and closes the list by writing nil. Ten raise sites build a literal and hand it here, so the three answers below are settled once rather than at each of them.
func (*PickState) Room ¶
Room is how many rows the list has, measured from the window in hand.
The count was wrong the first time it was written and the screen said so: the body has c.Height-4 lines to draw in, and this screen spends **seven** of them — its heading, its hint, a blank, the rows, a blank, the summary, the refusal for the row under the cursor, and the empty string that the trailing newline leaves behind when frame splits the body. Miss one and frame truncates the bottom of the list, which is exactly the failure a scrolling list is for.
Three rows is the floor: below that the list is not a list, and a window that small is already refused by the too-small screen.
A picker carrying a field of its own spends two more — the field's row and the blank above it — and it is counted here rather than subtracted at the call site, so the one place that knows what this screen draws is the one place that counts it.
func (*PickState) Toggle ¶
func (p *PickState) Toggle()
Toggle takes the row under the cursor in or out.
Taking one out always works, including one that has become unavailable since it was chosen and including one taken out of a list that is already over its slots — that is the state an author most needs to be able to fix, which is why it is the first branch and has to stay the first branch. A loadout hand-edited past the limit in squads.json opens here, and the whole reason to open it is to give a row back.
Taking one in is refused when the carrier may not have it, and refused again when the slots are full. Nothing is said about either refusal here because it is already on screen: the row carries its mark, the line under the list carries the whole sentence, and the counter beside the title says how much of the loadout is spoken for — all before space is ever pressed. A message raised by the keypress would be the same words twice.
A full list **blocks** rather than swapping the oldest row out. With one trait slot that swap is tempting and it would make space two verbs at once, worded differently on the two pickers of the same screen depending on how many slots each has. One rule instead: the list is full, space does nothing, take one out first — which is what the trait hint already says.
func (*PickState) Update ¶
func (p *PickState) Update(_ Context, message tea.KeyPressMsg) (*PickState, PickResult)
Update reads one keystroke and hands back the picker and what the client owes it.
Three outcomes, and the pair says which without a fourth field: the picker comes back with the list still up, or nil with nothing answered, which is esc, or nil with an answer and the destination it belongs to, which is enter.
func (*PickState) Visible ¶
func (p *PickState) Visible() []PickOption
Visible is the rows the filter in force leaves on screen.
Everything chosen stays chosen, whether or not the filter shows it: the summary under the list is the whole answer and it is drawn from chosen rather than from this, so narrowing the list is a way to find a row and never a way to lose one.
type PlayAnswer ¶
type PlayAnswer struct {
// Choice is the skill and the cell, and is the zero value for a pass.
Choice battle.Choice
// Acted is false for a pass, which is the same false a chooser returns.
Acted bool
}
PlayAnswer is a decision taken on a battle this screen does not drive: the choice, and whether the turn was spent at all.
⚠️ **It is exactly battle.Chooser's return pair, deliberately.** A client hands it to the chooser unchanged and socket.Mirror.Decide is what turns it into a wire.Act or a wire.Pass — including the rule that a pass carries no reason, which lives on battle.Decision and may not be restated. A second vocabulary for a decision would be the two-callers-wording-one-choice mistake CLAUDE.md § *Mistakes already made here* records, at the other end of the wire.
type PlayClock ¶
type PlayClock struct {
// Waiting is whose answer the open turn is waiting for, and **nought is
// nobody** — which is the reading a screen handed a zero value falls into,
// and the safe one: no turn is being counted, so no clock is drawn.
Waiting PlayClockSeat
// Yours and Theirs are the seconds left, this screen's reader first.
//
// ⚠️ **Only one of them is counting down.** The allowance is per prompt
// rather than per match — a chess clock is not what a room runs — so the
// player who is not being asked has the whole of it waiting for them, and
// that is what their number says.
Yours, Theirs int
}
PlayClock is the two countdowns a live battle draws, in **seconds**.
⚠️ **This package reads no clock and this type is how it stays that way.** It is the same arrangement one layer down: internal/room never asks what time it is either — `Allowance` is a number the room *carries* and hands to its clients, and whoever owns the transport counts it down and reports what happened. A screen is one layer further out and gets the same treatment. It is handed two counts of seconds and draws them; it does not know what a second is, when this turn opened, or which machine's clock said so.
So there is no time.Duration here on purpose, for wire.Welcome.Allowance's own reason: seconds as an int, because the number crosses a boundary and a Duration is a count of nanoseconds that means nothing on the other side of one.
type PlayClockSeat ¶
type PlayClockSeat int
PlayClockSeat is which side of the wire the open turn belongs to.
const ( // PlayClockNobody is no turn open to count: between turns, before the first // one, and on a battle that is over. PlayClockNobody PlayClockSeat = iota // PlayClockYou is this player being asked, PlayClockThem the other one. PlayClockYou PlayClockThem )
type PlayLive ¶
type PlayLive struct {
// Fight is the mirror's battle, nil between battles and before the first.
Fight *battle.Battle
// Asking is the open prompt when it is this player's to answer, and nil
// otherwise — which is socket.Mirror.Asking exactly, because that derivation
// and PlayScreen.Pending are the same fact.
Asking *battle.Prompt
// Side is the half of the board this player is on in this battle, and Seed
// which battle it is. Both change between battles of a match, which is why
// they arrive on every reading rather than being set once.
Side hex.Side
Seed uint64
// Watching is this client watching the match rather than playing in it, which
// is socket.Sight.Watching and therefore wire.Welcome.Watching.
//
// ⚠️ **Side above is then the HOST's half rather than this client's**, because
// a spectator plays neither and the wire.Start on the room's record carries the
// host's. So the board a watcher reads is the board the host reads, and the two
// halves are the same `A` and `E` on both screens — which is what lets the
// clocks be worded off those letters. → PlayScreen.Watching.
Watching bool
// Refusal is the name of the latest protocol refusal, empty when there has
// been none. → PlayScreen.LiveRefusal for why it is a name.
Refusal string
// Clock is the two countdowns, **already computed by the client**, and a
// zero value is a turn nobody is being asked about. → PlayClock for why the
// arithmetic is not done here.
Clock PlayClock
// Reconnecting is this client having lost its socket mid-match and being in
// the middle of taking its seat back.
//
// ⚠️ **A board that simply stopped moving is indistinguishable from the other
// player thinking**, and the two want opposite things from a reader: one is
// nothing to do about, and the other is somebody staring at a frozen screen
// wondering whether to quit — which, inside the window the seat is held for,
// is the one thing that would actually lose the match. So it is drawn, on the
// row the waiting line already has rather than on one of its own, because
// this screen has no row to give. → PlayScreen.waiting.
Reconnecting bool
}
PlayLive is a battle somebody else is driving, as one reading of it.
⚠️ **It is a value taken under the mirror's read lock and it does not outlive the call.** The *battle.Battle in it is the mirror's own — a client computes the board by computing the battle, which is the whole design and the reason no type walk can refuse the pointer — so the caller's job is to build one of these inside socket.Mirror.Read and hand it straight here.
⚠️ **There is deliberately no index of the battle within the series.** The plan this arrived under carried one; nothing on this screen reads it, the heading already names the seed and a seed changes between battles of a match, and a field a screen does not draw is a field the next reader wonders about. The series standing is the *result* screen's, off socket.Mirror.Fought.
type PlayScreen ¶
type PlayScreen struct {
// Seed is which battle this is. Walking it is how a player asks for another
// arrangement of the same pairing, and it is the same number the log carries,
// so a battle played here can be replayed by the game client.
Seed uint64
// Side is the half the player is fighting on: the home squad's, always, so
// that the squad under the catalogue's cursor is the one being played rather
// than the one being played against.
Side hex.Side
// Home and Away are the pairing this screen was opened on, and they are
// **handed in** rather than fetched.
//
// ⚠️ This is the one thing about the move that was design rather than
// mechanics. The screen used to ask the client's own fight screen — a screen
// that has not moved and is not going to — which two squads it was between,
// twice: once to field the roster when a battle starts, and once to name the
// log file a save writes. Both are the same question, and it is a question
// about *opening* this screen rather than something to reach sideways for. So
// the client, which owns the fight, answers it once and passes the answer to
// Open; the same fix #207 made for the two describers, which used to read
// three other screens and are now handed a Subject.
//
// Both are kept rather than reduced to what each caller wants, because the
// two callers want different halves of them: fielding needs the units and the
// save needs the ids, and undo and another seed both re-field from here.
Home, Away placement.Squad
// Fight is the battle in hand, and nil is a screen with no pairing to open
// one on.
//
// ⚠️ **On a LIVE screen this pointer is the mirror's own, and the drawing
// path may not touch it.** Another goroutine steps that battle every time a
// turn arrives, so a read taken while drawing is a read with no lock on it —
// which is a data race whatever it reads, and the detector caught the board
// and the roster doing exactly that. Live mode may dereference it in Attach
// and nowhere else: Attach runs inside socket.Mirror.Read, under the lock, so
// that is the one moment the battle is safe to ask anything. Everything a
// draw needs is taken there and carried in the reading field below.
//
// A **local** battle is this screen's own — nothing else holds it and nothing
// else steps it — so the local path reads it freely, as it always has. → read.
Fight *battle.Battle
// Roster is what the battle was built from, kept because a log records it:
// a log carrying the resolved placement is what makes it re-runnable across
// a data edit, and asking the battle for it afterwards would be asking for
// the units as they are now rather than as they were placed.
Roster []battle.Roster
// Tags and Names are what a drawing calls each unit, read off the board once
// when the battle is built.
Tags map[string]string
Names map[string]string
// Events is every event the battle has emitted, which is the whole history
// the log is a frame over.
Events []battle.Event
// Script is every decision taken, the player's and the engine's alike. It is
// what undo shortens and what the whole battle is rebuilt from, which is why
// a rebuild needs nothing else: a battle is a pure function of its seed and
// the decisions taken.
Script battle.Script
// Pending is the turn waiting on the player. Nil means the battle is between
// turns, which is where the engine's own units act.
Pending *battle.Prompt
// Option and Aim are the two questions a turn asks, and Aiming says which of
// them is in front.
Option int
Aim int
Aiming bool
// LogFollow and LogOffset are where the log's frame sits, and they are two
// fields rather than one for the one reason that decides this whole feature.
//
// ⚠️ **Following the tail is a state, not an offset value, because the tail
// moves.** The reader is normally looking at the newest rows; an offset
// storing "the newest rows" would be a number that means something different
// every time an event arrives, so every turn taken would silently shift what
// is under the reader. So LogOffset counts rows **from the start of the
// history** — which is exactly what the position on the heading row states —
// and following is carried **beside** it rather than encoded into it.
//
// This is the rule Suggest's abandoned queue tie-break paid for: Queue.Pending
// answers 0 for a unit it has never heard of and 0 is *soonest*, so absence
// had to be declared rather than detected. A sentinel offset meaning "the
// tail" would be that mistake again — and it would read as working, because
// the sentinel is a legal offset on the turn it is written.
//
// LogOffset is meaningless while LogFollow holds, and it is clamped against
// the history's current length wherever it is read rather than only where it
// is written: undo rebuilds the battle from a shortened script, so the
// history it rebuilds is shorter and an offset kept across it can point past
// the end.
LogFollow bool
LogOffset int
// Err is what went wrong building or stepping the battle, drawn in place of
// the screen.
Err error
// Notes are what a write left behind, held as facts rather than as a
// sentence so a language toggle redraws them in the other one.
Notes []forge.Note
// Live says somebody else is driving this battle, and it is the whole of
// what a PvP battle is on this screen: the engine is a socket.Mirror's, the
// decisions are the server's, and this screen renders and chooses.
//
// ⚠️ **One battle exists per client and it is the mirror's.** A screen that
// also called Fight.Act would step the same battle twice and diverge from
// the room on turn one — the mirror applies on the wire.Turn that comes
// back, deliberately, which is why the room sends every turn to both clients
// including the one that asked. So every key that spends a turn is guarded
// on this field, at the key, once.
//
// Nought is the local reading, which is the half a forgotten declaration has
// to fall into: a local screen that quietly went live would stop driving its
// own battle and sit for ever, while a live screen that quietly went local
// would play the opponent's turns for them.
Live bool
// Watching says this client is a **spectator** of the live battle rather than
// one of the two people in it, and it is a third reading of this screen rather
// than a fourteenth screen.
//
// ⚠️ **A mode and not a screen of its own, which is the opposite of the
// decision ArrangeScreen took, and the two differ in what they SHARE.** The
// arrangement is a cursor over a 3x3 where the draft is a cursor over a list:
// no key, no section and no budget in common, so a mode there would have been
// two screens in one type. A spectator shares **everything** — the board, the
// roster, the queue line, the log and the frame the log is read through, the
// heading, the notice and the whole priority in playFit — and differs only by
// **absence**. Two copies of that budget is the defect this screen's own row
// arithmetic was written to stop, and the second copy is the one that would
// silently stop matching.
//
// ⚠️ **What makes "a watcher is never asked" hold is NOT this field, and that
// is deliberate.** It is Pending being nil, which is socket.Mirror.Asking
// being false for a watching mirror at the one derivation there is — so every
// key that spends a turn is already behind the `p.Pending == nil` return in
// Update, which is a guard that was there before spectators existed and is
// exercised on every turn of every match. A second guard reading this field
// would be a guard a mutation could delete for free, which is the mistake
// recorded on battle.healingFor's single floor.
//
// So what this field decides is only what is **said**: three wordings that
// address the reader as one of the two players are replaced by three that do
// not. That is Context.Footer's rule, and here the difference is a whole
// match — → View, the tail in drawings, and clocks.
//
// Nought is the reading a forgotten declaration falls into and it is the safe
// half: a spectator that quietly went back to being a player would be offered
// a turn it can never answer, and a player that quietly went to watching would
// be told to press keys that are not there.
Watching bool
// Reconnecting is this client having lost its socket mid-match and being in
// the middle of taking its seat back. → PlayLive.Reconnecting, where the
// argument for drawing it at all is, and waiting, which is the row it takes.
Reconnecting bool
// Cursor is this screen's own read position in a battle it does not own.
//
// ⚠️ **Live mode may not call Drain.** Drain is Since(b.drained) over an
// append-only record and it *writes* b.drained — and a live battle is read
// under a lock that admits several readers, so a read that moved the mirror's
// own cursor would be a write smuggled through one. Two consumers of one
// battle is exactly what the record-and-cursor work bought; this is the
// second cursor. Local mode keeps Drain untouched, which is what keeps the
// hot-seat goldens still.
Cursor int
// Answered is the decision already sent for the open prompt, so a screen
// that has answered stops offering the same turn again — and stops drawing
// an option list whose keys it would ignore.
//
// Cleared by Attach when the prompt names a different (unit, turn), which is
// the pair a decision is identified by everywhere else in this repository.
// ⚠️ Not the prompt pointer: a mirror hands back a pointer into its own
// battle and two prompts for one turn are the same turn however they are
// allocated.
Answered bool
// LiveRefusal is the **name** of the latest protocol refusal this client has
// been sent mid-match, drawn where a save's note goes and empty when there
// has been none.
//
// ⚠️ **A name and never a typed value.** i18n.Lang.Refusal takes a string
// for exactly this reason: a wire.Code on a field here would pull the
// protocol into the package two clients share, and this package must not
// know a socket exists. The client turns the enum into its own id and this
// screen hands it to the language book.
//
// ⚠️ It is the one place three of the ten refusals can ever be read —
// not-your-turn, illegal-action and unknown-message are only reachable
// **during** a match, because a refusal does not end a connection.
LiveRefusal string
// Clock is what is left of the open turn's allowance on both sides, **handed
// in already counted**. → PlayClock.
Clock PlayClock
// contains filtered or unexported fields
}
PlayScreen is a battle fought by hand against the opponent the engine plays.
It is raised from the fight for the reason the fight is raised from the catalogue: that is where a pairing is already chosen, and a battle wants two squads before it wants anything else. What the simulation answers over two hundred battles, this answers once — and the two are worth having side by side, because a rate says which squad is better and playing one says why.
⚠️ **This is the one screen holding something the model does not copy.** Every other screen is a value the model carries, so a field written while drawing is thrown away with the copy; a battle is a pointer, and a mutation reaches every copy of the model there is. So the battle is stepped in update and **never** touched in view — view reads it and draws, and that division is what keeps a redraw from playing a turn.
func NewPlayScreen ¶
func NewPlayScreen() PlayScreen
NewPlayScreen is the screen before a pairing has been handed to it: no battle, the first seed, and the player on the home side.
func (PlayScreen) Attach ¶
func (p PlayScreen) Attach(c Context, live PlayLive) PlayScreen
Attach points this screen at a battle it does not drive.
It is the live counterpart of Open and it is called on **every** redraw, not only when something changed: the client reads its mirror under a lock and hands over whatever it found, so this has to be cheap and idempotent. The one thing it is not idempotent about is the event cursor, which is the point — the run since the last call is what a renderer has not drawn yet.
What it resets and when:
- A **different battle pointer** is the next battle of the series, so the cursor, the history, the option cursor and the aim all start again, and the tags and names are read off the new board. The seed and the side come off the message rather than being kept, because both change between battles of a match.
- A **different (unit, turn)** on the prompt is a new turn, so Answered is cleared and the option cursor opens on the first option the unit may actually take.
- Anything else is the same turn seen again, and nothing moves.
func (PlayScreen) Choices ¶
func (p PlayScreen) Choices(c Context) string
choices is the turn in front: whose it is, what they may do, and where it may be pointed once a skill is picked.
func (PlayScreen) LogRows ¶
func (p PlayScreen) LogRows(c Context) []string
logRows is the whole history, rendered.
⚠️ **Every event, and it used to be the last few.** The old reading walked from the end and stopped at the budget, which meant the rows past the frame were not merely off screen — they did not exist, so no key could have reached them and the frame had nothing to be a window into. p.Events holds every event a battle has emitted (collect appends and never trims), so the history was always there and it was the view that threw it away.
Counted in **rendered rows** and not in events, because tui.Line opens a turn with a blank row and one event therefore arrives as two rows. Each event is rendered exactly as it was before there was a budget — the indent goes on the front of whatever tui.Line returned, once, so a turn's blank row still reads as a blank row — and the rows are then counted rather than the events.
Nothing here reads the battle: the event log is the only contract a reader of one has.
func (PlayScreen) Move ¶
func (p PlayScreen) Move(by int) PlayScreen
func (PlayScreen) Open ¶
func (p PlayScreen) Open(c Context, home, away placement.Squad) PlayScreen
Open enters the screen on a pairing and plays it up to the player's first decision.
The two squads are the whole of what this screen needs from the client, and they are a **parameter of opening** rather than something to fetch — see Home and Away for why that is the design and not a signature preference. The seed and the side are kept, so re-opening the same pairing walks on from the seed the reader had reached.
⚠️ **A squad with nobody in it is not a pairing**, which is what a client with an empty catalogue has to hand over, and the screen then says nothing has been built rather than reporting the refusal fielding one would give. That is a reading of the value rather than a sentinel: placement.Squad.Validate already refuses an empty squad, so nothing that could be fielded arrives this way. ⚠️ **A live screen refuses to be opened**, and that is the guard the two risks of this feature meet at: a client whose menu still offers a battle while a match is running would build a second one over the mirror's, and the reader would be playing a hot-seat game against a copy of themselves while a person on another machine waited. Attach is the live entrance and Open is the local one; neither is the other's fallback.
func (PlayScreen) OptionWidth ¶
func (p PlayScreen) OptionWidth() int
optionWidth is the id column, measured over the turn's own options.
func (PlayScreen) Subject ¶
func (p PlayScreen) Subject() Subject
move walks whichever of the two lists is in front. subject is what the description screen raised from here is about: the option under the cursor, named by its skill id and by where it sits in this unit's offered list.
⚠️ **It names the skill and hands over nothing of the battle**, which is what keeps the promise above the ? key: PlayScreen is the one screen holding something the model does not copy, so a describer given a battle to read is a redraw that could step a turn. The id is looked up in the library instead, because a battle carries a unit's resolved kit and the sentences are about the declared skill.
Nothing pending and no options are both ordinary answers rather than errors — a turn nobody is being asked about is a turn with nothing to describe — and they come back as a subject with Of at nought, which is how the describer is told so without looking.
func (PlayScreen) Update ¶
func (p PlayScreen) Update(c Context, message tea.KeyPressMsg) (PlayScreen, Action)
Update routes one keystroke.
⚠️ **Two returns and not three.** A screen with a text field on it has to hand back the field's own command — the cursor blink — which is why the skill form answers with three; this screen has no field on it at all, so there is nothing to carry and an Action says the whole of what it wants.
The live guards ¶
Six keys are answered differently, or not at all, when Live. Each guard is on the key it turns off and there is exactly **one** of them per key, which is the rule the "which guard masks" measurement in this repository asked for: a second guard further down would mean deleting the first leaves every test green.
n another seed ignored — a match's seeds are the room's
u undo ignored — the opponent has already seen the
events it would take back
ctrl+s save the log ignored — Home and Away are empty in a match,
and the room is what writes a match's log
a let it pick ignored — it is a decision, and the decision is
the player's
enter/ take the turn answered rather than taken: an Action, because
space Mirror.Decide applies nothing and a local Act
would step the battle twice
p pass the same, with Acted false
esc, ?, ↑/↓ and the log's own keys are unchanged: reading and scrolling touch no turn, and a Back is still the client's to interpret.
A watcher, and why it needed no seventh guard ¶
⚠️ **A spectator presses every key here and changes nothing, and it is the `p.Pending == nil` return below that says so rather than a guard of its own.** A watching mirror is never asking — socket.Mirror.asking refuses one at the one derivation there is — so Pending is nil on every turn of the match including the host's, and ↑/↓, enter, space, `?`, `a` and `p` all fall past that return without reaching the switch under it. The six live guards above cover the rest: `n`, `u` and the save key are behind `!p.Live`, and a watcher is Live.
A seventh guard reading PlayScreen.Watching would be a second declaration of one invariant, and the note on battle.healingFor's single floor is what says what that costs: with two floors, deleting either reddens nothing. What Watching decides is the **wording** — → View, waiting, clocks.
func (PlayScreen) View ¶
func (p PlayScreen) View(c Context) (string, string)
⚠️ **The three live footers are second wordings and not the local ones with clauses deleted.** Context.Footer already states why for the authoring pair: dropping a clause out of a rendered line leaves the separators either side of it and nothing measures what is left. A live battle names neither `u`, `n` nor the save key and gains nothing, so they are shorter than the local three — which is a reason to measure them rather than a reason not to.
func (PlayScreen) Wrote ¶
func (p PlayScreen) Wrote(c Context) []string
wrote is the line a save leaves behind, in the shape every other write in this client reports itself. It hands back the rows rather than a block, because the budget above counts them: a section that reported itself as one string would have to be measured twice, once to place it and once to draw it.
type PreviewScreen ¶
type PreviewScreen struct {
// Subject is the character and the level being looked at, pushed in by the
// browser. The zero value draws the same "nothing here" line an empty
// listing does.
Subject Subject
// contains filtered or unexported fields
}
PreviewScreen draws the picture a character shows at the level it is being read at.
It keeps no cursor and no level of its own: the browser that raises it hands both over as a Subject and re-pushes on every key that moves either, so the two cannot disagree about which character is in front and walking the level here walks it there. ⚠️ It used to read the authoring tool's browser — its level and its cursor — directly, which is a screen that could not live here and could not be drawn by a client whose browser is a different one.
What it does own is the cache, because rasterising the shipped art takes tens of milliseconds and a full-screen client redraws on every keystroke — without one, holding the arrow key down would spend a second a second.
⚠️ **It is the one screen in this package that draws something other than text**, which is why it asks the palette whether colour is available rather than only rendering through it: the monochrome path is a *different drawing*, a ramp of weights keeping the shading, not the coloured one with the escape codes stripped out.
func NewPreviewScreen ¶
func NewPreviewScreen() PreviewScreen
NewPreviewScreen is a preview with an empty cache, which is the only state it has that a zero value would get wrong.
type SkillsPick ¶
type SkillsPick uint8
SkillsPick is where one of this form's six lists lands: one named field of this screen.
⚠️ **It is declared here and not in a client, and that is the move rather than a widening.** PickState.Into is an `any` because a destination used to name a field of a *client's* screen — so cmd/hexforge-tui declared all ten of them. Six of the ten named fields of this form, and this form is no longer a client's, so its destinations came with it. The four that still name a client's screens — the character form's two and the squad builder's two — stayed where they are, and the client is the one thing that knows both vocabularies, which is what a client is for.
⚠️ **A destination is *where*, never *how*.** Five of the six assign the answer to a list field; SkillsPickInflicts composes it into a text field through forge.AddApplications. Both are destinations, and what the receiving field does when the answer arrives is that field's business.
const ( // SkillsPickNothing is the zero value: a destination that names no field. // No raise here uses it, and Picked declines it, which is what a picker // carrying no destination at all already gets. SkillsPickNothing SkillsPick = iota // The five allowlists and the inflicts field, each named after the field it // fills, so a destination pointed at the wrong one reads wrong at the raise // site as well as at the landing. SkillsPickElements SkillsPickRoles SkillsPickWorlds SkillsPickKinds SkillsPickWho SkillsPickInflicts // SkillsPickCount is the count a dispatch is held total against, in the // shape SubjectKindCount, TargetCount and KindCount already have: a // destination added above it enters the walk without anybody remembering to // list it, which a hand-written list of six would not give. SkillsPickCount )
type SkillsScreen ¶
type SkillsScreen struct {
Skills []skill.Skill
Cursor int
// Query is the typed filter, and Filtering is whether the field under the
// heading has the keyboard.
//
// ⚠️ **The two are carried side by side rather than one derived from the
// other**, and that is the decision the whole mode rests on: enter closes
// the field and *keeps* the query, so a narrowed listing with the keyboard
// back on the rows is an ordinary state and the one the feature exists for.
// Reading focus off "the query is not empty" would make that state
// unreachable and would also make a filter impossible to open before
// anything has been typed into it — the same shape as PlayScreen carrying
// LogFollow beside LogOffset instead of encoding "follow" as a sentinel
// offset, and as a queue reading having to declare absence rather than
// detect it.
//
// Query is a plain string and not a bubbles textinput, which every other
// typed field on this screen is. The reason is the keys: the arrows belong
// to the *listing* while this field has focus — letters are text, so k and j
// cannot walk the rows and the arrows are all that is left — so a text field
// here would draw a caret that none of its own keys could move. What is
// left of a text field once its arrows are gone is a string with a
// backspace, which is what this is.
Query string
Filtering bool
// Adding is whether the form is in front of the listing to author a new
// skill, and Editing is the id it is in front to change. They are two fields
// rather than one because one form serves both jobs and the difference
// decides three things: the heading, what Escape is asking to throw away, and
// whether the write appends or replaces. FormInFront is the two together, and
// they are never both set.
Adding bool
Editing string
// Inputs is every typed field of the form, indexed by the SkillField
// constants above.
//
// ⚠️ **A slice, so two copies of this screen SHARE it, and that is the one
// place "a screen is a value" is not true here.** Every other field is
// copied when the screen is; these text fields are not — writing through
// `a.Inputs[i]` is visible through `b.Inputs[i]` for any copy `b` taken
// before the write. It was measured rather than reasoned about, in #216:
// dropping the client's write-back of the screen after a status pick left
// the inflicts entry filled in anyway, because the landing wrote through
// storage the copies share, while every flag beside it was lost.
//
// It is moved here **as it is** and deliberately unchanged. The behaviour is
// relied on today and changing it is a measurement of its own, not a side
// effect of a move — so TestTheSkillFormsFieldsAreSharedBetweenCopies pins
// it in both directions, and whoever changes it later has to mean it.
Inputs []textinput.Model
Field int
// The three choosers and the five allowlists, held as their answers rather
// than as text fields: an element, a side and a shape are all ids out of a
// book, so typing one is only a way to get it wrong.
ElementIndex int
TargetIndex int
ShapeIndex int
KeptElements []string
KeptRoles []string
KeptWho []string
KeptKinds []string
KeptWorlds []string
Touched bool
// ShapeDrawn is whether the shape diagram is over the form.
//
// A flag rather than a state of its own, because the diagram has no answer
// to hold: it draws the shape the chooser is already on and the arrow keys
// on it are the chooser's own, so there is one ShapeIndex and the drawing
// cannot disagree with the field behind it. That is the difference from the
// picker, which collects an answer and hands it back on enter.
ShapeDrawn bool
Err error
// Added is the last skill written, kept as what it was rather than as the
// line announcing it, so a language switch redraws the announcement.
Added *skill.Skill
// Edited is the last change written, kept whole rather than as its id: the
// damage before and after is what an author needs from an edit, and it is
// carried so a language switch redraws that too.
Edited *forge.SkillChange
}
SkillsScreen is the skill book, and the form that adds to it and changes it.
It is the other half of the new-character form in the same way the origins screen is: a kit can only name a skill the book holds, so an author who finds the skill they want missing can add it and go straight back.
Nothing here decides whether an answer is acceptable, and nothing here works out what a skill is worth. The damage comes from forge.Library.PreviewDraft, which is combat.Rules.Damage against the reference pair skills.golden's own table is measured from, and the write goes through forge.SkillDraft.Resolve, which appends to the book and therefore applies exactly the checks a load applies.
func NewSkillsScreen ¶
func NewSkillsScreen(c Context) SkillsScreen
NewSkillsScreen is the listing filled from a library, with an empty form behind it.
⚠️ **It takes a Context rather than a library**, which is the one signature this move had to change, and the reason is that the form dresses text fields: NewInput wants to know whether colour would be noise, this package may not read an environment, and Palette already carries the answer the binary was handed. Same arrangement the preview's cache key has.
func (SkillsScreen) Confirmed ¶
func (s SkillsScreen) Confirmed(c Context, _ any) (SkillsScreen, Action)
Confirmed throws the half-written skill away and closes the form.
⚠️ **Two questions reach it and there is one answer**, which is why it does not read the question: SkillFormDiscard and SkillFormEditDiscard differ only in what they say is being lost — a skill nobody has written yet, or a set of changes to one already in the book — and ResetForm is what both of them meant. A wording is not an identity, so a screen branching on which one was asked would be a screen with two answers where the book has one.
⚠️ **What the question was about arrives as an `any` and is ignored**, which is honest rather than lazy: a guard's subject is a client's own vocabulary — the squad builder's two questions are told apart by a squad id — and this screen's one question is about the screen itself. The parameter is here so the shape matches the other four Confirmed methods, which a client dispatch is held total over.
func (SkillsScreen) DamageRow ¶
func (s SkillsScreen) DamageRow(c Context, labelWidth int) string
DamageRow is the point of authoring a skill on a screen rather than in a file: what the power being typed is actually worth, before it is written.
Exported for the reason SkillLabelWidth and FieldValue are: the client's width sweep measures this row at two windows in both languages, and a fixture cannot follow a screen across a package boundary.
func (SkillsScreen) Draft ¶
func (s SkillsScreen) Draft(c Context) forge.SkillDraft
Draft is the answers as internal/forge wants them, which is the only thing this screen hands outwards.
Exported because a client test compares what the form resolves to against what the command line's flags resolve to — the two front-ends must be incapable of disagreeing, and that comparison needs the draft.
func (SkillsScreen) FieldValue ¶
func (s SkillsScreen) FieldValue(c Context, field, labelWidth int) string
FieldValue is what one row shows: a chooser, a chosen list, or what was typed.
Exported for the reason DamageRow is — the client's width sweep reads two of these rows, the allowlist and the chance reading, as the two callers of FieldValueRoom that live on this screen.
func (SkillsScreen) FormInFront ¶
func (s SkillsScreen) FormInFront() bool
FormInFront reports whether the form is over the listing, either to author a skill or to change one.
func (SkillsScreen) OpenAllowlist ¶
func (s SkillsScreen) OpenAllowlist(c Context, field int) *PickState
OpenAllowlist builds the picker for one of the five lists.
The list is offered rather than typed for the reason the origin and the archetype are on the other form: every entry is an id out of a book, so a picker cannot produce a name that does not exist — and an allowlist naming somebody who does not exist is the same mistake as an empty one, satisfied by nobody.
It **builds** the state and does not put it in front, which is the whole of what moving this screen changed here: a picker's lifetime is the client's, because the client is the only thing with a field to keep one in. The state travels back as Action.Pick's payload and the client raises it.
Exported because this client's own width fixture registers three of these pickers as screens of their own and has to reach them the way a keystroke does; a fixture cannot follow a screen across a package boundary.
func (SkillsScreen) OpenStatuses ¶
func (s SkillsScreen) OpenStatuses(c Context) *PickState
OpenStatuses builds the picker over the status book, whose answer is written into the inflicts field.
The shortest path from "I want a poison" to a valid entry: pick the status out of the book, type the chance in the field under the list, enter. The syntax is forge.AddApplications' — the same spelling ParseApplications reads back — so the screen never spells an entry itself, and nothing about the field changes: it is still a text field, an author who knows the syntax still types it, and a script writes the same thing.
Nothing is preselected. The field may already hold entries and the picker appends to them, so starting with those rows ticked would mean the author had to untick them to avoid writing each one twice.
⚠️ **The destination is the inflicts field whichever of the two status fields raised it**, which is what the field write below already did and is preserved unchanged: space on "on itself" opens this list and its answer lands in "inflicts". Moving the screen is not the change that gets to decide whether that is right.
func (SkillsScreen) Paste ¶
func (s SkillsScreen) Paste(_ Context, text string) (SkillsScreen, tea.Cmd)
Paste puts a pasted string where a typed one would go: into the form's focused field, or into the filter's query, or nowhere.
⚠️ **This screen has two text targets and they belong to different clients.** The form's fields open behind Context.Authoring; the typed filter opens on `/` and is guarded by nothing, so it is the one text target a **game** client has on a screen out of this package. The order below is Update's own — form, then filter — so a paste cannot reach a form the keystrokes could not have opened.
⚠️ **`FormInFront` is load-bearing twice over.** ResetForm focuses the id field and runs at construction, so a client on the bare **listing** holds a focused text field nobody is looking at — a paste there would fill a form that has not been opened. And it is what keeps a read-only client out of the authoring half: the form can only be in front because `a` or `e` put it there, and both are guarded on Context.Authoring, so a paste on cmd/hexarena-tui falls to the filter or to nothing.
There is no predicate beside this. The two arms have to find their target anyway, and a `Pasting` restating them would be one rule written twice.
func (SkillsScreen) Picked ¶
func (s SkillsScreen) Picked(c Context, into any, answer PickAnswer) (SkillsScreen, Action)
Picked is what the six lists this form raises write back.
⚠️ **Five of the six are one line and the sixth is not, and that is the shape rather than an exception.** A destination says *where* an answer lands; what the field does with it belongs to the field. The five allowlists take the chosen ids as the list they are, and the inflicts field is text that already holds entries, so its answer is composed into what is there through forge.AddApplications — the same call the typed syntax goes through, which is why it is a branch here rather than a second kind of picker.
The destination arrives as an `any` because that is what PickState carries it as; a value that is not one of this screen's own is a picker somebody else raised, and it lands nowhere for the same reason SkillsPickNothing does.
func (SkillsScreen) Prefill ¶
func (s SkillsScreen) Prefill(c Context, current skill.Skill) SkillsScreen
Prefill is ResetForm over a skill that already exists, which is what makes one form serve both jobs.
Every value comes from forge.SkillAnswers rather than being formatted here, so that accepting the form as it stands reproduces the skill exactly. A screen that wrote its own "1200" or turned an absent restriction into an empty list would turn opening the form into a change.
func (SkillsScreen) Refresh ¶
func (s SkillsScreen) Refresh(c Context) SkillsScreen
Refresh re-reads the book, keeping the query and clamping the cursor — entering the screen after a write should show the changed row rather than a stale list.
func (SkillsScreen) ResetForm ¶
func (s SkillsScreen) ResetForm(c Context) SkillsScreen
ResetForm empties the form and puts every chooser back on its default, which is what both opening a new one and discarding a half-written one come to.
func (SkillsScreen) Rows ¶
func (s SkillsScreen) Rows() []skill.Skill
Rows is the skills the filter in force leaves on screen, and it is the ONE place the listing's cursor may be indexed against.
⚠️ **Every read goes through here or through Selected below.** The cursor counts the *visible* rows, so a read that reached into s.Skills with it would silently act on a different skill than the one under the marker — and the two agree exactly while nothing is typed, which is every existing test. That is the same funnel PickState.Visible is for, and the reason it is one function rather than a filter written out at each site.
Matching is i18n.MatchesSkill, which reads the skill's **id and its authored Vietnamese name** and asks nothing about the language in front. See that function for why: a query that found different rows after ctrl+l would be the screen mutating behind the author.
func (SkillsScreen) Selected ¶
func (s SkillsScreen) Selected() (skill.Skill, bool)
Selected is the skill under the cursor, and false when the filter has left nothing to point at.
The second return is what the three keys that read a row ask, rather than each of them measuring the list itself: a query matching nothing is an ordinary state that arrives one keystroke at a time, so e and ? have to decline rather than index an empty slice.
func (SkillsScreen) Subject ¶
func (s SkillsScreen) Subject() Subject
Subject is what the description screen raised from here is about: the skill under the cursor, and where it sits in the rows the filter has left.
Off Rows() rather than off the book, for the reason Selected is: the cursor indexes the filtered view, so the position beside the name — "3 / 5" — has to count the same list the marker was moving through.
func (SkillsScreen) Update ¶
func (s SkillsScreen) Update(c Context, message tea.KeyPressMsg) (SkillsScreen, Action, tea.Cmd)
Update routes a keystroke on the listing, the form over it, or the diagram over that, and says what the client owes it.
⚠️ **Three returns rather than two, and the third is a tea.Cmd.** Every other screen here answers (itself, Action); this one has text fields, and a bubbles textinput answers an Update with a command — the cursor's blink — which has to come out or the field loses its cursor. That is the same fact PickResult.Cmd carries. It is not a field on Action, deliberately: an Action is a comparable value a screen returns and a test writes out as a literal, and a func field would take that away from every screen to serve one. A result type of exactly {Action, Cmd} would be a tuple with a name; PickResult earned its type by carrying four things.
e is the edit key. It does not collide with anything: this screen is a list rather than a form, so no field has the keyboard, and its only other letters are q, k, j and a. It sits beside a for the reason those two belong together — adding a skill and changing one are the same form reached two ways.
The filter is a **mode** and not another letter, and that follows from the line above rather than from taste: every letter this screen has is already a command, so a field sharing the keyboard with them could take no query at all. / is the key because it is the one neither client had spent anywhere, and because it is what a reader of any other full-screen program will already try.
type SpeciesScreen ¶
type SpeciesScreen struct {
Kinds []cast.Species
// claimed and skills are keyed by species id and read by key only; nothing
// ranges over either into an ordered output, so neither can reach a rendered
// line out of order.
//
// claimed counts rather than naming, because the names are no longer drawn:
// all the screen asks is whether anybody is one, and keeping the joined list
// for a question that is answered by "is it nought" would be a row's worth of
// string built per kind per refresh and thrown away.
Claimed map[string]int
Cursor int
}
SpeciesScreen is what a character can *be*: the declared kinds, each under its name, with the note that says where the line is drawn under the cursor.
It is the other half of the restriction column the skills listing draws. That column says "chủng loài dragon" and had nowhere to go: a species was reachable only through the picker on the new-skill form, so a reader who was not in the middle of authoring a restriction could not find out what the word covered, and the note the author wrote beside it reached nobody at all.
⚠️ It does not list the skills kept for a kind either, and for the same reason it does not list who is one: both are lists that grow with the books. Four dragon skills fit on a line and fourteen do not, and the reader who wants them is on the skills listing, whose restriction column names the kind on every row that has one. This screen answers "what does this word mean", once, and leaves the cross-reference to the listings that are already sorted for it.
⚠️ There is no **who is one** column, and that is a decision rather than an omission. It was drawn here first, as the twin of the trait listing's carriers column: a species is not restricted, it is *claimed*, so "who may be one" is everybody and answers nothing, while who actually is one is a fact. But the two columns scale differently. A trait is carried by the handful of characters that learn it; a species is what a character **is**, so every character in the book lands in exactly one or two kinds — and a cast of thirty puts thirty ids on five rows. A column whose width is the size of the cast is a column that stops fitting, and it stops fitting on the row that has the most to say.
What survives is the half that does not grow: a kind **nobody** is still says so, in words, under the cursor. That is the fact the column was worth having for — a kind may be written before the character that fills it, exactly as a trait may, and it is not an error, but it is a gate that cannot open. Who is one is answered the other way round, by the browser, where a character says what it is.
Read-only, unlike the origins listing. A species is a word plus a note today, but the gate it drives is a skill's allowlist, so adding one is only ever half a change: the other half is the skill kept for it, and that is authored on the skills form. A form here would offer to make a kind nothing can use.
func NewSpeciesScreen ¶
func NewSpeciesScreen(lib *forge.Library) SpeciesScreen
NewSpeciesScreen is the reference filled from a library, ready to draw.
func (SpeciesScreen) Refresh ¶
func (s SpeciesScreen) Refresh(lib *forge.Library) SpeciesScreen
Refresh re-reads the kinds and who claims each, keeping the cursor inside the book.
func (SpeciesScreen) Update ¶
func (s SpeciesScreen) Update(_ Context, message tea.KeyPressMsg) (SpeciesScreen, Action)
Update reads one keystroke: the cursor moves, or the reader leaves.
type SquadMode ¶
type SquadMode int
The squad builder is three views of one thing, and they are one screen rather than three because they are one decision taken at three depths: which squads exist, who is in this one, and what that unit brings. Splitting them would put the half-built squad somewhere both of the others could reach, which is the shape that lets two screens disagree about what is being edited.
⚠️ **It is the one screen in this package that writes the author's own file**, and that is a constraint on the tests rather than on the code: `SaveSquad` and `DeleteSquad` go through internal/forge like every other write here, but screens.golden loads the books straight out of ../seed/data with no temp copy, so a golden entry has to be a value built by hand rather than a file written.
type SquadsAsk ¶
type SquadsAsk struct {
Kind SquadsAskKind
// ID is a squad id, and only SquadsAskSavedSquad spends it.
ID string
}
SquadsAsk is what one of the builder's two questions is about.
⚠️ **This is the vocabulary Action.About exists to carry**, and it is the screen's own rather than a client's. The delete needs a value the screen does not hold — the id under the catalogue's cursor when `d` was pressed — and the two questions need telling apart by something other than what mode the screen happens to be in, which would be state read to recover what the question could simply have said.
A comparable struct, so an Action carrying one stays a comparable value a test can write out as a literal.
type SquadsAskKind ¶
type SquadsAskKind uint8
SquadsAskKind is which of the builder's questions was put.
const ( // SquadsAskNothing is the zero value, and it is what a question this screen // did not ask comes back as: About is an `any`, so a value out of another // screen's vocabulary lands here through a failed type assertion and is // declined rather than guessed at. SquadsAskNothing SquadsAskKind = iota // SquadsAskSavedSquad names a squad on the file, by the id that was under // the catalogue's cursor when the question was asked. SquadsAskSavedSquad // SquadsAskSquadInHand is the half-built squad under edit, which is the // other question and the reason a kind is carried at all. SquadsAskSquadInHand )
type SquadsPick ¶
type SquadsPick uint8
SquadsPick is where one of the builder's two lists lands.
⚠️ **A destination names a field of one screen**, which is why it lives beside that screen and not in the client: the two halves of a loadout are one keystroke apart and differ in nothing else, so a screen alone cannot say which was being filled. It is the same shape SkillsPick has, and PickState carries either as the `any` it always was.
const ( // SquadsPickNothing is the zero value: a destination that names no field. // No raise here uses it, and Picked declines it. SquadsPickNothing SquadsPick = iota // SquadsPickKit is the four skills a member brings. SquadsPickKit // SquadsPickTrait is the one trait it brings. SquadsPickTrait // SquadsPickCount is the count a client's dispatch is held total against, in // the shape SkillsPickCount, SubjectKindCount and TargetCount already have. SquadsPickCount )
type SquadsScreen ¶
type SquadsScreen struct {
Mode SquadMode
// Saved is the catalogue as it is on disk, refreshed when the screen is
// entered so a squad written by the other front-end is not invisible here.
Saved []placement.Squad
Cursor int
// Characters is the WHOLE cast, held rather than looked up per keystroke
// because cycling walks it.
//
// The whole cast rather than the offered part of it, because this slice
// answers two different questions and only one of them is about choosing.
// Character() looks a member's character up here to read its forms, its
// learnset and its traits, and a squad on the file may name a character that
// has since been hidden — so a filtered slice would leave that member with no
// forms and an empty kit picker. What may be *chosen* is offeredCharacters,
// asked of this one at each of the two sites that choose.
Characters []cast.Character
// Editing is the squad in hand. It is a whole squad rather than an index
// into Saved, because a squad being built has not been saved yet and an
// index would have nothing to point at.
Editing placement.Squad
// Baseline is the squad as it was last written down: what Open read off
// the file, what Save put back, or the empty squad Begin started from.
// The guard on leaving compares against it.
//
// It is a reading rather than a latched flag because a latch cannot tell a
// squad that changed from one that was merely touched. Commit writes a
// member back whether or not anything moved, and it runs on the way out of
// every member, so opening one and pressing escape used to be
// indistinguishable from editing it — the question was asked over changes
// nobody had made, which is how a question stops being read.
//
// It is a Clone, not the value Editing was set from: Editing is mutated in
// place, and a baseline sharing its slices would compare equal to itself
// for ever.
Baseline placement.Squad
// Units is the cursor over the squad's members, and it may sit one past the
// last, which is the row that adds another.
Units int
IDInput textinput.Model
NameInput textinput.Model
// EditingID is true while the id field is the one being typed into. An id is
// asked once, when a squad is created: changing it later would write a
// second squad rather than rename this one, and a field that silently makes
// a copy is worse than one that is not offered.
EditingID bool
// Unit is the member under edit, and UnitIndex is where it sits in the squad.
Unit placement.Placement
UnitIndex int
// UnitOpenedAs is the character this member named when it was opened, and it
// is what the character chooser keeps offering however held back that
// character is. See offeredCharacters.
//
// Read from here rather than from Unit.Character — the obvious spelling —
// because the obvious spelling makes the list change shape while it is being
// walked: stepping off a held-back character drops it, so `right` then
// `left` lands one row short of where it started and the character is
// unreachable for the rest of the edit. A chooser is a fixed list the arrows
// walk, so what may be chosen has to be settled when the member is opened
// rather than recomputed from the answer in hand.
UnitOpenedAs string
Field int
LevelInput textinput.Model
Err error
Notes []forge.Note
}
SquadsScreen is the squad builder: the catalogue, one squad under edit, and one member of it.
func NewSquadsScreen ¶
func NewSquadsScreen(c Context) SquadsScreen
NewSquadsScreen builds the builder over a library.
⚠️ **It takes a Context rather than a library**, for the reason NewSkillsScreen does: three text fields have to be dressed, NewInput wants to know whether colour would be noise, this package may not read an environment, and Palette already carries the answer the binary was handed.
func (SquadsScreen) Begin ¶
func (s SquadsScreen) Begin() SquadsScreen
Begin starts a squad nobody has written yet.
func (SquadsScreen) Character ¶
func (s SquadsScreen) Character() (cast.Character, bool)
Character is the member under edit's own character, looked up in the whole cast this screen holds.
func (SquadsScreen) Commit ¶
func (s SquadsScreen) Commit() SquadsScreen
Commit writes the unit under edit back into the squad.
func (SquadsScreen) Confirmed ¶
func (s SquadsScreen) Confirmed(c Context, about any) (SquadsScreen, Action)
Confirmed answers whichever of the builder's two questions was asked, told apart by what the question was about rather than by what mode the screen is in.
⚠️ **This is the one screen with two confirms**, and it is why Action.About exists. The mode would answer it — the guard freezes every other key, so the screen cannot have changed depth between the question and the answer — and that is state being read to recover something the question could simply have said. The delete also needs a value the screen does not hold: the id under the catalogue's cursor when `d` was pressed.
Both stay on this screen, so both hand back the zero action.
func (SquadsScreen) Dirty ¶
func (s SquadsScreen) Dirty() bool
Dirty reports whether the squad in hand differs from the one last written down, which is the whole of what the guard on leaving asks.
It is a comparison rather than a flag, so a round trip that changes nothing — opening a member and leaving it, stepping the cell chooser onto another cell and back — leaves the question unasked. Everything under edit has reached s.Editing by the time this is read: the only route out of a member commits first, and so does opening either of its lists, while the id and the name are written on every keypress that reaches them.
func (SquadsScreen) EditUnit ¶
func (s SquadsScreen) EditUnit(index int) SquadsScreen
EditUnit takes one member of the squad in hand up for editing.
func (SquadsScreen) Form ¶
func (s SquadsScreen) Form() string
Form is the stage name the unit's learnset is read against: the one chosen, or the furthest the level reaches when nothing is.
⚠️ **On a fork the placement has not named it is the empty string, and that is a refusal rather than an answer.** progression.Line.StageAt will not pick an arm — a wrong arm is a wrong learnset written into the author's own file — so there is nothing to resolve to, and cast.SkillsAt/PassivesAt read an empty form as "no gate is held", which leaves the two pickers offering only what every arm learns. That narrowing is silent by construction: a list cannot say why a row is not on it. What says so is the screen — stageLabel stops calling this state *furthest*, a word with no meaning on a line with two ends, and the SquadForkArms line under the fields names the arms, the key that chooses one, and both consequences. The choice itself needs nothing new: the form field is already a chooser and StageChoices already lists both arms by name.
func (SquadsScreen) Open ¶
func (s SquadsScreen) Open(squad placement.Squad) SquadsScreen
Open takes a saved squad up for editing, on its own copy.
func (SquadsScreen) OpenPassives ¶
func (s SquadsScreen) OpenPassives() *PickState
func (SquadsScreen) OpenSkills ¶
func (s SquadsScreen) OpenSkills() *PickState
OpenSkills and OpenPassives are two pickers over one rule: what this character knows at this level as this form. They are separate methods rather than one taking a field because each writes a different half of the loadout back, and a picker that decided which half it was would be a switch inside a callback.
Each names its own hint for the reason the allowlists do: the picker's default is the form's, and the form is choosing out of the whole skill book, where a row may carry a refusal. Here the options are the learnset already, so a mark for what cannot be taken names something no row can ever draw — and on the trait list an order says nothing either, since there is one slot to fill.
These two are also the only pickers that carry slots, and they carry the constants the write reads rather than numbers of their own. The cap stops an over-full answer being built; Refuse below and the save still ask the rule through cast.ChooseFrom, because the cap is a courtesy on top of the rule and never a replacement for it — a loadout hand-edited into squads.json never came through a keystroke at all.
Nil is a member naming nobody the book knows, which is the one state that has no learnset to offer; the key that raises it declines rather than opening an empty list.
func (SquadsScreen) Paste ¶
func (s SquadsScreen) Paste(_ Context, text string) (SquadsScreen, tea.Cmd)
Paste puts a pasted string where a typed one would go, and nowhere when the keyboard is not on a field.
⚠️ **The SquadList fall-through is the load-bearing half of that.** The level field is a NumberField, which focuses itself at construction, and the id and the name stay focused after the builder is escaped — so the **catalogue**, which is the screen a game client draws and the one this screen opens on, has a focused text field on it at all times. A paste routed at "whichever field is focused" would go into a squad nobody is building. The switch is what says so, and there is no second predicate beside it: this method has to find the field anyway, so a `Pasting` restating these three facts would be the same rule declared twice, and only one of the two could be wrong at a time.
The two depths want different things of it and both are the key path's own rule: the id and the name are free text and take a paste as they take a keystroke, while the level is a number field, so PasteDigits refuses anything else for the reason spelled out beside it. The bookkeeping either side is updateEdit's and updateUnit's, on the same condition each of them uses.
func (SquadsScreen) Picked ¶
func (s SquadsScreen) Picked(_ Context, into any, answer PickAnswer) (SquadsScreen, Action)
Picked is what the builder's two lists write back: one half of the member's loadout each, judged by the rule the write uses and committed to the squad in hand.
⚠️ **The character is looked up here rather than carried from the raise.** The two closures this replaces captured it at the moment the list opened, and the capture was doing nothing a lookup does not: the picker takes every key while it is up, so the member under edit cannot have changed character between the question and the answer — and the screen already knows how to find its own, because every other row on it is read the same way.
⚠️ **The destination arrives as an `any`** — see SkillsScreen.Picked for why there is more than one destination vocabulary to tell apart.
func (SquadsScreen) Refresh ¶
func (s SquadsScreen) Refresh(c Context) SquadsScreen
Refresh re-reads the catalogue, and leaves a squad under edit alone: entering the screen while building one is the ordinary way back from a picker.
⚠️ **The catalogue is the game's sides AND the player's own**, laid over each other by forge.SquadsOffered rather than concatenated, because the id a row is named by has to be unique for a raise about one to name a row. A client that brings no player file (the authoring tool, which has no business in one) gets exactly what Lib.Squads() answered, so this is the game's own catalogue unchanged wherever nobody declared otherwise. → Context.Player.
func (SquadsScreen) Refuse ¶
func (s SquadsScreen) Refuse(slots int, chosen []string, kind string, available []string, insist bool) error
Refuse is the loadout rule asked early, so an over-filled slot is a line under the picker rather than a surprise at the save.
It is the same call the write makes — cast.ChooseFrom — because a builder that judged a choice for itself would be a second copy of the rule, and the copy would be the one an author trusted.
func (SquadsScreen) Save ¶
func (s SquadsScreen) Save(c Context) SquadsScreen
Save writes the squad, and refuses exactly as a battle would.
func (SquadsScreen) StageChoices ¶
func (s SquadsScreen) StageChoices() []string
StageChoices is the forms this unit may be fielded as: the empty string, which is the furthest the level reaches, and then every form by name.
The empty option is offered first because it is what a placement means when it says nothing — and it is deliberately not the only option, because a line that forks has no furthest and the arms have to be nameable.
func (SquadsScreen) Update ¶
func (s SquadsScreen) Update(c Context, message tea.KeyPressMsg) (SquadsScreen, Action, tea.Cmd)
Update routes a keystroke to whichever of the three depths is in front, and says what the client owes it.
⚠️ **Three returns rather than two, and the third is a tea.Cmd**, for the reason SkillsScreen.Update has three: this screen has text fields — the id, the name and the level — and a bubbles textinput answers an Update with a command, the cursor's blink, which has to come out or the field loses its cursor.
type StatusRow ¶
StatusRow is one line of the listing: either a category heading or a status filed under it.
Headings are rows rather than something drawn between them, because the listing scrolls: a heading computed while rendering would fall off the top of the window and leave the rows under it with nothing saying what they are.
type StatusesScreen ¶
type StatusesScreen struct {
Rows []StatusRow
// cursor indexes rows and is always on a status. Nothing is learnt by
// selecting a heading, and a cursor that could land on one would make the
// description below blink out for a keystroke.
Cursor int
}
StatusesScreen is the reference for the timed effects: what each buff and debuff does, how long it lasts and how many will layer.
It is the sixth listing and the one that was missing. The other five — works, species, presets, traits, skills — each name a status somewhere in their rows, and until this existed the only way to find out what one of those names meant was to open statuses.json. A skill's own description has the same hole from the other side: it says *inflicts mire, 70% of the time*, which tells a reader that something will happen and not what.
Read-only, unlike the origins and skills listings. A status carries modifier terms and a tick power, which are balance rather than content: adding one is a change to what every skill inflicting it does, and that belongs in a diff rather than behind a form. This screen exists to be read.
func NewStatusesScreen ¶
func NewStatusesScreen(lib *forge.Library) StatusesScreen
NewStatusesScreen is the reference filled from a library, ready to draw.
func (StatusesScreen) Focus ¶
func (s StatusesScreen) Focus(id string) (StatusesScreen, bool)
Focus puts the cursor on a named status and reports whether it found one.
It reports rather than settling for the nearest, because the caller is acting on a name it read out of a trait: a book that has lost that status is a book where the trait's own description is printing a bare id, and moving the cursor to whatever sorted next would answer a question nobody asked.
func (StatusesScreen) Refresh ¶
func (s StatusesScreen) Refresh(lib *forge.Library) StatusesScreen
Refresh re-files every row against a library that may have been written to since the screen was last drawn, keeping the cursor on a status.
func (StatusesScreen) Update ¶
func (s StatusesScreen) Update(_ Context, message tea.KeyPressMsg) (StatusesScreen, Action)
Update reads one keystroke: the cursor steps over the headings, or the reader leaves.
type Subject ¶
type Subject struct {
Kind SubjectKind
// ID is a status id, a skill id, a character id or a squad id, depending on
// Kind.
ID string
// Level is the level a character is being read at, and only a
// CharacterSubject spends it. A trait comes in at a level, so "what is this
// unit carrying" has no answer without one.
Level int
// Stage is the form a character is being read as, and only a
// CharacterSubject spends it. Empty is progression.Furthest, which is what a
// line that does not fork resolves with and what every subject carried
// before this field existed.
//
// ⚠️ **It is here because a level is not enough to name a form.** A line that
// forks reaches two grown forms at one level, and progression.Line.StageAt
// refuses to choose between them rather than hand a reader the wrong one's
// stat line — so the raiser, which is the only screen with a cursor, says
// which arm and the two describers read the same one. Without it the art
// preview and the traits blurb would each settle a fork of their own, and
// walking from one to the other could change the form for a reason nothing
// on either screen said. See screen.ChosenForm.
Stage string
// At and Of are where the subject sat in the list it was chosen out of, At
// counting from one.
//
// ⚠️ **Of is nought when that list was empty**, which is how a raiser says
// there was nothing to describe without the describer reaching back into the
// screen behind it to count. A describer handed nought draws the same "none
// of these" line it used to draw after looking.
At, Of int
}
Subject is what a raise is about: the thing the screen being raised is being asked to land on, or to describe.
⚠️ **A tagged struct rather than an interface**, and the reason is Action rather than taste. An Action is a comparable value a screen returns and a test writes out as a literal; an interface field would make the zero Action hold a nil the applier has to test for separately from "no subject", which is the absence-encoded-into-a-value mistake this repository has paid for twice (a queue reading of nought meaning soonest, a sentinel log offset meaning following). A Kind at nought means nothing was asked for, exactly as NoTarget does, and SubjectKindCount is what lets a client prove it handles the rest.
**Every kind carries an ID and that is the whole idiom**: a raise names what it wants by id and asks nobody where it lives, so the describer looks the id up in the books it was handed. Handing the resolved value over instead would put the lookup — and its refusal — on the raiser, which is the screen with nowhere to draw one.
type SubjectKind ¶
type SubjectKind uint8
SubjectKind is what sort of thing a Subject names.
const ( // NoSubject is the zero value and is what a raise about nothing carries — the // elements listing opening the chart is a whole screen rather than a thing on // one, so it names none. NoSubject SubjectKind = iota // StatusSubject is a status the raised screen should put its cursor on. // // ⚠️ An id the raised screen cannot find is a raise that does **not happen**: // the reader stays where they are. A trait naming a status the book has lost // is a trait already printing a bare id, and landing a cursor on whatever // sorted next would answer a question nobody asked. StatusSubject // SkillSubject is a skill to describe, and where it sat in the list it came // out of. // // ⚠️ **One kind covers the authoring listing and the battle's option list**, // which were measured as two and are one. Both hand over a skill id and a // position, both are drawn by the same paragraph under the same heading with // the same footer, and the only difference — which list the position counts — // is already carried in At and Of. A second kind nothing could branch on // would be two vocabularies for one idea. SkillSubject // CharacterSubject is a character read at a level. // // ⚠️ **Two describers answer it and that is why it is one kind.** The traits // blurb says what the character carries at that level and the art preview // draws the form it wears there; both are readings of the same subject, so // naming them apart would be naming the *describer* rather than the thing, // which is what Target already does. CharacterSubject // SquadSubject is a squad, named by its id, and it is the first kind that // is neither described nor put under a cursor: the fight is raised **about** // one, and lands it as the side it opens on. // // ⚠️ **A raise says which, rather than the client reading it back.** The // catalogue's `f` means "fight the squad under the cursor", and the client // owns both screens, so it could recover the answer from the catalogue's own // cursor after the raise had arrived. That is the mistake Action.About // exists to have stopped one field up, made worse: a pending question at // least freezes the keyboard while it waits, and a raise applier reading // another screen's cursor rests on nothing at all. // // It is an **id** and not the index the fight keeps, which is the idiom // stated above: a raise names what it wants and asks nobody where it lives, // so turning the id back into a row of the catalogue is the client's job and // the refusal is the client's too. SquadSubject )
func (SubjectKind) String ¶
func (k SubjectKind) String() string
String names a SubjectKind for a diagnostic, and nothing draws it — the same shape, and the same reason, as Target.String below.
type Target ¶
type Target uint8
Target is a screen a raise may name.
A short closed list rather than a screen id of any kind, because the whole point is that this package does not know what views the client in front has: a Target is a **request**, and the client's own map is what turns it into whichever of its screens answers to it.
const ( // NoTarget is the zero value and is what every Action that is not a Raise // carries. NoTarget Target = iota // Chart is the affinity chart drawn as the rings it was declared in. Chart // Statuses is the reference for the timed effects, raised on a // StatusSubject so it lands on the one that was named. Statuses // Blurb is the description screen: what the thing under the cursor behind it // does, in the sentences a player reads. // // ⚠️ **Two of its three raisers name it now** — the cast browser and the // skill listing — and the third, the played battle, still writes the // client's own enum because that screen has not moved. Declaring the target // ahead of any raiser is what put both of them under // TestEveryRaiseTargetNamesAScreenInThisClient before they arrived rather // than after. Blurb // Preview is the art a character shows at the level it is being read at, and // is declared ahead of its raiser for the reason Blurb is. Preview // Fight is two squads measured against each other. // // ⚠️ **It names a screen that has not moved and may never**, and that is // what a Target is for rather than a hole in the scheme: a Target is a // *request*, and the client's own map is what turns one into whichever of // its views answers to it. The squad catalogue is in this package now and // the fight it raises is not, so the raise has to be sayable without the // screen being sayable — which is exactly the sentence at the top of this // type. What the client owes in exchange is an entry in that map, which // TargetCount is what collects. Fight )
func (Target) String ¶
String names a Target for a diagnostic, and nothing draws it.
It is not wording: a client's screens are named in internal/i18n like everything a reader sees, and these are the ids a failing test prints so the value it is complaining about can be found. Same shape, and the same reason, as the fallback on every other enum here.