From 796acdd259516e5f911627e9c6161306a964f6cb Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Tue, 27 Jan 2004 02:12:04 +0000 Subject: [PATCH] remove all references to removed zones --- direct/src/level/EntityTypeDesc.py | 8 +++++++ direct/src/level/LevelSpec.py | 34 +++++++++++++++++++++++++++++- direct/src/level/SpecUtil.py | 11 +--------- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/direct/src/level/EntityTypeDesc.py b/direct/src/level/EntityTypeDesc.py index b045cf3bc8..7891f1ad94 100755 --- a/direct/src/level/EntityTypeDesc.py +++ b/direct/src/level/EntityTypeDesc.py @@ -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 diff --git a/direct/src/level/LevelSpec.py b/direct/src/level/LevelSpec.py index f725af503c..7e271a0de9 100755 --- a/direct/src/level/LevelSpec.py +++ b/direct/src/level/LevelSpec.py @@ -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' diff --git a/direct/src/level/SpecUtil.py b/direct/src/level/SpecUtil.py index a77a413213..9e3ec46e38 100755 --- a/direct/src/level/SpecUtil.py +++ b/direct/src/level/SpecUtil.py @@ -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)