Skip to content

Commit

Permalink
Replay mode improvements
Browse files Browse the repository at this point in the history
* Disabling prev and next
* Fixed podium bug
* Generate binaries no console
  • Loading branch information
MegatronJeremy committed Sep 13, 2024
1 parent 9f7a341 commit f5ba055
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
4 changes: 2 additions & 2 deletions generate_binaries.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ $userChoice = Read-Host "Enter your choice (1 or 2)"
switch ($userChoice)
{
1 {
pyinstaller --noconfirm --onedir --console --icon "icon.ico" --name "team_segfault" --optimize "2" --add-data "assets;assets/" --add-data "mab/data/server_data;mab/data/server_data/" --add-data "mab/data/training_data;mab/data/training_data/" --add-data "replays;replays/" main.py
pyinstaller --noconfirm --onedir --noconsole --icon "icon.ico" --name "team_segfault" --optimize "2" --add-data "assets;assets/" --add-data "mab/data/server_data;mab/data/server_data/" --add-data "mab/data/training_data;mab/data/training_data/" --add-data "replays;replays/" main.py
}
2 {
pyinstaller --noconfirm --onefile --console --icon "icon.ico" --name "team_segfault" --optimize "2" --add-data "assets;assets/" --add-data "mab/data/server_data;mab/data/server_data/" --add-data "mab/data/training_data;mab/data/training_data/" --add-data "replays;replays/" main.py
pyinstaller --noconfirm --onefile --noconsole --icon "icon.ico" --name "team_segfault" --optimize "2" --add-data "assets;assets/" --add-data "mab/data/server_data;mab/data/server_data/" --add-data "mab/data/training_data;mab/data/training_data/" --add-data "replays;replays/" main.py
}
default {
Write-Host "Invalid choice. Please enter 1 or 2."
Expand Down
9 changes: 4 additions & 5 deletions src/game_client/types/archived_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from src.game_client.game_client import GameClient
from src.parameters import ARCHIVED_GAME_SPEED, MAX_ARCHIVED_GAME_DELAY, MIN_ARCHIVED_GAME_DELAY, \
ARCHIVED_GAME_TURN, \
ARCHIVED_GAME_PAUSED, REPLAYS_LOCATION, DISABLE_ANIMATIONS_GLOBAL
ARCHIVED_GAME_PAUSED, REPLAYS_LOCATION, DISABLE_ANIMATIONS_GLOBAL, ARCHIVED_GAME_MAX_TURN


class ArchivedGameClient(GameClient, ABC):
Expand All @@ -18,8 +18,7 @@ def __init__(self, file_path: str):
with open(os.path.join(REPLAYS_LOCATION, f'{file_path}.replay'), 'r') as f:
self.__archive_file = json.load(f)

self.__max_turn: int = (self.__archive_file["0"]["game_state"]["num_turns"] + 1) \
* self.__archive_file["0"]["game_state"]["num_rounds"] - 1
ARCHIVED_GAME_MAX_TURN[0] = len(self.__archive_file) - 1

def __enter__(self):
return self
Expand Down Expand Up @@ -101,8 +100,8 @@ def force_turn(self) -> bool:
def __current_turn(self) -> list[int]:
if ARCHIVED_GAME_TURN[0] < 0:
ARCHIVED_GAME_TURN[0] = 0
if ARCHIVED_GAME_TURN[0] > self.__max_turn:
ARCHIVED_GAME_TURN[0] = self.__max_turn
if ARCHIVED_GAME_TURN[0] > ARCHIVED_GAME_MAX_TURN[0]:
ARCHIVED_GAME_TURN[0] = ARCHIVED_GAME_MAX_TURN[0]

return ARCHIVED_GAME_TURN

Expand Down
16 changes: 11 additions & 5 deletions src/gui/control_utils/archived_game_ui_controller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from src.gui.control_utils.button import Button
from src.gui.control_utils.slider import Slider
from src.parameters import SCREEN_HEIGHT, WHITE, GRAY, BLUE, ARCHIVED_GAME_PAUSED, SCREEN_WIDTH, \
ANIMATION_SPEED_MULTIPLIER, ARCHIVED_GAME_SPEED, ARCHIVED_GAME_TURN
ANIMATION_SPEED_MULTIPLIER, ARCHIVED_GAME_SPEED, ARCHIVED_GAME_TURN, ARCHIVED_GAME_MAX_TURN


class ArchivedGameUIController:
Expand Down Expand Up @@ -71,6 +71,12 @@ def update_states(self):
self.__button_prev.disabled = True
self.__button_next.disabled = True

if ARCHIVED_GAME_TURN[0] == 0:
self.__button_prev.disabled = True

if ARCHIVED_GAME_MAX_TURN[0] != 0 and ARCHIVED_GAME_TURN[0] == ARCHIVED_GAME_MAX_TURN[0] - 1:
self.__button_next.disabled = True

def __unpause_game(self):
"""Unpause the game and update button states."""
ARCHIVED_GAME_PAUSED[0] = False
Expand All @@ -81,15 +87,15 @@ def __pause_game(self):
ARCHIVED_GAME_PAUSED[0] = True
self.update_states()

@staticmethod
def __advance_turn():
def __advance_turn(self):
"""Advance to the next turn."""
ARCHIVED_GAME_TURN[0] += 1
self.update_states()

@staticmethod
def __rewind_turn():
def __rewind_turn(self):
"""Rewind to the previous turn."""
ARCHIVED_GAME_TURN[0] -= 1
self.update_states()

def handle_mouse_click(self, mouse_pos):
self.__button_play.check_click(mouse_pos)
Expand Down
5 changes: 4 additions & 1 deletion src/gui/menus_and_screens/end_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ def draw_podium(self, screen: Surface, players: list[tuple[str, str | tuple[int,
player_points)
"""
# index representing current podium position that tank should be drawn on
current_index = 1
current_index = 0
longest_name_len = 0

# Make sure the points are sorted
players.sort(key=lambda x: x[2], reverse=True)

# draw tanks / players
for i, player in enumerate(players):
longest_name_len = max(longest_name_len, self.__scoreboard_font.size(player[0])[0])
Expand Down
9 changes: 6 additions & 3 deletions src/gui/menus_and_screens/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from src.gui.menus_and_screens.menu_utils import play_menu_music
from src.parameters import MENU_POSITION, SOUND_VOLUME, PLAYER_NAMES, DEFAULT_GAME_NAME, WHITE, MENU_BACKGROUND_COLOR, \
MENU_SELECTED_TEXT_COLOR, GAME_SPEED, MENU_MIN_WIDTH, MENU_FONT, ADVANCED_GRAPHICS, SELECTOR_WIDGET_COLOR, \
MAX_PLAYERS, MENU_THEME, MUSIC_VOLUME, BATTLE_THEME, MAP_TYPE, REPLAYS_LOCATION, SOUND_MUTED, MUSIC_MUTED
MAX_PLAYERS, MENU_THEME, MUSIC_VOLUME, BATTLE_THEME, MAP_TYPE, REPLAYS_LOCATION, SOUND_MUTED, MUSIC_MUTED, \
DEFAULT_NUM_TURNS_ONE_PLAYER
from src.settings_utils import save_settings, get_music_volume, strip_number_from_name_end


Expand Down Expand Up @@ -133,7 +134,8 @@ def __create_local_game_menu(self) -> None:
self.__local_game_menu.add.button('Battle!', self.__battle)
self.__local_game_menu.add.text_input('Game name: ', default=DEFAULT_GAME_NAME[0], textinput_id='game_name',
maxwidth=10)
self.__local_game_menu.add.text_input('Number of turns: ', input_type=pygame_menu.locals.INPUT_INT, maxchar=2,
self.__local_game_menu.add.text_input('Number of turns: ', default=DEFAULT_NUM_TURNS_ONE_PLAYER,
input_type=pygame_menu.locals.INPUT_INT, maxchar=2,
textinput_id='num_turns')
self.__local_game_menu.add.range_slider('Number of players', default=MAX_PLAYERS, rangeslider_id='num_players',
range_values=[i for i in range(1, MAX_PLAYERS + 1)], increment=1)
Expand All @@ -155,7 +157,8 @@ def __create_multiplayer_menu(self) -> None:
password=True)
self.__multiplayer_menu.add.text_input('Game name: ', default=DEFAULT_GAME_NAME[0], textinput_id='game_name',
maxwidth=10)
self.__multiplayer_menu.add.text_input('Number of turns: ', input_type=pygame_menu.locals.INPUT_INT, maxchar=2,
self.__multiplayer_menu.add.text_input('Number of turns: ', default=DEFAULT_NUM_TURNS_ONE_PLAYER,
input_type=pygame_menu.locals.INPUT_INT, maxchar=2,
textinput_id='num_turns')
self.__multiplayer_menu.add.range_slider('Number of players', default=MAX_PLAYERS, rangeslider_id='num_players',
range_values=[i for i in range(1, MAX_PLAYERS + 1)], increment=1)
Expand Down
1 change: 1 addition & 0 deletions src/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
MIN_ARCHIVED_GAME_DELAY = 0.3
MAX_ARCHIVED_GAME_DELAY = 3.0
ARCHIVED_GAME_TURN = [0]
ARCHIVED_GAME_MAX_TURN = [0]
ARCHIVED_GAME_PAUSED = [True]

# mab constants
Expand Down

0 comments on commit f5ba055

Please sign in to comment.