diff --git a/direct/src/level/DistributedLevel.py b/direct/src/level/DistributedLevel.py index 2faf83cd66..58ffd736d1 100755 --- a/direct/src/level/DistributedLevel.py +++ b/direct/src/level/DistributedLevel.py @@ -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) + value = eval(valueStr) + self.levelSpec.setAttribChange(entId, attribName, value) """ if __debug__: diff --git a/direct/src/level/DistributedLevelAI.py b/direct/src/level/DistributedLevelAI.py index e09a38db1a..7e1eee4abf 100755 --- a/direct/src/level/DistributedLevelAI.py +++ b/direct/src/level/DistributedLevelAI.py @@ -78,19 +78,11 @@ 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""" diff --git a/direct/src/level/Level.py b/direct/src/level/Level.py index 7429071a5f..33bea55a44 100755 --- a/direct/src/level/Level.py +++ b/direct/src/level/Level.py @@ -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) diff --git a/direct/src/level/LevelSpec.py b/direct/src/level/LevelSpec.py index d7b6f98bd5..3182a69b92 100755 --- a/direct/src/level/LevelSpec.py +++ b/direct/src/level/LevelSpec.py @@ -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