toktoktheeo

return appearance

Mar 23rd, 2022
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.40 KB | None | 0 0
  1.  # populated by `return_appearance`
  2.     appearance_template = """
  3.    {header}
  4.    |c\n{name}|n
  5.    {desc}
  6.    {exits}{characters}{things}
  7.    {footer}
  8.        """
  9.  
  10.     def return_appearance(self, looker, **kwargs):
  11.         """
  12.        Main callback used by 'look' for the object to describe itself.
  13.        This formats a description. By default, this looks for the `appearance_template`
  14.        string set on this class and populates it with formatting keys
  15.            'name', 'desc', 'exits', 'characters', 'things' as well as
  16.            (currently empty) 'header'/'footer'.
  17.  
  18.        Args:
  19.            looker (Object): Object doing the looking.
  20.            **kwargs (dict): Arbitrary, optional arguments for users
  21.                overriding the call. This is passed into the helper
  22.                methods and into `get_display_name` calls.
  23.  
  24.        Returns:
  25.            str: The description of this entity. By default this includes
  26.                the entity's name, description and any contents inside it.
  27.  
  28.        Notes:
  29.            To simply change the layout of how the object displays itself (like
  30.            adding some line decorations or change colors of different sections),
  31.            you can simply edit `.appearance_template`. You only need to override
  32.            this method (and/or its helpers) if you want to change what is passed
  33.            into the template or want the most control over output.
  34.  
  35.        """
  36.  
  37.         if not looker:
  38.             return ""
  39.  
  40.         # ourselves
  41.         name = self.get_display_name(looker, **kwargs)
  42.         desc = self.db.desc or "Description non définie."
  43.  
  44.         # contents
  45.         content_names_map = self.get_content_names(looker, **kwargs)
  46.         exits = list_to_string(content_names_map["exits"])
  47.         characters = list_to_string(content_names_map["characters"])
  48.         things = list_to_string(content_names_map["things"])
  49.  
  50.         # populate the appearance_template string. It's a good idea to strip it and
  51.         # let the client add any extra spaces instead.
  52.         return self.appearance_template.format(
  53.             header="",
  54.             name=name,
  55.             desc=desc,
  56.             exits=f"|wExits:|n {exits}" if exits else "",
  57.             characters=f"\n|wPersonnages:|n {characters}" if characters else "",
  58.             things=f"\n|wAgents:|n {things}" if things else "",
  59.             footer="",
  60.         ).strip()
Advertisement
Add Comment
Please, Sign In to add comment