home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 56 / CDPowerplay56Disc2.iso / demos / blade / data1.cab / Program_Executable_Files / Scripts / ScriptSkip.py < prev    next >
Encoding:
Text File  |  2000-10-27  |  2.2 KB  |  95 lines

  1. # Created 3/7/2000 by Wolfson
  2. # Script handling data and procs needed to perform scripted animation skipping
  3. # cenerates .py files in the .\\pak directory
  4.  
  5. import pickle
  6. import Bladex
  7. import AuxFuncs
  8. import Reference
  9.  
  10. TempTime    = 0
  11. TempName    = 0
  12. SkipTimes    = {}
  13.  
  14. # To be Called at the deactivateinput() call level
  15. def SkipScriptStart(name):
  16.     global TempName
  17.     global TempTime
  18.     global SkipTimes
  19.  
  20.     #print("oka, started")
  21.  
  22.     AuxFuncs.DeactivateKeyboard()
  23.     
  24.     # Open File w data
  25.     opened = 1
  26.     
  27.     try:
  28.         SkippingDataFile = open(".\\pak\\SDF.txt","r")
  29.     except:
  30.         opened    = 0
  31.  
  32.     # Place Data in phython object
  33.     if opened:
  34.         SkipTimes = pickle.load(SkippingDataFile)
  35.         SkippingDataFile.close()
  36.  
  37.     TempName = name
  38.     TempTime = Bladex.GetTime()
  39.  
  40. # To be Called at the activateinput() call level
  41. # In script end, we always save time data, but, since we alter the clock in the enter/esc call
  42. # the saved value still holds the correct timming data
  43.  
  44. def SkipScriptEnd2():
  45.     global TempTime
  46.     global SkipTimes
  47.     global TempName
  48.  
  49.     #print("oka, ended")
  50.     
  51.     AuxFuncs.ActivateKeyboard()
  52.  
  53.     TempTime = Bladex.GetTime() - TempTime # Elapsed time from script-begin to script-end
  54.     SkipTimes[TempName] = TempTime
  55.     TempName = "NonValidName" # Security lock, in case we call SkipCalled out-of-the-nest
  56.  
  57.     opened = 1
  58.     
  59.     try:
  60.         SkippingDataFile = open(".\\pak\\SDF.txt","w")
  61.     except:
  62.         opened    = 0
  63.  
  64.     # Place data in file
  65.     if opened:
  66.         pickle.dump(SkipTimes, SkippingDataFile, 0)
  67.         SkippingDataFile.close()
  68.  
  69.  
  70. # To be Called on ESC event while input is deactivated
  71. def SkipCalled():
  72.     global TempName
  73.     global SkipTimes
  74.     global TempTime
  75.  
  76.  
  77.     if Reference.DEMO_MODE==1:
  78.         return
  79.  
  80.     #print("Hello my baby, hello my good!!!")
  81.  
  82.     Bladex.ShutDownSoundChannels()
  83.     
  84.     if SkipTimes.has_key(TempName):
  85.         TimeToSkip = SkipTimes[TempName] - (Bladex.GetTime() - TempTime)
  86.         if TimeToSkip > 0: # Safety check
  87.             Bladex.GoToTime(Bladex.GetTime() + TimeToSkip)
  88.         else:
  89.             print("Wolfson's Error: Negative index for script skipping, timing may be wrong")
  90.     else:
  91.         print("Wolfson's Error: SkipCalled called outta nest")
  92.  
  93. def SkipScriptEnd():
  94.     Bladex.AddScheduledFunc(Bladex.GetTime(), SkipScriptEnd2, (), "SkipScriptEnd2")
  95.