def select_clothing_interpreter(clothing_list, key_event, previous_selection): """ Based on player input, selects the desired article of clothing from clothing_list, and returns the chosen article. :param clothing_list: The list of clothing to choose from. :param key_event: The keyboard event representing the next number in the player's choice. :param previous_selection: :return The article of clothing selected by the user, or None if the user hasn't finished selectin yet. """ global user_input next_digit = universal.key_name(key_event) if len(clothing_list) < 10: try: num = int(next_digit) - 1 except ValueError: if key_event.key == K_BACKSPACE: previous_selection() else: try: chosen_clothing = clothing_list[num] except IndexError: return else: return chosen_clothing else: try: int(next_digit) except ValueError: if key_event.key == K_BACKSPACE: if user_input: user_input = user_input[:-1] set_commands(universal.add_number_to_select_number_command( user_input)) else: previous_selection() elif key_event.key == K_RETURN: clothing_index = int(user_input) - 1 try: selected_clothing = clothing_list[clothing_index] except IndexError: universal.say(' '.join(['"' + user_input + '"', 'is too large. Please provide a number between 1 and', str(len(clothing_list))])) acknowledge(select_shirt, ()) else: global user_input user_input = '' return selected_clothing else: user_input += next_digit set_commands(universal.add_number_to_select_number_command( user_input))
def select_shirt(): """ Asks the player to select a shirt for the player character. """ global shirtList, user_input user_input = '' universal.say_title('Select Shirt') shirtList = [item for item in STARTING_INVENTORY if items.is_upper_clothing(item)] universal.say( '\n'.join( universal.numbered_list([shirt.name for shirt in shirtList]) ), justification=0 ) if user_input: set_commands(universal.add_number_to_select_number_command(user_input)) set_command_interpreter(select_shirt_interpreter)