marked error_screen as a protected module, added --dev launch option
This commit is contained in:
parent
30e25999c4
commit
8c49c62f66
@ -11,7 +11,6 @@ if __name__ == '__main__':
|
|||||||
enable_dev = False
|
enable_dev = False
|
||||||
resolution = 240
|
resolution = 240
|
||||||
|
|
||||||
# enable dev mode if --dev argument is passed
|
|
||||||
if len(sys.argv) > 0:
|
if len(sys.argv) > 0:
|
||||||
for arg in sys.argv:
|
for arg in sys.argv:
|
||||||
if arg == '--delete-save':
|
if arg == '--delete-save':
|
||||||
@ -19,8 +18,10 @@ if __name__ == '__main__':
|
|||||||
os.remove(save_dir + '/save.json')
|
os.remove(save_dir + '/save.json')
|
||||||
if '--res=' in arg:
|
if '--res=' in arg:
|
||||||
resolution = int(arg.split('=')[1])
|
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()
|
pygame.quit()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
@ -12,6 +12,7 @@ def shutdown_system():
|
|||||||
os.system('sudo shutdown now')
|
os.system('sudo shutdown now')
|
||||||
|
|
||||||
def update():
|
def update():
|
||||||
|
pygame.quit()
|
||||||
os.system('bash ~/update.sh')
|
os.system('bash ~/update.sh')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -6,22 +6,20 @@ import importlib
|
|||||||
valid_surfaces = [
|
valid_surfaces = [
|
||||||
'_dev_menu',
|
'_dev_menu',
|
||||||
'_black_screen',
|
'_black_screen',
|
||||||
|
'_error_screen',
|
||||||
'title',
|
'title',
|
||||||
'egg_select',
|
'egg_select',
|
||||||
'selection_info',
|
'selection_info',
|
||||||
'error_screen'
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Add all the surface modules to a dictionary for easy switching
|
# Add all the surface modules to a dictionary for easy switching
|
||||||
surface_modules = {}
|
surface_modules = {}
|
||||||
for module in valid_surfaces:
|
for module in valid_surfaces:
|
||||||
print(module[0])
|
|
||||||
if module[0] == '_':
|
if module[0] == '_':
|
||||||
surface_modules[module] = importlib.import_module('pocket_friends._development.surfaces.{0}'.format(module))
|
surface_modules[module] = importlib.import_module('pocket_friends._development.surfaces.{0}'.format(module))
|
||||||
else:
|
else:
|
||||||
surface_modules[module] = importlib.import_module('pocket_friends.surfaces.{0}'.format(module))
|
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.
|
# FPS for the game to run at.
|
||||||
game_fps = 16
|
game_fps = 16
|
||||||
# The internal resolution of the game
|
# The internal resolution of the game
|
||||||
@ -35,12 +33,13 @@ resources_dir = script_dir + '/resources'
|
|||||||
os.environ['SDL_FBDEV'] = '/dev/fb1'
|
os.environ['SDL_FBDEV'] = '/dev/fb1'
|
||||||
|
|
||||||
|
|
||||||
def start_game(resolution=240):
|
def start_game(resolution, dev):
|
||||||
"""
|
"""
|
||||||
Starts the game.
|
Starts the game.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
resolution (int, optional): Resolution to display the game at. Defaults to 240.
|
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()
|
pygame.init()
|
||||||
@ -48,6 +47,11 @@ def start_game(resolution=240):
|
|||||||
# Hide the cursor for the Pi display.
|
# Hide the cursor for the Pi display.
|
||||||
pygame.mouse.set_visible(False)
|
pygame.mouse.set_visible(False)
|
||||||
|
|
||||||
|
if dev:
|
||||||
|
starting_surface = '_dev_menu'
|
||||||
|
else:
|
||||||
|
starting_surface = 'title'
|
||||||
|
|
||||||
window = pygame.display.set_mode((resolution, resolution))
|
window = pygame.display.set_mode((resolution, resolution))
|
||||||
surface = surface_modules.get(starting_surface).Surface((game_res, game_res), resources_dir, game_fps)
|
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))
|
frame = pygame.transform.scale(surface, (resolution, resolution))
|
||||||
window.blit(frame, frame.get_rect())
|
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:
|
if not surface.running:
|
||||||
|
# Force the dev menu to appear if the flag has been passed
|
||||||
if surface.dev_override:
|
if surface.dev_override:
|
||||||
next_surface = '_dev_menu'
|
next_surface = '_dev_menu'
|
||||||
else:
|
else:
|
||||||
next_surface = surface.next_surface
|
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:
|
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,
|
surface = surface_modules.get(next_surface).Surface((game_res, game_res), resources_dir,
|
||||||
game_fps, **additional_args)
|
game_fps, **additional_args)
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
Loading…
Reference in New Issue
Block a user