mirror of
https://github.com/evennia/evennia.git
synced 2026-04-04 15:07:16 +02:00
Merge pull request #2945 from Machine-Garden-MUD/exit_match
Add matching_exit() to DefaultExit
This commit is contained in:
commit
c545eb6679
2 changed files with 34 additions and 0 deletions
|
|
@ -3133,3 +3133,20 @@ class DefaultExit(DefaultObject):
|
|||
|
||||
"""
|
||||
traversing_object.msg(_("You cannot go there."))
|
||||
|
||||
def get_return_exit(self, return_all=False):
|
||||
"""
|
||||
Get the exits that pair with this one in its destination room
|
||||
(i.e. returns to its location)
|
||||
|
||||
Args:
|
||||
return_all (bool): Whether to return available results as a
|
||||
list or single matching exit.
|
||||
|
||||
Returns:
|
||||
queryset or exit (Exit): The matching exit(s).
|
||||
"""
|
||||
query = ObjectDB.objects.filter(db_location=self.destination, db_destination=self.location)
|
||||
if return_all:
|
||||
return query
|
||||
return query.first()
|
||||
|
|
|
|||
|
|
@ -69,6 +69,23 @@ class DefaultObjectTest(BaseEvenniaTest):
|
|||
self.assertEqual(description, obj.db.desc)
|
||||
self.assertEqual(obj.db.creator_ip, self.ip)
|
||||
|
||||
def test_exit_get_return_exit(self):
|
||||
ex1, _ = DefaultExit.create("north", self.room1, self.room2, account=self.account)
|
||||
single_return_exit = ex1.get_return_exit()
|
||||
all_return_exit = ex1.get_return_exit(return_all=True)
|
||||
self.assertEqual(single_return_exit, None)
|
||||
self.assertEqual(len(all_return_exit), 0)
|
||||
|
||||
ex2, _ = DefaultExit.create("south", self.room2, self.room1, account=self.account)
|
||||
single_return_exit = ex1.get_return_exit()
|
||||
all_return_exit = ex1.get_return_exit(return_all=True)
|
||||
self.assertEqual(single_return_exit, ex2)
|
||||
self.assertEqual(len(all_return_exit), 1)
|
||||
|
||||
ex3, _ = DefaultExit.create("also_south", self.room2, self.room1, account=self.account)
|
||||
all_return_exit = ex1.get_return_exit(return_all=True)
|
||||
self.assertEqual(len(all_return_exit), 2)
|
||||
|
||||
def test_urls(self):
|
||||
"Make sure objects are returning URLs"
|
||||
self.assertTrue(self.char1.get_absolute_url())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue