diff options
| author | historia <[not public]> | 2026-09-30 03:55:37 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-09-30 03:55:37 -0400 |
| commit | 735428f0667f67c12fdf3caca872d7dc65e2ce26 (patch) | |
| tree | 92c9931f223bfd50ced4f1954130d879640a435b /internal/casino/table_ux.go | |
| parent | ffc7b582e9c14fdc2e579b9239b5ff7ad9a0d90a (diff) | |
| download | thehouseoficarus-735428f0667f67c12fdf3caca872d7dc65e2ce26.tar.gz | |
feat: restyle roulette presentation
Diffstat (limited to 'internal/casino/table_ux.go')
| -rw-r--r-- | internal/casino/table_ux.go | 127 |
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 } |
