Some cleanup. Fixed all examples to match the changes in the states and help systems, also
ran them through pylint to pretty them up. /Griatch
This commit is contained in:
parent
8074617285
commit
84aeabb272
11 changed files with 323 additions and 211 deletions
|
|
@ -1,29 +1,40 @@
|
|||
"""
|
||||
This is an example command module for showing the pluggable command system
|
||||
in action.
|
||||
This is an example command module for showing the pluggable command
|
||||
system in action.
|
||||
|
||||
You'll need to make sure that this or any new modules you create are added to
|
||||
game/settings.py under CUSTOM_COMMAND_MODULES or CUSTOM_UNLOGGED_COMMAND_MODULES,
|
||||
which are tuples of module import path strings. See src/config_defaults.py for more details.
|
||||
You'll need to make sure that this or any new modules you create are
|
||||
added to game/settings.py under CUSTOM_COMMAND_MODULES or
|
||||
CUSTOM_UNLOGGED_COMMAND_MODULES, which are tuples of module import
|
||||
path strings. See src/config_defaults.py for more details.
|
||||
|
||||
E.g. to add this example command for testing, your entry in game/settings.py would
|
||||
look like this:
|
||||
E.g. to add this example command for testing, your entry in
|
||||
game/settings.py would look like this:
|
||||
|
||||
CUSTOM_COMMAND_MODULES = ('game.gamesrc.commands.examples.example',)
|
||||
|
||||
(note the extra comma at the end to make this into a Python tuple. It's only
|
||||
needed if you have only one entry.) You need to restart the Evennia server before new
|
||||
files are recognized.
|
||||
|
||||
(note the extra comma at the end to make this into a Python
|
||||
tuple. It's only needed if you have only one entry.) You need to
|
||||
restart the Evennia server before new files are recognized. Once this
|
||||
is done once, you don't have to restart again, just use
|
||||
@reload/commands to use the changes you make to your modules.
|
||||
"""
|
||||
|
||||
# This is the common global CommandTable object which we'll be adding the
|
||||
# example command to. We can add any number of commands this way in the
|
||||
# same file.
|
||||
# example command(s) to.
|
||||
from src.cmdtable import GLOBAL_CMD_TABLE
|
||||
|
||||
# The main command definition. We can add any number of commands this way in the
|
||||
# same file.
|
||||
def cmd_example(command):
|
||||
"""
|
||||
example - example command
|
||||
|
||||
Usage:
|
||||
example[/switches] <text>
|
||||
|
||||
switches:
|
||||
use any string
|
||||
|
||||
This is the help text for the 'example' command, a command to
|
||||
show how the pluggable command system works.
|
||||
|
||||
|
|
@ -32,15 +43,17 @@ def cmd_example(command):
|
|||
> example/test/test2 Hello
|
||||
and see what is returned.
|
||||
|
||||
<<TOPIC:example_auto_help>>
|
||||
[[example_auto_help]]
|
||||
|
||||
This is a subtopic to the main example command help entry.
|
||||
This is a subtopic to the main example command help entry. It is
|
||||
done by the help system splitting the text by markup of the
|
||||
form [ [title ] ] (with no spaces between the square brackets)
|
||||
|
||||
Note that this text is auto-added since auto_help=True
|
||||
was set in the call to add_function. Any number of subtopics like
|
||||
this one can be added on the fly using the auto-help system. See
|
||||
help topics on 'help' and 'help_staff' for more information and
|
||||
options.
|
||||
Note that this help entry is auto-added as long as HELP_AUTO
|
||||
is not set to False in your game/settings.py file.
|
||||
Any number of subtopics like this one can be added on the fly
|
||||
using the auto-help system. See help topics on 'help' and
|
||||
'help_markup' for more information and options.
|
||||
"""
|
||||
|
||||
# By building one big string and passing it at once, we cut down on a lot
|
||||
|
|
@ -65,32 +78,35 @@ def cmd_example(command):
|
|||
command.source_object.emit_to(retval)
|
||||
|
||||
# Add the command to the common global command table. Note that
|
||||
# since auto_help=True, help entries named "example" and
|
||||
# "example_auto_help" (as defined in the __doc__ string) will
|
||||
# automatically be created for us.
|
||||
GLOBAL_CMD_TABLE.add_command("example", cmd_example, auto_help=True),
|
||||
|
||||
#another simple example
|
||||
# this will auto-create help entries 'example' and
|
||||
# "example_auto_help" for us.
|
||||
GLOBAL_CMD_TABLE.add_command("example", cmd_example)
|
||||
|
||||
#
|
||||
# another simple example
|
||||
#
|
||||
def cmd_emote_smile(command):
|
||||
"""
|
||||
Simplistic 'smile' emote.
|
||||
smile - break a smile
|
||||
|
||||
Usage:
|
||||
smile
|
||||
|
||||
A 'smile' emote.
|
||||
"""
|
||||
#get the source object (that is, the player using the command)
|
||||
caller = command.source_object
|
||||
source_object = command.source_object
|
||||
#find name of caller
|
||||
name = caller.get_name(show_dbref=False)
|
||||
name = source_object.get_name(show_dbref=False)
|
||||
#get the location caller is at
|
||||
location = caller.get_location()
|
||||
location = source_object.get_location()
|
||||
#build the emote
|
||||
text = "%s smiles." % name
|
||||
#emit the emote to everyone at the current location
|
||||
location.emit_to_contents(text)
|
||||
|
||||
#add to global command table (no auto_help activated)
|
||||
GLOBAL_CMD_TABLE.add_command('smile', cmd_emote_smile)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# add to global command table (we probably want an auto-help entry
|
||||
# for this, but we are turning auto-help off anyway, to show
|
||||
# how it works)
|
||||
GLOBAL_CMD_TABLE.add_command('smile', cmd_emote_smile,
|
||||
auto_help_override=False)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue