From 8441c80785f22fe480c7b7283b8a79c9d6be0176 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Tue, 26 Jan 2021 20:09:14 -0800 Subject: [PATCH 1/2] Fix Shroomie Gate state consistency The state was being modified regardless of whether the gate had power or not, but should only be changed when power is on (and when the relevant responders are run). Closes #792. --- Scripts/Python/tldnShroomieGate.py | 57 ++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/Scripts/Python/tldnShroomieGate.py b/Scripts/Python/tldnShroomieGate.py index ba344dcf2b..3b45c59978 100644 --- a/Scripts/Python/tldnShroomieGate.py +++ b/Scripts/Python/tldnShroomieGate.py @@ -56,17 +56,19 @@ respGateDown = ptAttribResponder(3, "resp: Gate Down", netForce=1) respGateUp = ptAttribResponder(4, "resp: Gate Up", netForce=1) +kGateVariable = "tldnShroomieGateUp" + class tldnShroomieGate(ptResponder): def __init__(self): # run parent class init ptResponder.__init__(self) self.id = 5042 - + version = 1 self.version = version PtDebugPrint("__init__tldnShroomieGate v.", version) - + def OnNotify(self,state,id,events): if id == clkLever.id and state: PtDebugPrint("tldnShroomieGate:\t---Someone Pulled the Lever") @@ -74,30 +76,47 @@ def OnNotify(self,state,id,events): elif id == respLeverPull.id: ageSDL = PtGetAgeSDL() - PtDebugPrint("tldnShroomieGate:\t---Shroomie Gate Up SDL: %d" % (ageSDL["tldnShroomieGateUp"][0])) - if ageSDL["tldnShroomieGatePowerOn"][0] and self.sceneobject.isLocallyOwned(): - if ageSDL["tldnShroomieGateUp"][0]: - respGateDown.run(self.key) - PtDebugPrint("tldnShroomieGate:\t---Shroomie Gate Going Down") - else: - respGateUp.run(self.key) - PtDebugPrint("tldnShroomieGate:\t---Shroomie Gate Going Up") - ageSDL["tldnShroomieGateUp"] = (not ageSDL["tldnShroomieGateUp"][0],) - - + PtDebugPrint("tldnShroomieGate:\t---Shroomie Gate Up SDL: %d" % (ageSDL[kGateVariable][0])) + if ageSDL["tldnShroomieGatePowerOn"][0] and self.sceneobject.isLocallyOwned(): + ageSDL[kGateVariable] = (not ageSDL[kGateVariable][0],) + + def OnSDLNotify(self, VARname, SDLname, playerID, tag): + if VARname != kGateVariable: + return + + ageSDL = PtGetAgeSDL() + value = ageSDL[kGateVariable][0] + + if playerID: + try: + avatar = PtGetAvatarKeyFromClientID(playerID).getSceneObject() + except: + avatar = None + ff = False + else: + avatar = None + ff = True + + if value: + respGateUp.run(self.key, avatar=avatar, fastforward=ff) + PtDebugPrint("tldnShroomieGate:\t---Shroomie Gate Going Up") + else: + respGateDown.run(self.key, avatar=avatar, fastforward=ff) + PtDebugPrint("tldnShroomieGate:\t---Shroomie Gate Going Down") + def OnServerInitComplete(self): try: ageSDL = PtGetAgeSDL() except: PtDebugPrint("tldnShroomieGate:\tERROR---Cannot find the Teledahn Age SDL") - ageSDL.sendToClients("tldnShroomieGateUp") - ageSDL.setFlags("tldnShroomieGateUp", 1, 1) - ageSDL.setNotify(self.key, "tldnShroomieGateUp", 0.0) - - if ageSDL["tldnShroomieGateUp"][0]: + ageSDL.sendToClients(kGateVariable) + ageSDL.setFlags(kGateVariable, 1, 1) + ageSDL.setNotify(self.key, kGateVariable, 0.0) + + if ageSDL[kGateVariable][0]: PtDebugPrint("tldnShroomieGate:\tInit---Shroomie Gate Up") respGateUp.run(self.key,fastforward=1) else: PtDebugPrint("tldnShroomieGate:\tInit---Shroomie Gate Down") - respGateDown.run(self.key,fastforward=1) \ No newline at end of file + respGateDown.run(self.key,fastforward=1) From 7e1df892e14525c104b31216818ade4f82d1f23c Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Thu, 28 Jan 2021 08:45:58 -0800 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Adam Johnson --- Scripts/Python/tldnShroomieGate.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Scripts/Python/tldnShroomieGate.py b/Scripts/Python/tldnShroomieGate.py index 3b45c59978..cad278d99f 100644 --- a/Scripts/Python/tldnShroomieGate.py +++ b/Scripts/Python/tldnShroomieGate.py @@ -76,7 +76,7 @@ def OnNotify(self,state,id,events): elif id == respLeverPull.id: ageSDL = PtGetAgeSDL() - PtDebugPrint("tldnShroomieGate:\t---Shroomie Gate Up SDL: %d" % (ageSDL[kGateVariable][0])) + PtDebugPrint(f"tldnShroomieGate:\t---Shroomie Gate Up SDL: {ageSDL[kGateVariable][0]}") if ageSDL["tldnShroomieGatePowerOn"][0] and self.sceneobject.isLocallyOwned(): ageSDL[kGateVariable] = (not ageSDL[kGateVariable][0],) @@ -87,15 +87,9 @@ def OnSDLNotify(self, VARname, SDLname, playerID, tag): ageSDL = PtGetAgeSDL() value = ageSDL[kGateVariable][0] - if playerID: - try: - avatar = PtGetAvatarKeyFromClientID(playerID).getSceneObject() - except: - avatar = None - ff = False - else: - avatar = None - ff = True + avatarKey = PtGetAvatarKeyFromClientID(playerID) + avatar = avatarKey.getSceneObject() if avatarKey else None + ff = avatar is None if value: respGateUp.run(self.key, avatar=avatar, fastforward=ff) @@ -116,7 +110,7 @@ def OnServerInitComplete(self): if ageSDL[kGateVariable][0]: PtDebugPrint("tldnShroomieGate:\tInit---Shroomie Gate Up") - respGateUp.run(self.key,fastforward=1) + respGateUp.run(self.key, fastforward=True) else: PtDebugPrint("tldnShroomieGate:\tInit---Shroomie Gate Down") - respGateDown.run(self.key,fastforward=1) + respGateDown.run(self.key, fastforward=True)