Fixed headers on contribs, they were still referring to the old base*.py -style files under gamesrc.
This commit is contained in:
parent
ad63abee39
commit
ca32950d90
4 changed files with 159 additions and 147 deletions
|
|
@ -14,15 +14,20 @@ while puppeting a Character already before.
|
||||||
|
|
||||||
Installation:
|
Installation:
|
||||||
|
|
||||||
Import this module in game.gamesrc.basecmdset and
|
Read the instructions in game/gamesrc/commands/examples/cmdset.py in
|
||||||
add the following line to the end of OOCCmdSet's at_cmdset_creation():
|
order to create a new default cmdset module for Evennia to use (copy
|
||||||
|
the template up one level, and change the settings file's relevant
|
||||||
self.add(chargen.OOCCmdSetCharGen)
|
variables to point to the cmdsets inside). If you already have such
|
||||||
|
a module you should of course use that.
|
||||||
|
|
||||||
|
Next import this module in your custom cmdset module and add the
|
||||||
|
following line to the end of OOCCmdSet's at_cmdset_creation():
|
||||||
|
|
||||||
|
self.add(chargen.OOCCmdSetCharGen)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from ev import Command, create_object, utils
|
from ev import Command, create_object, utils
|
||||||
from ev import default_cmds, db_objects
|
from ev import default_cmds, db_objects
|
||||||
|
|
||||||
|
|
@ -58,45 +63,45 @@ class CmdOOCLook(default_cmds.CmdLook):
|
||||||
is that only the CmdCharacterCreate command adds this attribute,
|
is that only the CmdCharacterCreate command adds this attribute,
|
||||||
and thus e.g. player #1 will not be listed (although it will work).
|
and thus e.g. player #1 will not be listed (although it will work).
|
||||||
Existence in this list does not depend on puppeting rights though,
|
Existence in this list does not depend on puppeting rights though,
|
||||||
that is checked by the @ic command directly.
|
that is checked by the @ic command directly.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# making sure caller is really a player
|
# making sure caller is really a player
|
||||||
self.character = None
|
self.character = None
|
||||||
if utils.inherits_from(self.caller, "src.objects.objects.Object"):
|
if utils.inherits_from(self.caller, "src.objects.objects.Object"):
|
||||||
# An object of some type is calling. Convert to player.
|
# An object of some type is calling. Convert to player.
|
||||||
#print self.caller, self.caller.__class__
|
#print self.caller, self.caller.__class__
|
||||||
self.character = self.caller
|
self.character = self.caller
|
||||||
if hasattr(self.caller, "player"):
|
if hasattr(self.caller, "player"):
|
||||||
self.caller = self.caller.player
|
self.caller = self.caller.player
|
||||||
|
|
||||||
if not self.character:
|
if not self.character:
|
||||||
# ooc mode, we are players
|
# ooc mode, we are players
|
||||||
|
|
||||||
avail_chars = self.caller.db._character_dbrefs
|
avail_chars = self.caller.db._character_dbrefs
|
||||||
if self.args:
|
if self.args:
|
||||||
# Maybe the caller wants to look at a character
|
# Maybe the caller wants to look at a character
|
||||||
if not avail_chars:
|
if not avail_chars:
|
||||||
self.caller.msg("You have no characters to look at. Why not create one?")
|
self.caller.msg("You have no characters to look at. Why not create one?")
|
||||||
return
|
return
|
||||||
objs = db_objects.get_objs_with_key_and_typeclass(self.args.strip(), CHARACTER_TYPECLASS)
|
objs = db_objects.get_objs_with_key_and_typeclass(self.args.strip(), CHARACTER_TYPECLASS)
|
||||||
objs = [obj for obj in objs if obj.id in avail_chars]
|
objs = [obj for obj in objs if obj.id in avail_chars]
|
||||||
if not objs:
|
if not objs:
|
||||||
self.caller.msg("You cannot see this Character.")
|
self.caller.msg("You cannot see this Character.")
|
||||||
return
|
return
|
||||||
self.caller.msg(objs[0].return_appearance(self.caller))
|
self.caller.msg(objs[0].return_appearance(self.caller))
|
||||||
return
|
return
|
||||||
|
|
||||||
# not inspecting a character. Show the OOC info.
|
# not inspecting a character. Show the OOC info.
|
||||||
charobjs = []
|
charobjs = []
|
||||||
charnames = []
|
charnames = []
|
||||||
if self.caller.db._character_dbrefs:
|
if self.caller.db._character_dbrefs:
|
||||||
dbrefs = self.caller.db._character_dbrefs
|
dbrefs = self.caller.db._character_dbrefs
|
||||||
charobjs = [db_objects.get_id(dbref) for dbref in dbrefs]
|
charobjs = [db_objects.get_id(dbref) for dbref in dbrefs]
|
||||||
charnames = [charobj.key for charobj in charobjs if charobj]
|
charnames = [charobj.key for charobj in charobjs if charobj]
|
||||||
if charnames:
|
if charnames:
|
||||||
charlist = "The following Character(s) are available:\n\n"
|
charlist = "The following Character(s) are available:\n\n"
|
||||||
charlist += "\n\r".join(["{w %s{n" % charname for charname in charnames])
|
charlist += "\n\r".join(["{w %s{n" % charname for charname in charnames])
|
||||||
charlist += "\n\n Use {w@ic <character name>{n to switch to that Character."
|
charlist += "\n\n Use {w@ic <character name>{n to switch to that Character."
|
||||||
else:
|
else:
|
||||||
charlist = "You have no Characters."
|
charlist = "You have no Characters."
|
||||||
|
|
@ -112,7 +117,7 @@ class CmdOOCLook(default_cmds.CmdLook):
|
||||||
self.caller.msg(string)
|
self.caller.msg(string)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# not ooc mode - leave back to normal look
|
# not ooc mode - leave back to normal look
|
||||||
self.caller = self.character # we have to put this back for normal look to work.
|
self.caller = self.character # we have to put this back for normal look to work.
|
||||||
super(CmdOOCLook, self).func()
|
super(CmdOOCLook, self).func()
|
||||||
|
|
||||||
|
|
@ -120,11 +125,11 @@ class CmdOOCCharacterCreate(Command):
|
||||||
"""
|
"""
|
||||||
creates a character
|
creates a character
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
create <character name>
|
create <character name>
|
||||||
|
|
||||||
This will create a new character, assuming
|
This will create a new character, assuming
|
||||||
the given character name does not already exist.
|
the given character name does not already exist.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = "create"
|
key = "create"
|
||||||
|
|
@ -133,34 +138,34 @@ class CmdOOCCharacterCreate(Command):
|
||||||
def func(self):
|
def func(self):
|
||||||
"""
|
"""
|
||||||
Tries to create the Character object. We also put an
|
Tries to create the Character object. We also put an
|
||||||
attribute on ourselves to remember it.
|
attribute on ourselves to remember it.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# making sure caller is really a player
|
# making sure caller is really a player
|
||||||
self.character = None
|
self.character = None
|
||||||
if utils.inherits_from(self.caller, "src.objects.objects.Object"):
|
if utils.inherits_from(self.caller, "src.objects.objects.Object"):
|
||||||
# An object of some type is calling. Convert to player.
|
# An object of some type is calling. Convert to player.
|
||||||
#print self.caller, self.caller.__class__
|
#print self.caller, self.caller.__class__
|
||||||
self.character = self.caller
|
self.character = self.caller
|
||||||
if hasattr(self.caller, "player"):
|
if hasattr(self.caller, "player"):
|
||||||
self.caller = self.caller.player
|
self.caller = self.caller.player
|
||||||
|
|
||||||
if not self.args:
|
if not self.args:
|
||||||
self.caller.msg("Usage: create <character name>")
|
self.caller.msg("Usage: create <character name>")
|
||||||
return
|
return
|
||||||
charname = self.args.strip()
|
charname = self.args.strip()
|
||||||
old_char = db_objects.get_objs_with_key_and_typeclass(charname, CHARACTER_TYPECLASS)
|
old_char = db_objects.get_objs_with_key_and_typeclass(charname, CHARACTER_TYPECLASS)
|
||||||
if old_char:
|
if old_char:
|
||||||
self.caller.msg("Character {c%s{n already exists." % charname)
|
self.caller.msg("Character {c%s{n already exists." % charname)
|
||||||
return
|
return
|
||||||
# create the character
|
# create the character
|
||||||
|
|
||||||
new_character = create_object(CHARACTER_TYPECLASS, key=charname)
|
new_character = create_object(CHARACTER_TYPECLASS, key=charname)
|
||||||
if not new_character:
|
if not new_character:
|
||||||
self.caller.msg("{rThe Character couldn't be created. This is a bug. Please contact an admin.")
|
self.caller.msg("{rThe Character couldn't be created. This is a bug. Please contact an admin.")
|
||||||
return
|
return
|
||||||
# make sure to lock the character to only be puppeted by this player
|
# make sure to lock the character to only be puppeted by this player
|
||||||
new_character.locks.add("puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)" %
|
new_character.locks.add("puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)" %
|
||||||
(new_character.id, self.caller.id))
|
(new_character.id, self.caller.id))
|
||||||
|
|
||||||
# save dbref
|
# save dbref
|
||||||
|
|
@ -171,15 +176,14 @@ class CmdOOCCharacterCreate(Command):
|
||||||
avail_chars = [new_character.id]
|
avail_chars = [new_character.id]
|
||||||
self.caller.db._character_dbrefs = avail_chars
|
self.caller.db._character_dbrefs = avail_chars
|
||||||
|
|
||||||
self.caller.msg("{gThe Character {c%s{g was successfully created!" % charname)
|
self.caller.msg("{gThe Character {c%s{g was successfully created!" % charname)
|
||||||
|
|
||||||
class OOCCmdSetCharGen(default_cmds.OOCCmdSet):
|
class OOCCmdSetCharGen(default_cmds.OOCCmdSet):
|
||||||
"""
|
"""
|
||||||
Extends the default OOC cmdset.
|
Extends the default OOC cmdset.
|
||||||
"""
|
"""
|
||||||
def at_cmdset_creation(self):
|
def at_cmdset_creation(self):
|
||||||
"Install everything from the default set, then overload"
|
"Install everything from the default set, then overload"
|
||||||
#super(OOCCmdSetCharGen, self).at_cmdset_creation()
|
#super(OOCCmdSetCharGen, self).at_cmdset_creation()
|
||||||
self.add(CmdOOCLook())
|
self.add(CmdOOCLook())
|
||||||
self.add(CmdOOCCharacterCreate())
|
self.add(CmdOOCCharacterCreate())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,9 @@ That's it. The cmdset in this module will now be used instead of the
|
||||||
default one.
|
default one.
|
||||||
|
|
||||||
The initial login "graphic" is taken from strings in the module given
|
The initial login "graphic" is taken from strings in the module given
|
||||||
by settings.CONNECTION_SCREEN_MODULE. You will want to edit the string
|
by settings.CONNECTION_SCREEN_MODULE. You will want to copy the
|
||||||
|
template file in game/gamesrc/conf/examples up one level and re-point
|
||||||
|
the settings file to this custom module. you can then edit the string
|
||||||
in that module (at least comment out the default string that mentions
|
in that module (at least comment out the default string that mentions
|
||||||
commands that are not available) and add something more suitable for
|
commands that are not available) and add something more suitable for
|
||||||
the initial splash screen.
|
the initial splash screen.
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
"""
|
"""
|
||||||
Evennia menu system.
|
Evennia menu system.
|
||||||
|
|
||||||
Contribution - Griatch 2011
|
Contribution - Griatch 2011
|
||||||
|
|
||||||
This module offers the ability for admins to let their game be fully
|
This module offers the ability for admins to let their game be fully
|
||||||
or partly menu-driven. Menu choices can be numbered or use arbitrary
|
or partly menu-driven. Menu choices can be numbered or use arbitrary
|
||||||
keys. There are also some formatting options, such a putting options
|
keys. There are also some formatting options, such a putting options
|
||||||
in one or more collumns.
|
in one or more collumns.
|
||||||
|
|
||||||
The menu system consists of a MenuTree object populated by MenuNode
|
The menu system consists of a MenuTree object populated by MenuNode
|
||||||
objects. Nodes are linked together with automatically created commands
|
objects. Nodes are linked together with automatically created commands
|
||||||
|
|
@ -18,12 +18,16 @@ There is also a simple Yes/No function supplied. This will create a
|
||||||
one-off Yes/No question and executes a given code depending on which
|
one-off Yes/No question and executes a given code depending on which
|
||||||
choice was made.
|
choice was made.
|
||||||
|
|
||||||
To test, import and add the CmdTestMenu command to the end of the default cmdset in
|
To test, make sure to follow the instructions in
|
||||||
game.gamesrc.commands.basecmdset. The test command is also a good
|
game/gamesrc/commands/examples/cmdset.py (copy the template up one level
|
||||||
example of how to use this module in code.
|
and change settings to point to the relevant cmdsets within). If you
|
||||||
|
already have such a module, you can of course use that. Next you
|
||||||
|
import and add the CmdTestMenu command to the end of the default cmdset in
|
||||||
|
this custom module.
|
||||||
|
The test command is also a good example of how to use this module in code.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from ev import syscmdkeys
|
from ev import syscmdkeys
|
||||||
|
|
||||||
from ev import Command, CmdSet, utils
|
from ev import Command, CmdSet, utils
|
||||||
from ev import default_cmds
|
from ev import default_cmds
|
||||||
|
|
@ -36,20 +40,20 @@ CMD_NOINPUT = syscmdkeys.CMD_NOINPUT
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Commands used by the Menu system
|
# Commands used by the Menu system
|
||||||
#
|
#
|
||||||
|
|
||||||
class CmdMenuNode(Command):
|
class CmdMenuNode(Command):
|
||||||
"""
|
"""
|
||||||
Parent for menu selection commands.
|
Parent for menu selection commands.
|
||||||
"""
|
"""
|
||||||
key = "selection"
|
key = "selection"
|
||||||
aliases = []
|
aliases = []
|
||||||
locks = "cmd:all()"
|
locks = "cmd:all()"
|
||||||
help_category = "Menu"
|
help_category = "Menu"
|
||||||
|
|
||||||
menutree = None
|
menutree = None
|
||||||
code = None
|
code = None
|
||||||
|
|
||||||
def func(self):
|
def func(self):
|
||||||
"Execute a selection"
|
"Execute a selection"
|
||||||
|
|
@ -80,57 +84,57 @@ class CmdMenuLook(default_cmds.CmdLook):
|
||||||
def func(self):
|
def func(self):
|
||||||
"implement the menu look command"
|
"implement the menu look command"
|
||||||
if self.caller.db._menu_data:
|
if self.caller.db._menu_data:
|
||||||
# if we have menu data, try to use that.
|
# if we have menu data, try to use that.
|
||||||
lookstring = self.caller.db._menu_data.get("look", None)
|
lookstring = self.caller.db._menu_data.get("look", None)
|
||||||
if lookstring:
|
if lookstring:
|
||||||
self.caller.msg(lookstring)
|
self.caller.msg(lookstring)
|
||||||
return
|
return
|
||||||
# otherwise we use normal look
|
# otherwise we use normal look
|
||||||
super(CmdMenuLook, self).func()
|
super(CmdMenuLook, self).func()
|
||||||
|
|
||||||
class CmdMenuHelp(default_cmds.CmdHelp):
|
class CmdMenuHelp(default_cmds.CmdHelp):
|
||||||
"""
|
"""
|
||||||
help
|
help
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
help
|
help
|
||||||
|
|
||||||
Get help specific to the menu, if available. If not,
|
Get help specific to the menu, if available. If not,
|
||||||
works like the normal help command.
|
works like the normal help command.
|
||||||
"""
|
"""
|
||||||
key = "help"
|
key = "help"
|
||||||
aliases = "h"
|
aliases = "h"
|
||||||
locks = "cmd:all()"
|
locks = "cmd:all()"
|
||||||
help_category = "Menu"
|
help_category = "Menu"
|
||||||
|
|
||||||
def func(self):
|
def func(self):
|
||||||
"implement the menu help command"
|
"implement the menu help command"
|
||||||
if self.caller.db._menu_data:
|
if self.caller.db._menu_data:
|
||||||
# if we have menu data, try to use that.
|
# if we have menu data, try to use that.
|
||||||
lookstring = self.caller.db._menu_data.get("help", None)
|
lookstring = self.caller.db._menu_data.get("help", None)
|
||||||
if lookstring:
|
if lookstring:
|
||||||
self.caller.msg(lookstring)
|
self.caller.msg(lookstring)
|
||||||
return
|
return
|
||||||
# otherwise we use normal help
|
# otherwise we use normal help
|
||||||
super(CmdMenuHelp, self).func()
|
super(CmdMenuHelp, self).func()
|
||||||
|
|
||||||
class MenuCmdSet(CmdSet):
|
class MenuCmdSet(CmdSet):
|
||||||
"""
|
"""
|
||||||
Cmdset for the menu. Will replace all other commands.
|
Cmdset for the menu. Will replace all other commands.
|
||||||
This always has a few basic commands available.
|
This always has a few basic commands available.
|
||||||
|
|
||||||
Note that you must always supply a way to exit the
|
Note that you must always supply a way to exit the
|
||||||
cmdset manually!
|
cmdset manually!
|
||||||
"""
|
"""
|
||||||
key = "menucmdset"
|
key = "menucmdset"
|
||||||
priority = 1
|
priority = 1
|
||||||
mergetype = "Replace"
|
mergetype = "Replace"
|
||||||
def at_cmdset_creation(self):
|
def at_cmdset_creation(self):
|
||||||
"populate cmdset"
|
"populate cmdset"
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#
|
#
|
||||||
# Menu Node system
|
# Menu Node system
|
||||||
#
|
#
|
||||||
|
|
||||||
class MenuTree(object):
|
class MenuTree(object):
|
||||||
|
|
@ -146,7 +150,7 @@ class MenuTree(object):
|
||||||
upon first entering the menu. The endnode need not actually
|
upon first entering the menu. The endnode need not actually
|
||||||
exist, the moment it is linked to and that link is used, the menu
|
exist, the moment it is linked to and that link is used, the menu
|
||||||
will be exited and cleanups run. The default keys for these are
|
will be exited and cleanups run. The default keys for these are
|
||||||
'START' and 'END' respectively.
|
'START' and 'END' respectively.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, caller, nodes=None, startnode="START", endnode="END", exec_end="look"):
|
def __init__(self, caller, nodes=None, startnode="START", endnode="END", exec_end="look"):
|
||||||
|
|
@ -154,15 +158,15 @@ class MenuTree(object):
|
||||||
We specify startnode/endnode so that the system knows where to
|
We specify startnode/endnode so that the system knows where to
|
||||||
enter and where to exit the menu tree. If nodes is given, it
|
enter and where to exit the menu tree. If nodes is given, it
|
||||||
shuld be a list of valid node objects to add to the tree.
|
shuld be a list of valid node objects to add to the tree.
|
||||||
|
|
||||||
exec_end - if not None, will execute the given command string
|
exec_end - if not None, will execute the given command string
|
||||||
directly after the menu system has been exited.
|
directly after the menu system has been exited.
|
||||||
"""
|
"""
|
||||||
self.tree = {}
|
self.tree = {}
|
||||||
self.startnode = startnode
|
self.startnode = startnode
|
||||||
self.endnode = endnode
|
self.endnode = endnode
|
||||||
self.exec_end = exec_end
|
self.exec_end = exec_end
|
||||||
self.caller = caller
|
self.caller = caller
|
||||||
if nodes and utils.is_iter(nodes):
|
if nodes and utils.is_iter(nodes):
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
self.add(node)
|
self.add(node)
|
||||||
|
|
@ -179,7 +183,7 @@ class MenuTree(object):
|
||||||
track of which nodes it is connected to.
|
track of which nodes it is connected to.
|
||||||
"""
|
"""
|
||||||
menunode.init(self)
|
menunode.init(self)
|
||||||
self.tree[menunode.key] = menunode
|
self.tree[menunode.key] = menunode
|
||||||
|
|
||||||
def goto(self, key):
|
def goto(self, key):
|
||||||
"""
|
"""
|
||||||
|
|
@ -192,23 +196,23 @@ class MenuTree(object):
|
||||||
del self.caller.db._menu_data
|
del self.caller.db._menu_data
|
||||||
if self.exec_end != None:
|
if self.exec_end != None:
|
||||||
self.caller.execute_cmd(self.exec_end)
|
self.caller.execute_cmd(self.exec_end)
|
||||||
return
|
return
|
||||||
# not exiting, look for a valid code.
|
# not exiting, look for a valid code.
|
||||||
node = self.tree.get(key, None)
|
node = self.tree.get(key, None)
|
||||||
if node:
|
if node:
|
||||||
if node.code:
|
if node.code:
|
||||||
# Execute eventual code active on this
|
# Execute eventual code active on this
|
||||||
# node. self.caller is available at this point.
|
# node. self.caller is available at this point.
|
||||||
try:
|
try:
|
||||||
exec(node.code)
|
exec(node.code)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.caller.msg("{rCode could not be executed for node %s. Continuing anyway.{n" % key)
|
self.caller.msg("{rCode could not be executed for node %s. Continuing anyway.{n" % key)
|
||||||
# clean old menu cmdset and replace with the new one
|
# clean old menu cmdset and replace with the new one
|
||||||
self.caller.cmdset.delete("menucmdset")
|
self.caller.cmdset.delete("menucmdset")
|
||||||
self.caller.cmdset.add(node.cmdset)
|
self.caller.cmdset.add(node.cmdset)
|
||||||
# set the menu flag data for the default commands
|
# set the menu flag data for the default commands
|
||||||
self.caller.db._menu_data = {"help":node.helptext, "look":str(node.text)}
|
self.caller.db._menu_data = {"help":node.helptext, "look":str(node.text)}
|
||||||
# display the node
|
# display the node
|
||||||
self.caller.msg(node.text)
|
self.caller.msg(node.text)
|
||||||
else:
|
else:
|
||||||
self.caller.msg("{rMenu node '%s' does not exist - maybe it's not created yet..{n" % key)
|
self.caller.msg("{rMenu node '%s' does not exist - maybe it's not created yet..{n" % key)
|
||||||
|
|
@ -221,29 +225,29 @@ class MenuNode(object):
|
||||||
commands are created automatically)
|
commands are created automatically)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, key, text="", links=None, linktexts=None,
|
def __init__(self, key, text="", links=None, linktexts=None,
|
||||||
keywords=None, cols=1, helptext=None, selectcmds=None, code="", nodefaultcmds=False, separator=""):
|
keywords=None, cols=1, helptext=None, selectcmds=None, code="", nodefaultcmds=False, separator=""):
|
||||||
"""
|
"""
|
||||||
key - the unique identifier of this node.
|
key - the unique identifier of this node.
|
||||||
text - is the text that will be displayed at top when viewing this node.
|
text - is the text that will be displayed at top when viewing this node.
|
||||||
links - a list of keys for unique menunodes this is connected to. The actual keys will not be
|
links - a list of keys for unique menunodes this is connected to. The actual keys will not be
|
||||||
printed - keywords will be used (or a number)
|
printed - keywords will be used (or a number)
|
||||||
linktexts - an optional list of texts to describe the links. Must match link list if defined. Entries can be None
|
linktexts - an optional list of texts to describe the links. Must match link list if defined. Entries can be None
|
||||||
to not generate any extra text for a particular link.
|
to not generate any extra text for a particular link.
|
||||||
keywords - an optional list of unique keys for choosing links. Must match links list. If not given, index numbers
|
keywords - an optional list of unique keys for choosing links. Must match links list. If not given, index numbers
|
||||||
will be used. Also individual list entries can be None and will be replaed by indices.
|
will be used. Also individual list entries can be None and will be replaed by indices.
|
||||||
If CMD_NOMATCH or CMD_NOENTRY, no text will be generated to indicate the option exists.
|
If CMD_NOMATCH or CMD_NOENTRY, no text will be generated to indicate the option exists.
|
||||||
cols - how many columns to use for displaying options.
|
cols - how many columns to use for displaying options.
|
||||||
helptext - if defined, this is shown when using the help command instead of the normal help index.
|
helptext - if defined, this is shown when using the help command instead of the normal help index.
|
||||||
selectcmds- a list of custom cmdclasses for handling each option. Must match links list, but some entries
|
selectcmds- a list of custom cmdclasses for handling each option. Must match links list, but some entries
|
||||||
may be set to None to use default menu cmds. The given command's key will be used for the menu
|
may be set to None to use default menu cmds. The given command's key will be used for the menu
|
||||||
list entry unless it's CMD_NOMATCH or CMD_NOENTRY, in which case no text will be generated. These
|
list entry unless it's CMD_NOMATCH or CMD_NOENTRY, in which case no text will be generated. These
|
||||||
commands have access to self.menutree and so can be used to select nodes.
|
commands have access to self.menutree and so can be used to select nodes.
|
||||||
code - functional code. This will be executed just before this node is loaded (i.e.
|
code - functional code. This will be executed just before this node is loaded (i.e.
|
||||||
as soon after it's been selected from another node). self.caller is available
|
as soon after it's been selected from another node). self.caller is available
|
||||||
to call from this code block, as well as ev.
|
to call from this code block, as well as ev.
|
||||||
nodefaultcmds - if true, don't offer the default help and look commands in the node
|
nodefaultcmds - if true, don't offer the default help and look commands in the node
|
||||||
separator - this string will be put on the line between menu nodes5B.
|
separator - this string will be put on the line between menu nodes5B.
|
||||||
"""
|
"""
|
||||||
self.key = key
|
self.key = key
|
||||||
self.cmdset = None
|
self.cmdset = None
|
||||||
|
|
@ -256,8 +260,8 @@ class MenuNode(object):
|
||||||
self.nodefaultcmds = nodefaultcmds
|
self.nodefaultcmds = nodefaultcmds
|
||||||
self.separator = separator
|
self.separator = separator
|
||||||
Nlinks = len(self.links)
|
Nlinks = len(self.links)
|
||||||
|
|
||||||
# validate the input
|
# validate the input
|
||||||
if not self.links:
|
if not self.links:
|
||||||
self.links = []
|
self.links = []
|
||||||
if not self.linktexts or (len(self.linktexts) != Nlinks):
|
if not self.linktexts or (len(self.linktexts) != Nlinks):
|
||||||
|
|
@ -267,19 +271,19 @@ class MenuNode(object):
|
||||||
if not selectcmds or (len(self.selectcmds) != Nlinks):
|
if not selectcmds or (len(self.selectcmds) != Nlinks):
|
||||||
self.selectcmds = [None for i in range(Nlinks)]
|
self.selectcmds = [None for i in range(Nlinks)]
|
||||||
|
|
||||||
# Format default text for the menu-help command
|
# Format default text for the menu-help command
|
||||||
if not helptext:
|
if not helptext:
|
||||||
helptext = "Select one of the valid options ("
|
helptext = "Select one of the valid options ("
|
||||||
for i in range(Nlinks):
|
for i in range(Nlinks):
|
||||||
if self.keywords[i]:
|
if self.keywords[i]:
|
||||||
if self.keywords[i] not in (CMD_NOMATCH, CMD_NOINPUT):
|
if self.keywords[i] not in (CMD_NOMATCH, CMD_NOINPUT):
|
||||||
helptext += "%s, " % self.keywords[i]
|
helptext += "%s, " % self.keywords[i]
|
||||||
else:
|
else:
|
||||||
helptext += "%s, " % (i + 1)
|
helptext += "%s, " % (i + 1)
|
||||||
helptext = helptext.rstrip(", ") + ")"
|
helptext = helptext.rstrip(", ") + ")"
|
||||||
self.helptext = helptext
|
self.helptext = helptext
|
||||||
|
|
||||||
# Format text display
|
# Format text display
|
||||||
string = ""
|
string = ""
|
||||||
if text:
|
if text:
|
||||||
string += "%s\n" % text
|
string += "%s\n" % text
|
||||||
|
|
@ -292,7 +296,7 @@ class MenuNode(object):
|
||||||
if self.keywords[ilink] not in (CMD_NOMATCH, CMD_NOINPUT):
|
if self.keywords[ilink] not in (CMD_NOMATCH, CMD_NOINPUT):
|
||||||
choice += "{g%s{n" % self.keywords[ilink]
|
choice += "{g%s{n" % self.keywords[ilink]
|
||||||
else:
|
else:
|
||||||
choice += "{g %i{n" % (ilink + 1)
|
choice += "{g %i{n" % (ilink + 1)
|
||||||
if self.linktexts[ilink]:
|
if self.linktexts[ilink]:
|
||||||
choice += " - %s" % self.linktexts[ilink]
|
choice += " - %s" % self.linktexts[ilink]
|
||||||
choices.append(choice)
|
choices.append(choice)
|
||||||
|
|
@ -304,33 +308,33 @@ class MenuNode(object):
|
||||||
else:
|
else:
|
||||||
cols[i].append(choices.pop(0))
|
cols[i].append(choices.pop(0))
|
||||||
if not choices:
|
if not choices:
|
||||||
break
|
break
|
||||||
ftable = utils.format_table(cols)
|
ftable = utils.format_table(cols)
|
||||||
for row in ftable:
|
for row in ftable:
|
||||||
string +="\n" + "".join(row)
|
string +="\n" + "".join(row)
|
||||||
# store text
|
# store text
|
||||||
self.text = self.separator + "\n" + string.rstrip()
|
self.text = self.separator + "\n" + string.rstrip()
|
||||||
|
|
||||||
def init(self, menutree):
|
def init(self, menutree):
|
||||||
"""
|
"""
|
||||||
Called by menu tree. Initializes the commands needed by the menutree structure.
|
Called by menu tree. Initializes the commands needed by the menutree structure.
|
||||||
"""
|
"""
|
||||||
# Create the relevant cmdset
|
# Create the relevant cmdset
|
||||||
self.cmdset = MenuCmdSet()
|
self.cmdset = MenuCmdSet()
|
||||||
if not self.nodefaultcmds:
|
if not self.nodefaultcmds:
|
||||||
# add default menu commands
|
# add default menu commands
|
||||||
self.cmdset.add(CmdMenuLook())
|
self.cmdset.add(CmdMenuLook())
|
||||||
self.cmdset.add(CmdMenuHelp())
|
self.cmdset.add(CmdMenuHelp())
|
||||||
|
|
||||||
for i, link in enumerate(self.links):
|
for i, link in enumerate(self.links):
|
||||||
if self.selectcmds[i]:
|
if self.selectcmds[i]:
|
||||||
cmd = self.selectcmds[i]()
|
cmd = self.selectcmds[i]()
|
||||||
else:
|
else:
|
||||||
cmd = CmdMenuNode()
|
cmd = CmdMenuNode()
|
||||||
cmd.key = str(i + 1)
|
cmd.key = str(i + 1)
|
||||||
# this is the operable command, it moves us to the next node.
|
# this is the operable command, it moves us to the next node.
|
||||||
cmd.code = "self.menutree.goto('%s')" % link
|
cmd.code = "self.menutree.goto('%s')" % link
|
||||||
# also custom commands get access to the menutree.
|
# also custom commands get access to the menutree.
|
||||||
cmd.menutree = menutree
|
cmd.menutree = menutree
|
||||||
if self.keywords[i] and cmd.key not in (CMD_NOMATCH, CMD_NOINPUT):
|
if self.keywords[i] and cmd.key not in (CMD_NOMATCH, CMD_NOINPUT):
|
||||||
cmd.aliases = [self.keywords[i]]
|
cmd.aliases = [self.keywords[i]]
|
||||||
|
|
@ -338,30 +342,30 @@ class MenuNode(object):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"Returns the string representation."
|
"Returns the string representation."
|
||||||
return self.text
|
return self.text
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# A simple yes/no question. Call this from a command to give object
|
# A simple yes/no question. Call this from a command to give object
|
||||||
# a cmdset where they may say yes or no to a question. Does not
|
# a cmdset where they may say yes or no to a question. Does not
|
||||||
# make use the node system since there is only one level of choice.
|
# make use the node system since there is only one level of choice.
|
||||||
#
|
#
|
||||||
|
|
||||||
def prompt_yesno(caller, question="", yescode="", nocode="", default="N"):
|
def prompt_yesno(caller, question="", yescode="", nocode="", default="N"):
|
||||||
"""
|
"""
|
||||||
This sets up a simple yes/no questionnaire. Question will
|
This sets up a simple yes/no questionnaire. Question will
|
||||||
be asked, followed by a Y/[N] prompt where the [x] signifies
|
be asked, followed by a Y/[N] prompt where the [x] signifies
|
||||||
the default selection.
|
the default selection.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# creating and defining commands
|
# creating and defining commands
|
||||||
cmdyes = CmdMenuNode()
|
cmdyes = CmdMenuNode()
|
||||||
cmdyes.key = "yes"
|
cmdyes.key = "yes"
|
||||||
cmdyes.aliases = ["y"]
|
cmdyes.aliases = ["y"]
|
||||||
# this will be executed in the context of the yes command (so self.caller will be available)
|
# this will be executed in the context of the yes command (so self.caller will be available)
|
||||||
cmdyes.code = yescode + "\nself.caller.cmdset.delete('menucmdset')\ndel self.caller.db._menu_data"
|
cmdyes.code = yescode + "\nself.caller.cmdset.delete('menucmdset')\ndel self.caller.db._menu_data"
|
||||||
|
|
||||||
cmdno = CmdMenuNode()
|
cmdno = CmdMenuNode()
|
||||||
cmdno.key = "no"
|
cmdno.key = "no"
|
||||||
cmdno.aliases = ["n"]
|
cmdno.aliases = ["n"]
|
||||||
# this will be executed in the context of the no command
|
# this will be executed in the context of the no command
|
||||||
|
|
@ -369,7 +373,7 @@ def prompt_yesno(caller, question="", yescode="", nocode="", default="N"):
|
||||||
|
|
||||||
errorcmd = CmdMenuNode()
|
errorcmd = CmdMenuNode()
|
||||||
errorcmd.key = CMD_NOMATCH
|
errorcmd.key = CMD_NOMATCH
|
||||||
errorcmd.code = "self.caller.msg('Please choose either Yes or No.')"
|
errorcmd.code = "self.caller.msg('Please choose either Yes or No.')"
|
||||||
|
|
||||||
defaultcmd = CmdMenuNode()
|
defaultcmd = CmdMenuNode()
|
||||||
defaultcmd.key = CMD_NOINPUT
|
defaultcmd.key = CMD_NOINPUT
|
||||||
|
|
@ -382,10 +386,10 @@ def prompt_yesno(caller, question="", yescode="", nocode="", default="N"):
|
||||||
yesnocmdset.add(errorcmd)
|
yesnocmdset.add(errorcmd)
|
||||||
yesnocmdset.add(defaultcmd)
|
yesnocmdset.add(defaultcmd)
|
||||||
|
|
||||||
# assinging menu data flags to caller.
|
# assinging menu data flags to caller.
|
||||||
caller.db._menu_data = {"help":"Please select Yes or No.",
|
caller.db._menu_data = {"help":"Please select Yes or No.",
|
||||||
"look":"Please select Yes or No."}
|
"look":"Please select Yes or No."}
|
||||||
# assign cmdset and ask question
|
# assign cmdset and ask question
|
||||||
caller.cmdset.add(yesnocmdset)
|
caller.cmdset.add(yesnocmdset)
|
||||||
if default == "Y":
|
if default == "Y":
|
||||||
prompt = "[Y]/N"
|
prompt = "[Y]/N"
|
||||||
|
|
@ -402,9 +406,9 @@ class CmdMenuTest(Command):
|
||||||
"""
|
"""
|
||||||
testing menu module
|
testing menu module
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
menu
|
menu
|
||||||
menu yesno
|
menu yesno
|
||||||
|
|
||||||
This will test the menu system. The normal operation will produce
|
This will test the menu system. The normal operation will produce
|
||||||
a small menu tree you can move around in. The 'yesno' option will
|
a small menu tree you can move around in. The 'yesno' option will
|
||||||
|
|
@ -417,31 +421,31 @@ class CmdMenuTest(Command):
|
||||||
help_category = "Menu"
|
help_category = "Menu"
|
||||||
def func(self):
|
def func(self):
|
||||||
"Testing the menu system"
|
"Testing the menu system"
|
||||||
|
|
||||||
if not self.args or self.args != "yesno":
|
|
||||||
# testing the full menu-tree system
|
|
||||||
|
|
||||||
node0 = MenuNode("START", text="Start node. Select one of the links below. Here the links are ordered in one column.",
|
if not self.args or self.args != "yesno":
|
||||||
|
# testing the full menu-tree system
|
||||||
|
|
||||||
|
node0 = MenuNode("START", text="Start node. Select one of the links below. Here the links are ordered in one column.",
|
||||||
links=["node1", "node2", "END"], linktexts=["Goto first node", "Goto second node", "Quit"])
|
links=["node1", "node2", "END"], linktexts=["Goto first node", "Goto second node", "Quit"])
|
||||||
node1 = MenuNode("node1", text="First node. This node shows letters instead of numbers for the choices.",
|
node1 = MenuNode("node1", text="First node. This node shows letters instead of numbers for the choices.",
|
||||||
links=["END", "START"], linktexts=["Quit", "Back to start"], keywords=["q","b"])
|
links=["END", "START"], linktexts=["Quit", "Back to start"], keywords=["q","b"])
|
||||||
node2 = MenuNode("node2", text="Second node. This node lists choices in two columns.",
|
node2 = MenuNode("node2", text="Second node. This node lists choices in two columns.",
|
||||||
links=["node3", "START"], linktexts=["Set an attribute", "Back to start"], cols=2)
|
links=["node3", "START"], linktexts=["Set an attribute", "Back to start"], cols=2)
|
||||||
node3 = MenuNode("node3", text="Attribute 'menutest' set on you. You can examine it (only works if you are allowed to use the examine command) or remove it. You can also quit and examine it manually.",
|
node3 = MenuNode("node3", text="Attribute 'menutest' set on you. You can examine it (only works if you are allowed to use the examine command) or remove it. You can also quit and examine it manually.",
|
||||||
links=["node4", "node5", "node2", "END"], linktexts=["Remove attribute", "Examine attribute",
|
links=["node4", "node5", "node2", "END"], linktexts=["Remove attribute", "Examine attribute",
|
||||||
"Back to second node", "Quit menu"], cols=2,
|
"Back to second node", "Quit menu"], cols=2,
|
||||||
code="self.caller.db.menutest='Testing!'")
|
code="self.caller.db.menutest='Testing!'")
|
||||||
node4 = MenuNode("node4", text="Attribute 'menutest' removed again.",
|
node4 = MenuNode("node4", text="Attribute 'menutest' removed again.",
|
||||||
links=["node2"], linktexts=["Back to second node."], cols=2,
|
links=["node2"], linktexts=["Back to second node."], cols=2,
|
||||||
code="del self.caller.db.menutest")
|
code="del self.caller.db.menutest")
|
||||||
node5 = MenuNode("node5", links=["node4", "node2"], linktexts=["Remove attribute", "Back to second node."], cols=2,
|
node5 = MenuNode("node5", links=["node4", "node2"], linktexts=["Remove attribute", "Back to second node."], cols=2,
|
||||||
code="self.caller.msg('%s/%s = %s' % (self.caller.key, 'menutest', self.caller.db.menutest))")
|
code="self.caller.msg('%s/%s = %s' % (self.caller.key, 'menutest', self.caller.db.menutest))")
|
||||||
|
|
||||||
menu = MenuTree(self.caller, nodes=(node0, node1, node2, node3, node4, node5))
|
menu = MenuTree(self.caller, nodes=(node0, node1, node2, node3, node4, node5))
|
||||||
menu.start()
|
menu.start()
|
||||||
else:
|
else:
|
||||||
"Testing the yesno question"
|
"Testing the yesno question"
|
||||||
prompt_yesno(self.caller, question="Please answer yes or no - Are you the master of this mud or not?",
|
prompt_yesno(self.caller, question="Please answer yes or no - Are you the master of this mud or not?",
|
||||||
yescode="self.caller.msg('{gGood for you!{n')",
|
yescode="self.caller.msg('{gGood for you!{n')",
|
||||||
nocode="self.caller.msg('{GNow you are just being modest ...{n')",
|
nocode="self.caller.msg('{GNow you are just being modest ...{n')",
|
||||||
default="N")
|
default="N")
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
"""
|
"""
|
||||||
Evennia misc commands
|
Evennia misc commands
|
||||||
|
|
||||||
Contribution - Griatch 2011
|
Contribution - Griatch 2011
|
||||||
|
|
||||||
|
|
@ -7,14 +7,16 @@ This module offers some miscellaneous commands that may be useful
|
||||||
depending on the game you run or the style of administration you
|
depending on the game you run or the style of administration you
|
||||||
prefer. Alternatively they can be looked at for inspiration.
|
prefer. Alternatively they can be looked at for inspiration.
|
||||||
|
|
||||||
To make available in the game, import this module to
|
To make available in the game, make sure to follow the instructions
|
||||||
game.gamesrc.commands.basecmdset.py (or your own equivalent) and add
|
in game/gamesrc/commands/examples.py (copy the template up one level
|
||||||
the command class(es) you want to the default command set. You need to
|
and re-point the relevant settings to this new module - if you already
|
||||||
reload the server to make them recognized.
|
have such a module, you can of course use that). Next import this module into
|
||||||
|
this custom module and add the command class(es) you want to the default
|
||||||
|
command set. You need to reload the server to make them recognized.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from src.commands.default.muxcommand import MuxCommand
|
from src.commands.default.muxcommand import MuxCommand
|
||||||
|
|
||||||
PERMISSION_HIERARCHY = settings.PERMISSION_HIERARCHY
|
PERMISSION_HIERARCHY = settings.PERMISSION_HIERARCHY
|
||||||
PERMISSION_HIERARCHY_LOWER = [perm.lower() for perm in PERMISSION_HIERARCHY]
|
PERMISSION_HIERARCHY_LOWER = [perm.lower() for perm in PERMISSION_HIERARCHY]
|
||||||
|
|
@ -23,15 +25,15 @@ class CmdQuell(MuxCommand):
|
||||||
"""
|
"""
|
||||||
Quelling permissions
|
Quelling permissions
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
quell <command> [=permission level]
|
quell <command> [=permission level]
|
||||||
|
|
||||||
This is an admin command that allows to execute another command as
|
This is an admin command that allows to execute another command as
|
||||||
another (lower) permission level than what you currently
|
another (lower) permission level than what you currently
|
||||||
have. This is useful for testing. Also superuser flag will be
|
have. This is useful for testing. Also superuser flag will be
|
||||||
deactivated by this command. If no permission level is given,
|
deactivated by this command. If no permission level is given,
|
||||||
the command will be executed as the lowest level available in
|
the command will be executed as the lowest level available in
|
||||||
settings.PERMISSION_HIERARCHY.
|
settings.PERMISSION_HIERARCHY.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = "quell"
|
key = "quell"
|
||||||
|
|
@ -43,30 +45,30 @@ class CmdQuell(MuxCommand):
|
||||||
|
|
||||||
if not self.args:
|
if not self.args:
|
||||||
self.caller.msg("Usage: quell <command> [=permission level]")
|
self.caller.msg("Usage: quell <command> [=permission level]")
|
||||||
return
|
return
|
||||||
|
|
||||||
cmd = self.lhs
|
cmd = self.lhs
|
||||||
perm = self.rhs
|
perm = self.rhs
|
||||||
|
|
||||||
if not PERMISSION_HIERARCHY:
|
if not PERMISSION_HIERARCHY:
|
||||||
self.caller.msg("settings.PERMISSION_HIERARCHY is not defined. Add a hierarchy to use this command.")
|
self.caller.msg("settings.PERMISSION_HIERARCHY is not defined. Add a hierarchy to use this command.")
|
||||||
return
|
return
|
||||||
if perm:
|
if perm:
|
||||||
if not perm.lower() in PERMISSION_HIERARCHY_LOWER:
|
if not perm.lower() in PERMISSION_HIERARCHY_LOWER:
|
||||||
self.caller.msg("Unknown permission. Permission hierarchy is: [%s]" % ", ".join(PERMISSION_HIERARCHY))
|
self.caller.msg("Unknown permission. Permission hierarchy is: [%s]" % ", ".join(PERMISSION_HIERARCHY))
|
||||||
return
|
return
|
||||||
if not self.caller.locks.check_lockstring(self.caller, "dummy:perm(%s)" % perm):
|
if not self.caller.locks.check_lockstring(self.caller, "dummy:perm(%s)" % perm):
|
||||||
self.caller.msg("You cannot use a permission higher than the one you have.")
|
self.caller.msg("You cannot use a permission higher than the one you have.")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
perm = PERMISSION_HIERARCHY_LOWER[0]
|
perm = PERMISSION_HIERARCHY_LOWER[0]
|
||||||
|
|
||||||
# replace permission
|
# replace permission
|
||||||
oldperm = self.caller.permissions
|
oldperm = self.caller.permissions
|
||||||
old_superuser = self.caller.player.user.is_superuser
|
old_superuser = self.caller.player.user.is_superuser
|
||||||
newperm = [perm] + [perm for perm in oldperm if perm not in PERMISSION_HIERARCHY_LOWER]
|
newperm = [perm] + [perm for perm in oldperm if perm not in PERMISSION_HIERARCHY_LOWER]
|
||||||
self.caller.permissions = newperm
|
self.caller.permissions = newperm
|
||||||
self.caller.player.user.is_superuser = False
|
self.caller.player.user.is_superuser = False
|
||||||
self.caller.player.user.save()
|
self.caller.player.user.save()
|
||||||
|
|
||||||
def callback(ret):
|
def callback(ret):
|
||||||
|
|
@ -76,8 +78,8 @@ class CmdQuell(MuxCommand):
|
||||||
|
|
||||||
# this returns a deferred, so we need to assign callbacks
|
# this returns a deferred, so we need to assign callbacks
|
||||||
self.caller.execute_cmd(cmd).addCallbacks(callback, errback)
|
self.caller.execute_cmd(cmd).addCallbacks(callback, errback)
|
||||||
|
|
||||||
self.caller.permissions = oldperm
|
self.caller.permissions = oldperm
|
||||||
self.caller.player.user.is_superuser = old_superuser
|
self.caller.player.user.is_superuser = old_superuser
|
||||||
self.caller.player.user.save()
|
self.caller.player.user.save()
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue