Fix replaying tabula games

This commit is contained in:
Trevor Slocum 2024-01-09 18:26:12 -08:00
parent 61b84621f1
commit 3bbebb1590
6 changed files with 56 additions and 94 deletions

View file

@ -1,3 +1,6 @@
1.2.3:
- Fix replaying tabula games
1.2.2:
- Support playing tabula games

View file

@ -806,14 +806,14 @@ func (b *board) toggleKeyboard() error {
b.lastKeyboardToggle = t
if game.keyboard.Visible() {
game.keyboard.Hide()
game.keyboard.SetVisible(false)
b.floatChatGrid.SetVisible(false)
b.uiGrid.SetRect(b.uiGrid.Rect())
b.showKeyboardButton.Label.SetText(gotext.Get("Show Keyboard"))
} else {
b.floatChatGrid.SetVisible(true)
b.floatChatGrid.SetRect(b.floatChatGrid.Rect())
game.keyboard.Show()
game.keyboard.SetVisible(true)
b.showKeyboardButton.Label.SetText(gotext.Get("Hide Keyboard"))
}
return nil
@ -2676,10 +2676,6 @@ func (bw *BoardWidget) HandleMouse(cursor image.Point, pressed bool, clicked boo
return false, nil
}
if game.keyboard.Visible() && cursor.In(game.keyboard.Rect()) {
return false, nil
}
cx, cy := cursor.X, cursor.Y
if b.dragging == nil {

View file

@ -132,6 +132,7 @@ var (
tutorialFrame *etk.Frame
connectFrame *etk.Frame
createGameFrame *etk.Frame
joinGameFrame *etk.Frame
historyFrame *etk.Frame
@ -461,7 +462,7 @@ func setViewBoard(view bool) {
g := game
if g.keyboard.Visible() || g.Board.floatChatGrid.Visible() {
g.keyboard.Hide()
g.keyboard.SetVisible(false)
g.Board.floatChatGrid.SetVisible(false)
g.connectKeyboardButton.Label.SetText(gotext.Get("Show Keyboard"))
g.lobby.showKeyboardButton.Label.SetText(gotext.Get("Show Keyboard"))
@ -484,7 +485,7 @@ func setViewBoard(view bool) {
game.Board.uiGrid.SetRect(game.Board.uiGrid.Rect())
} else {
if !game.loggedIn {
game.setRoot(connectGrid)
game.setRoot(connectFrame)
} else if game.lobby.showCreateGame {
game.setRoot(createGameFrame)
} else if game.lobby.showJoinGame {
@ -583,7 +584,7 @@ type Game struct {
debugImg *ebiten.Image
keyboard *kibodo.Keyboard
keyboard *etk.Keyboard
keyboardInput []*kibodo.Input
cpuProfile *os.File
@ -601,7 +602,6 @@ type Game struct {
resetInfo *etk.Text
resetInProgress bool
tutorial *tutorialWidget
tutorialFrame *etk.Frame
pressedKeys []ebiten.Key
@ -615,7 +615,6 @@ type Game struct {
lastRefresh time.Time
skipUpdate bool
forceLayout bool
scaleFactor float64
@ -664,7 +663,7 @@ func NewGame() *Game {
g := &Game{
runeBuffer: make([]rune, 24),
keyboard: kibodo.NewKeyboard(),
keyboard: etk.NewKeyboard(),
TouchInput: AutoEnableTouchInput,
@ -677,6 +676,7 @@ func NewGame() *Game {
Mutex: &sync.Mutex{},
}
g.keyboard.SetScheduleFrameFunc(scheduleFrame)
g.keyboard.SetVisible(false)
g.tutorialFrame.SetPositionChildren(true)
game = g
@ -839,13 +839,13 @@ func NewGame() *Game {
g.connectKeyboardButton = etk.NewButton(gotext.Get("Show Keyboard"), func() error {
if g.keyboard.Visible() {
g.keyboard.Hide()
g.keyboard.SetVisible(false)
g.connectKeyboardButton.Label.SetText(gotext.Get("Show Keyboard"))
g.lobby.showKeyboardButton.Label.SetText(gotext.Get("Show Keyboard"))
g.Board.showKeyboardButton.Label.SetText(gotext.Get("Show Keyboard"))
} else {
g.EnableTouchInput()
g.keyboard.Show()
g.keyboard.SetVisible(true)
g.connectKeyboardButton.Label.SetText(gotext.Get("Hide Keyboard"))
}
return nil
@ -917,6 +917,9 @@ func NewGame() *Game {
grid.AddChildAt(infoLabel, 1, g.connectGridY+2, 3, 1)
grid.AddChildAt(footerLabel, 1, g.connectGridY+3, 3, 1)
connectGrid = grid
connectFrame = etk.NewFrame(connectGrid, etk.NewFrame(game.keyboard))
connectFrame.SetPositionChildren(true)
}
{
@ -1011,7 +1014,7 @@ func NewGame() *Game {
createGameFrame = etk.NewFrame()
createGameFrame.SetPositionChildren(true)
createGameFrame.AddChild(createGameContainer)
createGameFrame.AddChild(etk.NewFrame(g.lobby.showKeyboardButton))
createGameFrame.AddChild(etk.NewFrame(g.keyboard, g.lobby.showKeyboardButton))
createGameFrame.AddChild(g.tutorialFrame)
}
@ -1044,7 +1047,7 @@ func NewGame() *Game {
joinGameFrame = etk.NewFrame()
joinGameFrame.SetPositionChildren(true)
joinGameFrame.AddChild(joinGameContainer)
joinGameFrame.AddChild(etk.NewFrame(g.lobby.showKeyboardButton))
joinGameFrame.AddChild(etk.NewFrame(g.keyboard, g.lobby.showKeyboardButton))
joinGameFrame.AddChild(g.tutorialFrame)
}
@ -1155,7 +1158,7 @@ func NewGame() *Game {
g.needLayoutLobby = true
g.needLayoutBoard = true
g.setRoot(connectGrid)
g.setRoot(connectFrame)
username := loadUsername()
if username != "" {
@ -1586,10 +1589,10 @@ func (g *Game) _handleReplay(gs *bgammon.GameState, line []byte, lineNumber int,
}
*gs = bgammon.GameState{
Game: bgammon.NewGame(int8(variant)),
Game: bgammon.NewGame(int8(variant)),
PlayerNumber: 1,
Spectating: true,
}
gs.PlayerNumber = 1
gs.Spectating = true
gs.Turn = 0
gs.Player1.Name, gs.Player2.Name = string(split[2]), string(split[3])
@ -1722,7 +1725,7 @@ func (g *Game) _handleReplay(gs *bgammon.GameState, line []byte, lineNumber int,
g.Client.Events <- ev
}
gs.Roll1, gs.Roll2 = int8(r1), int8(r2)
gs.Roll1, gs.Roll2, gs.Roll3 = int8(r1), int8(r2), int8(r3)
gs.Turn = player
gs.Available = gs.LegalMoves(true)
gs.Moves = nil
@ -1973,7 +1976,7 @@ func (g *Game) Connect() {
l("*** " + gotext.Get("Connecting..."))
g.keyboard.Hide()
g.keyboard.SetVisible(false)
g.connectKeyboardButton.Label.SetText(gotext.Get("Show Keyboard"))
g.lobby.showKeyboardButton.Label.SetText(gotext.Get("Show Keyboard"))
g.Board.showKeyboardButton.Label.SetText(gotext.Get("Show Keyboard"))
@ -2021,7 +2024,7 @@ func (g *Game) Connect() {
}
g.loggedIn = false
g.setRoot(connectGrid)
g.setRoot(connectFrame)
scheduleFrame()
return
}
@ -2044,7 +2047,7 @@ func (g *Game) ConnectLocal(conn net.Conn) {
l("*** " + gotext.Get("Playing offline."))
g.keyboard.Hide()
g.keyboard.SetVisible(false)
g.connectKeyboardButton.Label.SetText(gotext.Get("Show Keyboard"))
g.lobby.showKeyboardButton.Label.SetText(gotext.Get("Show Keyboard"))
g.Board.showKeyboardButton.Label.SetText(gotext.Get("Show Keyboard"))
@ -2091,7 +2094,7 @@ func (g *Game) selectReset() error {
func (g *Game) selectCancel() error {
g.showRegister = false
g.showReset = false
g.setRoot(connectGrid)
g.setRoot(connectFrame)
etk.SetFocus(g.connectUsername)
return nil
}
@ -2304,7 +2307,7 @@ func (g *Game) handleTouch(p image.Point) {
}
switch w.(type) {
case *etk.Input:
g.keyboard.Show()
g.keyboard.SetVisible(true)
var btn *etk.Button
if !g.loggedIn {
btn = g.connectKeyboardButton
@ -2385,6 +2388,19 @@ func (g *Game) Update() error {
etk.SetDebug(Debug == 2)
}
// Handle touch input.
if cx == 0 && cy == 0 {
g.touchIDs = inpututil.AppendJustPressedTouchIDs(g.touchIDs[:0])
for _, id := range g.touchIDs {
g.EnableTouchInput()
cx, cy = ebiten.TouchPosition(id)
if cx != 0 || cy != 0 {
g.handleTouch(image.Point{cx, cy})
break
}
}
}
// Handle physical keyboard.
g.pressedKeys = inpututil.AppendJustPressedKeys(g.pressedKeys[:0])
err := g.handleInput(g.pressedKeys)
@ -2392,59 +2408,17 @@ func (g *Game) Update() error {
return err
}
// Handle on-screen keyboard.
err = g.keyboard.Update()
if err != nil {
return err
}
g.keyboardInput = g.keyboard.AppendInput(g.keyboardInput[:0])
g.pressedKeys = g.pressedKeys[:0]
for _, input := range g.keyboardInput {
if input.Rune == 0 {
g.pressedKeys = append(g.pressedKeys, input.Key)
}
}
if len(g.pressedKeys) > 0 {
err = g.handleInput(g.pressedKeys)
if err != nil {
return err
}
}
var pressed bool
var pressedTouch image.Point
if cx == 0 && cy == 0 {
if !g.TouchInput {
g.touchIDs = inpututil.AppendJustPressedTouchIDs(g.touchIDs[:0])
for _, id := range g.touchIDs {
game.EnableTouchInput()
cx, cy = ebiten.TouchPosition(id)
if cx != 0 || cy != 0 {
pressed = true
pressedTouch = image.Point{cx, cy}
break
}
if len(g.touchIDs) > 0 {
g.EnableTouchInput()
}
} else {
pressed = ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft)
}
if len(ebiten.AppendTouchIDs(g.touchIDs[:0])) != 0 {
scheduleFrame()
}
var skipUpdate bool
if pressed && g.keyboard.Visible() {
p := image.Point{X: cx, Y: cy}
if p.In(g.keyboard.Rect()) {
skipUpdate = true
g.skipUpdate = true
}
}
if g.skipUpdate && !skipUpdate {
skipUpdate = true
g.skipUpdate = false
}
if !g.loggedIn {
if len(g.keyboardInput) > 0 {
w := etk.Focused()
@ -2459,14 +2433,10 @@ func (g *Game) Update() error {
}
}
if skipUpdate {
return nil
}
err = etk.Update()
if err != nil {
return err
}
g.handleTouch(pressedTouch)
return nil
}
@ -2515,14 +2485,10 @@ func (g *Game) Update() error {
}
}
if skipUpdate {
return nil
}
err = etk.Update()
if err != nil {
return err
}
g.handleTouch(pressedTouch)
return nil
}
@ -2562,7 +2528,6 @@ func (g *Game) Draw(screen *ebiten.Image) {
if err != nil {
log.Fatal(err)
}
game.keyboard.Draw(screen)
return
}
@ -2577,8 +2542,6 @@ func (g *Game) Draw(screen *ebiten.Image) {
g.Board.drawDraggedCheckers(screen)
game.keyboard.Draw(screen)
if Debug > 0 {
g.drawBuffer.Reset()
@ -2790,7 +2753,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
g.Board.updateOpponentLabel()
g.Board.updatePlayerLabel()
g.keyboard.SetRect(0, game.screenH-game.screenH/3, game.screenW, game.screenH/3)
g.keyboard.SetRect(image.Rect(0, game.screenH-game.screenH/3, game.screenW, game.screenH))
if g.LoadReplay != nil {
go g.HandleReplay(g.LoadReplay)

View file

@ -141,10 +141,10 @@ func NewLobby() *lobby {
func (l *lobby) toggleKeyboard() error {
if game.keyboard.Visible() {
game.keyboard.Hide()
game.keyboard.SetVisible(false)
l.showKeyboardButton.Label.SetText(gotext.Get("Show Keyboard"))
} else {
game.keyboard.Show()
game.keyboard.SetVisible(true)
l.showKeyboardButton.Label.SetText(gotext.Get("Hide Keyboard"))
}
return nil

6
go.mod
View file

@ -5,10 +5,10 @@ go 1.17
require (
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240108183627-118a7f78eb98
code.rocket9labs.com/tslocum/bgammon-tabula-bot v0.0.0-20240108213827-c677af332056
code.rocket9labs.com/tslocum/etk v0.0.0-20231225090418-db70da18e067
code.rocket9labs.com/tslocum/etk v0.0.0-20240110022520-8493ce83dfc4
code.rocket9labs.com/tslocum/tabula v0.0.0-20240108183445-695ea428ae21
code.rocketnine.space/tslocum/kibodo v1.0.3-0.20231214093410-c8a7dcdbc544
code.rocketnine.space/tslocum/messeji v1.0.6-0.20240105201028-fc0897906b05
code.rocketnine.space/tslocum/kibodo v1.0.3-0.20240109203209-1e5886fd3422
code.rocketnine.space/tslocum/messeji v1.0.6-0.20240109205105-4ffeffdd2441
github.com/hajimehoshi/ebiten/v2 v2.6.3
github.com/leonelquinteros/gotext v1.5.3-0.20231003122255-12a99145a351
github.com/llgcode/draw2d v0.0.0-20231212091825-f55e0c776b44

12
go.sum
View file

@ -4,14 +4,14 @@ code.rocket9labs.com/tslocum/bgammon v0.0.0-20240108183627-118a7f78eb98 h1:6lndX
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240108183627-118a7f78eb98/go.mod h1:0DTOM6NviKJsDDBANcB7hbk2fseN5qtHJZAFeKsnAPQ=
code.rocket9labs.com/tslocum/bgammon-tabula-bot v0.0.0-20240108213827-c677af332056 h1:RNSgusDjNJjw5bpYVZlnAulF945MdczMysgxy79CayM=
code.rocket9labs.com/tslocum/bgammon-tabula-bot v0.0.0-20240108213827-c677af332056/go.mod h1:O3EuShNwEt4CJd3yQ9UDqK7+rx4a5FIcFzzdIsEnLJ4=
code.rocket9labs.com/tslocum/etk v0.0.0-20231225090418-db70da18e067 h1:DmzeAyFImu/z58bv3hPLybYoFEviCt4ugEp7SM0Y+qM=
code.rocket9labs.com/tslocum/etk v0.0.0-20231225090418-db70da18e067/go.mod h1:D1BZGu6ViunGkN9iE8x2if6Z43LGbSj2lj4Paoia/gk=
code.rocket9labs.com/tslocum/etk v0.0.0-20240110022520-8493ce83dfc4 h1:nb/7h9IOPP8nM/uy9pCtNYJ+q1GSi7bvTOvkmHt9JSg=
code.rocket9labs.com/tslocum/etk v0.0.0-20240110022520-8493ce83dfc4/go.mod h1:rClnvZGGTlW7nKl5lK+TApKlS7dfWJj3ypuXhJIzQkA=
code.rocket9labs.com/tslocum/tabula v0.0.0-20240108183445-695ea428ae21 h1:1VG88tdhCSVv7wGoIKQe8A8KfBXJsdz5pDsyP4ymDwk=
code.rocket9labs.com/tslocum/tabula v0.0.0-20240108183445-695ea428ae21/go.mod h1:WEJXESKXqrMFLAArikQ79lpRibNeeE1C0VruxXYMF5M=
code.rocketnine.space/tslocum/kibodo v1.0.3-0.20231214093410-c8a7dcdbc544 h1:G+yE90iQh2Pmzd6otFl7LEGVI+a/HRCnehcU01CjXyo=
code.rocketnine.space/tslocum/kibodo v1.0.3-0.20231214093410-c8a7dcdbc544/go.mod h1:FEGJwIgz3VmyN5khErdyEVX0YBG/VIPwogvNApc9TTQ=
code.rocketnine.space/tslocum/messeji v1.0.6-0.20240105201028-fc0897906b05 h1:2nhD6fTuIJU94hIFD9hoSx+Jwr2WKxGLFv6jxgdmEIU=
code.rocketnine.space/tslocum/messeji v1.0.6-0.20240105201028-fc0897906b05/go.mod h1:cznUGfvC7BKbc5sx4I36XpLsF0ar3TPJYZlrND0IlDQ=
code.rocketnine.space/tslocum/kibodo v1.0.3-0.20240109203209-1e5886fd3422 h1:T2WK/ci6fc/Ee+Puu/0k+ziU3EI49F7uYEREhrtmqbA=
code.rocketnine.space/tslocum/kibodo v1.0.3-0.20240109203209-1e5886fd3422/go.mod h1:U9KpaLHr7nPZ8XfRUI81uAQMrxob+bI3C/IXzeXe7gw=
code.rocketnine.space/tslocum/messeji v1.0.6-0.20240109205105-4ffeffdd2441 h1:pe5QsaN6Tvil0Y+jodbMLfdMWaL5MBb2vyorBIfQwqk=
code.rocketnine.space/tslocum/messeji v1.0.6-0.20240109205105-4ffeffdd2441/go.mod h1:cznUGfvC7BKbc5sx4I36XpLsF0ar3TPJYZlrND0IlDQ=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=