Untitled

From Little Macaque, 2 Weeks ago, written in Plain Text, viewed 1 times. This paste will give up the ghost in 1 Week.
URL https://paste.afonso.co/view/55c3453a Embed
Download Paste or View Raw
  1. from System import DateTime, TimeSpan
  2. from System.Globalization import CultureInfo
  3.  
  4. def Execute():
  5.         Project.EventsManager.SubscribeEvent("GraphicsEnginesObserver.GraphicsEngineConnected", Script.Id, "OnGraphicsEnginesObserver_GraphicsEngineConnected", True)
  6.         Project.EventsManager.SubscribeEvent("GameOnline.ClockStarted", Script.Id, "OnGameOnline_ClockStarted", True)
  7.         Project.EventsManager.SubscribeEvent("GameOnline.ClockStopped", Script.Id, "OnGameOnline_ClockStopped", True)
  8.         Project.EventsManager.SubscribeEvent("GameOnline.ClockActivePartChanged", Script.Id, "OnGameOnline_ClockStopped", True)
  9.         Project.EventsManager.SubscribeEvent("GameOpened", Script.Id, "OnGameOpened", True)
  10.        
  11.  
  12. def OnGraphicsEnginesObserver_GraphicsEngineConnected(sender, args):
  13.         pass
  14.  
  15.  
  16. def FormatClock(timeSpan):
  17. #       print "#INVARIANT--->"+timeSpan.ToString('o',CultureInfo.InvariantCulture)
  18. #       print "#0--->"+timeSpan.ToString('O')
  19.        
  20.         return timeSpan.ToString('O',CultureInfo.InvariantCulture)#ToString("####0.00",CultureInfo.InvariantCulture)
  21.        
  22.  
  23. def OnGameOnline_ClockStarted(sender, args):
  24.         if GameOnline.IsOnAir:
  25.                 for r3, matchClockPlugin in GetClockPluginFromAllConnectedEngines(Script.Description):    
  26.                         try:
  27.                                 SetupClock(matchClockPlugin)
  28.                                 startRef = FormatClock(DateTime.Now - sender.Clock.ElapsedTime)
  29.                                 cmd = "ENGINE PLUGIN \"%s\" SET \"Worker.StartReference\" \"%s\" \"Worker.StopReference\" \"%s\"" % (
  30.                                     Script.Description, startRef, FormatClock(DateTime.Now + TimeSpan.FromHours(99)))
  31.                                 r3.SendCommandAndResponse(cmd)
  32.                                 cmd = "ENGINE PLUGIN \"%s\" SET \"Worker.StopType\" \"None\"" % (Script.Description)
  33.                                 r3.SendCommandAndResponse(cmd)
  34.                                 matchClockPlugin.Start()
  35.                         except:
  36.                                 #TODO: Engine is not connected or have errors
  37.                                 continue
  38.                                
  39.                        
  40.                 extraTimerClockName = "GameClockExtraTime"
  41.                 for r3, matchClockPlugin in GetClockPluginFromAllConnectedEngines(extraTimerClockName):
  42.                         try:
  43.                                 #SetupClock(matchClockPlugin)
  44.                                 SetupClockExtraTimer(matchClockPlugin)
  45.                                 startRef = FormatClock(DateTime.Now - sender.Clock.ElapsedTime  + Game.Clock.ActivePart.EndAt + TimeSpan.FromMilliseconds(100))#.ToString('O')
  46.                                 cmd = "ENGINE PLUGIN \"%s\" SET \"Worker.StartReference\" \"%s\""%(extraTimerClockName, startRef)
  47.                                 r3.SendCommandAndResponse(cmd)
  48.                                 cmd = "ENGINE PLUGIN \"%s\" SET \"Worker.StopType\" \"None\""%(extraTimerClockName)
  49.                                 r3.SendCommandAndResponse(cmd)
  50.                                 matchClockPlugin.Start()
  51.                         except:
  52.                                 #TODO: Engine is not connected or have errors
  53.                                 continue                       
  54.                        
  55.                 kickOffTimerClockName = "GameClockKickOff"
  56.                 for r3, matchClockPlugin in GetClockPluginFromAllConnectedEngines(kickOffTimerClockName):  
  57.                         try:
  58.                                 SetupClockKickOff(matchClockPlugin)
  59.                                
  60.                                 startRef = FormatClock( DateTime.Now - sender.Clock.ElapsedTime)#.ToString('O')
  61.                                 endRef = FormatClock(DateTime.Now - sender.Clock.ElapsedTime  + Game.Clock.ActivePart.EndAt + TimeSpan.FromMilliseconds(100))#.ToString('O')
  62.                                
  63.                                 cmd = "ENGINE PLUGIN \"%s\" SET \"Worker.StartReference\" \"%s\" \"Worker.StopReference\" \"%s\""%(kickOffTimerClockName,startRef, endRef)
  64.                                 r3.SendCommandAndResponse(cmd)
  65.                                 cmd = "ENGINE PLUGIN \"%s\" SET \"Worker.StopType\" \"StopAtReference\""%(kickOffTimerClockName)
  66.                                 r3.SendCommandAndResponse(cmd)
  67.                                 matchClockPlugin.Start()
  68.                         except:
  69.                                 #TODO: Engine is not connected or have errors
  70.                                 continue                               
  71.                        
  72. def OnGameOnline_ClockStopped(sender, args):
  73.         if GameOnline.IsOnAir:
  74.                 for r3, matchClockPlugin in GetClockPluginFromAllConnectedEngines(Script.Description):
  75.                         SetupClock(matchClockPlugin)
  76.                        
  77.                         if GameOnline.Clock.ActivePart.Name.ToString() == "Finished" or GameOnline.Clock.ActivePart.Name.ToString() == "Full Time" or GameOnline.Clock.ActivePart.Name.ToString() == "Penalties":
  78.                                 pass
  79.                         else:
  80.                                 if sender.Clock.ElapsedTime > sender.Clock.ActivePart.EndAt:
  81.                                         matchClockPlugin.Stop(sender.Clock.ActivePart.EndAt)
  82.                                 else:
  83.                                         matchClockPlugin.Stop(sender.Clock.ElapsedTime)
  84.                                        
  85.  
  86.                         if  Game.Clock.ActivePart.EndAt == "penalties": return
  87.                        
  88.                         endRef = FormatClock(DateTime.Now - sender.Clock.ElapsedTime  + Game.Clock.ActivePart.EndAt + TimeSpan.FromMilliseconds(100))#.ToString('O')
  89.                        
  90.                         if Game.Clock.ActivePart.Duration  == TimeSpan.FromSeconds(0):
  91.                         #this prevent the extra timer to be shown when the part duration is 0, PS: Not supposed to happen
  92.                                 cmd = "ENGINE PLUGIN \"%s\" SET \"Worker.StopReference\" \"%s\""%(Script.Description, DateTime.Now + TimeSpan.FromHours(99))
  93.                         else:
  94.                                 cmd = "ENGINE PLUGIN \"%s\" SET \"Worker.StopReference\" \"%s\""%(Script.Description, endRef)
  95.                
  96.                         r3.SendCommandAndResponse(cmd)                   
  97.  
  98.                 extraTimerClockName = "GameClockExtraTime"
  99.                 for r3, matchClockPlugin in GetClockPluginFromAllConnectedEngines(extraTimerClockName):    
  100.                         SetupClockExtraTimer(matchClockPlugin)
  101. #                       if sender.Clock.ElapsedTime> sender.Clock.ActivePart.EndAt:
  102. #                               matchClockPlugin.Stop( sender.Clock.ElapsedTime-sender.Clock.ActivePart.EndAt)
  103. #                       else:
  104. #                               matchClockPlugin.Stop(TimeSpan.FromSeconds(0))
  105.  
  106.  
  107.                 kickOffTimerClockName = "GameClockKickOff"
  108.                 for r3, matchClockPlugin in GetClockPluginFromAllConnectedEngines(kickOffTimerClockName):    
  109.                         SetupClockKickOff(matchClockPlugin)
  110.                        
  111.                         if GameOnline.Clock.ActivePart.Name.ToString() == "Finished" or GameOnline.Clock.ActivePart.Name.ToString() == "Full Time" or GameOnline.Clock.ActivePart.Name.ToString() == "Penalties":
  112.                                 pass
  113.                         else:
  114.                                 if sender.Clock.ElapsedTime > sender.Clock.ActivePart.EndAt:
  115.                                         matchClockPlugin.Stop(sender.Clock.ActivePart.EndAt)
  116.                                 else:
  117.                                         matchClockPlugin.Stop(sender.Clock.ElapsedTime)
  118.                        
  119.                         endRef = FormatClock(DateTime.Now - sender.Clock.ElapsedTime  + Game.Clock.ActivePart.EndAt + TimeSpan.FromMilliseconds(100))#.ToString('O')
  120.                        
  121.                         if Game.Clock.ActivePart.Duration  == TimeSpan.FromSeconds(0):
  122.                                 cmd = "ENGINE PLUGIN \"%s\" SET \"Worker.StopReference\" \"%s\""%(kickOffTimerClockName, FormatClock(DateTime.Now + TimeSpan.FromHours(99)))
  123.                         else:
  124.                                 cmd = "ENGINE PLUGIN \"%s\" SET \"Worker.StopReference\" \"%s\""%(kickOffTimerClockName, endRef)
  125.                
  126.                         r3.SendCommandAndResponse(cmd)                   
  127.  
  128.  
  129. def GetClockPluginFromAllConnectedEngines(clockName):
  130.         list = []
  131.         if hasattr(Context, "OutputManager"):
  132.                 for channelOutput in OutputManager.ChannelOutputs:
  133.                         for engineAss in channelOutput.EnginesAssignmentProfiles:
  134.                                 for pgmConfig in engineAss.ProgramGraphicsEngines:
  135.                                         if pgmConfig.IsValid and pgmConfig.GraphicsEngine and pgmConfig.GraphicsEngine.IsConnected:
  136.                                                 r3 = pgmConfig.GraphicsEngine
  137.                                                 list.append((r3, r3.CreateClockPlugin(clockName)))
  138.         else:
  139.                 for r3 in R3GraphicsEngines:  
  140.                         if r3.IsConnected:
  141.                                 list.append((r3, r3.CreateClockPlugin(clockName)))
  142.         return list
  143.        
  144. def SetupClock(clock):
  145.         clock.SetClockType("Count");
  146.         clock.SetMaskFormat("MaxMinSec");      
  147.         clock.SetPlusSignalVisibility(False);
  148.        
  149. def SetupClockKickOff(clock):
  150.         clock.SetClockType("Count");
  151.         clock.SetMaskFormat("MaxMinSec");      
  152.         clock.SetPlusSignalVisibility(False);
  153.  
  154. def SetupClockExtraTimer(clock):
  155.         clock.SetClockType("Count");
  156.         clock.SetMaskFormat("MaxMinSec");      
  157.         clock.SetPlusSignalVisibility(False);
  158.        
  159. def OnTimeSetSafe(sender, args):
  160.         #runs the script with the script runner avoiding to have to reset the script during the development..
  161.         Core.ScriptRunner.Execute(Script, "OnTimeSet", sender, args)
  162.  
  163. def OnTimeSet(sender, args):
  164.         if sender.IsRunning:
  165.                 OnGameOnline_ClockStarted(ClockWrapper(sender), args)
  166.         else:
  167.                 OnGameOnline_ClockStopped(ClockWrapper(sender), args)
  168.  
  169. class ClockWrapper:
  170.         def __init__(self, clock):
  171.                 self.Clock = clock
  172.  
  173. import System
  174.  
  175. def SetTime():
  176.         OnTimeSet(GameOnline.Clock, System.EventArgs.Empty)
  177.  
  178. def OnGameOpened(sender, args):
  179.         #check if the object exists in the context, then removes the subscription
  180.         if hasattr(Context, "GameOnline"):
  181.                 if Globals["OnTimeSetSubscription"]:
  182.                         GameOnline.Clock.TimeSet -= Globals["OnTimeSetSubscription"]
  183.        
  184.                 Globals["OnTimeSetSubscription"] = OnTimeSetSafe
  185.                 GameOnline.Clock.TimeSet += Globals["OnTimeSetSubscription"]
  186.                
  187.         #if hasattr(Context, "GameOnline"):
  188.         #       OnTimeSet(GameOnline.Clock, args)

Reply to "Untitled"

Here you can reply to the paste above