from naja.constants import SCREEN
from naja.engine import Engine
from naja.sound import sound
-from naja.options import parse_args
+from naja.options import parse_args, options
from naja.resources.loader import Loader
from naja.scenes.menu import MenuScene
+from naja.utils import warp_to_game_state
def main():
screen = pygame.display.get_surface()
scene = MenuScene(None)
engine = Engine(screen, scene, None)
+
+ if options.game_state is not None:
+ warp_to_game_state(options.game_state)
+
engine.run()
options = AttrDict()
+def check_min_max(option, value, min_value, max_value):
+ '''
+ Check value lies between min and max and raise OptionValueError if it does
+ not.
+ '''
+ if not (min_value <= value <= max_value):
+ raise optparse.OptionValueError(
+ "Value of %s should be between %s and %s but got: %r"
+ % (option.dest, min, max, value))
+
+
+def load_game(option, opt_str, value, parser):
+ '''
+ Load a save game and store it in parser.values.game_state.
+ '''
+ check_min_max(option, value, 0, 7)
+ # madness takes its toll ...
+ options.save_location = parser.values.save_location
+ from naja.scenes.load_save import SaveGameSlot
+ state = SaveGameSlot(value).load()
+ if state is None:
+ raise optparse.OptionValueError(
+ "Could not load game from slot %s" % (value,))
+ parser.values.game_state = state
+
+
+def load_deck(option, opt_str, value, parser):
+ '''
+ Create a new game for a specific deck and store it in
+ parser.values.game_state.
+ '''
+ raise optparse.OptionalValueError(
+ "Deck loading not implemented.")
+
+
def parse_args(args):
'''
Parse arguments and store them in the options dictionary.
parser.add_option('--cheat-enabled', default=False,
action='store_true',
help='For those too lazy to type the KONAMI code')
- parser.add_option('--deck', default=None,
+ parser.add_option('--deck', default=None, action="callback",
+ callback=load_deck,
help='Start with a new game for a specific deck')
- parser.add_option('--load', default=None,
- help='Start with a specific save game loaded')
+ parser.add_option('--load', default=None, type=int, action="callback",
+ callback=load_game,
+ help='Start with a specific save game loaded (0-7)')
opts, _ = parser.parse_args(args)