From e1eac9de0f0ee02f2732301f6a0a1c656683c9b5 Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Sun, 2 Apr 2023 00:36:12 -0700 Subject: [PATCH] displayStatsMenu --- cardsim/card.go | 9 ++++----- cardsim/infopanel.go | 6 +++--- cardsim/terminalui.go | 25 +++++++++++++++---------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/cardsim/card.go b/cardsim/card.go index 5d3cc55..a1eb4da 100644 --- a/cardsim/card.go +++ b/cardsim/card.go @@ -5,9 +5,8 @@ package cardsim type Card[C StatsCollection] interface { // Title is the short name of the card displayed in the hand // and at the top of the card output. It receives the current - // player as an argument. If it returns an error that is not - // a warning, the game crashes. - Title(p *Player[C]) (Message, error) + // player as an argument. + Title(p *Player[C]) Message // Urgent reports whether the card is considered urgent. If // the player has any urgent cards in hand, they cannot choose to act @@ -68,8 +67,8 @@ type BasicCard[C StatsCollection] struct { } // Title implements Card. -func (b *BasicCard[C]) Title(_ *Player[C]) (Message, error) { - return b.CardTitle, nil +func (b *BasicCard[C]) Title(_ *Player[C]) Message { + return b.CardTitle } // Urgent implements Card. diff --git a/cardsim/infopanel.go b/cardsim/infopanel.go index 01a3c5a..4e07459 100644 --- a/cardsim/infopanel.go +++ b/cardsim/infopanel.go @@ -11,7 +11,7 @@ import ( type InfoPanel[C StatsCollection] interface { // Title returns the title of this InfoPanel, which is also used as the // label presented to the player to access this panel. - Title(p *Player[C]) (Message, error) + Title(p *Player[C]) Message // Info returns the displayable contents of this InfoPanel. A nil Message // in the output is interpreted as a paragraph break. @@ -44,8 +44,8 @@ func VisibleOrDebug[C StatsCollection](p *Player[C], s Stat) bool { } // Title implements `InfoPanel[C]` by returning b's `Name`. -func (b *BasicStatsPanel[C]) Title(p *Player[C]) (Message, error) { - return b.Name, nil +func (b *BasicStatsPanel[C]) Title(p *Player[C]) Message { + return b.Name } // Info implements `InfoPanel[C]` by dumpiing p.Stats, showing those items for diff --git a/cardsim/terminalui.go b/cardsim/terminalui.go index 6f504af..d85edda 100644 --- a/cardsim/terminalui.go +++ b/cardsim/terminalui.go @@ -151,25 +151,18 @@ func confirmQuit() { } func displayOnePanel[C StatsCollection](p *Player[C], panel InfoPanel[C]) error { - var errs ErrorCollector - t, err := panel.Title(p) - if IsSeriousError(err) { - return err - } - errs.Add(err) - ts := t.String() + ts := panel.Title(p).String() if len(ts) > 0 { fmt.Println(ts) fmt.Println(strings.Repeat("-", len(ts))) fmt.Println() } m, err := panel.Info(p) - errs.Add(err) if IsSeriousError(err) { - return errs.Emit() + return err } display(MultiMessage(m)) - return errs.Emit() + return err } func displayMessageSection[C StatsCollection](p *Player[C]) bool { @@ -179,3 +172,15 @@ func displayMessageSection[C StatsCollection](p *Player[C]) bool { display(MultiMessage(p.TemporaryMessages)) return true } + +func displayStatsMenu[C StatsCollection](p *Player[C]) int { + if len(p.InfoPanels) == 0 { + return 0 + } + fmt.Println("Info Panels") + fmt.Println("-----------") + for i, s := range p.InfoPanels { + fmt.Printf("[%2d]: %s", i+1, s.Title(p).String()) + } + return len(p.InfoPanels) +}