Reworked object command tables.

Object commands used to require re-adding every call in the script parent's __init__ or factory functions, adding the commands to a new command table directly on the object. Since all other attributes can be set up in at_object_creation(), this was both inconsistent and a bit confusing to work with. There is now a method add_commands() directly defined on all objects. It takes the same arguments as the normal add_command()o but use a reserved attribute to create and update a command table on the object. This has the advantange of completely removing the __init__ call in the script parent, all definitions can now be kept in at_object_creation() and are, more importantly, persistent without having to be recreated every call.
- I updated the examine command to show all the commands defined on an object (if any).
- I updated gamesrc/parents/examples/red_button.py considerably using the new command methodology and also using the updated Events.
.
Griatch
This commit is contained in:
Griatch 2009-12-03 00:41:53 +00:00
parent 5f6454ea1e
commit c7cbc4854e
7 changed files with 252 additions and 53 deletions

View file

@ -6,7 +6,7 @@ something.
#import time
from traceback import format_exc
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
#from django.contrib.contenttypes.models import ContentType
from objects.models import Object
import defines_global
import cmdtable
@ -420,9 +420,10 @@ def match_neighbor_ctables(command,test=False):
neighbors = location.get_contents() + [location] + source_object.get_contents()
for neighbor in neighbors:
#print "neighbor:", neighbor
if command_table_lookup(command,
neighbor.scriptlink.command_table,
test=test, neighbor=neighbor):
obj_cmdtable = neighbor.get_cmdtable()
if obj_cmdtable and command_table_lookup(command, obj_cmdtable,
test=test,
neighbor=neighbor):
# If there was a command match, set the scripted_obj attribute
# for the script parent to pick up.