changed json formatting

This commit is contained in:
2023-04-29 19:59:16 -07:00
parent 23716a7bc7
commit ce51e5c35c
3 changed files with 15 additions and 20 deletions

View File

@@ -60,7 +60,7 @@ class ClientVCKO(wx.App):
class GameFrame(wx.Frame): class GameFrame(wx.Frame):
def __init__(self, app): def __init__(self, app):
super().__init__(parent=None, title='VCK Online', size=Constants.default_window_size) super().__init__(parent=None, title='VCK Online', size=Constants.medium_window_size)
self.app = app self.app = app
self.panel = wx.Panel(self) self.panel = wx.Panel(self)
@@ -82,22 +82,18 @@ class GameFrame(wx.Frame):
# Set the sizer for the panel # Set the sizer for the panel
self.panel.SetSizer(vbox) self.panel.SetSizer(vbox)
self.SetMinSize(Constants.minimum_window_size) self.SetMinSize(Constants.small_window_size)
self.last_pretty_game_state = "" self.last_game_state = ""
self.timer_interval = 500
self.timer = wx.Timer(self) self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.get_game_status, self.timer) self.Bind(wx.EVT_TIMER, self.get_game_status, self.timer)
self.timer.Start(self.timer_interval) self.timer.Start(500)
def get_game_status(self, event=None): def get_game_status(self, event=None):
if connection_check() and self.app.in_game: if connection_check() and self.app.in_game:
self.app.parse_response(send(f"game get_status {self.app.game_id}")) self.app.parse_response(send(f"game get_status {self.app.game_id}"))
new_pretty_game_state = pprint.pformat(self.app.last_game_state) new_pretty_game_state = pprint.pformat(self.app.last_game_state)
if self.last_pretty_game_state == new_pretty_game_state: if self.last_game_state == self.app.game_state:
# If the current game state is the same as the last one, don't update the list control # If the current game state is the same as the last one, don't update the list control
if self.timer_interval < 9500:
self.timer_interval += 500
self.timer.Start(self.timer_interval)
return return
self.game_state_list.ClearAll() self.game_state_list.ClearAll()
self.game_state_list.InsertColumn(0, "Game State") self.game_state_list.InsertColumn(0, "Game State")
@@ -105,15 +101,14 @@ class GameFrame(wx.Frame):
self.game_state_list.InsertItem(idx, state.strip()) self.game_state_list.InsertItem(idx, state.strip())
self.game_state_list.SetColumnWidth(0, wx.LIST_AUTOSIZE) self.game_state_list.SetColumnWidth(0, wx.LIST_AUTOSIZE)
# Save the new game state # Save the new game state
self.last_pretty_game_state = new_pretty_game_state self.last_game_state = self.app.game_state
self.timer_interval = 500
else: else:
self.timer.Stop() self.timer.Stop()
class LobbyFrame(wx.Frame): class LobbyFrame(wx.Frame):
def __init__(self, app): def __init__(self, app):
super().__init__(parent=None, title='VCK Online Lobby', size=(250, 300)) super().__init__(parent=None, title='VCK Online Lobby', size=Constants.medium_window_size)
self.app = app self.app = app
self.panel = wx.Panel(self) self.panel = wx.Panel(self)
self.vertical_sizer = wx.BoxSizer(wx.VERTICAL) self.vertical_sizer = wx.BoxSizer(wx.VERTICAL)
@@ -132,7 +127,7 @@ class LobbyFrame(wx.Frame):
self.vertical_sizer.Add(self.list_ctrl, 1, wx.ALL | wx.EXPAND, 5) self.vertical_sizer.Add(self.list_ctrl, 1, wx.ALL | wx.EXPAND, 5)
self.vertical_sizer.Add(ready_button, 0, wx.ALL | wx.CENTER, 5) self.vertical_sizer.Add(ready_button, 0, wx.ALL | wx.CENTER, 5)
self.panel.SetSizer(self.vertical_sizer) self.panel.SetSizer(self.vertical_sizer)
self.SetMinSize(Constants.minimum_window_size) self.SetMinSize(Constants.small_window_size)
# Bind the size event to adjust the column widths # Bind the size event to adjust the column widths
self.Bind(wx.EVT_SIZE, self.on_size) self.Bind(wx.EVT_SIZE, self.on_size)
@@ -200,7 +195,7 @@ class LobbyFrame(wx.Frame):
class StartFrame(wx.Frame): class StartFrame(wx.Frame):
def __init__(self, parent): def __init__(self, parent):
super().__init__(parent=None, title='Enter Name', size=Constants.minimum_window_size) super().__init__(parent=None, title='Enter Name', size=Constants.small_window_size)
self.panel = wx.Panel(self) self.panel = wx.Panel(self)
self.app = parent self.app = parent
# Create text field with suggestion text # Create text field with suggestion text
@@ -243,7 +238,7 @@ class StartFrame(wx.Frame):
class DebugFrame(wx.Frame): class DebugFrame(wx.Frame):
def __init__(self, app): def __init__(self, app):
super().__init__(parent=None, title='VCKO Debug Console', size=Constants.default_window_size) super().__init__(parent=None, title='VCKO Debug Console', size=Constants.small_window_size)
self.app = app self.app = app
self.panel = wx.Panel(self) self.panel = wx.Panel(self)
self.vertical_sizer = wx.BoxSizer(wx.VERTICAL) self.vertical_sizer = wx.BoxSizer(wx.VERTICAL)
@@ -264,7 +259,7 @@ class DebugFrame(wx.Frame):
self.vertical_sizer.AddStretchSpacer() self.vertical_sizer.AddStretchSpacer()
self.vertical_sizer.Add(self.status_sizer, 0, wx.ALIGN_LEFT | wx.BOTTOM, 5) self.vertical_sizer.Add(self.status_sizer, 0, wx.ALIGN_LEFT | wx.BOTTOM, 5)
self.panel.SetSizer(self.vertical_sizer) self.panel.SetSizer(self.vertical_sizer)
self.SetMinSize(Constants.minimum_window_size) self.SetMinSize(Constants.small_window_size)
self.Show() self.Show()
# Create a timer to call the connection_check method every 2 seconds # Create a timer to call the connection_check method every 2 seconds
self.timer = wx.Timer(self) self.timer = wx.Timer(self)

View File

@@ -1,9 +1,9 @@
class Constants: class Constants:
green = (106, 171, 115) green = (106, 171, 115)
red = (219, 92, 92) red = (219, 92, 92)
host = "127.0.1.1" host = "lukesau.com"
port = 8328 port = 8328
header_size = 1024 header_size = 1024
text_format = "utf-8" text_format = "utf-8"
minimum_window_size = (300, 150) small_window_size = (300, 150)
default_window_size = (300, 150) medium_window_size = (300, 500)

View File

@@ -152,7 +152,7 @@ class ServerVCKO:
if not game: if not game:
response = "game state error: game not found" response = "game state error: game not found"
else: else:
game_json = json.dumps(game, cls=GameObjectEncoder) game_json = json.dumps(game, cls=GameObjectEncoder, indent=2)
response = f"game state {game_json}" response = f"game state {game_json}"
conn.send(response.encode(Constants.text_format)) conn.send(response.encode(Constants.text_format))