Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.02 KB | None | 0 0
  1.     # Format the room description.
  2.     def return_appearance(self, looker, **kwargs):
  3.         """
  4.        This formats a description. It is the hook a 'look' command
  5.        should call.
  6.  
  7.        Args:
  8.            looker (Object): Object doing the looking.
  9.            **kwargs (dict): Arbitrary, optional arguments for users
  10.                overriding the call (unused by default).
  11.        """
  12.         if not looker:
  13.             return ""
  14.  
  15.         # Cache the looker's screenwidth. This will default to 80.
  16.         len = looker.screenwidth()
  17.  
  18.         # Get and identify all objects. This needs to be replaced with
  19.         # the new visible_contents method that knows about dark and
  20.         # visibility.
  21.         visible = (con for con in self.contents if con != looker and
  22.                    con.access(looker, "view"))
  23.         # Initialize the lists of the various types of objects we're looking for.
  24.         exits, users, things, places, views  = [], [], [], [], []
  25.  
  26.         # Add the looker to the front of the users list.
  27.         if looker.location is self:
  28.             users = [looker]
  29.  
  30.         # Filter the visible objects into lists based on their type.
  31.         for con in visible:
  32.             if con.destination:
  33.                 exits.append(con)
  34.             elif con.has_account and con.sessions:
  35.                 # If you want dark sleepers, remove 'and con.sessions > 0'
  36.                 users.append(con)
  37.             elif isinstance(con, Place):
  38.                 places.append(con)
  39.             else:
  40.                 things.append(con)
  41.  
  42.         string = header(self.format_name(looker), len)
  43.         desc = self.db.desc
  44.         if desc:
  45.             string += "%s\n" % desc
  46.  
  47.         if places:
  48.             string += subheader("Places", len)
  49.             string += self.format_contents(looker, places, len)
  50.  
  51.         if views:
  52.             string += subheader("Views", len)
  53.             string += self.format_views(looker, views, len)
  54.  
  55.         if users:
  56.             string += subheader('Players', len, nonewline=True)
  57.             string += self.format_players(looker, users, len)
  58.  
  59.         if things:
  60.             string += subheader('Things', len)
  61.             string += self.format_contents(looker, things, len)
  62.             string += '\n'
  63.  
  64.         # TODO: This needs to be spit into it's own method!
  65.         if exits:
  66.             # Sort exits.
  67.             ex = self.sort_exits(exits)
  68.             # Initialize a list to hold our formatted exits.
  69.             out = []
  70.  
  71.             # Process our exits.
  72.             for x in ex:
  73.                 # Grab the aliases from the aliasmanager.
  74.                 # This could be a string -or- a list of strings.
  75.                 a = x.aliases.all()
  76.                 if a:
  77.                     # If `a` is a List then use the first element only,
  78.                     # otherwise we'll use the whole thing.
  79.                     if type(a) is list:
  80.                         # Uppercase this shit.
  81.                         s = a[0].upper()
  82.                     else:
  83.                         s = a.upper()
  84.                 else:
  85.                     # No aliases, just use the name of the exit.
  86.                     s = x.key
  87.                 # Append the formatted exit spec to the output list.
  88.                 out.append( "%s |r<|530%s|r>|n" % (x.key, s))
  89.             # Add our header to the output string.
  90.             string += subheader('Exits', len)
  91.             # Columnize the output list and add it to the output string.
  92.             string += columnize(out, width=len, cols=3)
  93.             # Add a trailing newline to the output string.
  94.             string += '\n'
  95.  
  96.         # Now let's look for other crap.
  97.         i = []
  98.  
  99.         if self.db.views:
  100.             i.append('views')
  101.         if self.db.features:
  102.             i.append('features')
  103.         if looker.admin() and self.db.jnotes:
  104.             i.append('jnotes')
  105.  
  106.         # Add the footer to the output string.
  107.         string += footer(", ".join(i), len, nonewline=True)
  108.  
  109.         # Return the output string.
  110.         return string
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement