attribute edits now reflected in the levelSpec

This commit is contained in:
Darren Ranalli 2003-09-30 21:33:13 +00:00
parent 48d033da79
commit b9a21aa785
4 changed files with 30 additions and 25 deletions

View File

@ -383,19 +383,8 @@ class DistributedLevel(DistributedObject.DistributedObject,
if __debug__:
# level editing stuff
def setAttribChange(self, entId, attribName, valueStr):
entity = self.getEntity(entId)
# the entity might be AI-only
if entity is None:
return
try:
value = eval(valueStr)
except Exception, e:
print ('Exception in %s(%s, %s, %s):\n\t%s' %
(lineInfo()[2], entId, attribName, valueStr, e))
raise e
entity.handleAttribChange(attribName, value)
self.levelSpec.setAttribChange(entId, attribName, value)
"""
if __debug__:

View File

@ -78,20 +78,12 @@ class DistributedLevelAI(DistributedObjectAI.DistributedObjectAI,
# level editors should call this func to tweak attributes of level
# entities
def setAttribChange(self, entId, attribName, valueStr):
value = eval(valueStr)
self.levelSpec.setAttribChange(entId, attribName, value)
# send a copy to the client-side level obj
self.sendUpdate('setAttribChange',
[entId, attribName, valueStr])
entity = self.getEntity(entId)
# the entity might be client-side-only
if entity is not None:
value = eval(valueStr)
entity.handleAttribChange(attribName, value)
# send a copy of the entire spec for any new users that
# might come in
##self.sendUpdate('setSpecOverride', [repr(self.levelSpec)])
def getCurrentLevelSpec(self):
"""returns the complete, current spec, including any edits"""
return self.levelSpec

View File

@ -62,6 +62,9 @@ class Level:
# TODO: we should leave this to a subclass or the level user
self.createAllEntities(priorityTypes=['levelMgr','zone'])
self.levelSpec.setAttribChangeEventName(self.getAttribChangeEvent())
self.accept(self.getAttribChangeEvent(), self.handleAttribChange)
def destroyLevel(self):
if hasattr(self, 'createdEntities'):
# destroy the entities in reverse order
@ -235,3 +238,15 @@ class Level:
"""Level is about to destroy this entity"""
# send the entity-destroy event
messenger.send(self.getEntityDestroyEvent(entId))
if __debug__:
def getAttribChangeEvent(self):
return 'attribChange-%s' % self.levelId
# This handler is called immediately after a new attribute value
# has been set in the level's spec.
def handleAttribChange(self, entId, attrib, value):
entity = self.getEntity(entId)
# the entity might be AI- or client-only
if entity is not None:
entity.handleAttribChange(attrib, value)

View File

@ -79,12 +79,21 @@ class LevelSpec:
def setAttribEditEventName(self, event):
self.attribEditEventName = event
def setAttribEdit(self, entId, attrib, value):
# This is a proposed change; it has not been approved yet.
# broadcast the change to someone else that knows what to do
# with it
messenger.send(self.attribEditEventName, [entId, attrib, value])
def setAttribChangeEventName(self, event):
self.attribChangeEventName = event
def setAttribChange(self, entId, attrib, value):
pass
specDict = self.entId2specDict[entId]
specDict[entId][attrib] = value
# locally broadcast the fact that this attribute value has
# officially changed
if self.attribChangeEventName is not None:
messenger.send(self.attribChangeEventName,
[entId, attrib, value])
def getSpecImportsModuleName(self):
# name of module that should be imported by spec py file