marked error_screen as a protected module, added --dev launch option

This commit is contained in:
Nicholas Dyer 2023-05-15 00:27:14 -04:00
parent 30e25999c4
commit 8c49c62f66
4 changed files with 22 additions and 10 deletions

View File

@ -11,7 +11,6 @@ if __name__ == '__main__':
enable_dev = False
resolution = 240
# enable dev mode if --dev argument is passed
if len(sys.argv) > 0:
for arg in sys.argv:
if arg == '--delete-save':
@ -19,8 +18,10 @@ if __name__ == '__main__':
os.remove(save_dir + '/save.json')
if '--res=' in arg:
resolution = int(arg.split('=')[1])
if arg == '--dev':
enable_dev = True
game.start_game(resolution)
game.start_game(resolution=resolution, dev=enable_dev)
pygame.quit()
sys.exit()

View File

@ -12,6 +12,7 @@ def shutdown_system():
os.system('sudo shutdown now')
def update():
pygame.quit()
os.system('bash ~/update.sh')
sys.exit(1)

View File

@ -6,22 +6,20 @@ import importlib
valid_surfaces = [
'_dev_menu',
'_black_screen',
'_error_screen',
'title',
'egg_select',
'selection_info',
'error_screen'
]
# Add all the surface modules to a dictionary for easy switching
surface_modules = {}
for module in valid_surfaces:
print(module[0])
if module[0] == '_':
surface_modules[module] = importlib.import_module('pocket_friends._development.surfaces.{0}'.format(module))
else:
surface_modules[module] = importlib.import_module('pocket_friends.surfaces.{0}'.format(module))
starting_surface = 'title'
print(surface_modules)
# FPS for the game to run at.
game_fps = 16
# The internal resolution of the game
@ -35,12 +33,13 @@ resources_dir = script_dir + '/resources'
os.environ['SDL_FBDEV'] = '/dev/fb1'
def start_game(resolution=240):
def start_game(resolution, dev):
"""
Starts the game.
Args:
resolution (int, optional): Resolution to display the game at. Defaults to 240.
dev (bool): Boolean to enable the developer menu at start or not
"""
pygame.init()
@ -48,6 +47,11 @@ def start_game(resolution=240):
# Hide the cursor for the Pi display.
pygame.mouse.set_visible(False)
if dev:
starting_surface = '_dev_menu'
else:
starting_surface = 'title'
window = pygame.display.set_mode((resolution, resolution))
surface = surface_modules.get(starting_surface).Surface((game_res, game_res), resources_dir, game_fps)
@ -67,15 +71,21 @@ def start_game(resolution=240):
frame = pygame.transform.scale(surface, (resolution, resolution))
window.blit(frame, frame.get_rect())
# When the current surface is not running, check to make sure that the next surface will be valid
if not surface.running:
# Force the dev menu to appear if the flag has been passed
if surface.dev_override:
next_surface = '_dev_menu'
else:
next_surface = surface.next_surface
additional_args = surface.additional_args
# Send to the error screen if the given surface isn't a valid one
if next_surface not in valid_surfaces:
print(next_surface)
next_surface = 'error_screen'
next_surface = '_error_screen'
# Get the additional args to pass on from the ending surface to the next one
additional_args = surface.additional_args
# Create the new surface and pass through the additional argss
surface = surface_modules.get(next_surface).Surface((game_res, game_res), resources_dir,
game_fps, **additional_args)
pygame.display.flip()