Panel display, MultiMessage.
This commit is contained in:
		| @@ -1,6 +1,9 @@ | ||||
| package cardsim | ||||
|  | ||||
| import "fmt" | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| // Message is an opaque interface representing a displayable message. | ||||
| // Using an interface here allows for implementation of new message display | ||||
| @@ -56,3 +59,19 @@ func IsSpecialMessage(m Message, s *SpecialMessage) bool { | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| // MultiMessage is a sequence of messages treated like one message. | ||||
| type MultiMessage []Message | ||||
|  | ||||
| func (m MultiMessage) String() string { | ||||
| 	s := make([]string, len(m)) | ||||
| 	for i, msg := range m { | ||||
| 		if msg == nil { | ||||
| 			s[i] = "" | ||||
| 			continue | ||||
| 		} | ||||
| 		s[i] = msg.String() | ||||
| 		continue | ||||
| 	} | ||||
| 	return strings.Join(s, "\n") | ||||
| } | ||||
|   | ||||
| @@ -63,7 +63,7 @@ func pickNextAction[C StatsCollection](p *Player[C]) (isCard bool, cardIdx int, | ||||
| 	if needsDivider { | ||||
| 		divider() | ||||
| 	} | ||||
| 	displayPrompt(p) | ||||
| 	displayOnePanel(p, p.Prompt) | ||||
| 	actionsOffset := displayStatsMenu(p) | ||||
| 	handOffset := displayPermanentActionsMenu(p, actionsOffset) | ||||
| 	max := displayHandMenu(p, handOffset) | ||||
| @@ -143,3 +143,25 @@ func confirmQuit() { | ||||
| 		os.Exit(0) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| 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() | ||||
| 	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() | ||||
| 	} | ||||
| 	displayAndWait(MultiMessage(m)) | ||||
| 	return errs.Emit() | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user