diff options
Diffstat (limited to 'internal/game/casino.go')
| -rw-r--r-- | internal/game/casino.go | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/internal/game/casino.go b/internal/game/casino.go index 97372f4..785666e 100644 --- a/internal/game/casino.go +++ b/internal/game/casino.go @@ -285,7 +285,7 @@ func (g *Game) emitCasinoEvents(events []casino.Event) { // renderCasinoMessage colorizes a casino message unless it is an // already-composed structured menu. func (g *Game) renderCasinoMessage(sess *net.Session, category string, menu *casino.MenuView, message string) string { - if category == "casino_menu" && menu != nil && menu.Kind != casino.MenuSlotCommands { + if category == "casino_menu" && menu != nil { return message } return g.colorize(sess, category, message) @@ -306,29 +306,47 @@ func (g *Game) casinoPrivateMessage(sess *net.Session, category string, menu *ca credits := g.colorize(sess, "casino_credits", fmt.Sprintf("%d", sess.Player.Credits)) balance := fmt.Sprintf("You have %s chips and %s credits.", chips, credits) switch menu.Kind { - case casino.MenuBlackjackBet: - command := func(value string) string { return g.colorize(sess, "casino_command", value) } - return fmt.Sprintf("%s\n\nNew hand! You can %s, %s (inc. min/max), or %s.", - balance, command("bet"), command("bet <amount>"), command("stop")) + case casino.MenuBlackjackBet, casino.MenuBaccaratBet: + return g.renderCasinoCommands(sess, balance, message, menu.Commands) case casino.MenuBlackjackTurn: - commands := make([]string, len(menu.Actions)) - for i, action := range menu.Actions { - commands[i] = g.colorize(sess, "casino_command", action) - } - return menu.Title + "\nActions: " + strings.Join(commands, ", ") - case casino.MenuBaccaratBet: - command := func(value string) string { return g.colorize(sess, "casino_command", value) } - return fmt.Sprintf("%s\n\nNew hand! You can %s, %s on player|banker|tie (inc. min/max), or %s.", - balance, command("bet"), command("bet <amount>"), command("stop")) + return g.renderCasinoCommands(sess, "", menu.Title, menu.Commands) case casino.MenuSlotCommands: - if message == "" { - return balance + "\n\n" + menu.Body - } - return message + "\n\n" + balance + "\n\n" + menu.Body + return g.renderCasinoCommands(sess, balance, message, menu.Commands) } return message } +// renderCasinoCommands lays every casino menu out in the same style: an +// optional balance line, a heading, and an aligned command list with each +// command in the "command" color and its description in plain text. +func (g *Game) renderCasinoCommands(sess *net.Session, balance, heading string, commands []casino.MenuCommand) string { + var sb strings.Builder + if balance != "" { + sb.WriteString(balance) + sb.WriteString("\n\n") + } + if heading != "" { + sb.WriteString(heading) + sb.WriteString("\n\n") + } + width := 0 + for _, c := range commands { + if n := utf8.RuneCountInString(c.Command); n > width { + width = n + } + } + for _, c := range commands { + padded := c.Command + strings.Repeat(" ", width-utf8.RuneCountInString(c.Command)) + cmd := g.colorize(sess, "command", padded) + if c.Desc != "" { + fmt.Fprintf(&sb, " %s %s\n", cmd, c.Desc) + } else { + fmt.Fprintf(&sb, " %s\n", cmd) + } + } + return strings.TrimRight(sb.String(), "\n") +} + func renderBlackjackSnapshot(snapshot *casino.BlackjackSnapshot, mode string, unicode bool, size int, style string, art *cardart.Store) string { if snapshot == nil { return "" |
