Skip to content

Commit

Permalink
Merge pull request #655 from Hoikas/kill-exec-code
Browse files Browse the repository at this point in the history
Kill `exec(code)`
  • Loading branch information
Hoikas committed May 20, 2020
2 parents 072ac0b + 8c0f9e2 commit f237b64
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 221 deletions.
126 changes: 31 additions & 95 deletions Scripts/Python/kdshPillarRoom.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ def OnNotify(self,state,id,events):
#~ PtDebugPrint("kdshPilllarRoom:OnNotify state=%f id=%d events=" % (state,id),events)

if id in [1,2,3,4,5]: # One of the four levers or the reset ring were clicked by a player
code = "respLever0" + str(id) + ".run(self.key, events=events)"
exec(code)
globals()["respLever0{}".format(id)].run(self.key, events=events)
return

elif id in [6,7,8,9] and OnlyOneOwner.sceneobject.isLocallyOwned(): # One of the four levers actually pulled by an avatar
Expand Down Expand Up @@ -276,13 +275,12 @@ def OnNotify(self,state,id,events):
return

elif id >= 18 and id <=28 and PtWasLocallyNotified(self.key):
PtDebugPrint("Ladderbox %s entered." % ( id- 17))
ladderbox = id - 17
PtDebugPrint("Ladderbox %s entered." % ladderbox)

LocalAvatar = PtFindAvatar(events)

code = "MultiStage" + str(id-17) + ".run(LocalAvatar)"
#~ PtDebugPrint("code = ", code)
exec(code)
globals()["MultiStage{}".format(ladderbox)].run(LocalAvatar)

return

Expand Down Expand Up @@ -343,8 +341,7 @@ def OnSDLNotify(self,VARname,SDLname,playerID,tag):

#this loop disables all ladder boxes, so the ladders can't be climbed.
for count in range(1,12):
code = "Ladderbox" + str(count) + ".disable()"
exec(code)
globals()["Ladderbox{}".format(count)].disable()

#determine the height of the highest pillar so we can reset them at the same speed as the pillars reset
highest = 0
Expand All @@ -358,9 +355,7 @@ def OnSDLNotify(self,VARname,SDLname,playerID,tag):

if highest != 0:
PtAtTimeCallback(self.key,5*highest,6) #disable everything until all the pillars are down

code = "respSfxResetFromHeight" + str(highest) + ".run(self.key)"
exec(code)
globals()["respSfxResetFromHeight{}".format(highest)].run(self.key)

# if the counterweights have been lowered at all, this loop resets them
if ageSDL["budget"][0] != 8:
Expand Down Expand Up @@ -439,8 +434,7 @@ def RaiseAPillar(self,id):
#~ PillarCamBlocker.byObject["pillar0" + str(id) + "Collision"].playRange(rangestart, rangeend)

#play the sound effect for that pillar
code = "respSfxRaisePillar0" + str(id) + ".run(self.key)"
exec(code)
globals()["respSfxRaisePillar0{}".format(id)].run(self.key)

PtDebugPrint("\n##")
PtDebugPrint("Pillar0%d height is now: %d" % (id, ageSDL["pheight0" + str(id)][0]))
Expand Down Expand Up @@ -531,13 +525,22 @@ def DisableAppropriateLadders(self,pillar): # only the ladders boxes affected by
#~ PtDebugPrint(" ladderstodisable = ", ladderstodisable)

for each in ladderstodisable:
code = "Ladderbox" +str(each) + ".disable()"
exec(code)
globals()["Ladderbox{}".format(each)].disable()
#~ PtDebugPrint("Immediately disabling ladderbox", each)

def EnableAppropriateLadders(self,id): # when pillar is done raising, enable appropriate ladder boxes with new lengths
ageSDL = PtGetAgeSDL()


def _ConfigLadder(ladderId, enable, deltaH=None):
ladderbox = globals()["Ladderbox{}".format(ladderId)]
if enable:
ladderbox.enable()
else:
ladderbox.disable()
if enable and deltaH is not None:
multistage = globals()["MultiStage{}".format(ladderId)]
multistage.setLoopCount(1, 6 * deltaH - 4)

# Manage the 2 ladder boxes related to the ladder ON this pillar (connecting this pillar with the PREVIOUS one)
if id != 1: # true unless the first pillar was raised; Pillar #1 has no proceeding pillar
difference01 = ageSDL["pheight0" + str(id)][0] - ageSDL["pheight0" + str(id-1)][0] # calculates difference between this and proceeding pillar
Expand All @@ -546,50 +549,14 @@ def EnableAppropriateLadders(self,id): # when pillar is done raising, enable app

if difference01 >= 1: # true if this pillar is higher than proceeding pillar
#~ PtDebugPrint("\nPillar0%d is %d notches higher than the proceeding pillar" % (id, difference01))
if difference01 > tolerance01: # true if the ladder on this pillar is out of reach from the proceeding pillar
#~ PtDebugPrint("Ascending Ladder box #%d is now disabled, since the ladder doesn't reach down that far" % (id * 2 - 1))
# do something to ladder box (id * 2 - 1)
code = "Ladderbox" + str(id * 2 - 1) + ".disable()"
exec(code)

#~ PtDebugPrint("Descending Ladder box #%d is now enabled, but only to %d rungs, and then you hang." % (id + 7, (6*(5-id) - 4)) #)
# do something to ladder box (id * 2)
code = "Ladderbox" + str(id * 2) + ".disable()"
exec(code)
#do something to ladderbox (id + 7)
code = "Ladderbox" + str(id + 7) + ".enable()"
exec(code)

else: # Now progression from the previous pillar can happen
#~ PtDebugPrint("Ascending Ladder box #%d enabled with %d rungs." % (id * 2 - 1, 6 * difference01 - 4))
# do something to ladder box (id * 2 - 1)
code = "Ladderbox" + str(id * 2 - 1) + ".enable()"
exec(code)
code = "MultiStage" + str(id * 2 - 1) + ".setLoopCount(1," + str( 6 * difference01 - 4) + ")"
exec(code)



#~ PtDebugPrint("Descending Ladder box #%d enabled with %d rungs." % (id * 2, 6 * difference01 - 4))
# do something to ladder box (id * 2)
code = "Ladderbox" + str(id * 2) + ".enable()"
exec(code)
code = "MultiStage" + str(id * 2) + ".setLoopCount(1," + str(6 * difference01 - 4) + ")"
exec(code)

#disable the "hang" ladder box
code = "Ladderbox" + str(id + 7) + ".disable()"
exec(code)



# False if the ladder on this pillar is out of reach from the proceeding pillar
canReach = difference01 <= tolerance01
_ConfigLadder(id * 2 - 1, enable=canReach, deltaH=difference01)
_ConfigLadder(id * 2, enable=canReach, deltaH=difference01)
_ConfigLadder(id + 7, enable=not canReach)
else:
#~ PtDebugPrint("\nPillar0%d is level with or below the proceeding pillar." % (id))
code = "Ladderbox" + str(id * 2 - 1) + ".disable()"
exec(code)
code = "Ladderbox" + str(id * 2) + ".disable()"
exec(code)

_ConfigLadder(id * 2 - 1, enable=False)
_ConfigLadder(id * 2, enable=False)

else: # special condition for pillar01
# do something to ladder box 1
Expand All @@ -616,42 +583,11 @@ def EnableAppropriateLadders(self,id): # when pillar is done raising, enable app

if difference02 >= 1:
#~ PtDebugPrint("\nPillar0%d is %d notches lower than the following pillar" % (id, difference02))
if difference02 > tolerance02: # true if the next pillar's ladder is out of reach from this pillar
#~ PtDebugPrint("Ascending Ladder box #%d is now disabled, since the ladder doesn't reach down that far" % (id * 2 + 1))
#do something to ladder box (id * 2 + 1)
code = "Ladderbox" + str(id * 2 + 1) + ".disable()"
exec(code)

#~ PtDebugPrint("Descending Ladder box #%d is enabled, but only down %d rungs, and then you hang." % (id + 8, (6 *(4-id) - 4)) # "4 - id" here same as "(5 - (id+1))")
# do something to ladder box (id * 2 + 2)
code = "Ladderbox" + str(id * 2 + 2) + ".disable()"
exec(code)
#do something to ladderbox (id + 8)
code = "Ladderbox" + str(id + 8) + ".enable()"
exec(code)



else: # Now progression to the following pillar can happen
#~ PtDebugPrint("Ascending Ladder box #%d enabled with %d rungs." % (id * 2 + 1, 6 * difference02 - 4))
# do something to ladder box (id * 2 + 1)
code = "Ladderbox" + str(id * 2 + 1) + ".enable()"
exec(code)
code = "MultiStage" + str(id * 2 + 1) + ".setLoopCount(1," + str( 6 * difference02 - 4) + ")"
exec(code)


#~ PtDebugPrint("Descending Ladder box #%d enabled with %d rungs." % (id * 2 + 2, 6 * difference02 -4))
# do something to ladder box (id * 2 + 2)
code = "Ladderbox" + str(id * 2 + 2) + ".enable()"
exec(code)
code = "MultiStage" + str(id * 2 + 2) + ".setLoopCount(1," + str(6 * difference02 - 4) + ")"
exec(code)

#disable the "hang" ladder box
code = "Ladderbox" + str(id + 8) + ".disable()"
exec(code)

# False if the next pillar's ladder is out of reach from this pillar
canReach = difference02 <= tolerance02
_ConfigLadder(id * 2 + 1, enable=canReach, deltaH=difference02)
_ConfigLadder(id * 2 + 2, enable=canReach, deltaH=difference02)
_ConfigLadder(id + 8, enable=not canReach)
else:
#~ PtDebugPrint("\nPillar0%d is level with or above the following pillar" % (id))
pass
Expand Down
40 changes: 14 additions & 26 deletions Scripts/Python/kdshShadowPath.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,8 @@ def OnServerInitComplete(self):
PtDebugPrint("\t ShadowPathLight0%s = %s " % (light, lightstate))

if lightstate == 1:

code = "respSwitch0" + str(light) + ".run(self.key,fastforward=1)"
exec(code)

PtDebugPrint("\t\tTurning on light #", light)
globals()["respSwitch0{}".format(light)].run(self.key, fastforward=True)
PtDebugPrint("\t\tTurning on light #", light, level=kWarningLevel)

solved = ageSDL["ShadowPathSolved"][0]
if solved:
Expand Down Expand Up @@ -214,8 +211,7 @@ def OnNotify(self,state,id,events):
return

PtDebugPrint("Light ", id, " clicked.")
code = 'respBtnPush0' + str(id) + '.run(self.key,events=events)'
exec(code)
globals()["respBtnPush0{}".format(id)].run(self.key, events=events)

elif id in [26,27,28,29,30]:
if lightClickedByAvatar != localAvatar: #Make sure we don't have any rogue avatars reporting...
Expand Down Expand Up @@ -260,14 +256,11 @@ def OnNotify(self,state,id,events):

#turn off the lights
for light in [1,2,3,4,5]:
lightstate = ageSDL["ShadowPathLight0" + str(light)][0]
if lightstate == 1:
code = 'ageSDL["ShadowPathLight0' + str(light) + '"] = (0,)'
PtDebugPrint("resetcode = ", code)
exec(code)

PtDebugPrint("\tTurning off light #", light)

var = "ShadowPathLight0{}".format(light)
if ageSDL[var][0]:
ageSDL[var] = (0,)
PtDebugPrint("\tTurning off light #", light, level=kWarningLevel)

#...and close the floor
ageSDL["ShadowPathSolved"] = (0,)

Expand All @@ -290,20 +283,15 @@ def OnSDLNotify(self,VARname,SDLname,playerID,tag):

newstate = ageSDL["ShadowPathLight0" + str(light)][0]

resp = globals()["respSwitch0{}".format(light)]
if newstate == 0: # true if that switch is now off
PtDebugPrint("kdshShadowPath.OnSDLNotify: Light", light," was on. Turning it off.")
code = "respSwitch0" + str(light) + ".run(self.key, state='off')"
#~ PtDebugPrint("off code = ", code)
exec(code)

PtDebugPrint("kdshShadowPath.OnSDLNotify: Light", light," was on. Turning it off.", level=kWarningLevel)
resp.run(self.key, state="off")
elif newstate == 1: # true if that switch is now on
PtDebugPrint("kdshShadowPath.OnSDLNotify: Light", light," was off. Turning it on.")
code = "respSwitch0" + str(light) + ".run(self.key, state='on')"
#~ PtDebugPrint("On code = ", code)
exec(code)

PtDebugPrint("kdshShadowPath.OnSDLNotify: Light", light," was off. Turning it on.", level=kWarningLevel)
resp.run(self.key, state="on")
else:
PtDebugPrint("Error. Not sure what the light thought it was.")
PtDebugPrint("kdshShadowPath.OnSDLNotify: Error. Not sure what the light thought it was.")

'''
def BatonPassCheck(self,id,events,ageSDL):
Expand Down
77 changes: 15 additions & 62 deletions Scripts/Python/kdshTreeRingsSolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,45 +241,15 @@ def OnServerInitComplete(self):
self.InitRings()

def InitRings(self):
ageSDL = PtGetAgeSDL()

OuterRing01 = ageSDL["OuterRing01"][0]
MiddleRing01 = ageSDL["MiddleRing01"][0]
InnerRing01 = ageSDL["InnerRing01"][0]
OuterRing02 = ageSDL["OuterRing02"][0]
MiddleRing02 = ageSDL["MiddleRing02"][0]
InnerRing02 = ageSDL["InnerRing02"][0]
OuterRing03 = ageSDL["OuterRing03"][0]
MiddleRing03 = ageSDL["MiddleRing03"][0]
InnerRing03 = ageSDL["InnerRing03"][0]
PtDebugPrint("kdshTreeRingSolution: When I got here:", level=kWarningLevel)

PtDebugPrint("kdshTreeRingSolution: When I got here:")
#~ PtDebugPrint("\tOuterRing01=",OuterRing01)
#~ PtDebugPrint("\tMiddleRing01=",MiddleRing01)
#~ PtDebugPrint("\tInnerRing01=",InnerRing01)
#~ PtDebugPrint("\tOuterRing02=",OuterRing02)
#~ PtDebugPrint("\tMiddleRing02=",MiddleRing02)
#~ PtDebugPrint("\tInnerRing02=",InnerRing02)
#~ PtDebugPrint("\tOuterRing03=",OuterRing03)
#~ PtDebugPrint("\tMiddleRing03=",MiddleRing03)
#~ PtDebugPrint("\tInnerRing03=",InnerRing03)

for i in ["Outer", "Middle", "Inner"]:
for j in ["1","2","3"]:

ffcode1 = "InitState = "+i + "Ring0" +j
#~ PtDebugPrint("ffcode1 = ", ffcode1)

exec(ffcode1)
#~ PtDebugPrint("InitState = ", InitState)

ffcode2 = i + "Ring0" + j + "_0" + str(InitState) + ".animation.skipToEnd()"
#~ PtDebugPrint("ffcode2 = ", ffcode2)

exec(ffcode2)

#~ PtDebugPrint("Fastforwarding: Set = ",j," Ring = ",i," Position = ",InitState)
PtDebugPrint("\t",i,"Ring0",j," = ", InitState)
ageSDL = PtGetAgeSDL()
for i in ("Outer", "Middle", "Inner"):
for j in ("1", "2", "3"):
ring = "{location}Ring0{idx}".format(location=i, idx=j)
ring_attrib = "{ring}_0{bearing}".format(ring=ring, bearing=ageSDL[ring][0])
globals()[ring_attrib].animation.skipToEnd()
PtDebugPrint("\t{} = {}".format(ring, ageSDL[ring][0]), level=kWarningLevel)


def OnSDLNotify(self,VARname,SDLname,playerID,tag):
Expand All @@ -290,10 +260,7 @@ def OnSDLNotify(self,VARname,SDLname,playerID,tag):
StillSolved = False
newbearing = ageSDL[VARname][0]
#~ PtDebugPrint("VARname = ", VARname, "newbear = ", newbearing)

code = VARname + "_0" + str(newbearing) + ".animation.play()"
#~ PtDebugPrint("code = ", code)
exec(code) # this runs the animation on the actual ring in the garden
globals()["{id}_0{bearing}".format(id=VARname, bearing=newbearing)].animation.play()

if "3" in VARname:
#~ PtDebugPrint("TRS: Nothing to ff. VARname = ", VARname)
Expand Down Expand Up @@ -357,27 +324,13 @@ def OnNotify(self,state,id,events):
if ageSDL == None:
PtDebugPrint("kdshTreeRings.OnFirstUpdate():\tERROR---missing age SDL (%s)" % varstring.value)

Outerbearing = ageSDL["OuterRing0" + str(ScopeNumber-1)][0]
Middlebearing = ageSDL["MiddleRing0" + str(ScopeNumber-1)][0]
Innerbearing = ageSDL["InnerRing0" + str(ScopeNumber-1)][0]
for bearing in ("Outer", "Middle", "Inner"):
sdl_var = "{location}Ring0{idx}".format(location=bearing, idx=ScopeNumber-1)
attrib_name = "GUI{location}0{idx}_0{newbearing}".format(location=bearing,
idx=ScopeNumber-1,
newbearing=ageSDL[sdl_var][0])
globals()[attrib_name].animation.skipToEnd()

#~ PtDebugPrint("Outerbearing = ", Outerbearing)
#~ PtDebugPrint("Middlebearing = ", Middlebearing)
#~ PtDebugPrint("Innerbearing = ", Innerbearing)


GUIcode = "GUIOuter0" + str(ScopeNumber-1) + "_0" + str(Outerbearing) + ".animation.skipToEnd()"
#~ PtDebugPrint("FF Outer code = ", GUIcode)
exec(GUIcode)

GUIcode = "GUIMiddle0" + str(ScopeNumber-1) + "_0" + str(Middlebearing) + ".animation.skipToEnd()"
#~ PtDebugPrint("FF Middle code = ", GUIcode)
exec(GUIcode)

GUIcode = "GUIInner0" + str(ScopeNumber-1) + "_0" + str(Innerbearing) + ".animation.skipToEnd()"
#~ PtDebugPrint("FF Inner code = ", GUIcode)
exec(GUIcode)

# this runs the animation on the "fake" ring in front of the GUI
#~ animname= "GUI{id}_0{bearing}".format(id="".join(VARname.split("Ring")), bearing=newbearing)
#~ globals()[animname].animation.play()
Expand Down
12 changes: 4 additions & 8 deletions Scripts/Python/kdshVault.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,11 @@ def OnSDLNotify(self,VARname,SDLname,playerID,tag):
#~ PtDebugPrint("kdshVault.OnSDLNotify: lastbuttonpushed = ", lastbuttonpushed)

#run the animation on the button itself
code = "respButton" + str(lastbuttonpushed) + ".run(self.key)"
#~ PtDebugPrint("code = ", code)
exec(code)

globals()["respButton{}".format(lastbuttonpushed)].run(self.key)

#disable the clickable for that button
code = "actButton" + str(lastbuttonpushed) + ".disable()"
#~ PtDebugPrint("code = ", code)
exec(code)

globals()["actButton{}".format(lastbuttonpushed)].disable()

def OnTimer(self,id):
global VaultDoorMoving

Expand Down
3 changes: 1 addition & 2 deletions Scripts/Python/minkDayClicks.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,4 @@ def OnNotify(self,state,id,events):
if id != behRespCage.id:
num = ResponderId.index(id) + 1
PtDebugPrint("minkDayClicks.OnNotify(): Should show %d" % (num))
code = "ageSDL[\"minkSymbolShow0%d\"] = (1,)" % (num)
exec(code)
ageSDL["minkSymbolShow0%d" % num] = (1,)
Loading

0 comments on commit f237b64

Please sign in to comment.