Local object command tables are now in. See game/gamesrc/parents/examples/red_button.py for example. Note that local command matches will override global matches. Command handler short circuits on the first command match. This will typically be the object with the lowest ID.
This commit is contained in:
parent
723cdab4aa
commit
ffa03309fc
5 changed files with 40 additions and 13 deletions
|
|
@ -1,25 +1,27 @@
|
||||||
"""
|
"""
|
||||||
An example script parent for a
|
An example script parent for a
|
||||||
"""
|
"""
|
||||||
from src.cmdtable import CommandTable
|
|
||||||
from game.gamesrc.parents.base.basicobject import BasicObject
|
from game.gamesrc.parents.base.basicobject import BasicObject
|
||||||
|
|
||||||
COMMAND_TABLE = CommandTable()
|
|
||||||
def cmd_push_button(command):
|
def cmd_push_button(command):
|
||||||
"""
|
"""
|
||||||
An example command to show how the pluggable command system works.
|
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
|
# 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.
|
# of emit_to() calls, which is generally a good idea.
|
||||||
retval = "Test"
|
retval = "You have pushed the button on: %s" % (command.scripted_obj.get_name())
|
||||||
command.source_object.emit_to(retval)
|
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):
|
class RedButton(BasicObject):
|
||||||
def __init__(self, source_obj, *args, **kwargs):
|
def __init__(self, scripted_obj, *args, **kwargs):
|
||||||
super(RedButton, self).__init__(source_obj, args, kwargs)
|
"""
|
||||||
self.command_table = COMMAND_TABLE
|
|
||||||
|
"""
|
||||||
|
# Calling the super classes __init__ is critical! Never forget to do
|
||||||
|
# this or everything else from here on out will fail.
|
||||||
|
super(RedButton, self).__init__(scripted_obj, args, kwargs)
|
||||||
|
# Add the command to the object's command table.
|
||||||
|
self.command_table.add_command("pushbutton", cmd_push_button)
|
||||||
|
|
||||||
def class_factory(source_obj):
|
def class_factory(source_obj):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -279,6 +279,25 @@ def command_table_lookup(command, command_table, eval_perms=True):
|
||||||
# If flow reaches this point, user has perms and command is ready.
|
# If flow reaches this point, user has perms and command is ready.
|
||||||
command.command_function = cmdtuple[0]
|
command.command_function = cmdtuple[0]
|
||||||
command.extra_vars = cmdtuple[2]
|
command.extra_vars = cmdtuple[2]
|
||||||
|
return True
|
||||||
|
|
||||||
|
def match_neighbor_ctables(command):
|
||||||
|
"""
|
||||||
|
Looks through the command tables of neighboring objects for command
|
||||||
|
matches.
|
||||||
|
"""
|
||||||
|
source_object = command.source_object
|
||||||
|
if source_object.location != None:
|
||||||
|
neighbors = source_object.location.get_contents()
|
||||||
|
for neighbor in neighbors:
|
||||||
|
if command_table_lookup(command,
|
||||||
|
neighbor.scriptlink.command_table):
|
||||||
|
# If there was a command match, set the scripted_obj attribute
|
||||||
|
# for the script parent to pick up.
|
||||||
|
command.scripted_obj = neighbor
|
||||||
|
return True
|
||||||
|
# No matches
|
||||||
|
return False
|
||||||
|
|
||||||
def handle(command):
|
def handle(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -308,6 +327,8 @@ def handle(command):
|
||||||
match_channel(command)
|
match_channel(command)
|
||||||
# See if the user is trying to traverse an exit.
|
# See if the user is trying to traverse an exit.
|
||||||
match_exits(command)
|
match_exits(command)
|
||||||
|
neighbor_match_found = match_neighbor_ctables(command)
|
||||||
|
if not neighbor_match_found:
|
||||||
# Retrieve the appropriate (if any) command function.
|
# Retrieve the appropriate (if any) command function.
|
||||||
command_table_lookup(command, cmdtable.GLOBAL_CMD_TABLE)
|
command_table_lookup(command, cmdtable.GLOBAL_CMD_TABLE)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,8 @@ You'll want to change the values below to reflect what you entered.
|
||||||
"""
|
"""
|
||||||
# Make sure this is True in your settings.py.
|
# Make sure this is True in your settings.py.
|
||||||
IMC2_ENABLED = False
|
IMC2_ENABLED = False
|
||||||
|
# While True, emit additional debugging info.
|
||||||
|
IMC2_DEBUG = False
|
||||||
# The hostname/ip address of your IMC2 server of choice.
|
# The hostname/ip address of your IMC2 server of choice.
|
||||||
IMC2_SERVER_ADDRESS = None
|
IMC2_SERVER_ADDRESS = None
|
||||||
# The port to connect to on your IMC2 server.
|
# The port to connect to on your IMC2 server.
|
||||||
|
|
|
||||||
|
|
@ -121,10 +121,10 @@ class IMC2Protocol(StatefulTelnetProtocol):
|
||||||
if not self.is_authenticated:
|
if not self.is_authenticated:
|
||||||
self._parse_auth_response(line)
|
self._parse_auth_response(line)
|
||||||
else:
|
else:
|
||||||
if 'is-alive' not in line:
|
if settings.IMC2_DEBUG and 'is-alive' not in line:
|
||||||
logger.log_infomsg("PACKET: %s" % line)
|
logger.log_infomsg("PACKET: %s" % line)
|
||||||
packet = IMC2Packet(packet_str = line)
|
packet = IMC2Packet(packet_str = line)
|
||||||
if packet.packet_type not in ['is-alive', 'keepalive-request']:
|
if settings.IMC2_DEBUG and packet.packet_type not in ['is-alive', 'keepalive-request']:
|
||||||
logger.log_infomsg(packet)
|
logger.log_infomsg(packet)
|
||||||
if packet.packet_type == 'is-alive':
|
if packet.packet_type == 'is-alive':
|
||||||
IMC2_MUDLIST.update_mud_from_packet(packet)
|
IMC2_MUDLIST.update_mud_from_packet(packet)
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ NOTE: This file should NOT be directly modified. Sub-class the BasicObject
|
||||||
class in game/gamesrc/parents/base/basicobject.py and change the
|
class in game/gamesrc/parents/base/basicobject.py and change the
|
||||||
SCRIPT_DEFAULT_OBJECT variable in settings.py to point to the new class.
|
SCRIPT_DEFAULT_OBJECT variable in settings.py to point to the new class.
|
||||||
"""
|
"""
|
||||||
|
from src.cmdtable import CommandTable
|
||||||
from src.ansi import ANSITable
|
from src.ansi import ANSITable
|
||||||
|
|
||||||
class EvenniaBasicObject(object):
|
class EvenniaBasicObject(object):
|
||||||
|
|
@ -25,6 +26,7 @@ class EvenniaBasicObject(object):
|
||||||
scripted_obj: (Object) A reference to the object being scripted (the child).
|
scripted_obj: (Object) A reference to the object being scripted (the child).
|
||||||
"""
|
"""
|
||||||
self.scripted_obj = scripted_obj
|
self.scripted_obj = scripted_obj
|
||||||
|
self.command_table = CommandTable()
|
||||||
|
|
||||||
def at_object_creation(self):
|
def at_object_creation(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue