- action_descriptions = {
- 'move': 'move',
- 'flatten': 'flatten surroundings',
- 'teleport': 'teleport',
- 'take_thing': 'pick up thing',
- 'drop_thing': 'drop thing',
- 'toggle_map_mode': 'toggle map view',
- 'toggle_tile_draw': 'toggle protection character drawing',
- 'install': '(un-)install',
- 'wear': '(un-)wear',
- 'door': 'open/close',
- 'consume': 'consume',
- 'spin': 'spin',
- 'dance': 'dance',
- }
-
- action_tasks = {
- 'flatten': 'FLATTEN_SURROUNDINGS',
- 'take_thing': 'PICK_UP',
- 'drop_thing': 'DROP',
- 'door': 'DOOR',
- 'install': 'INSTALL',
- 'wear': 'WEAR',
- 'move': 'MOVE',
- 'command': 'COMMAND',
- 'consume': 'INTOXICATE',
- 'spin': 'SPIN',
- 'dance': 'DANCE',
- }
-
- curses.start_color()
- self.set_default_colors()
- curses.init_pair(1, 7, 0)
- if not curses.can_change_color():
- self.log_msg('@ unfortunately, your terminal does not seem to '
- 'support re-definition of colors; you might miss out '
- 'on some color effects')
- reset_screen_size()
- self.explorer = YX(0, 0)
- self.input_ = ''
- store_widechar = False
- input_prompt = '> '
- while True:
- prev_disconnected = self.socket.disconnected
- self.socket.keep_connection_alive()
- if prev_disconnected and not self.socket.disconnected:
- self.update_on_connect()
- if self.flash:
- curses.flash()
- self.flash = False
- if self.do_refresh:
- draw_screen()
- self.do_refresh = False
- for msg in self.socket.get_message():
- handle_input(msg)
- try:
- key = self.screen.stdscr.getkey()
- self.do_refresh = True
- except curses.error:
- continue
- keycode = None
- if len(key) == 1:
- keycode = ord(key)
- # workaround for <https://stackoverflow.com/a/56390915>
- if store_widechar:
- store_widechar = False
- key = bytes([195, keycode]).decode()
- if keycode == 195:
- store_widechar = True
- continue
- self.show_help = False
- self.draw_face = False
- if key == 'KEY_RESIZE':
- reset_screen_size()
- elif self.mode.has_input_prompt and key == 'KEY_BACKSPACE':
- self.input_ = self.input_[:-1]
- elif (((not self.mode.is_intro) and keycode == 27) # Escape
- or (self.mode.has_input_prompt and key == '\n'
- and self.input_ == ''\
- and self.mode.name in {'chat', 'command_thing',
- 'take_thing', 'drop_thing',
- 'admin_enter'})):
- if self.mode.name not in {'chat', 'play', 'study', 'edit'}:
- self.log_msg('@ aborted')
- self.switch_mode('play')
- elif self.mode.has_input_prompt and key == '\n' and self.input_ == '/help':
- self.show_help = True
- self.input_ = ""
- self.restore_input_values()
- elif self.mode.has_input_prompt and key != '\n': # Return key
- self.input_ += key
- max_length = self.right_window_width * self.screen.size.y - len(input_prompt) - 1
- if len(self.input_) > max_length:
- self.input_ = self.input_[:max_length]
- elif key == self.keys['help'] and not self.mode.is_single_char_entry:
- self.show_help = True
- elif self.mode.name == 'login' and key == '\n':
- self.login_name = self.input_
- self.send('LOGIN ' + quote(self.input_))
- self.input_ = ""
- elif self.mode.name == 'enter_face' and key == '\n':
- enter_ascii_art('PLAYER_FACE', 3, 6)
- elif self.mode.name == 'enter_design' and key == '\n':
- if self.game.player.carrying.type_ == 'Hat':
- enter_ascii_art('THING_DESIGN',
- self.game.player.carrying.design[0].y,
- self.game.player.carrying.design[0].x, True)
- else:
- enter_ascii_art('THING_DESIGN',
- self.game.player.carrying.design[0].y,
- self.game.player.carrying.design[0].x,
- True, True)
- elif self.mode.name == 'take_thing' and key == '\n':
- pick_selectable('PICK_UP')
- elif self.mode.name == 'drop_thing' and key == '\n':
- pick_selectable('DROP')
- elif self.mode.name == 'command_thing' and key == '\n':
- self.send('TASK:COMMAND ' + quote(self.input_))
- self.input_ = ""
- elif self.mode.name == 'control_pw_pw' and key == '\n':
- if self.input_ == '':
- self.log_msg('@ aborted')
- else:
- self.send('SET_MAP_CONTROL_PASSWORD ' + quote(self.tile_control_char) + ' ' + quote(self.input_))
- self.log_msg('@ sent new password for protection character "%s"' % self.tile_control_char)
+ prev_disconnected = self.socket.disconnected
+ self.socket.keep_connection_alive()
+ if prev_disconnected and not self.socket.disconnected:
+ self.update_on_connect()
+ if self.flash:
+ curses.flash()
+ self.flash = False
+ if self.do_refresh:
+ draw_screen()
+ self.do_refresh = False
+ for msg in self.socket.get_message():
+ handle_input(msg)
+ try:
+ key = self.stdscr.getkey()
+ self.do_refresh = True
+ except curses.error:
+ return
+ keycode = None
+ if len(key) == 1:
+ keycode = ord(key)
+ # workaround for <https://stackoverflow.com/a/56390915>
+ if self.store_widechar:
+ self.store_widechar = False
+ key = bytes([195, keycode]).decode()
+ if keycode == 195:
+ self.store_widechar = True
+ return
+ self.show_help = False
+ self.draw_face = False
+ if key == 'KEY_RESIZE':
+ self.reset_size()
+ elif self.mode.has_input_prompt and key == 'KEY_BACKSPACE':
+ self.input_ = self.input_[:-1]
+ elif (((not self.mode.is_intro) and keycode == 27) # Escape
+ or (self.mode.has_input_prompt and key == '\n'
+ and self.input_ == ''\
+ and self.mode.name in {'chat', 'command_thing',
+ 'take_thing', 'drop_thing',
+ 'admin_enter'})):
+ if self.mode.name not in {'chat', 'play', 'study', 'edit'}:
+ self.log('@ aborted')
+ self.switch_mode('play')
+ elif self.mode.has_input_prompt and key == '\n' and self.input_ == '/help':
+ self.show_help = True
+ self.input_ = ""
+ self.restore_input_values()
+ elif self.mode.has_input_prompt and key != '\n': # Return key
+ self.input_ += key
+ max_length = self.right_window_width * self.size.y - len(self.input_prompt) - 1
+ if len(self.input_) > max_length:
+ self.input_ = self.input_[:max_length]
+ elif key == self.keys['help'] and not self.mode.is_single_char_entry:
+ self.show_help = True
+ elif self.mode.name == 'login' and key == '\n':
+ self.login_name = self.input_
+ self.send('LOGIN ' + quote(self.input_))
+ self.input_ = ""
+ elif self.mode.name == 'enter_face' and key == '\n':
+ enter_ascii_art('PLAYER_FACE', 3, 6)
+ elif self.mode.name == 'enter_design' and key == '\n':
+ if self.game.player.carrying.type_ == 'Hat':
+ enter_ascii_art('THING_DESIGN',
+ self.game.player.carrying.design[0].y,
+ self.game.player.carrying.design[0].x, True)
+ else:
+ enter_ascii_art('THING_DESIGN',
+ self.game.player.carrying.design[0].y,
+ self.game.player.carrying.design[0].x,
+ True, True)
+ elif self.mode.name == 'take_thing' and key == '\n':
+ pick_selectable('PICK_UP')
+ elif self.mode.name == 'drop_thing' and key == '\n':
+ pick_selectable('DROP')
+ elif self.mode.name == 'command_thing' and key == '\n':
+ self.send('TASK:COMMAND ' + quote(self.input_))
+ self.input_ = ""
+ elif self.mode.name == 'control_pw_pw' and key == '\n':
+ if self.input_ == '':
+ self.log('@ aborted')
+ else:
+ self.send('SET_MAP_CONTROL_PASSWORD ' + quote(self.tile_control_char) + ' ' + quote(self.input_))
+ self.log('@ sent new password for protection character "%s"' % self.tile_control_char)
+ self.switch_mode('admin')
+ elif self.mode.name == 'password' and key == '\n':
+ if self.input_ == '':
+ self.input_ = ' '
+ self.password = self.input_
+ self.switch_mode('edit')
+ elif self.mode.name == 'admin_enter' and key == '\n':
+ self.send('BECOME_ADMIN ' + quote(self.input_))
+ self.switch_mode('play')
+ elif self.mode.name == 'control_pw_type' and key == '\n':
+ if len(self.input_) != 1:
+ self.log('@ entered non-single-char, therefore aborted')