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_char_quickspells_interpreter(keyEvent): try: num = int(universal.key_name(keyEvent)) - 1 except ValueError: if keyEvent.key == K_BACKSPACE: previousMode() else: try: modify_quick_spells(universal.state.party[num]) except IndexError: return
def store_items_interpreter(keyEvent): global chosenItemIndex, bedroom try: chosenItemIndex = int(universal.key_name(keyEvent)) - 1 except ValueError: if keyEvent.key == K_i: bedroom.store_inventory() elif keyEvent.key == K_BACKSPACE: bedroom_actions() else: display_item()
def request_hair_style_interpreter(key_event): try: num = int(universal.key_name(key_event)) - 1 except ValueError: if key_event.key == K_BACKSPACE: request_hair_length() return else: try: universal.state.player.hairStyle = get_hair_style()[num] except IndexError: return else: select_shirt()
def request_hair_length_interpreter(key_event): try: num = int(universal.key_name(key_event)) - 1 except ValueError: if key_event.key == K_BACKSPACE: request_musculature() return else: try: universal.state.player.hairLength = person.HAIR_LENGTH[num] except IndexError: return else: request_hair_style()
def request_musculature_interpreter(key_event): try: num = int(universal.key_name(key_event)) - 1 except ValueError: if key_event.key == K_BACKSPACE: request_height() return else: try: universal.state.player.musculature = person.MUSCULATURE[num] except IndexError: return else: request_hair_length()
def request_height_interpreter(key_event): try: num = int(universal.key_name(key_event)) - 1 except ValueError: if key_event.key == K_BACKSPACE: request_body_type() return else: try: universal.state.player.height = person.HEIGHTS[num] except IndexError: return else: request_musculature()
def request_body_type_interpreter(key_event): try: num = int(universal.key_name(key_event)) - 1 except ValueError: if key_event.key == K_BACKSPACE: request_nickname() return else: try: universal.state.player.bodyType = person.BODY_TYPES[num] except IndexError: return else: request_height()
def select_weapon_interpreter(key_event): global chosenWeapon try: num = int(universal.key_name(key_event)) - 1 except ValueError: if key_event.key == K_BACKSPACE: select_underwear() return else: try: chosenWeapon = weaponList[num] except IndexError: return else: universal.say(chosenWeapon.display()) set_commands(['(Enter) Equip Weapon', '<==Back']) set_command_interpreter(confirm_weapon_interpreter)
def style_hair_interpreter(keyEvent): try: num = int(universal.key_name(keyEvent)) - 1 except ValueError: if keyEvent.key == K_BACKSPACE: bedroom = universal.state.bedroom rest_mode(bedroom) else: global chosenPerson try: chosenPerson.hairStyle = chosenPerson.hair_styles()[num] except IndexError: return else: universal.say(format_line([chosenPerson.name, format_line(['''frees''', person.hisher(chosenPerson), '''hair.''']) if chosenPerson.hair_styles()[num] == 'down' else format_line(['''pulls''', person.hisher(chosenPerson), '''hair into''', '''some cute pigtails''' if chosenPerson.hair_styles()[num] == 'pigtails' else format_line(['''a''', chosenPerson.hair_styles()[num]]) + "."])]), justification=0)
def style_character_interpreter(keyEvent): bedroom = universal.state.bedroom try: num = int(universal.key_name(keyEvent)) - 1 except ValueError: if keyEvent.key == K_BACKSPACE: rest_mode(bedroom) else: global chosenPerson try: chosenPerson = universal.state.party[num] except IndexError: return else: say_title(format_line(['How should', chosenPerson.name + "'s", '''hair be styled?'''])) if chosenPerson.hairLength == 'short': hairStyles = person.SHORT_HAIR_STYLE universal.say('\n'.join(universal.numbered_list(chosenPerson.hair_styles())), justification=0) set_command_interpreter(style_hair_interpreter) set_commands(universal.SELECT_NUMBER_BACK_COMMAND)