remove all references to removed zones

This commit is contained in:
Darren Ranalli 2004-01-27 02:12:04 +00:00
parent 4927912722
commit 796acdd259
3 changed files with 42 additions and 11 deletions

View File

@ -45,6 +45,14 @@ class EntityTypeDesc:
""" returns dict of attribName -> attribDescriptor """
return self.attribDescDict
def getAttribsOfType(self, type):
"""returns list of attrib names of the given type"""
names = []
for attribName, desc in self.attribDescDict.items():
if desc.getDatatype() == type:
names.append(attribName)
return names
def privCompileAttribDescs(entTypeClass):
"""this compiles an ordered list of attribDescs for the Entity class
passed in. The attribute descriptors describe the properties of each

View File

@ -98,8 +98,16 @@ class LevelSpec:
return self.privGetScenarioEntityDict(scenario).keys()
def getAllEntIds(self):
"""this returns all of the entIds involved in the current scenario"""
return self.getGlobalEntIds() + self.getScenarioEntIds()
def getAllEntIdsFromAllScenarios(self):
"""this returns all of the entIds involved in all scenarios"""
entIds = self.getGlobalEntIds()
for scenario in xrange(self.getNumScenarios()):
entIds.extend(self.getScenarioEntIds(scenario))
return entIds
def getEntitySpec(self, entId):
assert entId in self.entId2specDict
specDict = self.entId2specDict[entId]
@ -120,7 +128,7 @@ class LevelSpec:
return self.getEntityZoneEntId(spec['parentEntId'])
def getEntType2ids(self, entIds):
"""given list of entIds, return dict of entType 2 entIds"""
"""given list of entIds, return dict of entType->entIds"""
entType2ids = {}
for entId in entIds:
type = self.getEntityType(entId)
@ -222,6 +230,30 @@ class LevelSpec:
del dict[entId]
del self.entId2specDict[entId]
def removeZoneReferences(self, removedZoneNums):
"""call with a list of zoneNums of zone entities that have just
been removed; will clean up references to those zones"""
assert self.hasEntityTypeReg()
# get dict of entType->entIds, for ALL scenarios
type2ids = self.getEntType2ids(self.getAllEntIdsFromAllScenarios())
# figure out which entity types have attributes that need to be
# updated
for type in type2ids:
typeDesc = self.entTypeReg.getTypeDesc(type)
visZoneListAttribs = typeDesc.getAttribsOfType('visZoneList')
if len(visZoneListAttribs) > 0:
# this entity type has at least one attrib of type
# 'visZoneList'.
# run through all of the existing entities of this type
for entId in type2ids[type]:
spec = self.getEntitySpec(entId)
# for each attrib of type 'visZoneList'...
for attribName in visZoneListAttribs:
# remove each of the removed zoneNums
for zoneNum in removedZoneNums:
while zoneNum in spec[attribName]:
spec[attribName].remove(zoneNum)
def getSpecImportsModuleName(self):
# name of module that should be imported by spec py file
return 'SpecImports'

View File

@ -121,13 +121,4 @@ def privUpdateSpec(spec, modelPath, entTypeModule, newZonesGloballyVisible=0):
spec.doSetAttrib(entId, 'visibility', visList)
# make sure none of the zones reference removed zones
# TODO: prune from other zoneList attribs
for entId in zoneEntIds:
visList = spec.getEntitySpec(entId)['visibility']
visDict = list2dict(visList)
for zoneNum in removedZoneNums:
if zoneNum in visDict:
del visDict[zoneNum]
visList = visDict.keys()
visList.sort()
spec.doSetAttrib(entId, 'visibility', visList)
spec.removeZoneReferences(removedZoneNums)