Added /edit switch to CmdDesc.

This commit is contained in:
Jonathan Piacenti 2015-03-26 17:10:19 -05:00
parent 89a39a8481
commit b0c71ee924

View file

@ -515,26 +515,68 @@ class CmdDesc(MuxCommand):
""" """
describe an object describe an object
Usage: Usage 1:
@desc [<obj> =] >description> @desc [<obj> =] >description>
Setts the "desc" attribute on an Sets the "desc" attribute on an
object. If an object is not given, object. If an object is not given,
describe the current room. describe the current room.
Usage 2:
@desc/edit [obj]
Opens up a line editor to set the "desc"
attribute on an object for advanced editing.
""" """
key = "@desc" key = "@desc"
aliases = "@describe" aliases = "@describe"
locks = "cmd:perm(desc) or perm(Builders)" locks = "cmd:perm(desc) or perm(Builders)"
help_category = "Building" help_category = "Building"
def edit_handler(self):
if self.rhs:
self.msg("{rYou may specify a description, or use the edit switch, "
"but not both.{n")
return
if self.args:
obj = self.caller.search(self.args)
else:
obj = self.caller.location or self.msg("{rYou can't describe oblivion.{n")
if not obj:
return
def load():
return obj.db.desc or ""
def save():
"""
Save line buffer to the desc prop. This should
return True if successful and also report its status to the user.
"""
obj.db.desc = self.editor.buffer
self.caller.msg("Saved.")
return True
self.editor = utils.get_line_editor()(
self.caller,
loadfunc=load,
savefunc=save,
key="desc",
)
return
def func(self): def func(self):
"Define command" "Define command"
caller = self.caller caller = self.caller
if not self.args: if not self.args and 'edit' not in self.switches:
caller.msg("Usage: @desc [<obj> =] >description>") caller.msg("Usage: @desc [<obj> =] >description>")
return return
if 'edit' in self.switches:
self.edit_handler()
return
if self.rhs: if self.rhs:
# We have an = # We have an =
obj = caller.search(self.lhs) obj = caller.search(self.lhs)
@ -542,9 +584,11 @@ class CmdDesc(MuxCommand):
return return
desc = self.rhs desc = self.rhs
else: else:
obj = caller.location obj = caller.location or self.msg("{rYou can't describe oblivion.{n")
if not obj:
return
desc = self.args desc = self.args
# storing the description
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.key)