Restructure loop, basic display functions

This commit is contained in:
Kistaro Windrider 2023-04-02 00:26:34 -07:00
parent a62de999ea
commit aecd8683b2
Signed by: kistaro
SSH Key Fingerprint: SHA256:TBE2ynfmJqsAf0CP6gsflA0q5X5wD5fVKWPsZ7eVUg8

View File

@ -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,6 +58,7 @@ 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) {
for {
cls() cls()
needsDivider := displayMessageSection(p) needsDivider := displayMessageSection(p)
if needsDivider { if needsDivider {
@ -101,7 +102,8 @@ func pickNextAction[C StatsCollection](p *Player[C]) (isCard bool, cardIdx int,
i -= 1 i -= 1
if i < actionsOffset { if i < actionsOffset {
cls() cls()
DisplayOnePanelAndWait(p, i) displayOnePanel(p, p.InfoPanels[i])
wait()
} else if i < handOffset { } else if i < handOffset {
cls() cls()
i -= actionsOffset i -= actionsOffset
@ -118,7 +120,7 @@ func pickNextAction[C StatsCollection](p *Player[C]) (isCard bool, cardIdx int,
} }
} }
} }
return pickNextAction(p) }
} }
func cls() { func cls() {
@ -162,6 +164,14 @@ func displayOnePanel[C StatsCollection](p *Player[C], panel InfoPanel[C]) error
if IsSeriousError(err) { if IsSeriousError(err) {
return errs.Emit() return errs.Emit()
} }
displayAndWait(MultiMessage(m)) display(MultiMessage(m))
return errs.Emit() return errs.Emit()
} }
func displayMessageSection[C StatsCollection](p *Player[C]) bool {
if len(p.TemporaryMessages) == 0 {
return false
}
display(MultiMessage(p.TemporaryMessages))
return true
}