Restructure loop, basic display functions
This commit is contained in:
parent
a62de999ea
commit
aecd8683b2
@ -27,7 +27,8 @@ func RunSimpleTerminalUI[C StatsCollection](p *Player[C]) error {
|
||||
if p.DebugLevel < 1 && IsSeriousError(err) {
|
||||
return err
|
||||
}
|
||||
displayAndWait(msg)
|
||||
display(msg)
|
||||
wait()
|
||||
}
|
||||
|
||||
review(p)
|
||||
@ -43,12 +44,11 @@ func RunSimpleTerminalUI[C StatsCollection](p *Player[C]) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func displayAndWait(m Message) {
|
||||
func display(m Message) {
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
fmt.Println(m.String())
|
||||
wait()
|
||||
}
|
||||
|
||||
func wait() {
|
||||
@ -58,6 +58,7 @@ func wait() {
|
||||
}
|
||||
|
||||
func pickNextAction[C StatsCollection](p *Player[C]) (isCard bool, cardIdx int, choiceIdx int) {
|
||||
for {
|
||||
cls()
|
||||
needsDivider := displayMessageSection(p)
|
||||
if needsDivider {
|
||||
@ -101,7 +102,8 @@ func pickNextAction[C StatsCollection](p *Player[C]) (isCard bool, cardIdx int,
|
||||
i -= 1
|
||||
if i < actionsOffset {
|
||||
cls()
|
||||
DisplayOnePanelAndWait(p, i)
|
||||
displayOnePanel(p, p.InfoPanels[i])
|
||||
wait()
|
||||
} else if i < handOffset {
|
||||
cls()
|
||||
i -= actionsOffset
|
||||
@ -118,7 +120,7 @@ func pickNextAction[C StatsCollection](p *Player[C]) (isCard bool, cardIdx int,
|
||||
}
|
||||
}
|
||||
}
|
||||
return pickNextAction(p)
|
||||
}
|
||||
}
|
||||
|
||||
func cls() {
|
||||
@ -162,6 +164,14 @@ func displayOnePanel[C StatsCollection](p *Player[C], panel InfoPanel[C]) error
|
||||
if IsSeriousError(err) {
|
||||
return errs.Emit()
|
||||
}
|
||||
displayAndWait(MultiMessage(m))
|
||||
display(MultiMessage(m))
|
||||
return errs.Emit()
|
||||
}
|
||||
|
||||
func displayMessageSection[C StatsCollection](p *Player[C]) bool {
|
||||
if len(p.TemporaryMessages) == 0 {
|
||||
return false
|
||||
}
|
||||
display(MultiMessage(p.TemporaryMessages))
|
||||
return true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user