mirror of
https://github.com/evennia/evennia.git
synced 2026-03-26 09:46:32 +01:00
Addition of matching_exit() function on DefaultExit to return the exit(s) that pair with it, optionally formatted as list or singular Exit with as_list parameter.
This commit is contained in:
parent
a4eb891f69
commit
473fba5c13
1 changed files with 22 additions and 0 deletions
|
|
@ -3133,3 +3133,25 @@ class DefaultExit(DefaultObject):
|
|||
|
||||
"""
|
||||
traversing_object.msg(_("You cannot go there."))
|
||||
|
||||
def matching_exit(self, as_list=False):
|
||||
"""
|
||||
Get the exits that pair with this one in its destination room
|
||||
(i.e. returns to its location)
|
||||
|
||||
Args:
|
||||
as_list (bool): Whether to return available results as a
|
||||
list or single matching exit.
|
||||
|
||||
Returns:
|
||||
list, exit (Exit), or None: The matching exit(s).
|
||||
"""
|
||||
no_match = [] if as_list else None
|
||||
if not self.destination:
|
||||
return no_match
|
||||
matching_exits = [x for x in self.destination.exits if x.destination == self.location]
|
||||
if not matching_exits:
|
||||
return no_match
|
||||
if as_list:
|
||||
return matching_exits
|
||||
return matching_exits[0]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue