dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 6d02ef69cd1d9c99a4f4118c921d09191f855ffc
parent aa543b55bafa48fee8bf51d7276800393efa8802
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon, 12 Jun 2023 10:13:33 -0700

improve UI

Diffstat:
Mpkg/web/handlers/handlers.go | 8+++++---
Mpkg/web/handlers/interceptors/chess.go | 24+++++++++++++++---------
2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -5193,9 +5193,11 @@ Loop: } // Render advantages - whiteAdv, blackAdv := interceptors.CalcAdvantage(g.Game.Position()) - send(fmt.Sprintf(`<style>#white-advantage:after { content: "%s" !important; }</style>`, whiteAdv)) - send(fmt.Sprintf(`<style>#black-advantage:after { content: "%s" !important; }</style>`, blackAdv)) + whiteAdv, whiteScore, blackAdv, blackScore := interceptors.CalcAdvantage(g.Game.Position()) + send(fmt.Sprintf(`<style>#white-advantage:before { content: "%s" !important; }</style>`, whiteAdv)) + send(fmt.Sprintf(`<style>#white-advantage .score:after { content: "%s" !important; }</style>`, whiteScore)) + send(fmt.Sprintf(`<style>#black-advantage:before { content: "%s" !important; }</style>`, blackAdv)) + send(fmt.Sprintf(`<style>#black-advantage .score:after { content: "%s" !important; }</style>`, blackScore)) // Render last move send(`<style>.square { background-color: transparent !important; }</style>`) diff --git a/pkg/web/handlers/interceptors/chess.go b/pkg/web/handlers/interceptors/chess.go @@ -318,8 +318,11 @@ func (g *ChessGame) drawPlayerCard(key string, isBlack, isSpectator, isYourTurn background-color: darkred; display: inline-block; } -#white-advantage:after { content: "{{ .WhiteAdvantage }}"; } -#black-advantage:after { content: "{{ .BlackAdvantage }}"; } +#white-advantage:before { content: "{{ .WhiteAdvantage }}"; } +#white-advantage .score:after { content: "{{ .WhiteScore }}"; } +#black-advantage:before { content: "{{ .BlackAdvantage }}"; } +#black-advantage .score:after { content: "{{ .BlackScore }}"; } +.score { font-size: 11px; } </style> <table style="width: 100%; height: 100%;"> <tr> @@ -350,8 +353,8 @@ func (g *ChessGame) drawPlayerCard(key string, isBlack, isSpectator, isYourTurn </form> {{ end }} <span style="color: #eee; display: inline-block;"> - (<span id="white-advantage" style="color: #888;" title="white advantage"></span> | - <span id="black-advantage" style="color: #888;" title="black advantage"></span>) + (<span id="white-advantage" style="color: #888;" title="white advantage"><span class="score"></span></span> | + <span id="black-advantage" style="color: #888;" title="black advantage"><span class="score"></span></span>) </span> </td> </tr> @@ -384,7 +387,7 @@ func (g *ChessGame) drawPlayerCard(key string, isBlack, isSpectator, isYourTurn enemy := utils.Ternary(isBlack, g.Player1, g.Player2) imgB64 := g.renderBoardB64(isBlack) - whiteAdvantage, blackAdvantage := CalcAdvantage(g.Game.Position()) + whiteAdvantage, whiteScore, blackAdvantage, blackScore := CalcAdvantage(g.Game.Position()) data := map[string]any{ "Key": key, @@ -399,7 +402,9 @@ func (g *ChessGame) drawPlayerCard(key string, isBlack, isSpectator, isYourTurn "GameOver": g.Game.Outcome() != chess.NoOutcome, "PGN": g.Game.String(), "WhiteAdvantage": whiteAdvantage, + "WhiteScore": whiteScore, "BlackAdvantage": blackAdvantage, + "BlackScore": blackScore, } fns := template.FuncMap{ @@ -627,7 +632,7 @@ black chess pawn ♟︎ U+265F &#9823; &#x265F; */ // CalcAdvantage ... -func CalcAdvantage(position *chess.Position) (string, string) { +func CalcAdvantage(position *chess.Position) (string, string, string, string) { m := pieceMap(position.Board()) var whiteAdvantage, blackAdvantage string var whiteScore, blackScore int @@ -656,11 +661,12 @@ func CalcAdvantage(position *chess.Position) (string, string) { blackScore += -diff * 1 whiteAdvantage += strings.Repeat("♟", utils.MaxInt(diff, 0)) blackAdvantage += strings.Repeat("♙", utils.MaxInt(-diff, 0)) + var whiteScoreLbl, blackScoreLbl string if whiteScore > 0 { - whiteAdvantage += fmt.Sprintf("+%d", whiteScore) + whiteScoreLbl = fmt.Sprintf("+%d", whiteScore) } if blackScore > 0 { - blackAdvantage += fmt.Sprintf("+%d", blackScore) + blackScoreLbl = fmt.Sprintf("+%d", blackScore) } if whiteAdvantage == "" { whiteAdvantage = "-" @@ -668,5 +674,5 @@ func CalcAdvantage(position *chess.Position) (string, string) { if blackAdvantage == "" { blackAdvantage = "-" } - return whiteAdvantage, blackAdvantage + return whiteAdvantage, whiteScoreLbl, blackAdvantage, blackScoreLbl }