Resolves issue 133. Added the location keyword to the ObjectDB.search() method for easier customizable object searches.
This commit is contained in:
parent
2bdaf034c8
commit
9dcfea5971
3 changed files with 20 additions and 15 deletions
|
|
@ -919,23 +919,21 @@ class CmdOpen(ObjManipCommand):
|
||||||
def create_exit(self, exit_name, location, destination, exit_aliases=None, typeclass=None):
|
def create_exit(self, exit_name, location, destination, exit_aliases=None, typeclass=None):
|
||||||
"""
|
"""
|
||||||
Helper function to avoid code duplication.
|
Helper function to avoid code duplication.
|
||||||
At this point we know destination is a valid location, but
|
At this point we know destination is a valid location
|
||||||
all arguments are strings/lists.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
caller = self.caller
|
caller = self.caller
|
||||||
string = ""
|
string = ""
|
||||||
# check if this exit object already exists. We need to
|
# check if this exit object already exists at the location.
|
||||||
# know what the result is before we can decide what to do;
|
# we need to ignore errors (so no automatic feedback)since we
|
||||||
# so we deactivate the automatic error handling. This
|
# have to know the result of the search to decide what to do.
|
||||||
# always returns a list.
|
exit_obj = caller.search(exit_name, location=location, ignore_errors=True)
|
||||||
exit_obj = caller.search(exit_name, ignore_errors=True)
|
|
||||||
if len(exit_obj) > 1:
|
if len(exit_obj) > 1:
|
||||||
# give error message and return
|
# give error message and return
|
||||||
caller.search(exit_name)
|
caller.search(exit_name, location=location)
|
||||||
return
|
return
|
||||||
exit_obj = exit_obj
|
|
||||||
if exit_obj:
|
if exit_obj:
|
||||||
|
exit_obj = exit_obj[0]
|
||||||
if not exit_obj.db._destination:
|
if not exit_obj.db._destination:
|
||||||
# we are trying to link a non-exit
|
# we are trying to link a non-exit
|
||||||
string = "'%s' already exists and is not an exit!\nIf you want to convert it "
|
string = "'%s' already exists and is not an exit!\nIf you want to convert it "
|
||||||
|
|
@ -946,12 +944,15 @@ class CmdOpen(ObjManipCommand):
|
||||||
old_destination = exit_obj.db._destination
|
old_destination = exit_obj.db._destination
|
||||||
if old_destination:
|
if old_destination:
|
||||||
string = "Exit %s already exists." % exit_name
|
string = "Exit %s already exists." % exit_name
|
||||||
if old_destination != destination:
|
if old_destination.id != destination.id:
|
||||||
# reroute the old exit.
|
# reroute the old exit.
|
||||||
exit_obj.db._destination = destination
|
exit_obj.db._destination = destination
|
||||||
exit_obj.aliases = exit_aliases
|
exit_obj.aliases = exit_aliases
|
||||||
string += " Rerouted its old destination '%s' to '%s' and changed aliases." % \
|
string += " Rerouted its old destination '%s' to '%s' and changed aliases." % \
|
||||||
(old_destination.name, destination.name)
|
(old_destination.name, destination.name)
|
||||||
|
else:
|
||||||
|
string += " It already points to the correct place."
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# exit does not exist before. Create a new one.
|
# exit does not exist before. Create a new one.
|
||||||
exit_obj = create.create_object(typeclass, key=exit_name,
|
exit_obj = create.create_object(typeclass, key=exit_name,
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ class ObjectManager(TypedObjectManager):
|
||||||
@returns_typeclass_list
|
@returns_typeclass_list
|
||||||
def object_search(self, character, ostring,
|
def object_search(self, character, ostring,
|
||||||
global_search=False,
|
global_search=False,
|
||||||
attribute_name=None):
|
attribute_name=None, location=None):
|
||||||
"""
|
"""
|
||||||
Search as an object and return results.
|
Search as an object and return results.
|
||||||
|
|
||||||
|
|
@ -177,12 +177,14 @@ class ObjectManager(TypedObjectManager):
|
||||||
global_search: Search all objects, not just the current location/inventory
|
global_search: Search all objects, not just the current location/inventory
|
||||||
attribute_name: (string) Which attribute to search in each object.
|
attribute_name: (string) Which attribute to search in each object.
|
||||||
If None, the default 'key' attribute is used.
|
If None, the default 'key' attribute is used.
|
||||||
|
location: If None, character.location will be used.
|
||||||
"""
|
"""
|
||||||
#ostring = str(ostring).strip()
|
#ostring = str(ostring).strip()
|
||||||
|
|
||||||
if not ostring or not character:
|
if not ostring or not character:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
if not location:
|
||||||
location = character.location
|
location = character.location
|
||||||
|
|
||||||
# Easiest case - dbref matching (always exact)
|
# Easiest case - dbref matching (always exact)
|
||||||
|
|
|
||||||
|
|
@ -434,7 +434,7 @@ class ObjectDB(TypedObject):
|
||||||
def search(self, ostring,
|
def search(self, ostring,
|
||||||
global_search=False,
|
global_search=False,
|
||||||
attribute_name=None,
|
attribute_name=None,
|
||||||
use_nicks=False,
|
use_nicks=False, location=None,
|
||||||
ignore_errors=False):
|
ignore_errors=False):
|
||||||
"""
|
"""
|
||||||
Perform a standard object search in the database, handling
|
Perform a standard object search in the database, handling
|
||||||
|
|
@ -451,6 +451,7 @@ class ObjectDB(TypedObject):
|
||||||
attribute_name: (string) Which attribute to match
|
attribute_name: (string) Which attribute to match
|
||||||
(if None, uses default 'name')
|
(if None, uses default 'name')
|
||||||
use_nicks : Use nickname replace (off by default)
|
use_nicks : Use nickname replace (off by default)
|
||||||
|
location : If None, use caller's current location
|
||||||
ignore_errors : Don't display any error messages even
|
ignore_errors : Don't display any error messages even
|
||||||
if there are none/multiple matches -
|
if there are none/multiple matches -
|
||||||
just return the result as a list.
|
just return the result as a list.
|
||||||
|
|
@ -473,7 +474,8 @@ class ObjectDB(TypedObject):
|
||||||
|
|
||||||
results = ObjectDB.objects.object_search(self, ostring,
|
results = ObjectDB.objects.object_search(self, ostring,
|
||||||
global_search=global_search,
|
global_search=global_search,
|
||||||
attribute_name=attribute_name)
|
attribute_name=attribute_name,
|
||||||
|
location=location)
|
||||||
|
|
||||||
if ignore_errors:
|
if ignore_errors:
|
||||||
return results
|
return results
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue