mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
remove all references to removed zones
This commit is contained in:
parent
4927912722
commit
796acdd259
@ -45,6 +45,14 @@ class EntityTypeDesc:
|
|||||||
""" returns dict of attribName -> attribDescriptor """
|
""" returns dict of attribName -> attribDescriptor """
|
||||||
return self.attribDescDict
|
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):
|
def privCompileAttribDescs(entTypeClass):
|
||||||
"""this compiles an ordered list of attribDescs for the Entity class
|
"""this compiles an ordered list of attribDescs for the Entity class
|
||||||
passed in. The attribute descriptors describe the properties of each
|
passed in. The attribute descriptors describe the properties of each
|
||||||
|
@ -98,8 +98,16 @@ class LevelSpec:
|
|||||||
return self.privGetScenarioEntityDict(scenario).keys()
|
return self.privGetScenarioEntityDict(scenario).keys()
|
||||||
|
|
||||||
def getAllEntIds(self):
|
def getAllEntIds(self):
|
||||||
|
"""this returns all of the entIds involved in the current scenario"""
|
||||||
return self.getGlobalEntIds() + self.getScenarioEntIds()
|
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):
|
def getEntitySpec(self, entId):
|
||||||
assert entId in self.entId2specDict
|
assert entId in self.entId2specDict
|
||||||
specDict = self.entId2specDict[entId]
|
specDict = self.entId2specDict[entId]
|
||||||
@ -120,7 +128,7 @@ class LevelSpec:
|
|||||||
return self.getEntityZoneEntId(spec['parentEntId'])
|
return self.getEntityZoneEntId(spec['parentEntId'])
|
||||||
|
|
||||||
def getEntType2ids(self, entIds):
|
def getEntType2ids(self, entIds):
|
||||||
"""given list of entIds, return dict of entType 2 entIds"""
|
"""given list of entIds, return dict of entType->entIds"""
|
||||||
entType2ids = {}
|
entType2ids = {}
|
||||||
for entId in entIds:
|
for entId in entIds:
|
||||||
type = self.getEntityType(entId)
|
type = self.getEntityType(entId)
|
||||||
@ -222,6 +230,30 @@ class LevelSpec:
|
|||||||
del dict[entId]
|
del dict[entId]
|
||||||
del self.entId2specDict[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):
|
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
|
||||||
return 'SpecImports'
|
return 'SpecImports'
|
||||||
|
@ -121,13 +121,4 @@ def privUpdateSpec(spec, modelPath, entTypeModule, newZonesGloballyVisible=0):
|
|||||||
spec.doSetAttrib(entId, 'visibility', visList)
|
spec.doSetAttrib(entId, 'visibility', visList)
|
||||||
|
|
||||||
# make sure none of the zones reference removed zones
|
# make sure none of the zones reference removed zones
|
||||||
# TODO: prune from other zoneList attribs
|
spec.removeZoneReferences(removedZoneNums)
|
||||||
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)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user