Added #INSERT capabilities to @batchcmd processor too. This allows to group and run multiple batch-cmd batchfiles from one central batchfile. You can not mix batchcmd and batchcode files however - that would go beyond the use cases for the respective batch processors (and give unnecessarily complex code for little gain).
This commit is contained in:
parent
2ebbf51a8a
commit
8350c7dca7
2 changed files with 73 additions and 28 deletions
|
|
@ -48,7 +48,7 @@ know you want to!
|
||||||
# Now let's place the button where it belongs (let's say limbo #2 is
|
# Now let's place the button where it belongs (let's say limbo #2 is
|
||||||
# the evil lair in our example)
|
# the evil lair in our example)
|
||||||
|
|
||||||
teleport #2
|
@teleport #2
|
||||||
|
|
||||||
#... and drop it (remember, this comment ends input to @teleport, so don't
|
#... and drop it (remember, this comment ends input to @teleport, so don't
|
||||||
#forget it!) The very last command in the file need not be ended with #.
|
#forget it!) The very last command in the file need not be ended with #.
|
||||||
|
|
|
||||||
|
|
@ -32,12 +32,21 @@ recommended that the batch-code processor is limited only to
|
||||||
superusers or highly trusted staff.
|
superusers or highly trusted staff.
|
||||||
|
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
Batch-command processor file syntax
|
Batch-command processor file syntax
|
||||||
|
|
||||||
The batch-command processor accepts 'batchcommand files' e.g 'batch.ev',
|
The batch-command processor accepts 'batchcommand files' e.g
|
||||||
containing a sequence of valid evennia commands in a simple
|
'batch.ev', containing a sequence of valid evennia commands in a
|
||||||
format. The engine runs each command in sequence, as if they had been
|
simple format. The engine runs each command in sequence, as if they
|
||||||
run at the game prompt.
|
had been run at the game prompt.
|
||||||
|
|
||||||
|
Each evennia command must be delimited by a line comment to mark its
|
||||||
|
end.
|
||||||
|
|
||||||
|
#INSERT path.batchcmdfile - this as the first entry on a line will
|
||||||
|
import and run a batch.ev file in this position, as if it was
|
||||||
|
written in this file.
|
||||||
|
|
||||||
This way entire game worlds can be created and planned offline; it is
|
This way entire game worlds can be created and planned offline; it is
|
||||||
especially useful in order to create long room descriptions where a
|
especially useful in order to create long room descriptions where a
|
||||||
|
|
@ -72,6 +81,9 @@ It seems the bottom of the box is a bit loose.
|
||||||
# (Assuming #221 is a warehouse or something.)
|
# (Assuming #221 is a warehouse or something.)
|
||||||
# (remember, this comment ends the @teleport command! Don'f forget it)
|
# (remember, this comment ends the @teleport command! Don'f forget it)
|
||||||
|
|
||||||
|
# Example of importing another file at this point.
|
||||||
|
#IMPORT examples.batch
|
||||||
|
|
||||||
@drop box
|
@drop box
|
||||||
|
|
||||||
# Done, the box is in the warehouse! (this last comment is not necessary to
|
# Done, the box is in the warehouse! (this last comment is not necessary to
|
||||||
|
|
@ -81,31 +93,45 @@ It seems the bottom of the box is a bit loose.
|
||||||
An example batch file is game/gamesrc/commands/examples/batch_example.ev.
|
An example batch file is game/gamesrc/commands/examples/batch_example.ev.
|
||||||
|
|
||||||
|
|
||||||
|
==========================================================================
|
||||||
|
|
||||||
|
|
||||||
Batch-code processor file syntax
|
Batch-code processor file syntax
|
||||||
|
|
||||||
The Batch-code processor accepts full python modules (e.g. "batch.py") that
|
The Batch-code processor accepts full python modules (e.g. "batch.py")
|
||||||
looks identical to normal Python files with a few exceptions that allows them
|
that looks identical to normal Python files with a few exceptions that
|
||||||
to the executed in blocks. This way of working assures a sequential execution
|
allows them to the executed in blocks. This way of working assures a
|
||||||
of the file and allows for features like stepping from block to block
|
sequential execution of the file and allows for features like stepping
|
||||||
(without executing those coming before), as well as automatic deletion
|
from block to block (without executing those coming before), as well
|
||||||
of created objects etc. You can however also run a batch-code python file
|
as automatic deletion of created objects etc. You can however also run
|
||||||
directly using Python (and can also be de).
|
a batch-code python file directly using Python (and can also be de).
|
||||||
|
|
||||||
Code blocks are separated by python comments starting with special code words.
|
Code blocks are separated by python comments starting with special
|
||||||
|
code words.
|
||||||
|
|
||||||
#HEADER - this denotes commands global to the entire file, such as
|
#HEADER - this denotes commands global to the entire file, such as
|
||||||
import statements and global variables. They will
|
import statements and global variables. They will
|
||||||
automatically be pasted at the top of all code blocks. Observe
|
automatically be pasted at the top of all code
|
||||||
that changes to these variables made in one block is not
|
blocks. Observe that changes to these variables made in one
|
||||||
preserved between blocks!
|
block is not preserved between blocks!
|
||||||
#CODE [objname, objname, ...] - This designates a code block that will be executed like a
|
#CODE
|
||||||
|
#CODE (info)
|
||||||
|
#CODE (info) objname1, objname1, ... -
|
||||||
|
This designates a code block that will be executed like a
|
||||||
stand-alone piece of code together with any #HEADER
|
stand-alone piece of code together with any #HEADER
|
||||||
defined. <objname>s mark the (variable-)names of objects created in the code,
|
defined. (info) text is used by the interactive mode to
|
||||||
and which may be auto-deleted by the processor if desired (such as when
|
display info about the node to run. <objname>s mark the
|
||||||
debugging the script). E.g., if the code contains the command
|
(variable-)names of objects created in the code, and which
|
||||||
myobj = create.create_object(...), you could put 'myobj' in the #CODE header
|
may be auto-deleted by the processor if desired (such as
|
||||||
regardless of what the created object is actually called in-game.
|
when debugging the script). E.g., if the code contains the
|
||||||
|
command myobj = create.create_object(...), you could put
|
||||||
|
'myobj' in the #CODE header regardless of what the created
|
||||||
|
object is actually called in-game.
|
||||||
|
#INSERT path.filename - This imports another batch_code.py file and
|
||||||
|
runs it in the given position. paths are given as python
|
||||||
|
path. The inserted file will retain its own HEADERs which
|
||||||
|
will not be mixed with the HEADERs of the file importing
|
||||||
|
this file.
|
||||||
|
|
||||||
The following variables are automatically made available for the script:
|
The following variables are automatically made available for the script:
|
||||||
|
|
||||||
|
|
@ -131,6 +157,8 @@ obj.location = caller.location
|
||||||
obj.db.gold = GOLD
|
obj.db.gold = GOLD
|
||||||
caller.msg("The object was created!")
|
caller.msg("The object was created!")
|
||||||
|
|
||||||
|
#INSERT another_batch_file
|
||||||
|
|
||||||
#CODE
|
#CODE
|
||||||
|
|
||||||
script = create.create_script()
|
script = create.create_script()
|
||||||
|
|
@ -237,13 +265,16 @@ class BatchCommandProcessor(object):
|
||||||
1) # at the beginning of a line marks the end of the command before it.
|
1) # at the beginning of a line marks the end of the command before it.
|
||||||
It is also a comment and any number of # can exist on subsequent
|
It is also a comment and any number of # can exist on subsequent
|
||||||
lines (but not inside comments).
|
lines (but not inside comments).
|
||||||
2) Commands are placed alone at the beginning of a line and their
|
2) #INSERT at the beginning of a line imports another
|
||||||
|
batch-cmd file file and pastes it into the batch file as if
|
||||||
|
it was written there.
|
||||||
|
3) Commands are placed alone at the beginning of a line and their
|
||||||
arguments are considered to be everything following (on any
|
arguments are considered to be everything following (on any
|
||||||
number of lines) until the next comment line beginning with #.
|
number of lines) until the next comment line beginning with #.
|
||||||
3) Newlines are ignored in command definitions
|
4) Newlines are ignored in command definitions
|
||||||
4) A completely empty line in a command line definition is condered
|
5) A completely empty line in a command line definition is condered
|
||||||
a newline (so two empty lines is a paragraph).
|
a newline (so two empty lines is a paragraph).
|
||||||
5) Excess spaces and indents inside arguments are stripped.
|
6) Excess spaces and indents inside arguments are stripped.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -253,7 +284,9 @@ class BatchCommandProcessor(object):
|
||||||
Identifies the line type (comment, commanddef or empty)
|
Identifies the line type (comment, commanddef or empty)
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if line.strip()[0] == '#':
|
if line.strip().startswith("#INSERT"):
|
||||||
|
return "insert"
|
||||||
|
elif line.strip()[0] == '#':
|
||||||
return "comment"
|
return "comment"
|
||||||
else:
|
else:
|
||||||
return "commanddef"
|
return "commanddef"
|
||||||
|
|
@ -278,10 +311,22 @@ class BatchCommandProcessor(object):
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
|
||||||
typ = identify_line(line)
|
typ = identify_line(line)
|
||||||
|
|
||||||
if typ == "commanddef":
|
if typ == "commanddef":
|
||||||
curr_cmd += line
|
curr_cmd += line
|
||||||
elif typ == "empty" and curr_cmd:
|
elif typ == "empty" and curr_cmd:
|
||||||
curr_cmd += "\r\n"
|
curr_cmd += "\r\n"
|
||||||
|
elif typ == "insert":
|
||||||
|
# note that we are not safeguarding for
|
||||||
|
# cyclic imports here!
|
||||||
|
if curr_cmd:
|
||||||
|
commands.append(curr_cmd.strip())
|
||||||
|
curr_cmd = ""
|
||||||
|
filename = line.lstrip("#INSERT").strip()
|
||||||
|
insert_commands = self.parse_file(filename)
|
||||||
|
if insert_commands == None:
|
||||||
|
insert_commands = ["{rINSERT ERROR: %s{n" % filename]
|
||||||
|
commands.extend(insert_commands)
|
||||||
else: #comment
|
else: #comment
|
||||||
if curr_cmd:
|
if curr_cmd:
|
||||||
commands.append(curr_cmd.strip())
|
commands.append(curr_cmd.strip())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue