Working on getting command tables implemented on individual objects. It's probably not a good idea to update to this revision in a 'production' environment yet.
This commit is contained in:
parent
6ca32cd5e0
commit
df69011134
6 changed files with 115 additions and 20 deletions
0
game/gamesrc/parents/examples/__init__.py
Normal file
0
game/gamesrc/parents/examples/__init__.py
Normal file
31
game/gamesrc/parents/examples/red_button.py
Normal file
31
game/gamesrc/parents/examples/red_button.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
"""
|
||||
An example script parent for a
|
||||
"""
|
||||
from src.cmdtable import CommandTable
|
||||
from game.gamesrc.parents.base.basicobject import BasicObject
|
||||
|
||||
COMMAND_TABLE = CommandTable()
|
||||
def cmd_push_button(command):
|
||||
"""
|
||||
An example command to show how the pluggable command system works.
|
||||
"""
|
||||
# By building one big string and passing it at once, we cut down on a lot
|
||||
# of emit_to() calls, which is generally a good idea.
|
||||
retval = "Test"
|
||||
command.source_object.emit_to(retval)
|
||||
# Add the command to the object's command table.
|
||||
COMMAND_TABLE.add_command("push button", cmd_push_button)
|
||||
|
||||
class RedButton(BasicObject):
|
||||
def __init__(self, source_obj, *args, **kwargs):
|
||||
super(RedButton, self).__init__(source_obj, args, kwargs)
|
||||
self.command_table = COMMAND_TABLE
|
||||
|
||||
def class_factory(source_obj):
|
||||
"""
|
||||
This method is called any script you retrieve (via the scripthandler). It
|
||||
creates an instance of the class and returns it transparently.
|
||||
|
||||
source_obj: (Object) A reference to the object being scripted (the child).
|
||||
"""
|
||||
return RedButton(source_obj)
|
||||
Loading…
Add table
Add a link
Reference in a new issue