dkforest

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

commit f53c945018b94e0d0b861f24dcfbd65828f8e3a1
parent 90bd3f95453c08b90fdcf4e2c173d984fc500755
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Fri,  8 Nov 2024 17:19:55 -0800

ugly / low-effort / win/lost/draw badges

Diffstat:
Mpkg/web/handlers/chess.go | 10++++++++++
Mpkg/web/handlers/interceptors/chess.go | 36+++++++++++++++++++++++++++++++++++-
2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/pkg/web/handlers/chess.go b/pkg/web/handlers/chess.go @@ -658,6 +658,16 @@ Loop: // If we loaded the page and game was ongoing, we will stop the infinite loading page and display pgn if game.Outcome() != chess.NoOutcome && !gameLoadedOver { + if game.Outcome() == chess.WhiteWon { + send(`<style>#piece_e1_winner { display: block !important; }</style>`) + send(`<style>#piece_e8_loser { display: block !important; }</style>`) + } else if game.Outcome() == chess.BlackWon { + send(`<style>#piece_e8_winner { display: block !important; }</style>`) + send(`<style>#piece_e1_loser { display: block !important; }</style>`) + } else if game.Outcome() == chess.Draw { + send(`<style>#piece_e8_draw { display: block !important; }</style>`) + send(`<style>#piece_e1_draw { display: block !important; }</style>`) + } send(`<style>#outcome:after { content: "` + game.Outcome().String() + `" }</style>`) send(`<style>.gameover { display: none !important; }</style>`) send(`<div style="position: absolute; width: 200px; left: calc(50% - 100px); bottom: 20px">`) diff --git a/pkg/web/handlers/interceptors/chess.go b/pkg/web/handlers/interceptors/chess.go @@ -258,7 +258,29 @@ func (g *ChessGame) renderBoardHTML1(moveIdx int, position *chess.Position, isFl {{ end }} {{ if $pidStr }} {{ $p := PieceFromSq $sq }} - <div id="{{ $pidStr }}" class="img" style=" display: none; background-image: url({{ GetPieceFileName $p }});"></div> + <div id="{{ $pidStr }}" class="img" style="display: none; background-image: url({{ GetPieceFileName $p }});"> + {{ if or (eq $pidStr "piece_e8") (eq $pidStr "piece_e1") }} + {{ if and $.WhiteWon }} + {{ if eq $pidStr "piece_e8" }} + <div id="{{ $pidStr }}_winner" style="display: block;" class="outcome winner">W</div> + {{ else }} + <div id="{{ $pidStr }}_loser" style="display: block;" class="outcome loser">L</div> + {{ end }} + {{ else if and $.BlackWon }} + {{ if eq $pidStr "piece_e8" }} + <div id="{{ $pidStr }}_winner" style="display: block;" class="outcome winner">W</div> + {{ else }} + <div id="{{ $pidStr }}_loser" style="display: block;" class="outcome loser">L</div> + {{ end }} + {{ else if and $.Draw }} + <div id="{{ $pidStr }}_draw" style="display: block;" class="outcome draw">1/2</div> + {{ else }} + <div id="{{ $pidStr }}_draw" style="display: none;" class="outcome draw">1/2</div> + <div id="{{ $pidStr }}_winner" style="display: none;" class="outcome winner">W</div> + <div id="{{ $pidStr }}_loser" style="display: none;" class="outcome loser">L</div> + {{ end }} + {{ end }} + </div> {{ end }} </td> {{ end }} @@ -311,6 +333,9 @@ func (g *ChessGame) renderBoardHTML1(moveIdx int, position *chess.Position, isFl "Cols": []int{0, 1, 2, 3, 4, 5, 6, 7}, "LastMoveColor": LastMoveColor, "CheckColor": CheckColor, + "WhiteWon": game.Outcome() == chess.WhiteWon, + "BlackWon": game.Outcome() == chess.BlackWon, + "Draw": game.Outcome() == chess.Draw, "Dead": dead, } @@ -439,6 +464,15 @@ func (g *ChessGame) drawPlayerCard(moveIdx int, key string, isBlack, isSpectator #black-advantage .score:after { content: "{{ .BlackScore }}"; } #outcome:after { content: "{{ .Outcome }}"; } .score { font-size: 11px; } +.outcome { + color: white; + border-radius: 10px; + width: 20px; + height: 20px; +} +.winner { background-color: green; } +.loser { background-color: red; } +.draw { background-color: gray; } </style> <table style="width: 100%; height: 100%;"> <tr>