Skip to content

Commit

Permalink
HSL GUI keybinds and board rotation fix (#919)
Browse files Browse the repository at this point in the history
* HSL GUI more keybinds for move navigation

* HSL GUI convert sgfmill to GameState coord system to fix board being rotated 90d
  • Loading branch information
Emanuel-de-Jong authored Apr 7, 2024
1 parent 6f5d1fb commit 50082a1
Showing 1 changed file with 48 additions and 26 deletions.
74 changes: 48 additions & 26 deletions python/humanslnet_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ def load_sgf_game_state(file_path):
for y in range(size):
color = board.get(x, y)
if color is not None:
moves.append((x, y, (Board.BLACK if color == "b" else Board.WHITE)))
moves.append((y, 18 - x, (Board.BLACK if color == "b" else Board.WHITE)))

for color, move in plays:
if move is not None:
x, y = move
moves.append((x, y, (Board.BLACK if color == "b" else Board.WHITE)))
moves.append((y, 18 - x, (Board.BLACK if color == "b" else Board.WHITE)))

game_state = GameState(size, GameState.RULES_JAPANESE)
for (x,y,color) in moves:
Expand Down Expand Up @@ -523,37 +523,59 @@ def handle_error(self, error_message):

def on_key_down(self, event):
key_code = event.GetKeyCode()
if key_code == wx.WXK_LEFT or key_code == wx.WXK_BACK:
if (key_code == wx.WXK_LEFT or key_code == wx.WXK_BACK) and event.ShiftDown():
self.undo(10)
elif key_code == wx.WXK_LEFT or key_code == wx.WXK_BACK:
self.undo()
if key_code == wx.WXK_RIGHT:
elif key_code == wx.WXK_RIGHT and event.ShiftDown():
self.redo(10)
elif key_code == wx.WXK_RIGHT:
self.redo()
elif key_code == wx.WXK_DOWN:
self.undo(len(self.game_state.moves))
elif key_code == wx.WXK_UP:
self.redo(len(self.game_state.redo_stack))
event.Skip()

def undo(self):
if not self.game_state.can_undo():
return
self.game_state.undo()
def undo(self, undo_count = 1):
is_refresh_needed = False
for i in range(undo_count):
if not self.game_state.can_undo():
break

is_refresh_needed = True

command = {"command": "undo"}
self.send_command(command)
response = self.receive_response()
if response != {"outputs": ""}:
self.handle_error(f"Unexpected response from server: {response}")
self.board.Refresh()
self.board.refresh_model()
self.game_state.undo()

def redo(self):
if not self.game_state.can_redo():
return
self.game_state.redo()
command = {"command": "undo"}
self.send_command(command)
response = self.receive_response()
if response != {"outputs": ""}:
self.handle_error(f"Unexpected response from server: {response}")

command = {"command": "redo"}
self.send_command(command)
response = self.receive_response()
if response != {"outputs": ""}:
self.handle_error(f"Unexpected response from server: {response}")
self.board.Refresh()
self.board.refresh_model()
if is_refresh_needed:
self.board.Refresh()
self.board.refresh_model()

def redo(self, redo_count = 1):
is_refresh_needed = False
for i in range(redo_count):
if not self.game_state.can_redo():
break

is_refresh_needed = True

self.game_state.redo()

command = {"command": "redo"}
self.send_command(command)
response = self.receive_response()
if response != {"outputs": ""}:
self.handle_error(f"Unexpected response from server: {response}")

if is_refresh_needed:
self.board.Refresh()
self.board.refresh_model()

def on_drop_files(self, sgf_files):
if len(sgf_files) == 0:
Expand Down

0 comments on commit 50082a1

Please sign in to comment.