mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
attribute edits now reflected in the levelSpec
This commit is contained in:
parent
48d033da79
commit
b9a21aa785
@ -383,19 +383,8 @@ class DistributedLevel(DistributedObject.DistributedObject,
|
|||||||
if __debug__:
|
if __debug__:
|
||||||
# level editing stuff
|
# level editing stuff
|
||||||
def setAttribChange(self, entId, attribName, valueStr):
|
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)
|
value = eval(valueStr)
|
||||||
except Exception, e:
|
self.levelSpec.setAttribChange(entId, attribName, value)
|
||||||
print ('Exception in %s(%s, %s, %s):\n\t%s' %
|
|
||||||
(lineInfo()[2], entId, attribName, valueStr, e))
|
|
||||||
raise e
|
|
||||||
|
|
||||||
entity.handleAttribChange(attribName, value)
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if __debug__:
|
if __debug__:
|
||||||
|
@ -78,20 +78,12 @@ class DistributedLevelAI(DistributedObjectAI.DistributedObjectAI,
|
|||||||
# level editors should call this func to tweak attributes of level
|
# level editors should call this func to tweak attributes of level
|
||||||
# entities
|
# entities
|
||||||
def setAttribChange(self, entId, attribName, valueStr):
|
def setAttribChange(self, entId, attribName, valueStr):
|
||||||
|
value = eval(valueStr)
|
||||||
|
self.levelSpec.setAttribChange(entId, attribName, value)
|
||||||
# send a copy to the client-side level obj
|
# send a copy to the client-side level obj
|
||||||
self.sendUpdate('setAttribChange',
|
self.sendUpdate('setAttribChange',
|
||||||
[entId, attribName, valueStr])
|
[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):
|
def getCurrentLevelSpec(self):
|
||||||
"""returns the complete, current spec, including any edits"""
|
"""returns the complete, current spec, including any edits"""
|
||||||
return self.levelSpec
|
return self.levelSpec
|
||||||
|
@ -62,6 +62,9 @@ class Level:
|
|||||||
# TODO: we should leave this to a subclass or the level user
|
# TODO: we should leave this to a subclass or the level user
|
||||||
self.createAllEntities(priorityTypes=['levelMgr','zone'])
|
self.createAllEntities(priorityTypes=['levelMgr','zone'])
|
||||||
|
|
||||||
|
self.levelSpec.setAttribChangeEventName(self.getAttribChangeEvent())
|
||||||
|
self.accept(self.getAttribChangeEvent(), self.handleAttribChange)
|
||||||
|
|
||||||
def destroyLevel(self):
|
def destroyLevel(self):
|
||||||
if hasattr(self, 'createdEntities'):
|
if hasattr(self, 'createdEntities'):
|
||||||
# destroy the entities in reverse order
|
# destroy the entities in reverse order
|
||||||
@ -235,3 +238,15 @@ class Level:
|
|||||||
"""Level is about to destroy this entity"""
|
"""Level is about to destroy this entity"""
|
||||||
# send the entity-destroy event
|
# send the entity-destroy event
|
||||||
messenger.send(self.getEntityDestroyEvent(entId))
|
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)
|
||||||
|
@ -79,12 +79,21 @@ class LevelSpec:
|
|||||||
def setAttribEditEventName(self, event):
|
def setAttribEditEventName(self, event):
|
||||||
self.attribEditEventName = event
|
self.attribEditEventName = event
|
||||||
def setAttribEdit(self, entId, attrib, value):
|
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
|
# broadcast the change to someone else that knows what to do
|
||||||
# with it
|
# with it
|
||||||
messenger.send(self.attribEditEventName, [entId, attrib, value])
|
messenger.send(self.attribEditEventName, [entId, attrib, value])
|
||||||
|
|
||||||
|
def setAttribChangeEventName(self, event):
|
||||||
|
self.attribChangeEventName = event
|
||||||
def setAttribChange(self, entId, attrib, value):
|
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):
|
def getSpecImportsModuleName(self):
|
||||||
# name of module that should be imported by spec py file
|
# name of module that should be imported by spec py file
|
||||||
|
Loading…
x
Reference in New Issue
Block a user