aboutsummaryrefslogtreecommitdiff
path: root/internal/casino/table_ux.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/casino/table_ux.go')
-rw-r--r--internal/casino/table_ux.go127
1 files changed, 120 insertions, 7 deletions
diff --git a/internal/casino/table_ux.go b/internal/casino/table_ux.go
index 002d9f0..b4a13ab 100644
--- a/internal/casino/table_ux.go
+++ b/internal/casino/table_ux.go
@@ -201,13 +201,126 @@ func (t *blackjackTable) insuranceMenuLocked(p *blackjackPlayer) Event {
return e
}
-func resultText(result string, stake, returned int) string {
- label := strings.ToUpper(result)
- switch result {
+// settlementLine is one settled bet within a round. Label names the bet for
+// the itemized line (empty for a lone anonymous hand); Result is the engine's
+// settlement word ("win", "loss", "bust", "push", "blackjack",
+// "surrender", "insurance").
+type settlementLine struct {
+ Label string
+ Result string
+ Stake int
+ Returned int
+ Tag string // optional color-category override (jackpot, for example)
+}
+
+func (l settlementLine) net() int { return l.Returned - l.Stake }
+
+// resultTextLabel renders a settled wager as a colored outcome plus its net,
+// naming the bet on its own line.
+func resultTextLabel(label, result string, stake, returned int) string {
+ return settlementText([]settlementLine{{Label: label, Result: result, Stake: stake, Returned: returned}})
+}
+
+// settlementText renders a settlement as a colored headline followed by one
+// line per named bet. The net is the only figure shown: the old
+// "Net ... | ... returned (stake included)" split is gone. Wins are green,
+// losses red and pushes white, with the headline taking the round's overall
+// result and each line its own.
+func settlementText(lines []settlementLine) string {
+ net := 0
+ for _, line := range lines {
+ net += line.net()
+ }
+ var sb strings.Builder
+ fmt.Fprintf(&sb, "{%s}%s{/} {casino_payout}%s{/}", settlementTag(lines), settlementLabel(lines), creditsText(net))
+ for _, line := range lines {
+ if line.Label == "" {
+ continue
+ }
+ fmt.Fprintf(&sb, "\n {casino_action}%s:{/} {%s}%s{/}", line.Label, lineTag(line), creditsText(line.net()))
+ }
+ return sb.String()
+}
+
+// creditsText formats a signed credit total with the right plural.
+func creditsText(n int) string {
+ word := "credits"
+ if n == 1 || n == -1 {
+ word = "credit"
+ }
+ return fmt.Sprintf("%+d %s", n, word)
+}
+
+// settlementLabel returns the headline word for a round.
+func settlementLabel(lines []settlementLine) string {
+ if len(lines) == 1 {
+ switch lines[0].Result {
+ case "blackjack":
+ return "BLACKJACK"
+ case "surrender":
+ return "SURRENDER"
+ }
+ }
+ switch {
+ case settlementNet(lines) > 0:
+ return "WIN"
+ case settlementNet(lines) < 0:
+ return "LOSS"
+ default:
+ return "PUSH"
+ }
+}
+
+// settlementTag returns the headline's color tag. A lone natural keeps the
+// jackpot gradient; otherwise the net decides green, red or white.
+func settlementTag(lines []settlementLine) string {
+ if len(lines) == 1 && lines[0].Tag != "" {
+ return lines[0].Tag
+ }
+ if len(lines) == 1 && lines[0].Result == "blackjack" {
+ return "casino_jackpot_win"
+ }
+ switch {
+ case settlementNet(lines) > 0:
+ return "casino_result_win"
+ case settlementNet(lines) < 0:
+ return "casino_result_loss"
+ default:
+ return "casino_result_push"
+ }
+}
+
+// lineTag colors one bet's outcome. Insurance is judged by its net because the
+// same result word covers a paid and a lost premium.
+func lineTag(line settlementLine) string {
+ if line.Tag != "" {
+ return line.Tag
+ }
+ switch line.Result {
case "blackjack":
- label = "BLACKJACK"
- case "bust", "loss", "dealer blackjack":
- label = "LOSS"
+ return "casino_jackpot_win"
+ case "push":
+ return "casino_result_push"
+ case "win":
+ return "casino_result_win"
+ case "insurance":
+ switch {
+ case line.net() > 0:
+ return "casino_result_win"
+ case line.net() < 0:
+ return "casino_result_loss"
+ default:
+ return "casino_result_push"
+ }
+ default:
+ return "casino_result_loss"
+ }
+}
+
+func settlementNet(lines []settlementLine) int {
+ net := 0
+ for _, line := range lines {
+ net += line.net()
}
- return fmt.Sprintf("%s | Net %+d credits | %d returned (stake included)", label, returned-stake, returned)
+ return net
}