From c2c1a9205ba8cf63ba967ee46c07af36b33ff874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mil=C3=A1n=20Boleradszki?= Date: Thu, 12 Oct 2023 23:16:46 +0100 Subject: [PATCH] feat: separate sequences of 3 digits in standings panel Group digits of 3 when displaying numbers in standings panel. For example: 100000 -> 100,000 Also, change hidden amount limits. --- go.mod | 1 + go.sum | 2 ++ internal/client/ui/standings_panel.go | 7 ++++--- internal/game/player.go | 16 ++++++++-------- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 17524fe..fbe88ff 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( require ( github.com/davecgh/go-spew v1.1.0 // indirect + github.com/dustin/go-humanize v1.0.1 // indirect github.com/gdamore/encoding v1.0.0 // indirect github.com/gobwas/httphead v0.1.0 // indirect github.com/gobwas/pool v0.2.1 // indirect diff --git a/go.sum b/go.sum index ccda46a..84f3524 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= github.com/gdamore/tcell/v2 v2.6.0 h1:OKbluoP9VYmJwZwq/iLb4BxwKcwGthaa1YNBJIyCySg= diff --git a/internal/client/ui/standings_panel.go b/internal/client/ui/standings_panel.go index 2fd759e..cab7b33 100644 --- a/internal/client/ui/standings_panel.go +++ b/internal/client/ui/standings_panel.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" + "github.com/dustin/go-humanize" "github.com/gdamore/tcell/v2" "github.com/milonoir/business-club-game/internal/message" "github.com/rivo/tview" @@ -120,9 +121,9 @@ func (p *StandingsPanel) generateBreakdownString(prices, stocks [4]int, cash int if showNumbers { for i := 0; i < 4; i++ { - sb.WriteString(fmt.Sprintf("[%s]%d\n", p.cp.ColorByIndex(i), stocks[i])) + sb.WriteString(fmt.Sprintf("[%s]%s\n", p.cp.ColorByIndex(i), humanize.Comma(int64(stocks[i])))) } - sb.WriteString(fmt.Sprintf("[green]%d\n", cash)) + sb.WriteString(fmt.Sprintf("[green]%s\n", humanize.Comma(int64(cash)))) } else { for i := 0; i < 4; i++ { s := strings.Repeat("♦", stocks[i]) @@ -140,7 +141,7 @@ func (p *StandingsPanel) generateBreakdownString(prices, stocks [4]int, cash int if showNumbers && showTotal { total := prices[0]*stocks[0] + prices[1]*stocks[1] + prices[2]*stocks[2] + prices[3]*stocks[3] + cash - sb.WriteString(fmt.Sprintf("[white]%d\n", total)) + sb.WriteString(fmt.Sprintf("[white]%s\n", humanize.Comma(int64(total)))) } return sb.String() diff --git a/internal/game/player.go b/internal/game/player.go index 0be9c54..db55555 100644 --- a/internal/game/player.go +++ b/internal/game/player.go @@ -13,13 +13,13 @@ func CashLevel(cash int) int { switch { case cash < 1: return 0 - case cash < 101: - return 1 case cash < 1_001: - return 2 + return 1 case cash < 10_001: - return 3 + return 2 case cash < 100_001: + return 3 + case cash < 1_000_001: return 4 default: return 5 @@ -31,13 +31,13 @@ func StockLevel(amount int) int { switch { case amount < 1: return 0 - case amount < 5: + case amount < 11: return 1 - case amount < 50: + case amount < 101: return 2 - case amount < 500: + case amount < 1_001: return 3 - case amount < 5_000: + case amount < 10_001: return 4 default: return 5