From 1425878410216e278b30552db554b2f1ca82d065 Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Wed, 15 Oct 2003 20:25:21 +0000 Subject: [PATCH] added spec edit username tracking --- direct/src/level/DistributedLevel.py | 23 ++++------------------- direct/src/level/DistributedLevelAI.py | 6 +++--- direct/src/level/EditMgrAI.py | 6 +++--- direct/src/level/EditMgrBase.py | 3 +++ direct/src/level/EditorGlobals.py | 3 +++ direct/src/level/Level.py | 10 ++++++++-- direct/src/level/LevelSpec.py | 8 ++++---- 7 files changed, 28 insertions(+), 31 deletions(-) diff --git a/direct/src/level/DistributedLevel.py b/direct/src/level/DistributedLevel.py index 578b9c78a9..b6729cdc2b 100755 --- a/direct/src/level/DistributedLevel.py +++ b/direct/src/level/DistributedLevel.py @@ -440,26 +440,12 @@ class DistributedLevel(DistributedObject.DistributedObject, if __debug__: # level editing stuff - def setAttribChange(self, entId, attribName, valueStr): + def setAttribChange(self, entId, attribName, valueStr, username): + """every time the spec is edited, we get this message + from the AI""" value = eval(valueStr) - self.levelSpec.setAttribChange(entId, attribName, value) + self.levelSpec.setAttribChange(entId, attribName, value, username) - """ - if __debug__: - # if someone has edited the level, we'll get the full up-to-date - # spec in this message - def setLevelSpecOverride(self, specStr): - if self.levelSpec is not None: - return - - try: - self.levelSpec = eval(specStr) - except Exception, e: - print ('Exception in %s(%s):\n\t%s' % - (lineInfo()[2], specStr, e)) - raise e - """ - def spawnTitleText(self): def getDescription(zoneId, self=self): entId = self.zoneNum2entId.get(zoneId) @@ -528,4 +514,3 @@ class DistributedLevel(DistributedObject.DistributedObject, assert(DistributedLevel.notify.debug("hideTitleTextTask()")) self.smallTitleText.hide() return Task.done - diff --git a/direct/src/level/DistributedLevelAI.py b/direct/src/level/DistributedLevelAI.py index 9d3c5363cb..c98d6819f4 100755 --- a/direct/src/level/DistributedLevelAI.py +++ b/direct/src/level/DistributedLevelAI.py @@ -95,12 +95,12 @@ class DistributedLevelAI(DistributedObjectAI.DistributedObjectAI, if __debug__: # level editors should call this func to tweak attributes of level # entities - def setAttribChange(self, entId, attribName, value): + def setAttribChange(self, entId, attribName, value, username='SYSTEM'): # send a copy to the client-side level obj FIRST # (it may be a message that creates an entity) self.sendUpdate('setAttribChange', - [entId, attribName, repr(value)]) - self.levelSpec.setAttribChange(entId, attribName, value) + [entId, attribName, repr(value), username]) + self.levelSpec.setAttribChange(entId, attribName, value, username) self.modified = 1 self.scheduleSave() diff --git a/direct/src/level/EditMgrAI.py b/direct/src/level/EditMgrAI.py index 3e6331773c..be7e89c41e 100755 --- a/direct/src/level/EditMgrAI.py +++ b/direct/src/level/EditMgrAI.py @@ -1,13 +1,13 @@ """EditMgrAI module: contains the EditMgrAI class""" import EditMgrBase +if __debug__: + from PythonUtil import list2dict + import EditorGlobals class EditMgrAI(EditMgrBase.EditMgrBase): """This class handles AI-side editor-specific functionality""" if __debug__: - from PythonUtil import list2dict - import EditorGlobals - def setRequestNewEntity(self, data): # pick an unused entId spec = self.level.levelSpec diff --git a/direct/src/level/EditMgrBase.py b/direct/src/level/EditMgrBase.py index f5c74c5009..4d7616bab5 100755 --- a/direct/src/level/EditMgrBase.py +++ b/direct/src/level/EditMgrBase.py @@ -15,6 +15,9 @@ class EditMgrBase(Entity.Entity): if __debug__: def setInsertEntity(self, data): + # tell the level who created this entity + self.level.setEntityCreatorUsername(data['entId'], data['username']) + # create the entity self.level.levelSpec.insertEntity(data['entId'], data['entType'], data['parentEntId'], diff --git a/direct/src/level/EditorGlobals.py b/direct/src/level/EditorGlobals.py index b4229176c5..61c35154f2 100755 --- a/direct/src/level/EditorGlobals.py +++ b/direct/src/level/EditorGlobals.py @@ -24,6 +24,9 @@ def assertReadyToEdit(): assert editUsername in username2entIdBase, ( "unknown editor username '%s'; see %s.py" % (editUsername, __name__)) +def getEditUsername(): + return editUsername + def getEntIdAllocRange(): """range of valid entId values for this user. returns [min, max+1] (values taken by range() and xrange())""" diff --git a/direct/src/level/Level.py b/direct/src/level/Level.py index f6d8d60297..76740a724f 100755 --- a/direct/src/level/Level.py +++ b/direct/src/level/Level.py @@ -277,13 +277,19 @@ class Level: return 'removeEntity-%s' % self.levelId # these handlers are called directly by our levelSpec - def handleAttribChange(self, entId, attrib, value): + def handleAttribChange(self, entId, attrib, value, username=None): entity = self.getEntity(entId) # the entity might be AI- or client-only if entity is not None: entity.handleAttribChange(attrib, value) messenger.send(self.getAttribChangeEventName(), - [entId, attrib, value]) + [entId, attrib, value, username]) + + def setEntityCreatorUsername(self, entId, editUsername): + # this is called just before an entity is inserted, with the + # entId of the new entity and the username of the editor + # that requested its creation. + pass def handleEntityInsert(self, entId): self.createEntity(entId) diff --git a/direct/src/level/LevelSpec.py b/direct/src/level/LevelSpec.py index 0fe2239d33..963937cc88 100755 --- a/direct/src/level/LevelSpec.py +++ b/direct/src/level/LevelSpec.py @@ -92,17 +92,17 @@ class LevelSpec: def setFilename(self, filename): self.filename = filename - def setAttribChange(self, entId, attrib, value): + def setAttribChange(self, entId, attrib, value, username): """ we're being asked to change an attribute """ - LevelSpec.notify.debug("setAttribChange: %s, %s = '%s'" % - (entId, attrib, repr(value))) + LevelSpec.notify.debug("setAttribChange(%s): %s, %s = '%s'" % + (username, entId, attrib, repr(value))) assert entId in self.entId2specDict specDict = self.entId2specDict[entId] assert specDict[entId].has_key(attrib) specDict[entId][attrib] = value # let the level know that this attribute value has # officially changed - self.level.handleAttribChange(entId, attrib, value) + self.level.handleAttribChange(entId, attrib, value, username) def insertEntity(self, entId, entType, parentEntId): LevelSpec.notify.debug('inserting entity %s' % entId)