Add display_name and disambiguation_tag for dynamic naming.
This commit is contained in:
parent
a5887d23e2
commit
1822b01086
6 changed files with 75 additions and 50 deletions
|
|
@ -187,9 +187,6 @@ def at_search_result(msg_obj, ostring, results, global_search=False,
|
||||||
# we have more than one match. We will display a
|
# we have more than one match. We will display a
|
||||||
# list of the form 1-objname, 2-objname etc.
|
# list of the form 1-objname, 2-objname etc.
|
||||||
|
|
||||||
# check if the msg_object may se dbrefs
|
|
||||||
show_dbref = global_search
|
|
||||||
|
|
||||||
if multimatch_string:
|
if multimatch_string:
|
||||||
# custom header
|
# custom header
|
||||||
string = multimatch_string
|
string = multimatch_string
|
||||||
|
|
@ -199,14 +196,7 @@ def at_search_result(msg_obj, ostring, results, global_search=False,
|
||||||
string = _(string)
|
string = _(string)
|
||||||
|
|
||||||
for num, result in enumerate(results):
|
for num, result in enumerate(results):
|
||||||
invtext = ""
|
string += "\n %i-%s%s" % (num + 1, result.name, result.get_extra_info(msg_obj))
|
||||||
dbreftext = ""
|
|
||||||
if hasattr(result, _("location")) and result.location == msg_obj:
|
|
||||||
invtext = _(" (carried)")
|
|
||||||
if show_dbref:
|
|
||||||
dbreftext = "(#%i)" % result.dbid
|
|
||||||
string += "\n %i-%s%s%s" % (num + 1, result.name,
|
|
||||||
dbreftext, invtext)
|
|
||||||
results = None
|
results = None
|
||||||
else:
|
else:
|
||||||
# we have exactly one match.
|
# we have exactly one match.
|
||||||
|
|
@ -292,26 +282,6 @@ def at_multimatch_cmd(caller, matches):
|
||||||
# each match is a tuple (candidate, cmd)
|
# each match is a tuple (candidate, cmd)
|
||||||
cmdname, arg, cmd, dum, dum = match
|
cmdname, arg, cmd, dum, dum = match
|
||||||
|
|
||||||
is_channel = hasattr(cmd, "is_channel") and cmd.is_channel
|
get_extra_info = cmd.get_extra_info(caller)
|
||||||
if is_channel:
|
string += "%s-%s%s" % (num + 1, cmdname, get_extra_info)
|
||||||
is_channel = _(" (channel)")
|
|
||||||
else:
|
|
||||||
is_channel = ""
|
|
||||||
if cmd.is_exit and cmd.destination:
|
|
||||||
is_exit = (" (exit to %s)") % cmd.destination
|
|
||||||
else:
|
|
||||||
is_exit = ""
|
|
||||||
|
|
||||||
id1 = ""
|
|
||||||
id2 = ""
|
|
||||||
if (not (is_channel or is_exit) and
|
|
||||||
(hasattr(cmd, 'obj') and cmd.obj != caller) and
|
|
||||||
hasattr(cmd.obj, "key")):
|
|
||||||
# the command is defined on some other object
|
|
||||||
id1 = "%s-%s" % (num + 1, cmdname)
|
|
||||||
id2 = " (%s)" % (cmd.obj.key)
|
|
||||||
else:
|
|
||||||
id1 = "%s-%s" % (num + 1, cmdname)
|
|
||||||
id2 = ""
|
|
||||||
string += "\n %s%s%s%s" % (id1, id2, is_channel, is_exit)
|
|
||||||
return string
|
return string
|
||||||
|
|
|
||||||
|
|
@ -348,3 +348,15 @@ class Command(object):
|
||||||
string += fill("current cmdset (self.cmdset): {w%s{n\n" % (self.cmdset.key if self.cmdset.key else self.cmdset.__class__))
|
string += fill("current cmdset (self.cmdset): {w%s{n\n" % (self.cmdset.key if self.cmdset.key else self.cmdset.__class__))
|
||||||
|
|
||||||
self.caller.msg(string)
|
self.caller.msg(string)
|
||||||
|
|
||||||
|
def get_extra_info(self, caller, **kwargs):
|
||||||
|
"""
|
||||||
|
Display some extra information that may help distinguish this command from others, for instance,
|
||||||
|
in a disambiguity prompt.
|
||||||
|
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
if hasattr(self, 'obj'):
|
||||||
|
return " (%s)" % self.obj.display_name(caller)
|
||||||
|
return ""
|
||||||
|
|
|
||||||
|
|
@ -138,9 +138,9 @@ class CmdSetObjAlias(MuxCommand):
|
||||||
# no =, so we just list aliases on object.
|
# no =, so we just list aliases on object.
|
||||||
aliases = obj.aliases.all()
|
aliases = obj.aliases.all()
|
||||||
if aliases:
|
if aliases:
|
||||||
caller.msg("Aliases for '%s': %s" % (obj.key, ", ".join(aliases)))
|
caller.msg("Aliases for '%s': %s" % (obj.display_name(caller), ", ".join(aliases)))
|
||||||
else:
|
else:
|
||||||
caller.msg("No aliases exist for '%s'." % obj.key)
|
caller.msg("No aliases exist for '%s'." % obj.display_name(caller))
|
||||||
return
|
return
|
||||||
|
|
||||||
if not obj.access(caller, 'edit'):
|
if not obj.access(caller, 'edit'):
|
||||||
|
|
@ -151,7 +151,7 @@ class CmdSetObjAlias(MuxCommand):
|
||||||
# we have given an empty =, so delete aliases
|
# we have given an empty =, so delete aliases
|
||||||
old_aliases = obj.aliases.all()
|
old_aliases = obj.aliases.all()
|
||||||
if old_aliases:
|
if old_aliases:
|
||||||
caller.msg("Cleared aliases from %s: %s" % (obj.key, ", ".join(old_aliases)))
|
caller.msg("Cleared aliases from %s: %s" % (obj.display_name(caller), ", ".join(old_aliases)))
|
||||||
obj.aliases.clear()
|
obj.aliases.clear()
|
||||||
else:
|
else:
|
||||||
caller.msg("No aliases to clear.")
|
caller.msg("No aliases to clear.")
|
||||||
|
|
@ -175,7 +175,7 @@ class CmdSetObjAlias(MuxCommand):
|
||||||
obj.at_cmdset_get(force_init=True)
|
obj.at_cmdset_get(force_init=True)
|
||||||
|
|
||||||
# report all aliases on the object
|
# report all aliases on the object
|
||||||
caller.msg("Alias(es) for '%s' set to %s." % (obj.key, str(obj.aliases)))
|
caller.msg("Alias(es) for '%s' set to %s." % (obj.display_name(caller), str(obj.aliases)))
|
||||||
|
|
||||||
|
|
||||||
class CmdCopy(ObjManipCommand):
|
class CmdCopy(ObjManipCommand):
|
||||||
|
|
@ -587,7 +587,7 @@ class CmdDesc(MuxCommand):
|
||||||
desc = self.args
|
desc = self.args
|
||||||
|
|
||||||
obj.db.desc = desc
|
obj.db.desc = desc
|
||||||
caller.msg("The description was set on %s." % obj.key)
|
caller.msg("The description was set on %s." % obj.display_name(caller))
|
||||||
|
|
||||||
|
|
||||||
class CmdDestroy(MuxCommand):
|
class CmdDestroy(MuxCommand):
|
||||||
|
|
@ -2085,8 +2085,7 @@ class CmdFind(MuxCommand):
|
||||||
string += "\n {RNo match found for '%s' in #dbref interval.{n" % (searchstring)
|
string += "\n {RNo match found for '%s' in #dbref interval.{n" % (searchstring)
|
||||||
else:
|
else:
|
||||||
result=result[0]
|
result=result[0]
|
||||||
string += "\n{g %s(%s) - %s{n" % (result.key, result.dbref,
|
string += "\n{g %s - %s{n" % (result.display_name(caller), result.path)
|
||||||
result.path)
|
|
||||||
else:
|
else:
|
||||||
# Not a player/dbref search but a wider search; build a queryset.
|
# Not a player/dbref search but a wider search; build a queryset.
|
||||||
# Searchs for key and aliases
|
# Searchs for key and aliases
|
||||||
|
|
@ -2118,10 +2117,10 @@ class CmdFind(MuxCommand):
|
||||||
if nresults > 1:
|
if nresults > 1:
|
||||||
string = "{w%i Matches{n(#%i-#%i%s):" % (nresults, low, high, restrictions)
|
string = "{w%i Matches{n(#%i-#%i%s):" % (nresults, low, high, restrictions)
|
||||||
for res in results:
|
for res in results:
|
||||||
string += "\n {g%s(%s) - %s{n" % (res.key, res.dbref, res.path)
|
string += "\n {g%s - %s{n" % (res.display_name(caller), res.path)
|
||||||
else:
|
else:
|
||||||
string = "{wOne Match{n(#%i-#%i%s):" % (low, high, restrictions)
|
string = "{wOne Match{n(#%i-#%i%s):" % (low, high, restrictions)
|
||||||
string += "\n {g%s(%s) - %s{n" % (results[0].key, results[0].dbref, results[0].path)
|
string += "\n {g%s - %s{n" % (results[0].display_name(caller), results[0].path)
|
||||||
else:
|
else:
|
||||||
string = "{wMatch{n(#%i-#%i%s):" % (low, high, restrictions)
|
string = "{wMatch{n(#%i-#%i%s):" % (low, high, restrictions)
|
||||||
string += "\n {RNo matches found for '%s'{n" % searchstring
|
string += "\n {RNo matches found for '%s'{n" % searchstring
|
||||||
|
|
@ -2279,18 +2278,18 @@ class CmdScript(MuxCommand):
|
||||||
# no rhs means we want to operate on all scripts
|
# no rhs means we want to operate on all scripts
|
||||||
scripts = obj.scripts.all()
|
scripts = obj.scripts.all()
|
||||||
if not scripts:
|
if not scripts:
|
||||||
string += "No scripts defined on %s." % obj.key
|
string += "No scripts defined on %s." % obj.display_name(caller)
|
||||||
elif not self.switches:
|
elif not self.switches:
|
||||||
# view all scripts
|
# view all scripts
|
||||||
from evennia.commands.default.system import format_script_list
|
from evennia.commands.default.system import format_script_list
|
||||||
string += format_script_list(scripts)
|
string += format_script_list(scripts)
|
||||||
elif "start" in self.switches:
|
elif "start" in self.switches:
|
||||||
num = sum([obj.scripts.start(script.key) for script in scripts])
|
num = sum([obj.scripts.start(script.key) for script in scripts])
|
||||||
string += "%s scripts started on %s." % (num, obj.key)
|
string += "%s scripts started on %s." % (num, obj.display_name(caller))
|
||||||
elif "stop" in self.switches:
|
elif "stop" in self.switches:
|
||||||
for script in scripts:
|
for script in scripts:
|
||||||
string += "Stopping script %s on %s." % (script.key,
|
string += "Stopping script %s on %s." % (script.display_name(caller),
|
||||||
obj.key)
|
obj.display_name(caller))
|
||||||
script.stop()
|
script.stop()
|
||||||
string = string.strip()
|
string = string.strip()
|
||||||
obj.scripts.validate()
|
obj.scripts.validate()
|
||||||
|
|
@ -2299,9 +2298,13 @@ class CmdScript(MuxCommand):
|
||||||
# adding a new script, and starting it
|
# adding a new script, and starting it
|
||||||
ok = obj.scripts.add(self.rhs, autostart=True)
|
ok = obj.scripts.add(self.rhs, autostart=True)
|
||||||
if not ok:
|
if not ok:
|
||||||
string += "\nScript %s could not be added and/or started on %s." % (self.rhs, obj.key)
|
string += "\nScript %s could not be added and/or started on %s." % (
|
||||||
|
self.rhs, obj.display_name(caller)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
string = "Script {w%s{n successfully added and started on %s." % (self.rhs, obj.key)
|
string = "Script {w%s{n successfully added and started on %s." % (
|
||||||
|
self.rhs, obj.display_name(caller)
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
paths = [self.rhs] + ["%s.%s" % (prefix, self.rhs)
|
paths = [self.rhs] + ["%s.%s" % (prefix, self.rhs)
|
||||||
|
|
@ -2371,7 +2374,7 @@ class CmdTag(MuxCommand):
|
||||||
if nobjs > 0:
|
if nobjs > 0:
|
||||||
catstr = " (category: '{w%s{n')" % category if category else \
|
catstr = " (category: '{w%s{n')" % category if category else \
|
||||||
("" if nobjs == 1 else " (may have different tag categories)")
|
("" if nobjs == 1 else " (may have different tag categories)")
|
||||||
matchstr = ", ".join("{w%s{n(#%i)" % (o.key, o.dbid) for o in objs)
|
matchstr = ", ".join(o.display_name(self.caller) for o in objs)
|
||||||
|
|
||||||
string = "Found {w%i{n object%s with tag '{w%s{n'%s:\n %s" % (nobjs,
|
string = "Found {w%i{n object%s with tag '{w%s{n'%s:\n %s" % (nobjs,
|
||||||
"s" if nobjs > 1 else "",
|
"s" if nobjs > 1 else "",
|
||||||
|
|
@ -2525,6 +2528,6 @@ class CmdSpawn(MuxCommand):
|
||||||
prototype["location"] = self.caller.location
|
prototype["location"] = self.caller.location
|
||||||
|
|
||||||
for obj in spawn(prototype):
|
for obj in spawn(prototype):
|
||||||
self.caller.msg("Spawned %s." % obj.key)
|
self.caller.msg("Spawned %s." % obj.display_name(self.caller))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,12 @@ class ChannelCommand(command.Command):
|
||||||
return
|
return
|
||||||
channel.msg(msg, senders=self.caller, online=True)
|
channel.msg(msg, senders=self.caller, online=True)
|
||||||
|
|
||||||
|
def get_extra_info(self, caller, **kwargs):
|
||||||
|
"""
|
||||||
|
Let users know that this exit is for communicating on a channel.
|
||||||
|
"""
|
||||||
|
return _(" (channel)")
|
||||||
|
|
||||||
|
|
||||||
class ChannelHandler(object):
|
class ChannelHandler(object):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1476,6 +1476,15 @@ class ExitCommand(command.Command):
|
||||||
# No shorthand error message. Call hook.
|
# No shorthand error message. Call hook.
|
||||||
self.obj.at_failed_traverse(self.caller)
|
self.obj.at_failed_traverse(self.caller)
|
||||||
|
|
||||||
|
def get_extra_info(self, caller, **kwargs):
|
||||||
|
"""
|
||||||
|
Shows a bit of information on where the exit leads.
|
||||||
|
"""
|
||||||
|
if self.obj.destination:
|
||||||
|
return " (exit to %s)" % self.obj.destination.display_name(caller)
|
||||||
|
else:
|
||||||
|
return " (%s)" % self.obj.display_name(caller)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Base Exit object
|
# Base Exit object
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -610,3 +610,28 @@ class TypedObject(SharedMemoryModel):
|
||||||
raise Exception("Cannot delete the ndb object!")
|
raise Exception("Cannot delete the ndb object!")
|
||||||
ndb = property(__ndb_get, __ndb_set, __ndb_del)
|
ndb = property(__ndb_get, __ndb_set, __ndb_del)
|
||||||
|
|
||||||
|
def 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.
|
||||||
|
"""
|
||||||
|
if self.access(looker, access_type='controls'):
|
||||||
|
return "{}(#{})".format(self.name, self.id)
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
def get_extra_info(self, viewer, **kwargs):
|
||||||
|
"""
|
||||||
|
Used when an object is in a list of ambiguous objects as an additional
|
||||||
|
information tag.
|
||||||
|
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if self.location == viewer:
|
||||||
|
return " (carried)"
|
||||||
|
return ""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue