Implement review mode.
This finishes the UI.
This commit is contained in:
parent
74ca51b21d
commit
2875dc5af8
@ -227,7 +227,7 @@ func (p *Player[C]) Simulate() error {
|
|||||||
|
|
||||||
if p.DebugLevel > 0 && !errs.IsEmpty() {
|
if p.DebugLevel > 0 && !errs.IsEmpty() {
|
||||||
p.ChapterBreak()
|
p.ChapterBreak()
|
||||||
p.TemporaryMessages = append(p.TemporaryMessages, Msgf("%d ERRORS AND WARNINGS:", len(errs.Errs)))
|
p.TemporaryMessages = append(p.TemporaryMessages, Msgf("%d ERRORS AND WARNINGS while simulating turn:", len(errs.Errs)))
|
||||||
for i, e := range errs.Errs {
|
for i, e := range errs.Errs {
|
||||||
yikes := " "
|
yikes := " "
|
||||||
if IsSeriousError(e) {
|
if IsSeriousError(e) {
|
||||||
|
@ -41,17 +41,26 @@ func RunSimpleTerminalUI[C StatsCollection](p *Player[C]) error {
|
|||||||
wait()
|
wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
review(p)
|
// Allow player to review state before continuing simulation.
|
||||||
|
// Errors from review mode are reported *after* the simulation
|
||||||
|
// step because the first thing Simulate does is throw out old
|
||||||
|
// messages -- like these errors.
|
||||||
|
reviewErr := review(p)
|
||||||
|
if p.DebugLevel < 1 && IsSeriousError(err) {
|
||||||
|
return reviewErr
|
||||||
|
}
|
||||||
err = p.Simulate()
|
err = p.Simulate()
|
||||||
if p.DebugLevel < 1 && IsSeriousError(err) {
|
if p.DebugLevel < 1 && IsSeriousError(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// Simulation errors are already in messages; now add the review error.
|
||||||
|
p.ReportError(reviewErr)
|
||||||
|
|
||||||
if p.DebugLevel < 1 && p.State.Over() {
|
if p.DebugLevel < 1 && p.State.Over() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
// loop forever until the game ends or the player quits
|
||||||
}
|
}
|
||||||
|
|
||||||
func display(m Message) {
|
func display(m Message) {
|
||||||
@ -67,8 +76,7 @@ func wait() {
|
|||||||
fmt.Scanln()
|
fmt.Scanln()
|
||||||
}
|
}
|
||||||
|
|
||||||
func pickNextAction[C StatsCollection](p *Player[C]) (isCard bool, cardIdx int, choiceIdx int, err error) {
|
func displayMainMenu[C StatsCollection](p *Player[C]) (actionsOffset, handOffset, max int) {
|
||||||
for {
|
|
||||||
cls()
|
cls()
|
||||||
needsDivider := displayMessageSection(p)
|
needsDivider := displayMessageSection(p)
|
||||||
if needsDivider {
|
if needsDivider {
|
||||||
@ -76,18 +84,25 @@ func pickNextAction[C StatsCollection](p *Player[C]) (isCard bool, cardIdx int,
|
|||||||
}
|
}
|
||||||
displayOnePanel(p, p.Prompt)
|
displayOnePanel(p, p.Prompt)
|
||||||
divider()
|
divider()
|
||||||
actionsOffset := displayStatsMenu(p)
|
actionsOffset = displayStatsMenu(p)
|
||||||
if actionsOffset > 0 {
|
if actionsOffset > 0 {
|
||||||
divider()
|
divider()
|
||||||
}
|
}
|
||||||
handOffset := displayPermanentActionsMenu(p, actionsOffset)
|
handOffset = displayPermanentActionsMenu(p, actionsOffset)
|
||||||
if handOffset > actionsOffset {
|
if handOffset > actionsOffset {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
max := displayHandMenu(p, handOffset)
|
max = displayHandMenu(p, handOffset)
|
||||||
|
return // uses named return values
|
||||||
|
}
|
||||||
|
|
||||||
|
func pickNextAction[C StatsCollection](p *Player[C]) (isCard bool, cardIdx int, choiceIdx int, err error) {
|
||||||
|
for {
|
||||||
|
actionsOffset, handOffset, max := displayMainMenu(p)
|
||||||
|
|
||||||
divider()
|
divider()
|
||||||
fmt.Printf("Show just (M)essages, (I)nfo Panels, (A)ctions, or consider an action (1-%d), or (Q)uit? > ", max)
|
fmt.Printf("%d actions remaining.\n", p.ActionsRemaining)
|
||||||
|
fmt.Printf("Show just (M)essages, (I)nfo Panels, (A)ctions, or consider an item (1-%d), or (Q)uit? > ", max)
|
||||||
input := getResponse()
|
input := getResponse()
|
||||||
switch input {
|
switch input {
|
||||||
// Special cases
|
// Special cases
|
||||||
@ -102,7 +117,7 @@ func pickNextAction[C StatsCollection](p *Player[C]) (isCard bool, cardIdx int,
|
|||||||
statsMode(p)
|
statsMode(p)
|
||||||
case "a", "act", "actions":
|
case "a", "act", "actions":
|
||||||
var committed bool
|
var committed bool
|
||||||
isCard, cardIdx, choiceIdx, committed, err = actionsMode(p)
|
isCard, cardIdx, choiceIdx, committed, err = actionsMode(p, true)
|
||||||
if committed {
|
if committed {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -150,6 +165,12 @@ func getResponse() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func divider() {
|
func divider() {
|
||||||
|
fmt.Println()
|
||||||
|
fmt.Println(ChapterBreak.String())
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
|
||||||
|
func lightDivider() {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println(SectionBreak.String())
|
fmt.Println(SectionBreak.String())
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
@ -184,7 +205,16 @@ func displayMessageSection[C StatsCollection](p *Player[C]) bool {
|
|||||||
if len(p.TemporaryMessages) == 0 {
|
if len(p.TemporaryMessages) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
display(MultiMessage(p.TemporaryMessages))
|
hasPrevious := false
|
||||||
|
for _, m := range p.TemporaryMessages {
|
||||||
|
if m != nil {
|
||||||
|
if hasPrevious {
|
||||||
|
lightDivider()
|
||||||
|
}
|
||||||
|
display(m)
|
||||||
|
hasPrevious = true
|
||||||
|
}
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,7 +259,7 @@ func displayHandMenu[C StatsCollection](p *Player[C], offset int) int {
|
|||||||
func promptCard[C StatsCollection](p *Player[C], card Card[C]) (optionIdx int, err error) {
|
func promptCard[C StatsCollection](p *Player[C], card Card[C]) (optionIdx int, err error) {
|
||||||
// Iterate until the player makes a valid choice.
|
// Iterate until the player makes a valid choice.
|
||||||
for {
|
for {
|
||||||
opts, valid, err := displayCard(p, card)
|
opts, valid, err := displayCard(p, card, true)
|
||||||
if IsSeriousError(err) {
|
if IsSeriousError(err) {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
@ -267,7 +297,7 @@ func promptCard[C StatsCollection](p *Player[C], card Card[C]) (optionIdx int, e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func displayCard[C StatsCollection](p *Player[C], card Card[C]) ([]CardOption[C], bool, error) {
|
func displayCard[C StatsCollection](p *Player[C], card Card[C], canAct bool) ([]CardOption[C], bool, error) {
|
||||||
cls()
|
cls()
|
||||||
t := card.Title(p).String()
|
t := card.Title(p).String()
|
||||||
urgent := card.Urgent(p)
|
urgent := card.Urgent(p)
|
||||||
@ -287,11 +317,10 @@ func displayCard[C StatsCollection](p *Player[C], card Card[C]) ([]CardOption[C]
|
|||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println(SectionBreak.String())
|
fmt.Println(SectionBreak.String())
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
lockout := false
|
|
||||||
if !urgent && p.HasUrgentCards() {
|
if !urgent && p.HasUrgentCards() {
|
||||||
fmt.Println("<You have more urgent matters to attend to! You cannot act on this right now.>")
|
fmt.Println("<You have more urgent matters to attend to! You cannot act on this right now.>")
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
lockout = true
|
canAct = false
|
||||||
}
|
}
|
||||||
opts, optErr := card.Options(p)
|
opts, optErr := card.Options(p)
|
||||||
errs.Add(optErr)
|
errs.Add(optErr)
|
||||||
@ -301,9 +330,13 @@ func displayCard[C StatsCollection](p *Player[C], card Card[C]) ([]CardOption[C]
|
|||||||
valid := false
|
valid := false
|
||||||
for i, opt := range opts {
|
for i, opt := range opts {
|
||||||
pfx := "[xx]:"
|
pfx := "[xx]:"
|
||||||
if !lockout && opt.Enabled(p) {
|
if opt.Enabled(p) {
|
||||||
|
if canAct {
|
||||||
pfx = fmt.Sprintf("[%2d]:", i+1)
|
pfx = fmt.Sprintf("[%2d]:", i+1)
|
||||||
valid = true
|
valid = true
|
||||||
|
} else {
|
||||||
|
pfx = "[--]:"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
t, err := opt.OptionText(p)
|
t, err := opt.OptionText(p)
|
||||||
errs.Add(err)
|
errs.Add(err)
|
||||||
@ -326,7 +359,7 @@ func statsMode[C StatsCollection](p *Player[C]) error {
|
|||||||
return errs.Emit()
|
return errs.Emit()
|
||||||
}
|
}
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Printf("Go (B)ack, (Q)uit, or view an info panel (1-%d)? > ")
|
fmt.Printf("Go (B)ack, (Q)uit, or view an info panel (1-%d)? > ", n)
|
||||||
s := getResponse()
|
s := getResponse()
|
||||||
switch s {
|
switch s {
|
||||||
case "b", "back":
|
case "b", "back":
|
||||||
@ -353,7 +386,7 @@ func statsMode[C StatsCollection](p *Player[C]) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func actionsMode[C StatsCollection](p *Player[C]) (isCard bool, cardIdx, choiceIdx int, committed bool, err error) {
|
func actionsMode[C StatsCollection](p *Player[C], canAct bool) (isCard bool, cardIdx, choiceIdx int, committed bool, err error) {
|
||||||
var errs ErrorCollector
|
var errs ErrorCollector
|
||||||
for {
|
for {
|
||||||
cls()
|
cls()
|
||||||
@ -372,7 +405,11 @@ func actionsMode[C StatsCollection](p *Player[C]) (isCard bool, cardIdx, choiceI
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
if canAct {
|
||||||
fmt.Printf("Go (B)ack, (Q)uit, or consider an action (1-%d)? > ", max)
|
fmt.Printf("Go (B)ack, (Q)uit, or consider an action (1-%d)? > ", max)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Go (B)ack, (Q)uit, or view an action (1-%d)? > ", max)
|
||||||
|
}
|
||||||
input := getResponse()
|
input := getResponse()
|
||||||
switch input {
|
switch input {
|
||||||
case "b", "back":
|
case "b", "back":
|
||||||
@ -389,20 +426,104 @@ func actionsMode[C StatsCollection](p *Player[C]) (isCard bool, cardIdx, choiceI
|
|||||||
wait()
|
wait()
|
||||||
} else if v <= pOff {
|
} else if v <= pOff {
|
||||||
v--
|
v--
|
||||||
|
if canAct {
|
||||||
optIdx, err := promptCard(p, p.PermanentActions[v])
|
optIdx, err := promptCard(p, p.PermanentActions[v])
|
||||||
errs.Add(err)
|
errs.Add(err)
|
||||||
if optIdx >= 0 || IsSeriousError(err) {
|
if optIdx >= 0 || IsSeriousError(err) {
|
||||||
return false, v, optIdx, true, errs.Emit()
|
return false, v, optIdx, true, errs.Emit()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
_, _, err := displayCard(p, p.PermanentActions[v], false)
|
||||||
|
errs.Add(err)
|
||||||
|
if IsSeriousError(err) {
|
||||||
|
return false, -1, -1, true, errs.Emit()
|
||||||
|
}
|
||||||
|
wait()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
v = v - pOff - 1
|
v = v - pOff - 1
|
||||||
|
if canAct {
|
||||||
optIdx, err := promptCard(p, p.Hand[v])
|
optIdx, err := promptCard(p, p.Hand[v])
|
||||||
errs.Add(err)
|
errs.Add(err)
|
||||||
if optIdx >= 0 || IsSeriousError(err) {
|
if optIdx >= 0 || IsSeriousError(err) {
|
||||||
return true, v, optIdx, true, errs.Emit()
|
return true, v, optIdx, false, errs.Emit()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_, _, err := displayCard(p, p.Hand[v], false)
|
||||||
|
errs.Add(err)
|
||||||
|
if IsSeriousError(err) {
|
||||||
|
return false, -1, -1, false, errs.Emit()
|
||||||
|
}
|
||||||
|
wait()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Re-prompt to get a valid choice.
|
// Re-prompt to get a valid choice.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func review[C StatsCollection](p *Player[C]) error {
|
||||||
|
var errs ErrorCollector
|
||||||
|
for {
|
||||||
|
actionsOffset, handOffset, max := displayMainMenu(p)
|
||||||
|
divider()
|
||||||
|
fmt.Println("No actions remaining.")
|
||||||
|
fmt.Printf("(C)ontinue, review just (M)essages, (I)nfo Panels, (A)ctions, or an item (1-%d), or (Q)uit? > ", max)
|
||||||
|
input := getResponse()
|
||||||
|
switch input {
|
||||||
|
// Special cases
|
||||||
|
case "m", "msg", "message", "messages":
|
||||||
|
cls()
|
||||||
|
if displayMessageSection(p) {
|
||||||
|
divider()
|
||||||
|
}
|
||||||
|
displayOnePanel(p, p.Prompt)
|
||||||
|
wait()
|
||||||
|
case "s", "stat", "stats", "i", "info", "p", "panel", "panels", "infopanel", "infopanels":
|
||||||
|
err := statsMode(p)
|
||||||
|
errs.Add(err)
|
||||||
|
if IsSeriousError(err) {
|
||||||
|
return errs.Emit()
|
||||||
|
}
|
||||||
|
case "a", "act", "actions":
|
||||||
|
_, _, _, _, err := actionsMode(p, false)
|
||||||
|
errs.Add(err)
|
||||||
|
if IsSeriousError(err) {
|
||||||
|
return errs.Emit()
|
||||||
|
}
|
||||||
|
case "q", "quit", "exit":
|
||||||
|
confirmQuit()
|
||||||
|
case "c", "continue", "ok":
|
||||||
|
return errs.Emit()
|
||||||
|
default:
|
||||||
|
i, err := strconv.Atoi(input)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Sorry, I don't understand.")
|
||||||
|
wait()
|
||||||
|
} else if i <= 0 || i > max {
|
||||||
|
fmt.Println("That's not on this menu. If the menu is too big to read, choose a detail view.")
|
||||||
|
wait()
|
||||||
|
} else if i <= actionsOffset {
|
||||||
|
cls()
|
||||||
|
displayOnePanel(p, p.InfoPanels[i-1])
|
||||||
|
wait()
|
||||||
|
} else if i < handOffset {
|
||||||
|
i = i - actionsOffset - 1
|
||||||
|
_, _, err := displayCard(p, p.PermanentActions[i], false)
|
||||||
|
errs.Add(err)
|
||||||
|
if IsSeriousError(err) {
|
||||||
|
return errs.Emit()
|
||||||
|
}
|
||||||
|
wait()
|
||||||
|
} else {
|
||||||
|
i = i - handOffset - 1
|
||||||
|
_, _, err := displayCard(p, p.Hand[i], false)
|
||||||
|
errs.Add(err)
|
||||||
|
if IsSeriousError(err) {
|
||||||
|
return errs.Emit()
|
||||||
|
}
|
||||||
|
wait()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user