Reshuffling the Evennia package into the new template paradigm.

This commit is contained in:
Griatch 2015-01-06 14:53:45 +01:00
parent 2846e64833
commit 2b3a32e447
371 changed files with 17250 additions and 304 deletions

View file

View file

@ -0,0 +1,121 @@
"""
Example command set template module.
To create new commands to populate the cmdset, see
examples/command.py.
To extend the character command set:
- copy this file up one level to gamesrc/commands and name it
something fitting.
- change settings.CMDSET_CHARACTER to point to the new module's
CharacterCmdSet class
- import/add commands at the end of CharacterCmdSet's add() method.
To extend Player cmdset:
- like character set, but point settings.PLAYER on your new cmdset.
To extend Unloggedin cmdset:
- like default set, but point settings.CMDSET_UNLOGGEDIN on your new cmdset.
To add a wholly new command set:
- copy this file up one level to gamesrc/commands and name it
something fitting.
- add a new cmdset class
- add it to objects e.g. with obj.cmdset.add(path.to.the.module.and.class)
"""
from ev import CmdSet, Command
from ev import default_cmds
#from contrib import menusystem, lineeditor
#from contrib import misc_commands
#from contrib import chargen
class ExampleCmdSet(CmdSet):
"""
Implements an empty, example cmdset.
"""
key = "ExampleSet"
def at_cmdset_creation(self):
"""
This is the only method defined in a cmdset, called during
its creation. It should populate the set with command instances.
As and example we just add the empty base Command object.
It prints some info.
"""
self.add(Command())
class CharacterCmdSet(default_cmds.CharacterCmdSet):
"""
This is an example of how to overload the default command
set defined in src/commands/default/cmdset_character.py.
Here we copy everything by calling the parent, but you can
copy&paste any combination of the default command to customize
your default set. Next you change settings.CMDSET_CHARACTER to point
to this class.
"""
key = "DefaultCharacter"
def at_cmdset_creation(self):
"""
Populates the cmdset
"""
# calling setup in src.commands.default.cmdset_character
super(CharacterCmdSet, self).at_cmdset_creation()
#
# any commands you add below will overload the default ones.
#
#self.add(menusystem.CmdMenuTest())
#self.add(lineeditor.CmdEditor())
#self.add(misc_commands.CmdQuell())
class UnloggedinCmdSet(default_cmds.UnloggedinCmdSet):
"""
This is an example of how to overload the command set of the
unloggedin commands, defined in
src/commands/default/cmdset_unloggedin.py.
Here we copy everything by calling the parent, but you can
copy&paste any combination of the default command to customize
your default set. Next you change settings.CMDSET_UNLOGGEDIN to
point to this class.
"""
key = "DefaultUnloggedin"
def at_cmdset_creation(self):
"""
Populates the cmdset
"""
# calling setup in src.commands.default.cmdset_unloggedin
super(UnloggedinCmdSet, self).at_cmdset_creation()
#
# any commands you add below will overload the default ones.
#
class PlayerCmdSet(default_cmds.PlayerCmdSet):
"""
This is set is available to the player when they have no
character connected to them (i.e. they are out-of-character, ooc).
"""
key = "DefaultPlayer"
def at_cmdset_creation(self):
"""
Populates the cmdset
"""
# calling setup in src.commands.default.cmdset_ooc
super(PlayerCmdSet, self).at_cmdset_creation()
#
# any commands you add below will overload the default ones.
#

View file

@ -0,0 +1,132 @@
"""
Example command module template
Copy this module up one level to gamesrc/commands/ and name it as
befits your use. You can then use it as a template to define your new
commands. To use them you also need to group them in a CommandSet (see
examples/cmdset.py)
"""
from ev import Command as BaseCommand
from ev import default_cmds
from ev import utils
class Command(BaseCommand):
"""
Inherit from this if you want to create your own
command styles. Note that Evennia's default commands
use MuxCommand instead (next in this module)
Note that the class's __doc__ string (this text) is
used by Evennia to create the automatic help entry for
the command, so make sure to document consistently here.
"""
# these need to be specified
key = "MyCommand"
aliases = ["mycmd", "myc"]
locks = "cmd:all()"
help_category = "General"
# auto_help = False # uncomment to deactive auto-help for this command.
# arg_regex = r"\s.*?|$" # optional regex detailing how the part after
# the cmdname must look to match this command.
# (we don't implement hook method access() here, you don't need to
# modify that unless you want to change how the lock system works
# (in that case see src.commands.command.Command))
def at_pre_cmd(self):
"""
This hook is called before self.parse() on all commands
"""
pass
def parse(self):
"""
This method is called by the cmdhandler once the command name
has been identified. It creates a new set of member variables
that can be later accessed from self.func() (see below)
The following variables are available to us:
# class variables:
self.key - the name of this command ('mycommand')
self.aliases - the aliases of this cmd ('mycmd','myc')
self.locks - lock string for this command ("cmd:all()")
self.help_category - overall category of command ("General")
# added at run-time by cmdhandler:
self.caller - the object calling this command
self.cmdstring - the actual command name used to call this
(this allows you to know which alias was used,
for example)
self.args - the raw input; everything following self.cmdstring.
self.cmdset - the cmdset from which this command was picked. Not
often used (useful for commands like 'help' or to
list all available commands etc)
self.obj - the object on which this command was defined. It is often
the same as self.caller.
"""
pass
def func(self):
"""
This is the hook function that actually does all the work. It is called
by the cmdhandler right after self.parser() finishes, and so has access
to all the variables defined therein.
"""
self.caller.msg("Command called!")
def at_post_cmd(self):
"""
This hook is called after self.func().
"""
pass
class MuxCommand(default_cmds.MuxCommand):
"""
This sets up the basis for a Evennia's 'MUX-like' command
style. The idea is that most other Mux-related commands should
just inherit from this and don't have to implement parsing of
their own unless they do something particularly advanced.
A MUXCommand command understands the following possible syntax:
name[ with several words][/switch[/switch..]] arg1[,arg2,...] [[=|,] arg[,..]]
The 'name[ with several words]' part is already dealt with by the
cmdhandler at this point, and stored in self.cmdname. The rest is stored
in self.args.
The MuxCommand parser breaks self.args into its constituents and stores them
in the following variables:
self.switches = optional list of /switches (without the /)
self.raw = This is the raw argument input, including switches
self.args = This is re-defined to be everything *except* the switches
self.lhs = Everything to the left of = (lhs:'left-hand side'). If
no = is found, this is identical to self.args.
self.rhs: Everything to the right of = (rhs:'right-hand side').
If no '=' is found, this is None.
self.lhslist - self.lhs split into a list by comma
self.rhslist - list of self.rhs split into a list by comma
self.arglist = list of space-separated args (including '=' if it exists)
All args and list members are stripped of excess whitespace around the
strings, but case is preserved.
"""
def func(self):
"""
This is the hook function that actually does all the work. It is called
by the cmdhandler right after self.parser() finishes, and so has access
to all the variables defined therein.
"""
# this can be removed in your child class, it's just
# printing the ingoing variables as a demo.
super(MuxCommand, self).func()