Пример #1
0
    def display_buffer(self, buf=None, offset=0, linenums=True, raw=False):
        """
        This displays the line editor buffer, or selected parts of it.

        Args:
            buf (str, optional): The buffer or part of buffer to display.
            offset (int, optional): If `buf` is set and is not the full buffer,
                `offset` should define the actual starting line number, to
                get the linenum display right.
            linenums (bool, optional): Show line numbers in buffer.
            raw (bool, optional): Tell protocol to not parse
                formatting information.

        """
        if buf == None:
            buf = self._buffer
        if is_iter(buf):
            buf = "\n".join(buf)

        lines = buf.split('\n')
        nlines = len(lines)
        nwords = len(buf.split())
        nchars = len(buf)

        sep = self._sep
        header = "{n" + sep * 10 + "Line Editor [%s]" % self._key + sep * (_DEFAULT_WIDTH-25-len(self._key))
        footer = "{n" + sep * 10 + "[l:%02i w:%03i c:%04i]" % (nlines, nwords, nchars) \
                    + sep * 12 + "(:h for help)" + sep * 23
        if linenums:
            main = "\n".join("{b%02i|{n %s" % (iline + 1 + offset, line) for iline, line in enumerate(lines))
        else:
            main = "\n".join(lines)
        string = "%s\n%s\n%s" % (header, main, footer)
        self._caller.msg(string, raw=raw)
Пример #2
0
    def display_buffer(self, buf=None, offset=0, linenums=True, raw=False):
        """
        This displays the line editor buffer, or selected parts of it.

        If `buf` is set and is not the full buffer, `offset` should define
        the starting line number, to get the linenum display right.
        """
        if buf == None:
            buf = self._buffer
        if is_iter(buf):
            buf = "\n".join(buf)

        lines = buf.split('\n')
        nlines = len(lines)
        nwords = len(buf.split())
        nchars = len(buf)

        sep = self._sep
        header = "{n" + sep * 10 + "Line Editor [%s]" % self._key + sep * (_DEFAULT_WIDTH-25-len(self._key))
        footer = "{n" + sep * 10 + "[l:%02i w:%03i c:%04i]" % (nlines, nwords, nchars) \
                    + sep * 12 + "(:h for help)" + sep * 23
        if linenums:
            main = "\n".join("{b%02i|{n %s" % (iline + 1 + offset, line) for iline, line in enumerate(lines))
        else:
            main = "\n".join(lines)
        string = "%s\n%s\n%s" % (header, main, footer)
        self._caller.msg(string, raw=raw)
Пример #3
0
    def __init__(self,
                 caller,
                 nodes=None,
                 startnode="START",
                 endnode="END",
                 exec_end="look"):
        """
        We specify startnode/endnode so that the system knows where to
        enter and where to exit the menu tree. If nodes is given, it
        should be a list of valid node objects to add to the tree.

        caller (Object): The caller triggering the menu
        nodes (tuple, optional): A tuple of `MenuNode` objects. This need
            not be in any particular order.
        startnode (str, optional): The key of the first `MenuNode` to jump
            to when starting the menu. Defaults to "START".
        endnode (str, optional): The key of the end node. When
            instructed to go to this node (by any means), the menu
            will be gracefully exited. Defaults to "END".
        exec_end (str, optional): If not `None`, this command name will be executed
            directly after the menu system has been exited. It is
            normally useful for making sure the user realizes their UI
            mode has changed.

        """
        self.tree = {}
        self.startnode = startnode
        self.endnode = endnode
        self.exec_end = exec_end
        self.caller = caller
        if nodes and utils.is_iter(nodes):
            for node in nodes:
                self.add(node)
Пример #4
0
    def __init__(self, caller, nodes=None,
                 startnode="START", endnode="END", exec_end="look"):
        """
        We specify startnode/endnode so that the system knows where to
        enter and where to exit the menu tree. If nodes is given, it
        should be a list of valid node objects to add to the tree.

        caller (Object): The caller triggering the menu
        nodes (tuple, optional): A tuple of `MenuNode` objects. This need
            not be in any particular order.
        startnode (str, optional): The key of the first `MenuNode` to jump
            to when starting the menu. Defaults to "START".
        endnode (str, optional): The key of the end node. When
            instructed to go to this node (by any means), the menu
            will be gracefully exited. Defaults to "END".
        exec_end (str, optional): If not `None`, this command name will be executed
            directly after the menu system has been exited. It is
            normally useful for making sure the user realizes their UI
            mode has changed.

        """
        self.tree = {}
        self.startnode = startnode
        self.endnode = endnode
        self.exec_end = exec_end
        self.caller = caller
        if nodes and utils.is_iter(nodes):
            for node in nodes:
                self.add(node)
Пример #5
0
    def display_buffer(self, buf=None, offset=0, linenums=True):
        """
        This displays the line editor buffer, or selected parts of it.

        If `buf` is set and is not the full buffer, `offset` should define
        the starting line number, to get the linenum display right.
        """
        if buf == None:
            buf = self.buffer
        if utils.is_iter(buf):
            buf = "\n".join(buf)

        lines = buf.split('\n')
        nlines = len(lines)
        nwords = len(buf.split())
        nchars = len(buf)

        sep = self.sep
        header = "{n" + sep * 10 + "Line Editor [%s]" % self.key + sep * (_DEFAULT_WIDTH-25-len(self.key))
        footer = "{n" + sep * 10 + "[l:%02i w:%03i c:%04i]" % (nlines, nwords, nchars) + sep * 12 + "(:h for help)" + sep * 23
        if linenums:
            main = "\n".join("{b%02i|{n %s" % (iline + 1 + offset, line) for iline, line in enumerate(lines))
        else:
            main = "\n".join(lines)
        string = "%s\n%s\n%s" % (header, main, footer)
        return string
Пример #6
0
    def display_buffer(self, buf=None, offset=0, linenums=True, options={"raw": False}):
        """
        This displays the line editor buffer, or selected parts of it.

        Args:
            buf (str, optional): The buffer or part of buffer to display.
            offset (int, optional): If `buf` is set and is not the full buffer,
                `offset` should define the actual starting line number, to
                get the linenum display right.
            linenums (bool, optional): Show line numbers in buffer.
            options: raw (bool, optional): Tell protocol to not parse
                formatting information.

        """
        if buf is None:
            buf = self._buffer
        if is_iter(buf):
            buf = "\n".join(buf)

        lines = buf.split('\n')
        nlines = len(lines)
        nwords = len(buf.split())
        nchars = len(buf)

        sep = self._sep
        header = "|n" + sep * 10 + "Line Editor [%s]" % self._key + sep * (_DEFAULT_WIDTH-20-len(self._key))
        footer = "|n" + sep * 10 +\
                 "[l:%02i w:%03i c:%04i]" % (nlines, nwords, nchars) + sep * 12 + "(:h for help)" + sep * 28
        if linenums:
            main = "\n".join("|b%02i|||n %s" % (iline + 1 + offset, line) for iline, line in enumerate(lines))
        else:
            main = "\n".join(lines)
        string = "%s\n%s\n%s" % (header, main, footer)
        self._caller.msg(string, options=options)
Пример #7
0
    def update_buffer(self, buf):
        """
        This should be called when the buffer has been changed
        somehow.  It will handle unsaved flag and undo updating.
        """
        if is_iter(buf):
            buf = "\n".join(buf)

        if buf != self._buffer:
            self._buffer = buf
            self.update_undo()
            self._unsaved = True
Пример #8
0
 def die(self):
     for i in range(0, len(self.db.card_hand)):
         self.discard(0)
     for i in range(0, len(self.db.card_played)):
         self.leaveplay(0)
     self.shuffle()
     self.spawn_loot(self.db.card_deck[0])
     self.for_contents(self.drop)
     if is_iter(self.db.death_message):
         death_message = random.choice(self.db.death_message)
     else:
         death_message = self.db.death_message
     self.location.msg_contents(f'{self.key} {death_message}')
     self.delete()
Пример #9
0
    def __init__(self, caller, nodes=None,
                 startnode="START", endnode="END", exec_end="look"):
        """
        We specify startnode/endnode so that the system knows where to
        enter and where to exit the menu tree. If nodes is given, it
        should be a list of valid node objects to add to the tree.

        exec_end - if not None, will execute the given command string
                   directly after the menu system has been exited.
        """
        self.tree = {}
        self.startnode = startnode
        self.endnode = endnode
        self.exec_end = exec_end
        self.caller = caller
        if nodes and utils.is_iter(nodes):
            for node in nodes:
                self.add(node)
Пример #10
0
    def update_buffer(self, buf):
        """
        This should be called when the buffer has been changed
        somehow.  It will handle unsaved flag and undo updating.

        Args:
            buf (str): The text to update the buffer with.

        """
        if is_iter(buf):
            buf = "\n".join(buf)

        if buf != self._buffer:
            self._buffer = buf
            self.update_undo()
            self._unsaved = True
            if self._persistent:
                self._caller.attributes.add("_eveditor_buffer_temp", (self._buffer, self._undo_buffer))
Пример #11
0
    def __init__(self,
                 caller,
                 nodes=None,
                 startnode="START",
                 endnode="END",
                 exec_end="look"):
        """
        We specify startnode/endnode so that the system knows where to
        enter and where to exit the menu tree. If nodes is given, it
        should be a list of valid node objects to add to the tree.

        exec_end - if not None, will execute the given command string
                   directly after the menu system has been exited.
        """
        self.tree = {}
        self.startnode = startnode
        self.endnode = endnode
        self.exec_end = exec_end
        self.caller = caller
        if nodes and utils.is_iter(nodes):
            for node in nodes:
                self.add(node)
Пример #12
0
 def test_is_iter(self):
     self.assertEqual(True, utils.is_iter([1, 2, 3, 4]))
     self.assertEqual(False, utils.is_iter("This is not an iterable"))
Пример #13
0
    def at_look(self, target=None, session=None, **kwargs):
        """
        Called when this object executes a look. It allows to customize
        just what this means.

        Args:
            target (Object or list, optional): An object or a list
                objects to inspect.
            session (Session, optional): The session doing this look.
            **kwargs (dict): Arbitrary, optional arguments for users
                overriding the call (unused by default).

        Returns:
            look_string (str): A prepared look string, ready to send
                off to any recipient (usually to ourselves)

        """

        if target and not is_iter(target):
            # single target - just show it
            if hasattr(target, "return_appearance"):
                return target.return_appearance(self)
            else:
                return _("{target} n'a pas d'apparence en jeu.").format(
                    target=target)
        else:
            # list of targets - make list to disconnect from db
            characters = list(tar for tar in target if tar) if target else []
            sessions = self.sessions.all()
            if not sessions:
                # no sessions, nothing to report
                return ""
            is_su = self.is_superuser

            # text shown when looking in the ooc area
            result = [f"Compte |g{self.key}|n (Vous êtes hors personnage)"]

            nsess = len(sessions)
            result.append(nsess == 1 and "\n\n|wSession connectée :|n"
                          or f"\n\n|wSessions connectées ({nsess}):|n")
            for isess, sess in enumerate(sessions):
                csessid = sess.sessid
                addr = "%s (%s)" % (
                    sess.protocol_key,
                    isinstance(sess.address, tuple) and str(sess.address[0])
                    or str(sess.address),
                )
                result.append("\n %s %s" % (
                    session and session.sessid == csessid and "|w* %s|n" %
                    (isess + 1) or "  %s" % (isess + 1),
                    addr,
                ))
            result.append("\n\n |wManuel|n - liste des commandes")
            charmax = _MAX_NR_CHARACTERS

            if is_su or len(characters) < charmax:
                if not characters:
                    result.append(
                        "\n\n Vous n'avez encore aucun personnages. Essayez |wmanuel @créer|n pour savoir comment en créer un."
                    )
                else:
                    result.append(
                        "\n |w@créer <nom> [=description]|n - crée un nouveau personnage"
                    )
                    result.append(
                        "\n |w@supprimer <nom>|n - supprime un personnage (définitif)"
                    )

            if characters:
                string_s_ending = len(characters) > 1 and "s" or ""
                result.append(
                    "\n |w@sélectionner <personnage>|n - se connecte au personnage (|w@ooc|n pour revenir ici)"
                )
                if is_su:
                    result.append(
                        f"\n\nVos personnages{string_s_ending} ({len(characters)}/illimité):"
                    )
                else:
                    result.append("\n\nVos personnages%s%s:" % (
                        string_s_ending,
                        charmax > 1 and " (%i/%i)" %
                        (len(characters), charmax) or "",
                    ))

                for char in characters:
                    csessions = char.sessions.all()
                    if csessions:
                        for sess in csessions:
                            # character is already puppeted
                            sid = sess in sessions and sessions.index(sess) + 1
                            if sess and sid:
                                result.append(
                                    f"\n - |G{char.key}|n [{', '.join(char.permissions.all())}] (Connecté sur la session {sid})"
                                )
                            else:
                                result.append(
                                    f"\n - |R{char.key}|n [{', '.join(char.permissions.all())}] (played by someone else)"
                                )
                    else:
                        # character is "free to puppet"
                        result.append(
                            f"\n - {char.key} [{', '.join(char.permissions.all())}]"
                        )
            look_string = ("-" * 68) + "\n" + "".join(result) + "\n" + ("-" *
                                                                        68)
            return look_string
Пример #14
0
 def test_is_iter(self):
     self.assertEqual(True, utils.is_iter([1,2,3,4]))
     self.assertEqual(False, utils.is_iter("This is not an iterable"))