def setup_deck(args): # Try to load an extant deck first. if args.deck and args.packs: print("Amending new packs to extant deck...") deck = disk.yaml_load(args.deck) deck = taskgen.expand_deck(deck, args.packs) if deck is None: print("Fatal error.") raise SystemExit elif args.deck and not args.packs: print("Loading deck...") deck = disk.yaml_load(args.deck) if deck is None: raise SystemExit elif not deck.filenames: print("Loaded deck is empty.") raise SystemExit else: # resets the working deck, but also catches any new changes deck = taskgen.create_new_deck(deck.filenames) if deck is None: print("Fatal error.") raise SystemExit elif not args.deck and args.packs: print("Creating new deck from given packs...") deck = taskgen.create_new_deck(args.packs) if deck is None: print("Fatal error.") raise SystemExit else: print("No deck or packs provided.") raise SystemExit return deck
def setup_party(args): # Load an existing savegame or start a new one. if args.resume: party = disk.yaml_load(args.resume) if party is None: print("Unable to load saved game from {}.".format(args.resume)) raise SystemExit else: party = Party() # An intensity value given on the console overrides the one already there. if args.max_intensity: party.intensity = args.max_intensity return party
def main_menu(args): """Run the main interactive menu. In this menu, party can be added to or removed from the game, and both the normal gameplay loop and the special debug loop can be accessed. """ try: deck = setup_deck(args) party = setup_party(args) except SystemExit: print("Aborting startup.") return # Immediately enter debug mode if --debug is given. if args.debug: malt.serve("entering debug mode...") with malt.indent(): debug.debug_menu(deck, party, args) options = [ 'start', 'mercy', 'daily', 'debug', 'add name', 'remove name', 'save game_file', 'resume game_file', 'export deck_file', 'autosave toggle', ] while True: response = malt.fill(options) if response == 'start': if len(party.players) < 2: malt.serve("Please register at least two players to begin the game.") continue # check if the users want to set a losing punishment with malt.indent(): play.game_menu(deck, party) elif response == 'debug': malt.serve("Entering debug mode.") with malt.indent(): debug.debug_menu(deck, party, args) elif response == 'add': name = response.name if name in party.names(): malt.serve("{} is already registered!".format(name)) else: malt.serve("Registering {} as a new player.".format(name)) party.add(name) elif response == 'remove': name = response.name if name in party.names(): malt.serve("Removing {} from the game.".format(name)) party.kick(name) else: malt.serve("{} is not a registered player!".format(name)) elif response == 'save': path = response.game_file disk.yaml_dump(path, party) elif response == 'resume': path = response.game_file new_party = disk.yaml_load(path) if new_party is not None: party = new_party elif response == 'export': path = response.deck_file disk.yaml_dump(path, deck) elif response == 'autosave': toggle = response.toggle if toggle == 'on': filename = malt.freefill("filename: ") if disk.yaml_dump(filename, party): party.autosave = True party.save_location = filename malt.serve("Enabled autosave.") else: malt.serve("Cancelled autosave.") elif toggle == 'off': party.autosave = False malt.serve("Disabled autosave.") elif toggle == 'check': malt.serve("Autosave is currently {}.".format( 'on' if party.autosave else 'off')) else: malt.serve("The only options for autosave are on, off, and check.") elif response == 'back': break