mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Rename display_name and improve docstrings.
This commit is contained in:
parent
1822b01086
commit
462b73b626
5 changed files with 59 additions and 26 deletions
|
|
@ -356,7 +356,13 @@ class Command(object):
|
|||
|
||||
If this command is a potential match in an ambiguous situation, one distinguishing
|
||||
feature may be its attachment to a nearby object, so we include this by default if available.
|
||||
|
||||
Args:
|
||||
caller (TypedObject): The caller who typed an ambiguous term handed to the search function.
|
||||
|
||||
Returns:
|
||||
A string with identifying information to disambiguate the object, conventionally with a preceding space.
|
||||
"""
|
||||
if hasattr(self, 'obj'):
|
||||
return " (%s)" % self.obj.display_name(caller)
|
||||
return " (%s)" % self.obj.get_display_name(caller)
|
||||
return ""
|
||||
|
|
|
|||
|
|
@ -138,9 +138,9 @@ class CmdSetObjAlias(MuxCommand):
|
|||
# no =, so we just list aliases on object.
|
||||
aliases = obj.aliases.all()
|
||||
if aliases:
|
||||
caller.msg("Aliases for '%s': %s" % (obj.display_name(caller), ", ".join(aliases)))
|
||||
caller.msg("Aliases for '%s': %s" % (obj.get_display_name(caller), ", ".join(aliases)))
|
||||
else:
|
||||
caller.msg("No aliases exist for '%s'." % obj.display_name(caller))
|
||||
caller.msg("No aliases exist for '%s'." % obj.get_display_name(caller))
|
||||
return
|
||||
|
||||
if not obj.access(caller, 'edit'):
|
||||
|
|
@ -151,7 +151,7 @@ class CmdSetObjAlias(MuxCommand):
|
|||
# we have given an empty =, so delete aliases
|
||||
old_aliases = obj.aliases.all()
|
||||
if old_aliases:
|
||||
caller.msg("Cleared aliases from %s: %s" % (obj.display_name(caller), ", ".join(old_aliases)))
|
||||
caller.msg("Cleared aliases from %s: %s" % (obj.get_display_name(caller), ", ".join(old_aliases)))
|
||||
obj.aliases.clear()
|
||||
else:
|
||||
caller.msg("No aliases to clear.")
|
||||
|
|
@ -175,7 +175,7 @@ class CmdSetObjAlias(MuxCommand):
|
|||
obj.at_cmdset_get(force_init=True)
|
||||
|
||||
# report all aliases on the object
|
||||
caller.msg("Alias(es) for '%s' set to %s." % (obj.display_name(caller), str(obj.aliases)))
|
||||
caller.msg("Alias(es) for '%s' set to %s." % (obj.get_display_name(caller), str(obj.aliases)))
|
||||
|
||||
|
||||
class CmdCopy(ObjManipCommand):
|
||||
|
|
@ -587,7 +587,7 @@ class CmdDesc(MuxCommand):
|
|||
desc = self.args
|
||||
|
||||
obj.db.desc = desc
|
||||
caller.msg("The description was set on %s." % obj.display_name(caller))
|
||||
caller.msg("The description was set on %s." % obj.get_display_name(caller))
|
||||
|
||||
|
||||
class CmdDestroy(MuxCommand):
|
||||
|
|
@ -2085,7 +2085,7 @@ class CmdFind(MuxCommand):
|
|||
string += "\n {RNo match found for '%s' in #dbref interval.{n" % (searchstring)
|
||||
else:
|
||||
result=result[0]
|
||||
string += "\n{g %s - %s{n" % (result.display_name(caller), result.path)
|
||||
string += "\n{g %s - %s{n" % (result.get_display_name(caller), result.path)
|
||||
else:
|
||||
# Not a player/dbref search but a wider search; build a queryset.
|
||||
# Searchs for key and aliases
|
||||
|
|
@ -2117,10 +2117,10 @@ class CmdFind(MuxCommand):
|
|||
if nresults > 1:
|
||||
string = "{w%i Matches{n(#%i-#%i%s):" % (nresults, low, high, restrictions)
|
||||
for res in results:
|
||||
string += "\n {g%s - %s{n" % (res.display_name(caller), res.path)
|
||||
string += "\n {g%s - %s{n" % (res.get_display_name(caller), res.path)
|
||||
else:
|
||||
string = "{wOne Match{n(#%i-#%i%s):" % (low, high, restrictions)
|
||||
string += "\n {g%s - %s{n" % (results[0].display_name(caller), results[0].path)
|
||||
string += "\n {g%s - %s{n" % (results[0].get_display_name(caller), results[0].path)
|
||||
else:
|
||||
string = "{wMatch{n(#%i-#%i%s):" % (low, high, restrictions)
|
||||
string += "\n {RNo matches found for '%s'{n" % searchstring
|
||||
|
|
@ -2278,18 +2278,18 @@ class CmdScript(MuxCommand):
|
|||
# no rhs means we want to operate on all scripts
|
||||
scripts = obj.scripts.all()
|
||||
if not scripts:
|
||||
string += "No scripts defined on %s." % obj.display_name(caller)
|
||||
string += "No scripts defined on %s." % obj.get_display_name(caller)
|
||||
elif not self.switches:
|
||||
# view all scripts
|
||||
from evennia.commands.default.system import format_script_list
|
||||
string += format_script_list(scripts)
|
||||
elif "start" in self.switches:
|
||||
num = sum([obj.scripts.start(script.key) for script in scripts])
|
||||
string += "%s scripts started on %s." % (num, obj.display_name(caller))
|
||||
string += "%s scripts started on %s." % (num, obj.get_display_name(caller))
|
||||
elif "stop" in self.switches:
|
||||
for script in scripts:
|
||||
string += "Stopping script %s on %s." % (script.display_name(caller),
|
||||
obj.display_name(caller))
|
||||
string += "Stopping script %s on %s." % (script.get_display_name(caller),
|
||||
obj.get_display_name(caller))
|
||||
script.stop()
|
||||
string = string.strip()
|
||||
obj.scripts.validate()
|
||||
|
|
@ -2299,11 +2299,11 @@ class CmdScript(MuxCommand):
|
|||
ok = obj.scripts.add(self.rhs, autostart=True)
|
||||
if not ok:
|
||||
string += "\nScript %s could not be added and/or started on %s." % (
|
||||
self.rhs, obj.display_name(caller)
|
||||
self.rhs, obj.get_display_name(caller)
|
||||
)
|
||||
else:
|
||||
string = "Script {w%s{n successfully added and started on %s." % (
|
||||
self.rhs, obj.display_name(caller)
|
||||
self.rhs, obj.get_display_name(caller)
|
||||
)
|
||||
|
||||
else:
|
||||
|
|
@ -2374,7 +2374,7 @@ class CmdTag(MuxCommand):
|
|||
if nobjs > 0:
|
||||
catstr = " (category: '{w%s{n')" % category if category else \
|
||||
("" if nobjs == 1 else " (may have different tag categories)")
|
||||
matchstr = ", ".join(o.display_name(self.caller) for o in objs)
|
||||
matchstr = ", ".join(o.get_display_name(self.caller) for o in objs)
|
||||
|
||||
string = "Found {w%i{n object%s with tag '{w%s{n'%s:\n %s" % (nobjs,
|
||||
"s" if nobjs > 1 else "",
|
||||
|
|
@ -2528,6 +2528,6 @@ class CmdSpawn(MuxCommand):
|
|||
prototype["location"] = self.caller.location
|
||||
|
||||
for obj in spawn(prototype):
|
||||
self.caller.msg("Spawned %s." % obj.display_name(self.caller))
|
||||
self.caller.msg("Spawned %s." % obj.get_display_name(self.caller))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -83,7 +83,13 @@ class ChannelCommand(command.Command):
|
|||
|
||||
def get_extra_info(self, caller, **kwargs):
|
||||
"""
|
||||
Let users know that this exit is for communicating on a channel.
|
||||
Let users know that this command is for communicating on a channel.
|
||||
|
||||
Args:
|
||||
caller (TypedObject): A Character or Player who has entered an ambiguous command.
|
||||
|
||||
Returns:
|
||||
A string with identifying information to disambiguate the object, conventionally with a preceding space.
|
||||
"""
|
||||
return _(" (channel)")
|
||||
|
||||
|
|
|
|||
|
|
@ -1479,11 +1479,17 @@ class ExitCommand(command.Command):
|
|||
def get_extra_info(self, caller, **kwargs):
|
||||
"""
|
||||
Shows a bit of information on where the exit leads.
|
||||
|
||||
Args:
|
||||
caller (Object): The object (usually a character) that entered an ambiguous command.
|
||||
|
||||
Returns:
|
||||
A string with identifying information to disambiguate the command, conventionally with a preceding space.
|
||||
"""
|
||||
if self.obj.destination:
|
||||
return " (exit to %s)" % self.obj.destination.display_name(caller)
|
||||
return " (exit to %s)" % self.obj.destination.get_display_name(caller)
|
||||
else:
|
||||
return " (%s)" % self.obj.display_name(caller)
|
||||
return " (%s)" % self.obj.get_display_name(caller)
|
||||
|
||||
#
|
||||
# Base Exit object
|
||||
|
|
|
|||
|
|
@ -610,19 +610,28 @@ class TypedObject(SharedMemoryModel):
|
|||
raise Exception("Cannot delete the ndb object!")
|
||||
ndb = property(__ndb_get, __ndb_set, __ndb_del)
|
||||
|
||||
def display_name(self, looker, **kwargs):
|
||||
def get_display_name(self, looker, **kwargs):
|
||||
"""
|
||||
Displays the name of the object in a viewer-aware manner.
|
||||
|
||||
Note that this function could be extended to change how object names
|
||||
appear to users, but be wary. This function does not change an object's keys or
|
||||
aliases when searching, and is expected to produce something useful for builders.
|
||||
Args:
|
||||
looker (TypedObject): The object or player that is looking at/getting inforamtion for this object.
|
||||
|
||||
Returns:
|
||||
A string containing the name of the object, including the DBREF if this user is privileged to control
|
||||
said object.
|
||||
|
||||
Notes:
|
||||
This function could be extended to change how object names
|
||||
appear to users in character, but be wary. This function does not change an object's keys or
|
||||
aliases when searching, and is expected to produce something useful for builders.
|
||||
|
||||
"""
|
||||
if self.access(looker, access_type='controls'):
|
||||
return "{}(#{})".format(self.name, self.id)
|
||||
return self.name
|
||||
|
||||
def get_extra_info(self, viewer, **kwargs):
|
||||
def get_extra_info(self, looker, **kwargs):
|
||||
"""
|
||||
Used when an object is in a list of ambiguous objects as an additional
|
||||
information tag.
|
||||
|
|
@ -630,8 +639,14 @@ class TypedObject(SharedMemoryModel):
|
|||
For instance, if you had potions which could have varying levels of liquid
|
||||
left in them, you might want to display how many drinks are left in each when
|
||||
selecting which to drop, but not in your normal inventory listing.
|
||||
|
||||
Args:
|
||||
looker (TypedObject): The object or player that is looking at/getting information for this object.
|
||||
|
||||
Returns:
|
||||
A string with disambiguating information, conventionally with a leading space.
|
||||
"""
|
||||
|
||||
if self.location == viewer:
|
||||
if self.location == looker:
|
||||
return " (carried)"
|
||||
return ""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue