added spec edit username tracking

This commit is contained in:
Darren Ranalli 2003-10-15 20:25:21 +00:00
parent 5d5cc31024
commit 1425878410
7 changed files with 28 additions and 31 deletions

View File

@ -440,26 +440,12 @@ 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, username):
"""every time the spec is edited, we get this message
from the AI"""
value = eval(valueStr) 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 spawnTitleText(self):
def getDescription(zoneId, self=self): def getDescription(zoneId, self=self):
entId = self.zoneNum2entId.get(zoneId) entId = self.zoneNum2entId.get(zoneId)
@ -528,4 +514,3 @@ class DistributedLevel(DistributedObject.DistributedObject,
assert(DistributedLevel.notify.debug("hideTitleTextTask()")) assert(DistributedLevel.notify.debug("hideTitleTextTask()"))
self.smallTitleText.hide() self.smallTitleText.hide()
return Task.done return Task.done

View File

@ -95,12 +95,12 @@ class DistributedLevelAI(DistributedObjectAI.DistributedObjectAI,
if __debug__: if __debug__:
# 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, value): def setAttribChange(self, entId, attribName, value, username='SYSTEM'):
# send a copy to the client-side level obj FIRST # send a copy to the client-side level obj FIRST
# (it may be a message that creates an entity) # (it may be a message that creates an entity)
self.sendUpdate('setAttribChange', self.sendUpdate('setAttribChange',
[entId, attribName, repr(value)]) [entId, attribName, repr(value), username])
self.levelSpec.setAttribChange(entId, attribName, value) self.levelSpec.setAttribChange(entId, attribName, value, username)
self.modified = 1 self.modified = 1
self.scheduleSave() self.scheduleSave()

View File

@ -1,13 +1,13 @@
"""EditMgrAI module: contains the EditMgrAI class""" """EditMgrAI module: contains the EditMgrAI class"""
import EditMgrBase import EditMgrBase
if __debug__:
from PythonUtil import list2dict
import EditorGlobals
class EditMgrAI(EditMgrBase.EditMgrBase): class EditMgrAI(EditMgrBase.EditMgrBase):
"""This class handles AI-side editor-specific functionality""" """This class handles AI-side editor-specific functionality"""
if __debug__: if __debug__:
from PythonUtil import list2dict
import EditorGlobals
def setRequestNewEntity(self, data): def setRequestNewEntity(self, data):
# pick an unused entId # pick an unused entId
spec = self.level.levelSpec spec = self.level.levelSpec

View File

@ -15,6 +15,9 @@ class EditMgrBase(Entity.Entity):
if __debug__: if __debug__:
def setInsertEntity(self, data): 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'], self.level.levelSpec.insertEntity(data['entId'],
data['entType'], data['entType'],
data['parentEntId'], data['parentEntId'],

View File

@ -24,6 +24,9 @@ def assertReadyToEdit():
assert editUsername in username2entIdBase, ( assert editUsername in username2entIdBase, (
"unknown editor username '%s'; see %s.py" % (editUsername, __name__)) "unknown editor username '%s'; see %s.py" % (editUsername, __name__))
def getEditUsername():
return editUsername
def getEntIdAllocRange(): def getEntIdAllocRange():
"""range of valid entId values for this user. """range of valid entId values for this user.
returns [min, max+1] (values taken by range() and xrange())""" returns [min, max+1] (values taken by range() and xrange())"""

View File

@ -277,13 +277,19 @@ class Level:
return 'removeEntity-%s' % self.levelId return 'removeEntity-%s' % self.levelId
# these handlers are called directly by our levelSpec # 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) entity = self.getEntity(entId)
# the entity might be AI- or client-only # the entity might be AI- or client-only
if entity is not None: if entity is not None:
entity.handleAttribChange(attrib, value) entity.handleAttribChange(attrib, value)
messenger.send(self.getAttribChangeEventName(), 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): def handleEntityInsert(self, entId):
self.createEntity(entId) self.createEntity(entId)

View File

@ -92,17 +92,17 @@ class LevelSpec:
def setFilename(self, filename): def setFilename(self, filename):
self.filename = 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 """ """ we're being asked to change an attribute """
LevelSpec.notify.debug("setAttribChange: %s, %s = '%s'" % LevelSpec.notify.debug("setAttribChange(%s): %s, %s = '%s'" %
(entId, attrib, repr(value))) (username, entId, attrib, repr(value)))
assert entId in self.entId2specDict assert entId in self.entId2specDict
specDict = self.entId2specDict[entId] specDict = self.entId2specDict[entId]
assert specDict[entId].has_key(attrib) assert specDict[entId].has_key(attrib)
specDict[entId][attrib] = value specDict[entId][attrib] = value
# let the level know that this attribute value has # let the level know that this attribute value has
# officially changed # officially changed
self.level.handleAttribChange(entId, attrib, value) self.level.handleAttribChange(entId, attrib, value, username)
def insertEntity(self, entId, entType, parentEntId): def insertEntity(self, entId, entType, parentEntId):
LevelSpec.notify.debug('inserting entity %s' % entId) LevelSpec.notify.debug('inserting entity %s' % entId)