コード例 #1
0
ファイル: player.py プロジェクト: elitegreg/mudpy
            self.request_window_size()

        self.colormap = ansi.DEFAULT_MAP

    def prompt(self, msg):
        while True:
            try:
                self.sendtext(msg)
                return self.readline().rstrip()
            except Interrupt:
                self.sendtext('\n')

    def write(self, msg):
        # textwrap ignoring ESC sequences
        msg = ansi.map_string(msg, self.colormap) 
        msg = textwrap.fill(msg, width=self.options.window_size[0])
        msg += '\n'
        self.sendtext(msg)



add_gameproperty(Player, 'name', readonly=True)
add_gameproperty(Player, 'display_name')
add_gameproperty(Player, 'password', readonly=True)
add_gameproperty(Player, 'email')
add_gameproperty(Player, 'last_ip')
add_gameproperty(Player, 'last_time')
add_gameproperty(Player, 'color', default='auto')
add_gameproperty(Player, 'aliases')

コード例 #2
0
ファイル: room.py プロジェクト: elitegreg/mudpy
    __slots__ = tuple()

    yaml_loader = yaml.SafeLoader
    yaml_tag = '!Room'

    def __setstate__(self, newstate):
        super().__setstate__(newstate)
        self.cached_exits = dict()
        if not self.exits:
            self.exits = dict()

    def get_exit(self, direction):
        # TODO we can get rid of lower() here if we enforce
        # the exit to be stored in lowercase elsewhere
        direction = direction.lower()

        try:
            return self.cached_exits[direction]
        except KeyError:
            pass

        exit = ObjectCache().get(self.exits[direction])
        self.cached_exits[direction] = exit.weakref()
        return exit


add_gameproperty(Room, 'short_description', readonly=True)
add_gameproperty(Room, 'long_description', readonly=True)
add_gameproperty(Room, 'exits')
add_gameproperty(Room, 'cached_exits', tmp=True)