Skip to content

Commit

Permalink
feat: separate sequences of 3 digits in standings panel
Browse files Browse the repository at this point in the history
Group digits of 3 when displaying numbers in standings panel. For
example: 100000 -> 100,000

Also, change hidden amount limits.
  • Loading branch information
milonoir committed Oct 12, 2023
1 parent 8719b94 commit c2c1a92
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
7 changes: 4 additions & 3 deletions internal/client/ui/standings_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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])
Expand All @@ -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()
Expand Down
16 changes: 8 additions & 8 deletions internal/game/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c2c1a92

Please sign in to comment.