gtfo has_key and range

This commit is contained in:
John Cote 2015-07-22 01:45:01 -04:00
parent c042107c4d
commit 4411cb805b
10 changed files with 22 additions and 23 deletions

View file

@ -50,7 +50,7 @@ class CatalogGardenItem(CatalogItem.CatalogItem):
def getPicture(self, avatar): def getPicture(self, avatar):
photoModel = GardenGlobals.Specials[self.gardenIndex]['photoModel'] photoModel = GardenGlobals.Specials[self.gardenIndex]['photoModel']
if GardenGlobals.Specials[self.gardenIndex].has_key('photoAnimation'): if 'photoAnimation' in GardenGlobals.Specials[self.gardenIndex]:
modelPath = photoModel + GardenGlobals.Specials[self.gardenIndex]['photoAnimation'][0] modelPath = photoModel + GardenGlobals.Specials[self.gardenIndex]['photoAnimation'][0]
animationName = GardenGlobals.Specials[self.gardenIndex]['photoAnimation'][1] animationName = GardenGlobals.Specials[self.gardenIndex]['photoAnimation'][1]
animationPath = photoModel + animationName animationPath = photoModel + animationName
@ -79,8 +79,9 @@ class CatalogGardenItem(CatalogItem.CatalogItem):
def cleanupPicture(self): def cleanupPicture(self):
CatalogItem.CatalogItem.cleanupPicture(self) CatalogItem.CatalogItem.cleanupPicture(self)
self.model.detachNode() if hasattr(self, 'model') and self.model:
self.model = None self.model.detachNode()
self.model = None
return return
def output(self, store = -1): def output(self, store = -1):
@ -160,7 +161,7 @@ class CatalogGardenItem(CatalogItem.CatalogItem):
result = False result = False
if canPlant < numBeansRequired: if canPlant < numBeansRequired:
result = True result = True
if not result and GardenGlobals.Specials.has_key(self.gardenIndex) and GardenGlobals.Specials[self.gardenIndex].has_key('minSkill'): if not result and self.gardenIndex in GardenGlobals.Specials and 'minSkill' in GardenGlobals.Specials[self.gardenIndex]:
minSkill = GardenGlobals.Specials[self.gardenIndex]['minSkill'] minSkill = GardenGlobals.Specials[self.gardenIndex]['minSkill']
if avatar.shovelSkill < minSkill: if avatar.shovelSkill < minSkill:
result = True result = True

View file

@ -51,7 +51,7 @@ class CatalogToonStatueItem(CatalogGardenItem.CatalogGardenItem):
def getAllToonStatues(self): def getAllToonStatues(self):
self.statueList = [] self.statueList = []
for index in range(self.startPoseIndex, self.endPoseIndex + 1): for index in xrange(self.startPoseIndex, self.endPoseIndex + 1):
self.statueList.append(CatalogToonStatueItem(index, 1, endPoseIndex=index)) self.statueList.append(CatalogToonStatueItem(index, 1, endPoseIndex=index))
return self.statueList return self.statueList

View file

@ -505,7 +505,7 @@ class DistributedEstateAI(DistributedObjectAI):
self.pond.setArea(ToontownGlobals.MyEstate) self.pond.setArea(ToontownGlobals.MyEstate)
self.pond.generateWithRequired(self.zoneId) self.pond.generateWithRequired(self.zoneId)
for i in range(FishingTargetGlobals.getNumTargets(ToontownGlobals.MyEstate)): for i in xrange(FishingTargetGlobals.getNumTargets(ToontownGlobals.MyEstate)):
target = DistributedFishingTargetAI(self.air) target = DistributedFishingTargetAI(self.air)
target.setPondDoId(self.pond.getDoId()) target.setPondDoId(self.pond.getDoId())
target.generateWithRequired(self.zoneId) target.generateWithRequired(self.zoneId)
@ -540,8 +540,8 @@ class DistributedEstateAI(DistributedObjectAI):
self.spots.append(spot) self.spots.append(spot)
ButterflyGlobals.generateIndexes(self.zoneId, ButterflyGlobals.ESTATE) ButterflyGlobals.generateIndexes(self.zoneId, ButterflyGlobals.ESTATE)
for i in range(0, ButterflyGlobals.NUM_BUTTERFLY_AREAS[ButterflyGlobals.ESTATE]): for i in xrange(0, ButterflyGlobals.NUM_BUTTERFLY_AREAS[ButterflyGlobals.ESTATE]):
for j in range(0, ButterflyGlobals.NUM_BUTTERFLIES[ButterflyGlobals.ESTATE]): for j in xrange(0, ButterflyGlobals.NUM_BUTTERFLIES[ButterflyGlobals.ESTATE]):
bfly = DistributedButterflyAI.DistributedButterflyAI(self.air, ButterflyGlobals.ESTATE, i, self.zoneId) bfly = DistributedButterflyAI.DistributedButterflyAI(self.air, ButterflyGlobals.ESTATE, i, self.zoneId)
bfly.generateWithRequired(self.zoneId) bfly.generateWithRequired(self.zoneId)
bfly.start() bfly.start()
@ -844,7 +844,7 @@ class DistributedEstateAI(DistributedObjectAI):
return self.items[5] return self.items[5]
def setIdList(self, idList): def setIdList(self, idList):
for i in range(len(idList)): for i in xrange(len(idList)):
if i >= 6: if i >= 6:
return return
self.toons[i] = idList[i] self.toons[i] = idList[i]

View file

@ -1,12 +1,11 @@
from toontown.estate import DistributedPlantBase
from direct.directnotify import DirectNotifyGlobal from direct.directnotify import DirectNotifyGlobal
from toontown.estate import DistributedPlantBase
from toontown.estate.DistributedGardenBox import DistributedGardenBox
from toontown.estate import FlowerBase from toontown.estate import FlowerBase
from toontown.estate import GardenGlobals from toontown.estate import GardenGlobals
from toontown.toontowngui import TTDialog from toontown.toontowngui import TTDialog
from toontown.toonbase import TTLocalizer from toontown.toonbase import TTLocalizer
from DistributedGardenBox import DistributedGardenBox
DIRT_AS_WATER_INDICATOR = True DIRT_AS_WATER_INDICATOR = True
DIRT_MOUND_HEIGHT = 0.3 DIRT_MOUND_HEIGHT = 0.3
@ -30,7 +29,7 @@ class DistributedFlower(DistributedPlantBase.DistributedPlantBase, FlowerBase.Fl
def delete(self): def delete(self):
DistributedPlantBase.DistributedPlantBase.delete(self) DistributedPlantBase.DistributedPlantBase.delete(self)
del self.dirtMound del self.dirtMound
del self.sandMound del self.sandMound
@ -53,7 +52,7 @@ class DistributedFlower(DistributedPlantBase.DistributedPlantBase, FlowerBase.Fl
desat = wilt.find('**/*desat*') desat = wilt.find('**/*desat*')
bloom.hide() bloom.hide()
leaves = wilt.findAllMatches('**/*leaf*') leaves = wilt.findAllMatches('**/*leaf*')
for leafIndex in range(leaves.getNumPaths()): for leafIndex in xrange(leaves.getNumPaths()):
leaf = leaves.getPath(leafIndex) leaf = leaves.getPath(leafIndex)
leaf.setColorScale(1.0, 0.3, 0.1, 1.0) leaf.setColorScale(1.0, 0.3, 0.1, 1.0)

View file

@ -79,7 +79,7 @@ class DistributedGagTree(DistributedPlantBase.DistributedPlantBase):
self.model.reparentTo(self.rotateNode) self.model.reparentTo(self.rotateNode)
if self.isFruiting() and not self.isWilted(): if self.isFruiting() and not self.isWilted():
self.fruits = [] self.fruits = []
for i in range(1, self.maxFruit + 1): for i in xrange(1, self.maxFruit + 1):
pos = self.model.find('**/locator' + str(i)) pos = self.model.find('**/locator' + str(i))
if pos and not pos.isEmpty(): if pos and not pos.isEmpty():
fruit = self.prop.copyTo(self.model) fruit = self.prop.copyTo(self.model)
@ -337,7 +337,7 @@ class DistributedGagTree(DistributedPlantBase.DistributedPlantBase):
picker.traverse(render) picker.traverse(render)
if queue.getNumEntries() > 0: if queue.getNumEntries() > 0:
queue.sortEntries() queue.sortEntries()
for index in range(queue.getNumEntries()): for index in xrange(queue.getNumEntries()):
entry = queue.getEntry(index) entry = queue.getEntry(index)
if DistributedLawnDecor.recurseParent(entry.getIntoNode(), 'terrain_DNARoot'): if DistributedLawnDecor.recurseParent(entry.getIntoNode(), 'terrain_DNARoot'):
self.signModel.wrtReparentTo(render) self.signModel.wrtReparentTo(render)

View file

@ -31,7 +31,7 @@ class DistributedGarden(DistributedObject.DistributedObject):
self.radius = 0 self.radius = 0
self.gridCells = 20 self.gridCells = 20
self.propTable = [None] * self.gridCells self.propTable = [None] * self.gridCells
for i in range(len(self.propTable)): for i in xrange(len(self.propTable)):
self.propTable[i] = [None] * self.gridCells self.propTable[i] = [None] * self.gridCells
self.dx = 1.0 / self.gridCells self.dx = 1.0 / self.gridCells

View file

@ -137,7 +137,6 @@ class DistributedGardenPlot(DistributedLawnDecor.DistributedLawnDecor):
recipeKey = GardenGlobals.getRecipeKey(recipeStr, special) recipeKey = GardenGlobals.getRecipeKey(recipeStr, special)
if recipeKey >= 0: if recipeKey >= 0:
species, variety = GardenGlobals.getSpeciesVarietyGivenRecipe(recipeKey) species, variety = GardenGlobals.getSpeciesVarietyGivenRecipe(recipeKey)
print 'RK>0', species, variety
if species >= 0 and variety >= 0: if species >= 0 and variety >= 0:
self.sendUpdate('plantFlower', [species, variety]) self.sendUpdate('plantFlower', [species, variety])
successPlanting = True successPlanting = True

View file

@ -177,7 +177,7 @@ class DistributedLawnDecor(DistributedNode.DistributedNode, NodePath, ShadowCast
picker.traverse(render) picker.traverse(render)
if queue.getNumEntries() > 0: if queue.getNumEntries() > 0:
queue.sortEntries() queue.sortEntries()
for index in range(queue.getNumEntries()): for index in xrange(queue.getNumEntries()):
entry = queue.getEntry(index) entry = queue.getEntry(index)
if recurseParent(entry.getIntoNode(), 'terrain_DNARoot'): if recurseParent(entry.getIntoNode(), 'terrain_DNARoot'):
self.movieNode.setZ(entry.getSurfacePoint(self)[2]) self.movieNode.setZ(entry.getSurfacePoint(self)[2])
@ -186,7 +186,7 @@ class DistributedLawnDecor(DistributedNode.DistributedNode, NodePath, ShadowCast
picker.traverse(render) picker.traverse(render)
if queue.getNumEntries() > 0: if queue.getNumEntries() > 0:
queue.sortEntries() queue.sortEntries()
for index in range(queue.getNumEntries()): for index in xrange(queue.getNumEntries()):
entry = queue.getEntry(index) entry = queue.getEntry(index)
if recurseParent(entry.getIntoNode(), 'terrain_DNARoot'): if recurseParent(entry.getIntoNode(), 'terrain_DNARoot'):
self.setZ(entry.getSurfacePoint(render)[2] + self.stickUp + 0.1) self.setZ(entry.getSurfacePoint(render)[2] + self.stickUp + 0.1)

View file

@ -43,10 +43,10 @@ class DistributedStatuary(DistributedLawnDecor.DistributedLawnDecor):
self.plantType = GardenGlobals.PlantAttributes[typeIndex]['plantType'] self.plantType = GardenGlobals.PlantAttributes[typeIndex]['plantType']
self.modelPath = GardenGlobals.PlantAttributes[typeIndex]['model'] self.modelPath = GardenGlobals.PlantAttributes[typeIndex]['model']
self.pinballScore = None self.pinballScore = None
if GardenGlobals.PlantAttributes[typeIndex].has_key('pinballScore'): if 'pinballScore' in GardenGlobals.PlantAttributes[typeIndex]:
self.pinballScore = GardenGlobals.PlantAttributes[typeIndex]['pinballScore'] self.pinballScore = GardenGlobals.PlantAttributes[typeIndex]['pinballScore']
self.worldScale = 1.0 self.worldScale = 1.0
if GardenGlobals.PlantAttributes[typeIndex].has_key('worldScale'): if 'worldScale' in GardenGlobals.PlantAttributes[typeIndex]:
self.worldScale = GardenGlobals.PlantAttributes[typeIndex]['worldScale'] self.worldScale = GardenGlobals.PlantAttributes[typeIndex]['worldScale']
return return

View file

@ -112,7 +112,7 @@ class DistributedToonStatuary(DistributedStatuary.DistributedStatuary):
if sleeves: if sleeves:
sleeves.setTexture(desatSleeveTex, 1) sleeves.setTexture(desatSleeveTex, 1)
bottoms = torso.findAllMatches('**/torso-bot*') bottoms = torso.findAllMatches('**/torso-bot*')
for bottomNum in range(0, bottoms.getNumPaths()): for bottomNum in xrange(0, bottoms.getNumPaths()):
bottom = bottoms.getPath(bottomNum) bottom = bottoms.getPath(bottomNum)
if bottom: if bottom:
if self.toon.style.torso[1] == 's': if self.toon.style.torso[1] == 's':