Compare commits
3 Commits
a62de999ea
...
e1eac9de0f
Author | SHA1 | Date | |
---|---|---|---|
e1eac9de0f | |||
7371cddab3 | |||
aecd8683b2 |
@ -5,9 +5,8 @@ package cardsim
|
|||||||
type Card[C StatsCollection] interface {
|
type Card[C StatsCollection] interface {
|
||||||
// Title is the short name of the card displayed in the hand
|
// Title is the short name of the card displayed in the hand
|
||||||
// and at the top of the card output. It receives the current
|
// and at the top of the card output. It receives the current
|
||||||
// player as an argument. If it returns an error that is not
|
// player as an argument.
|
||||||
// a warning, the game crashes.
|
Title(p *Player[C]) Message
|
||||||
Title(p *Player[C]) (Message, error)
|
|
||||||
|
|
||||||
// Urgent reports whether the card is considered urgent. If
|
// Urgent reports whether the card is considered urgent. If
|
||||||
// the player has any urgent cards in hand, they cannot choose to act
|
// 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.
|
// Title implements Card.
|
||||||
func (b *BasicCard[C]) Title(_ *Player[C]) (Message, error) {
|
func (b *BasicCard[C]) Title(_ *Player[C]) Message {
|
||||||
return b.CardTitle, nil
|
return b.CardTitle
|
||||||
}
|
}
|
||||||
|
|
||||||
// Urgent implements Card.
|
// Urgent implements Card.
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
type InfoPanel[C StatsCollection] interface {
|
type InfoPanel[C StatsCollection] interface {
|
||||||
// Title returns the title of this InfoPanel, which is also used as the
|
// Title returns the title of this InfoPanel, which is also used as the
|
||||||
// label presented to the player to access this panel.
|
// 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
|
// Info returns the displayable contents of this InfoPanel. A nil Message
|
||||||
// in the output is interpreted as a paragraph break.
|
// 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`.
|
// Title implements `InfoPanel[C]` by returning b's `Name`.
|
||||||
func (b *BasicStatsPanel[C]) Title(p *Player[C]) (Message, error) {
|
func (b *BasicStatsPanel[C]) Title(p *Player[C]) Message {
|
||||||
return b.Name, nil
|
return b.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
// Info implements `InfoPanel[C]` by dumpiing p.Stats, showing those items for
|
// Info implements `InfoPanel[C]` by dumpiing p.Stats, showing those items for
|
||||||
|
@ -27,7 +27,8 @@ func RunSimpleTerminalUI[C StatsCollection](p *Player[C]) error {
|
|||||||
if p.DebugLevel < 1 && IsSeriousError(err) {
|
if p.DebugLevel < 1 && IsSeriousError(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
displayAndWait(msg)
|
display(msg)
|
||||||
|
wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
review(p)
|
review(p)
|
||||||
@ -43,12 +44,11 @@ func RunSimpleTerminalUI[C StatsCollection](p *Player[C]) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func displayAndWait(m Message) {
|
func display(m Message) {
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Println(m.String())
|
fmt.Println(m.String())
|
||||||
wait()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func wait() {
|
func wait() {
|
||||||
@ -58,67 +58,73 @@ func wait() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func pickNextAction[C StatsCollection](p *Player[C]) (isCard bool, cardIdx int, choiceIdx int) {
|
func pickNextAction[C StatsCollection](p *Player[C]) (isCard bool, cardIdx int, choiceIdx int) {
|
||||||
cls()
|
for {
|
||||||
needsDivider := displayMessageSection(p)
|
|
||||||
if needsDivider {
|
|
||||||
divider()
|
|
||||||
}
|
|
||||||
displayOnePanel(p, p.Prompt)
|
|
||||||
actionsOffset := displayStatsMenu(p)
|
|
||||||
handOffset := displayPermanentActionsMenu(p, actionsOffset)
|
|
||||||
max := displayHandMenu(p, handOffset)
|
|
||||||
|
|
||||||
divider()
|
|
||||||
var input string
|
|
||||||
fmt.Printf("Show just (M)essages, (S)tats, (A)ctions, make a choice (1-%d), or (Q)uit? >", max+1)
|
|
||||||
fmt.Scanln(&input)
|
|
||||||
input = strings.TrimSpace(input)
|
|
||||||
input = strings.ToLower(input)
|
|
||||||
switch input {
|
|
||||||
// Special cases
|
|
||||||
case "m":
|
|
||||||
cls()
|
cls()
|
||||||
displayMessageSection(p)
|
needsDivider := displayMessageSection(p)
|
||||||
wait()
|
if needsDivider {
|
||||||
case "s":
|
divider()
|
||||||
statsMode(p)
|
|
||||||
case "a":
|
|
||||||
actionsMode(p)
|
|
||||||
case "q":
|
|
||||||
confirmQuit()
|
|
||||||
default:
|
|
||||||
i, err := strconv.Atoi(input)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Sorry, I don't understand.")
|
|
||||||
wait()
|
|
||||||
return pickNextAction(p)
|
|
||||||
}
|
}
|
||||||
if i > max {
|
displayOnePanel(p, p.Prompt)
|
||||||
fmt.Println("That's not a valid action.")
|
divider()
|
||||||
wait()
|
actionsOffset := displayStatsMenu(p)
|
||||||
return pickNextAction(p)
|
if actionsOffset > 0 {
|
||||||
|
divider()
|
||||||
}
|
}
|
||||||
i -= 1
|
handOffset := displayPermanentActionsMenu(p, actionsOffset)
|
||||||
if i < actionsOffset {
|
max := displayHandMenu(p, handOffset)
|
||||||
|
|
||||||
|
divider()
|
||||||
|
var input string
|
||||||
|
fmt.Printf("Show just (M)essages, (S)tats, (A)ctions, make a choice (1-%d), or (Q)uit? >", max+1)
|
||||||
|
fmt.Scanln(&input)
|
||||||
|
input = strings.TrimSpace(input)
|
||||||
|
input = strings.ToLower(input)
|
||||||
|
switch input {
|
||||||
|
// Special cases
|
||||||
|
case "m":
|
||||||
cls()
|
cls()
|
||||||
DisplayOnePanelAndWait(p, i)
|
displayMessageSection(p)
|
||||||
} else if i < handOffset {
|
wait()
|
||||||
cls()
|
case "s":
|
||||||
i -= actionsOffset
|
statsMode(p)
|
||||||
option, ok := promptPermanentAction(p, i)
|
case "a":
|
||||||
if ok {
|
actionsMode(p)
|
||||||
return false, i, option
|
case "q":
|
||||||
|
confirmQuit()
|
||||||
|
default:
|
||||||
|
i, err := strconv.Atoi(input)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Sorry, I don't understand.")
|
||||||
|
wait()
|
||||||
|
return pickNextAction(p)
|
||||||
}
|
}
|
||||||
} else {
|
if i > max {
|
||||||
cls()
|
fmt.Println("That's not a valid action.")
|
||||||
i -= handOffset
|
wait()
|
||||||
option, ok := promptCard(p, i)
|
return pickNextAction(p)
|
||||||
if ok {
|
}
|
||||||
return true, i, option
|
i -= 1
|
||||||
|
if i < actionsOffset {
|
||||||
|
cls()
|
||||||
|
displayOnePanel(p, p.InfoPanels[i])
|
||||||
|
wait()
|
||||||
|
} else if i < handOffset {
|
||||||
|
cls()
|
||||||
|
i -= actionsOffset
|
||||||
|
option, ok := promptPermanentAction(p, i)
|
||||||
|
if ok {
|
||||||
|
return false, i, option
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cls()
|
||||||
|
i -= handOffset
|
||||||
|
option, ok := promptCard(p, i)
|
||||||
|
if ok {
|
||||||
|
return true, i, option
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pickNextAction(p)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func cls() {
|
func cls() {
|
||||||
@ -145,23 +151,36 @@ func confirmQuit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func displayOnePanel[C StatsCollection](p *Player[C], panel InfoPanel[C]) error {
|
func displayOnePanel[C StatsCollection](p *Player[C], panel InfoPanel[C]) error {
|
||||||
var errs ErrorCollector
|
ts := panel.Title(p).String()
|
||||||
t, err := panel.Title(p)
|
|
||||||
if IsSeriousError(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
errs.Add(err)
|
|
||||||
ts := t.String()
|
|
||||||
if len(ts) > 0 {
|
if len(ts) > 0 {
|
||||||
fmt.Println(ts)
|
fmt.Println(ts)
|
||||||
fmt.Println(strings.Repeat("-", len(ts)))
|
fmt.Println(strings.Repeat("-", len(ts)))
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
m, err := panel.Info(p)
|
m, err := panel.Info(p)
|
||||||
errs.Add(err)
|
|
||||||
if IsSeriousError(err) {
|
if IsSeriousError(err) {
|
||||||
return errs.Emit()
|
return err
|
||||||
}
|
}
|
||||||
displayAndWait(MultiMessage(m))
|
display(MultiMessage(m))
|
||||||
return errs.Emit()
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func displayMessageSection[C StatsCollection](p *Player[C]) bool {
|
||||||
|
if len(p.TemporaryMessages) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user