Fix viewing replays

This commit is contained in:
Trevor Slocum 2024-11-18 17:55:33 -08:00
parent e7beccdd70
commit f33edf763a
2 changed files with 17 additions and 2 deletions

View file

@ -38,7 +38,7 @@ import (
)
const (
AppVersion = "v1.4.6p1"
AppVersion = "v1.4.6"
baseButtonHeight = 54
MaxDebug = 2
DefaultServerAddress = "wss://ws.bgammon.org:1338"
@ -2365,6 +2365,7 @@ func (g *Game) cancelHistoryPage() error {
g.lobby.historyPageDialog.SetVisible(false)
return nil
}
func (g *Game) handleInput(keys []ebiten.Key) error {
if len(keys) == 0 {
return nil

View file

@ -115,6 +115,9 @@ func (g *Game) _handleReplay(gs *bgammon.GameState, line []byte, lineNumber int,
if bytes.Equal(split[0], []byte("2")) {
player = 2
}
for i := range split {
split[i] = bytes.ReplaceAll(split[i], []byte(","), nil)
}
switch {
case bytes.Equal(split[1], []byte("d")):
if len(split) < 4 {
@ -421,6 +424,17 @@ func (g *Game) HandleReplay(replay []byte) {
}
}
var mv []byte
var last byte
for _, r := range move {
if r == ' ' && last != ',' {
mv = append(mv, []byte(", ")...)
} else {
mv = append(mv, r)
}
last = r
}
var x int
if player == 1 {
x = 1
@ -445,7 +459,7 @@ func (g *Game) HandleReplay(replay []byte) {
rollLabel.SetVertical(etk.AlignCenter)
rollLabel.SetAutoResize(true)
rollLabel.SetForeground(etk.Style.ButtonTextColor)
moveLabel := etk.NewText(string(move))
moveLabel := etk.NewText(string(mv))
moveLabel.SetPadding(etk.Scale(etk.Style.ButtonBorderSize + 2))
moveLabel.SetVertical(etk.AlignCenter)
moveLabel.SetAutoResize(true)