From 4411cb805bc74b33f304910d273cf13740ff55b8 Mon Sep 17 00:00:00 2001 From: John Cote Date: Wed, 22 Jul 2015 01:45:01 -0400 Subject: [PATCH] gtfo has_key and range --- toontown/catalog/CatalogGardenItem.py | 9 +++++---- toontown/catalog/CatalogToonStatueItem.py | 2 +- toontown/estate/DistributedEstateAI.py | 8 ++++---- toontown/estate/DistributedFlower.py | 9 ++++----- toontown/estate/DistributedGagTree.py | 4 ++-- toontown/estate/DistributedGarden.py | 2 +- toontown/estate/DistributedGardenPlot.py | 1 - toontown/estate/DistributedLawnDecor.py | 4 ++-- toontown/estate/DistributedStatuary.py | 4 ++-- toontown/estate/DistributedToonStatuary.py | 2 +- 10 files changed, 22 insertions(+), 23 deletions(-) diff --git a/toontown/catalog/CatalogGardenItem.py b/toontown/catalog/CatalogGardenItem.py index 97ed7fb2..799f32d7 100755 --- a/toontown/catalog/CatalogGardenItem.py +++ b/toontown/catalog/CatalogGardenItem.py @@ -50,7 +50,7 @@ class CatalogGardenItem(CatalogItem.CatalogItem): def getPicture(self, avatar): 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] animationName = GardenGlobals.Specials[self.gardenIndex]['photoAnimation'][1] animationPath = photoModel + animationName @@ -79,8 +79,9 @@ class CatalogGardenItem(CatalogItem.CatalogItem): def cleanupPicture(self): CatalogItem.CatalogItem.cleanupPicture(self) - self.model.detachNode() - self.model = None + if hasattr(self, 'model') and self.model: + self.model.detachNode() + self.model = None return def output(self, store = -1): @@ -160,7 +161,7 @@ class CatalogGardenItem(CatalogItem.CatalogItem): result = False if canPlant < numBeansRequired: 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'] if avatar.shovelSkill < minSkill: result = True diff --git a/toontown/catalog/CatalogToonStatueItem.py b/toontown/catalog/CatalogToonStatueItem.py index ea09a38c..dcd4fe99 100755 --- a/toontown/catalog/CatalogToonStatueItem.py +++ b/toontown/catalog/CatalogToonStatueItem.py @@ -51,7 +51,7 @@ class CatalogToonStatueItem(CatalogGardenItem.CatalogGardenItem): def getAllToonStatues(self): 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)) return self.statueList diff --git a/toontown/estate/DistributedEstateAI.py b/toontown/estate/DistributedEstateAI.py index 49b9613b..eb0c12b0 100755 --- a/toontown/estate/DistributedEstateAI.py +++ b/toontown/estate/DistributedEstateAI.py @@ -505,7 +505,7 @@ class DistributedEstateAI(DistributedObjectAI): self.pond.setArea(ToontownGlobals.MyEstate) 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.setPondDoId(self.pond.getDoId()) target.generateWithRequired(self.zoneId) @@ -540,8 +540,8 @@ class DistributedEstateAI(DistributedObjectAI): self.spots.append(spot) ButterflyGlobals.generateIndexes(self.zoneId, ButterflyGlobals.ESTATE) - for i in range(0, ButterflyGlobals.NUM_BUTTERFLY_AREAS[ButterflyGlobals.ESTATE]): - for j in range(0, ButterflyGlobals.NUM_BUTTERFLIES[ButterflyGlobals.ESTATE]): + for i in xrange(0, ButterflyGlobals.NUM_BUTTERFLY_AREAS[ButterflyGlobals.ESTATE]): + for j in xrange(0, ButterflyGlobals.NUM_BUTTERFLIES[ButterflyGlobals.ESTATE]): bfly = DistributedButterflyAI.DistributedButterflyAI(self.air, ButterflyGlobals.ESTATE, i, self.zoneId) bfly.generateWithRequired(self.zoneId) bfly.start() @@ -844,7 +844,7 @@ class DistributedEstateAI(DistributedObjectAI): return self.items[5] def setIdList(self, idList): - for i in range(len(idList)): + for i in xrange(len(idList)): if i >= 6: return self.toons[i] = idList[i] diff --git a/toontown/estate/DistributedFlower.py b/toontown/estate/DistributedFlower.py index d90f0cab..2e885dab 100755 --- a/toontown/estate/DistributedFlower.py +++ b/toontown/estate/DistributedFlower.py @@ -1,12 +1,11 @@ -from toontown.estate import DistributedPlantBase 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 GardenGlobals from toontown.toontowngui import TTDialog from toontown.toonbase import TTLocalizer -from DistributedGardenBox import DistributedGardenBox - DIRT_AS_WATER_INDICATOR = True DIRT_MOUND_HEIGHT = 0.3 @@ -30,7 +29,7 @@ class DistributedFlower(DistributedPlantBase.DistributedPlantBase, FlowerBase.Fl def delete(self): DistributedPlantBase.DistributedPlantBase.delete(self) - + del self.dirtMound del self.sandMound @@ -53,7 +52,7 @@ class DistributedFlower(DistributedPlantBase.DistributedPlantBase, FlowerBase.Fl desat = wilt.find('**/*desat*') bloom.hide() leaves = wilt.findAllMatches('**/*leaf*') - for leafIndex in range(leaves.getNumPaths()): + for leafIndex in xrange(leaves.getNumPaths()): leaf = leaves.getPath(leafIndex) leaf.setColorScale(1.0, 0.3, 0.1, 1.0) diff --git a/toontown/estate/DistributedGagTree.py b/toontown/estate/DistributedGagTree.py index f5f3cb64..69167904 100755 --- a/toontown/estate/DistributedGagTree.py +++ b/toontown/estate/DistributedGagTree.py @@ -79,7 +79,7 @@ class DistributedGagTree(DistributedPlantBase.DistributedPlantBase): self.model.reparentTo(self.rotateNode) if self.isFruiting() and not self.isWilted(): 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)) if pos and not pos.isEmpty(): fruit = self.prop.copyTo(self.model) @@ -337,7 +337,7 @@ class DistributedGagTree(DistributedPlantBase.DistributedPlantBase): picker.traverse(render) if queue.getNumEntries() > 0: queue.sortEntries() - for index in range(queue.getNumEntries()): + for index in xrange(queue.getNumEntries()): entry = queue.getEntry(index) if DistributedLawnDecor.recurseParent(entry.getIntoNode(), 'terrain_DNARoot'): self.signModel.wrtReparentTo(render) diff --git a/toontown/estate/DistributedGarden.py b/toontown/estate/DistributedGarden.py index e52a5a72..f7b1263e 100755 --- a/toontown/estate/DistributedGarden.py +++ b/toontown/estate/DistributedGarden.py @@ -31,7 +31,7 @@ class DistributedGarden(DistributedObject.DistributedObject): self.radius = 0 self.gridCells = 20 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.dx = 1.0 / self.gridCells diff --git a/toontown/estate/DistributedGardenPlot.py b/toontown/estate/DistributedGardenPlot.py index e5367909..f56538a3 100755 --- a/toontown/estate/DistributedGardenPlot.py +++ b/toontown/estate/DistributedGardenPlot.py @@ -137,7 +137,6 @@ class DistributedGardenPlot(DistributedLawnDecor.DistributedLawnDecor): recipeKey = GardenGlobals.getRecipeKey(recipeStr, special) if recipeKey >= 0: species, variety = GardenGlobals.getSpeciesVarietyGivenRecipe(recipeKey) - print 'RK>0', species, variety if species >= 0 and variety >= 0: self.sendUpdate('plantFlower', [species, variety]) successPlanting = True diff --git a/toontown/estate/DistributedLawnDecor.py b/toontown/estate/DistributedLawnDecor.py index b9bf5046..1a2a7c1b 100755 --- a/toontown/estate/DistributedLawnDecor.py +++ b/toontown/estate/DistributedLawnDecor.py @@ -177,7 +177,7 @@ class DistributedLawnDecor(DistributedNode.DistributedNode, NodePath, ShadowCast picker.traverse(render) if queue.getNumEntries() > 0: queue.sortEntries() - for index in range(queue.getNumEntries()): + for index in xrange(queue.getNumEntries()): entry = queue.getEntry(index) if recurseParent(entry.getIntoNode(), 'terrain_DNARoot'): self.movieNode.setZ(entry.getSurfacePoint(self)[2]) @@ -186,7 +186,7 @@ class DistributedLawnDecor(DistributedNode.DistributedNode, NodePath, ShadowCast picker.traverse(render) if queue.getNumEntries() > 0: queue.sortEntries() - for index in range(queue.getNumEntries()): + for index in xrange(queue.getNumEntries()): entry = queue.getEntry(index) if recurseParent(entry.getIntoNode(), 'terrain_DNARoot'): self.setZ(entry.getSurfacePoint(render)[2] + self.stickUp + 0.1) diff --git a/toontown/estate/DistributedStatuary.py b/toontown/estate/DistributedStatuary.py index 4af314d4..4d9680b1 100755 --- a/toontown/estate/DistributedStatuary.py +++ b/toontown/estate/DistributedStatuary.py @@ -43,10 +43,10 @@ class DistributedStatuary(DistributedLawnDecor.DistributedLawnDecor): self.plantType = GardenGlobals.PlantAttributes[typeIndex]['plantType'] self.modelPath = GardenGlobals.PlantAttributes[typeIndex]['model'] self.pinballScore = None - if GardenGlobals.PlantAttributes[typeIndex].has_key('pinballScore'): + if 'pinballScore' in GardenGlobals.PlantAttributes[typeIndex]: self.pinballScore = GardenGlobals.PlantAttributes[typeIndex]['pinballScore'] self.worldScale = 1.0 - if GardenGlobals.PlantAttributes[typeIndex].has_key('worldScale'): + if 'worldScale' in GardenGlobals.PlantAttributes[typeIndex]: self.worldScale = GardenGlobals.PlantAttributes[typeIndex]['worldScale'] return diff --git a/toontown/estate/DistributedToonStatuary.py b/toontown/estate/DistributedToonStatuary.py index 4449a2dc..3926a79e 100755 --- a/toontown/estate/DistributedToonStatuary.py +++ b/toontown/estate/DistributedToonStatuary.py @@ -112,7 +112,7 @@ class DistributedToonStatuary(DistributedStatuary.DistributedStatuary): if sleeves: sleeves.setTexture(desatSleeveTex, 1) bottoms = torso.findAllMatches('**/torso-bot*') - for bottomNum in range(0, bottoms.getNumPaths()): + for bottomNum in xrange(0, bottoms.getNumPaths()): bottom = bottoms.getPath(bottomNum) if bottom: if self.toon.style.torso[1] == 's':