Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #120 from aqua-uru/isinstance
Browse files Browse the repository at this point in the history
replace `type(x) == y` checks by `isinstance(x, y)` and clean up resulting code
  • Loading branch information
Hoikas committed Mar 26, 2020
2 parents b198c73 + 090897f commit 999582f
Show file tree
Hide file tree
Showing 109 changed files with 776 additions and 845 deletions.
4 changes: 2 additions & 2 deletions Python/BaronCityOffice.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def OnFirstUpdate(self):
#~ kChronicleVarName = "LinksIntoGarden"
#~ kChronicleVarType = 0
#~ vault = ptVault()
#~ if type(vault) != type(None):
#~ if vault is not None:
#~ entry = vault.findChronicleEntry(kChronicleVarName)
#~ if type(entry) == type(None):
#~ if entry is None:
#~ # not found... add current level chronicle
#~ vault.addChronicleEntry(kChronicleVarName,kChronicleVarType,"%d" %(1))
#~ PtDebugPrint("%s:\tentered new chronicle counter %s" % (kModuleName,kChronicleVarName))
Expand Down
8 changes: 4 additions & 4 deletions Python/Cleft.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ def __init__(self):

vault = ptVault()
entryCleft = vault.findChronicleEntry("CleftSolved")
if type(entryCleft) != type(None):
if entryCleft is not None:
entryCleftValue = entryCleft.chronicleGetValue()
if entryCleftValue != "yes":
loadZandi = 1
loadBook = 1
elif type(entryCleft) == type(None):
elif entryCleft is None:
loadZandi = 1
loadBook = 1

vault = ptVault()
entryTomahna = vault.findChronicleEntry("TomahnaLoad")
if type(entryTomahna) != type(None):
if entryTomahna is not None:
entryTomahnaValue = entryTomahna.chronicleGetValue()
if entryTomahnaValue == "yes":
loadTomahna = 1
Expand Down Expand Up @@ -151,7 +151,7 @@ def OnFirstUpdate(self):
#~ # test for first time to play the intro movie
#~ vault = ptVault()
#~ entry = vault.findChronicleEntry(kIntroPlayedChronicle)
#~ if type(entry) != type(None):
#~ if entry is not None:
#~ # already played intro sometime in the past... just let 'em play
#~ PtSendKIMessage(kEnableKIandBB,0)
#~ else:
Expand Down
2 changes: 1 addition & 1 deletion Python/ErcanaCitySilo.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def OnServerInitComplete(self):

vault = ptVault()
entry = vault.findChronicleEntry("GotPellet")
if type(entry) != type(None):
if entry is not None:
entryValue = entry.chronicleGetValue()
gotPellet = string.atoi(entryValue)
if gotPellet != 0:
Expand Down
4 changes: 2 additions & 2 deletions Python/Garden.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def OnFirstUpdate(self):
#~ kChronicleVarName = "LinksIntoGarden"
#~ kChronicleVarType = 0
#~ vault = ptVault()
#~ if type(vault) != type(None):
#~ if vault is not None:
#~ entry = vault.findChronicleEntry(kChronicleVarName)
#~ if type(entry) == type(None):
#~ if entry is None:
#~ # not found... add current level chronicle
#~ vault.addChronicleEntry(kChronicleVarName,kChronicleVarType,"%d" %(1))
#~ PtDebugPrint("%s:\tentered new chronicle counter %s" % (kModuleName,kChronicleVarName))
Expand Down
24 changes: 11 additions & 13 deletions Python/GardenBugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,20 @@ def __init__(self):

def ISaveBugCount(self, count):
vault = ptVault()
if type(vault) != type(None):
entry = vault.findChronicleEntry(chronicleEntryName)
if type(entry) == type(None):
# not found... add chronicle
vault.addChronicleEntry(chronicleEntryName,0,str(count))
else:
entry.chronicleSetValue(str(count))
entry.save()
entry = vault.findChronicleEntry(chronicleEntryName)
if entry is None:
# not found... add chronicle
vault.addChronicleEntry(chronicleEntryName,0,str(count))
else:
entry.chronicleSetValue(str(count))
entry.save()

def IGetBugCount(self):
vault = ptVault()
if type(vault) != type(None):
entry = vault.findChronicleEntry(chronicleEntryName)
if type(entry) != type(None):
return int(entry.chronicleGetValue())
return 0 # no vault or no chronicle var
entry = vault.findChronicleEntry(chronicleEntryName)
if entry is not None:
return int(entry.chronicleGetValue())
return 0 # no chronicle var

def OnServerInitComplete(self):
self.ageSDL = PtGetAgeSDL()
Expand Down
4 changes: 2 additions & 2 deletions Python/Gira.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def OnFirstUpdate(self):
#~ kChronicleVarName = "LinksIntoGarden"
#~ kChronicleVarType = 0
#~ vault = ptVault()
#~ if type(vault) != type(None):
#~ if vault is not None:
#~ entry = vault.findChronicleEntry(kChronicleVarName)
#~ if type(entry) == type(None):
#~ if entry is None:
#~ # not found... add current level chronicle
#~ vault.addChronicleEntry(kChronicleVarName,kChronicleVarType,"%d" %(1))
#~ PtDebugPrint("%s:\tentered new chronicle counter %s" % (kModuleName,kChronicleVarName))
Expand Down
24 changes: 11 additions & 13 deletions Python/GiraBugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,20 @@ def __init__(self):

def ISaveBugCount(self, count):
vault = ptVault()
if type(vault) != type(None):
entry = vault.findChronicleEntry(chronicleEntryName)
if type(entry) == type(None):
# not found... add chronicle
vault.addChronicleEntry(chronicleEntryName,0,str(count))
else:
entry.chronicleSetValue(str(count))
entry.save()
entry = vault.findChronicleEntry(chronicleEntryName)
if entry is None:
# not found... add chronicle
vault.addChronicleEntry(chronicleEntryName,0,str(count))
else:
entry.chronicleSetValue(str(count))
entry.save()

def IGetBugCount(self):
vault = ptVault()
if type(vault) != type(None):
entry = vault.findChronicleEntry(chronicleEntryName)
if type(entry) != type(None):
return int(entry.chronicleGetValue())
return 0 # no vault or no chronicle var
entry = vault.findChronicleEntry(chronicleEntryName)
if entry is not None:
return int(entry.chronicleGetValue())
return 0 # no chronicle var

def OnServerInitComplete(self):
avatar = 0
Expand Down
2 changes: 1 addition & 1 deletion Python/GiraCave1.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self):
self.version = 1

def OnServerInitComplete(self):
if type(sdlSolved.value) == type("") and sdlSolved.value != "":
if sdlSolved.value:
self.ageSDL = PtGetAgeSDL()
self.ageSDL.setFlags(sdlSolved.value,1,1)
self.ageSDL.sendToClients(sdlSolved.value)
Expand Down
4 changes: 2 additions & 2 deletions Python/Kadish.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def OnFirstUpdate(self):
#~ kChronicleVarName = "LinksIntoGarden"
#~ kChronicleVarType = 0
#~ vault = ptVault()
#~ if type(vault) != type(None):
#~ if vault is not None:
#~ entry = vault.findChronicleEntry(kChronicleVarName)
#~ if type(entry) == type(None):
#~ if entry is None:
#~ # not found... add current level chronicle
#~ vault.addChronicleEntry(kChronicleVarName,kChronicleVarType,"%d" %(1))
#~ PtDebugPrint("%s:\tentered new chronicle counter %s" % (kModuleName,kChronicleVarName))
Expand Down
4 changes: 2 additions & 2 deletions Python/Neighborhood.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def OnFirstUpdate(self):
#~ kChronicleVarName = "LinksIntoNeighborhood"
#~ kChronicleVarType = 0
#~ vault = ptVault()
#~ if type(vault) != type(None):
#~ if vault is not None:
#~ entry = vault.findChronicleEntry(kChronicleVarName)
#~ if type(entry) == type(None):
#~ if entry is None:
#~ # not found... add current level chronicle
#~ vault.addChronicleEntry(kChronicleVarName,kChronicleVarType,"%d" %(1))
#~ PtDebugPrint("%s:\tentered new chronicle counter %s" % (kModuleName,kChronicleVarName))
Expand Down
2 changes: 1 addition & 1 deletion Python/PelletBahroCave.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def OnServerInitComplete(self):
lowerCave = 0
vault = ptVault()
entry = vault.findChronicleEntry("GotPellet")
if type(entry) != type(None):
if entry is not None:
entryValue = entry.chronicleGetValue()
gotPellet = string.atoi(entryValue)
if gotPellet != 0:
Expand Down
6 changes: 3 additions & 3 deletions Python/Personal.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def OnFirstUpdate(self):
# test for first time to play the intro movie
vault = ptVault()
entry = vault.findChronicleEntry(kIntroPlayedChronicle)
if type(entry) != type(None):
if entry is not None:
# already played intro sometime in the past... just let 'em play
# enable twice because if we came from the ACA (closet->ACA->personal) it was disabled twice
PtSendKIMessage(kEnableKIandBB,0)
Expand Down Expand Up @@ -132,9 +132,9 @@ def OnFirstUpdate(self):
#~ kChronicleVarName = "LinksIntoPersonalAge"
#~ kChronicleVarType = 0
#~ vault = ptVault()
#~ if type(vault) != type(None):
#~ if vault is not None:
#~ entry = vault.findChronicleEntry(kChronicleVarName)
#~ if type(entry) == type(None):
#~ if entry is None:
#~ # not found... add current level chronicle
#~ vault.addChronicleEntry(kChronicleVarName,kChronicleVarType,"%d" %(1))
#~ PtDebugPrint("%s:\tentered new chronicle counter %s" % (kModuleName,kChronicleVarName))
Expand Down
4 changes: 2 additions & 2 deletions Python/Teledahn.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def OnFirstUpdate(self):
#~ kChronicleVarName = "LinksIntoTeledahn"
#~ kChronicleVarType = 0
#~ vault = ptVault()
#~ if type(vault) != type(None):
#~ if vault is not None:
#~ entry = vault.findChronicleEntry(kChronicleVarName)
#~ if type(entry) == type(None):
#~ if entry is None:
#~ # not found... add current level chronicle
#~ vault.addChronicleEntry(kChronicleVarName,kChronicleVarType,"%d" %(1))
#~ PtDebugPrint("%s:\tentered new chronicle counter %s" % (kModuleName,kChronicleVarName))
Expand Down
2 changes: 1 addition & 1 deletion Python/ahnyVogondolaRideV2.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
def DisableVogControls( enabledControlList ):
disableControlList = [actVogEjectFront, actVogEjectRear, actVogThrottleF, actVogThrottleB, actVogThrottleRevF, actVogThrottleRevB, actVogDirection, actVogDirectionRev]

if type(enabledControlList) == type( [] ):
if isinstance(enabledControlList, list):
for control in enabledControlList:
disableControlList.remove(control)
control.enable()
Expand Down
50 changes: 24 additions & 26 deletions Python/bhroBahroYeeshaCave.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def OnFirstUpdate(self):
vault = ptVault()
entry = vault.findChronicleEntry("BahroCave")

if type(entry) == type(None):
if entry is None:
PtDebugPrint("DEBUG: bhroBahroYeeshaCave.OnFirstUpdate: Did not find BahroCave chronicle...creating")
vault.addChronicleEntry("BahroCave",0,"0")

Expand Down Expand Up @@ -432,7 +432,7 @@ def UpdatePoleStates(self):


def SetState(self, age, state):
if type(state) == type(0):
if isinstance(state, int):
#PtDebugPrint("Setting %s state to %d" % (age, state))
psnlSDL = xPsnlVaultSDL()

Expand Down Expand Up @@ -542,16 +542,15 @@ def DisablePole(self, age, fforward = 0):
self.ageDict[age]['PoleCollider'].value.physics.suppress(1)
if not fforward:
vault = ptVault()
if type(vault) != type(None): #is the Vault online?
psnlSDL = vault.getPsnlAgeSDL()
if psnlSDL:
ypageSDL = psnlSDL.findVar("YeeshaPage25")
if ypageSDL:
size, state = divmod(ypageSDL.getInt(), 10)
print "YeeshaPage25 = ",state
if state == 1:
print "bhroBahroYeeshaCave.DisablePole(): sending the pole and YeeshaPage25 is on! will do the age's wedge..."
self.DoWedge()
psnlSDL = vault.getPsnlAgeSDL()
if psnlSDL:
ypageSDL = psnlSDL.findVar("YeeshaPage25")
if ypageSDL:
size, state = divmod(ypageSDL.getInt(), 10)
print "YeeshaPage25 = ",state
if state == 1:
print "bhroBahroYeeshaCave.DisablePole(): sending the pole and YeeshaPage25 is on! will do the age's wedge..."
self.DoWedge()


def EnablePole(self, age, fforward = 0):
Expand Down Expand Up @@ -580,18 +579,17 @@ def PostPoleRemove(self, age):

def PostJCOneShot(self, age):
vault = ptVault()
if type(vault) != type(None): #is the Vault online?
psnlSDL = vault.getPsnlAgeSDL()
if psnlSDL:
ypageSDL = psnlSDL.findVar("YeeshaPage25")
if ypageSDL:
size, state = divmod(ypageSDL.getInt(), 10)
print "YeeshaPage25 = ",state
if state != 1:
print "bhroBahroYeeshaCave.PostJCOneShot(): can't send pole to Relto, YeeshaPage25 is off! Returning the pole..."
self.ageDict[age]['JCClickable'].disable()
self.ageDict[age]['PoleRemove'].run(self.key, state="Reject")
return
psnlSDL = vault.getPsnlAgeSDL()
if psnlSDL:
ypageSDL = psnlSDL.findVar("YeeshaPage25")
if ypageSDL:
size, state = divmod(ypageSDL.getInt(), 10)
print "YeeshaPage25 = ",state
if state != 1:
print "bhroBahroYeeshaCave.PostJCOneShot(): can't send pole to Relto, YeeshaPage25 is off! Returning the pole..."
self.ageDict[age]['JCClickable'].disable()
self.ageDict[age]['PoleRemove'].run(self.key, state="Reject")
return

self.UpdatePoleStates()

Expand Down Expand Up @@ -784,7 +782,7 @@ def GetAutoStartLevel(self):
print "bhroBahroYeeshaCave.GetAutoStartLevel()"
vault = ptVault()
bc = vault.findChronicleEntry("BahroCave")
if type(bc) != type(None):
if bc is not None:
val = bc.chronicleGetValue()
if val == "":
return 0
Expand All @@ -797,7 +795,7 @@ def GetAutoStartLevel(self):
def IncrementAutoStartLevel(self):
vault = ptVault()
bc = vault.findChronicleEntry("BahroCave")
if type(bc) != type(None):
if bc is not None:
val = bc.chronicleGetValue()
if val == "":
val = 0
Expand Down
4 changes: 2 additions & 2 deletions Python/clftGetPersonalBook.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def OnFirstUpdate(self):
pass
#~ vault = ptVault()
#~ entry = vault.findChronicleEntry("JourneyClothProgress")
#~ if type(entry) != type(None):
#~ if entry is not None:
#~ FoundJCs = entry.chronicleGetValue()
#~ if "Z" in FoundJCs:
#~ PtPageOutNode("clftYeeshaBookVis")
Expand Down Expand Up @@ -245,7 +245,7 @@ def OnTimer(self,id):
gDemoMovie.playPaused()
elif id == kTrailerFadeInID:
PtDebugPrint("xLiveTrailer - roll the movie",level=kDebugDumpLevel)
if type(gDemoMovie) != type(None):
if gDemoMovie is not None:
gDemoMovie.resume()
elif id == kTrailerDoneID:
print "Quitting demo now..."
Expand Down
12 changes: 6 additions & 6 deletions Python/clftImager.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,10 @@ def GetAgeNode(self, age):
vault = ptVault()

chron = vault.findChronicleEntry("BahroCave")
if type(chron) != type(None):
if chron is not None:
ageChronRefList = chron.getChildNodeRefList()

if type(ageChronRefList) != type(None):
if ageChronRefList is not None:
for ageChron in ageChronRefList:
ageChild = ageChron.getChild()

Expand Down Expand Up @@ -637,7 +637,7 @@ def EndgameSolved(self):
boolCleftSolved = 0
vault = ptVault()
entry = vault.findChronicleEntry("CleftSolved")
if type(entry) != type(None):
if entry is not None:
if entry.chronicleGetValue() == "yes":
boolCleftSolved = 1

Expand All @@ -649,7 +649,7 @@ def EndgameSolved(self):

for age in ["Teledahn", "Garden", "Garrison", "Kadish"]:
symbol = self.GetAgeSolutionSymbol(age)
if type(symbol) == type(""):
if isinstance(symbol, str):
symbol = int(symbol)
solutionList.append(symbol)

Expand Down Expand Up @@ -803,7 +803,7 @@ def StartVision(self):
elif PlayFinal == 0 and PlayFull == 1:
vault = ptVault()
entry = vault.findChronicleEntry("YeeshaVisionViewed")
if type(entry) == type(None):
if entry is None:
vault.addChronicleEntry("YeeshaVisionViewed", 0, "1")
else:
entry.chronicleSetValue("1")
Expand Down Expand Up @@ -894,7 +894,7 @@ def IDoCityLinksChron(self,agePanel):
CityLinks = []
vault = ptVault()
entryCityLinks = vault.findChronicleEntry("CityBookLinks")
if type(entryCityLinks) != type(None):
if entryCityLinks is not None:
valCityLinks = entryCityLinks.chronicleGetValue()
print "valCityLinks = ",valCityLinks
CityLinks = valCityLinks.split(",")
Expand Down
Loading

0 comments on commit 999582f

Please sign in to comment.