home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 January / Chip_1997-01_cd.bin / dirwin / data.z / ANIMWIZ.DIR / 00013_Script_ScoreMgr < prev    next >
Text File  |  1996-03-15  |  16KB  |  474 lines

  1. -- ScoreMgr script
  2.  
  3. property iUsersScoreSelection
  4. property iGeneratedScoreSelection
  5. property ichStart
  6. property ichEnd
  7. property iFrameStart
  8. property iFrameEnd
  9. property iStageWidth
  10. property iStageHeight
  11. property iStageRight
  12. property iStageBottom
  13. property iChannelAvailList
  14. property ichReselect
  15. property iLocReselect
  16.  
  17. property ikChStart
  18. property ikChEnd
  19. property ikFrameStart
  20. property ikFrameEnd
  21.  
  22. property iLastFrame
  23. property iNeedClean
  24.  
  25. on birth me
  26.   tell the stage
  27.     set iStageRight = the StageRight
  28.     set iStageBottom = the StageBottom
  29.     set iStageWidth = iStageRight - the StageLeft
  30.     set iStageHeight = iStageBottom - the StageTop
  31.   end tell
  32.   set ikChStart = 1
  33.   set ikChEnd = 2
  34.   set ikFrameStart = 3
  35.   set ikFrameEnd = 4
  36.   set iChannelAvailList = []
  37.   set iGeneratedScoreSelection = []
  38.   set ichReselect = 18
  39.   
  40.   return me
  41. end birth
  42.  
  43. on mGetStageWidth me
  44.   return iStageWidth
  45. end mGetStageWidth
  46.  
  47. on mGetStageHeight me
  48.   return iStageHeight
  49. end mGetStageHeight
  50.  
  51. on mGetStageRight me
  52.   return iStageRight
  53. end mGetStageRight
  54.  
  55. on mGetStageBottom me
  56.   return iStageBottom
  57. end mGetStageBottom
  58.  
  59. on mInit me, nFramesNeeded, nChannelsNeeded
  60.   global gDevelopmentFlag 
  61.   
  62.   if nFramesNeeded > 32000 then
  63.     alert("The combination of text and settings you have chosen would generate an " & ¼
  64.     "animation of more than 32000 frames.  Please simplify your selections and try again.")
  65.     return FALSE
  66.   end if
  67.   
  68.   tell the stage   
  69.     set iUsersScoreSelection = the scoreSelection
  70.     set iLastFrame = the lastFrame
  71.     set iStageRight = the StageRight   --check the stage location again, in case it has changed.
  72.     set iStageBottom = the StageBottom
  73.     set iStageWidth = iStageRight - the StageLeft
  74.     set iStageHeight = iStageBottom - the StageTop
  75.   end tell
  76.   if iUsersScoreSelection = [] then
  77.     alert("Please select a range of cells or frames in the score and try again.")
  78.     return FALSE
  79.   end if
  80.   
  81.   if gDevelopmentFlag then -- for development only
  82.     mForceSelection(me)    
  83.   end if
  84.   set iLocReselect = the loc of sprite ichReselect -- save for later
  85.   puppetSprite ichReselect, TRUE
  86.   
  87.   -- We must parse the user's selection and do the appropriate thing.
  88.   
  89.   set firstScoreSelectionList = getAt(iUsersScoreSelection, 1)
  90.   set ichStart = getAt(firstScoreSelectionList, ikChStart)
  91.   set ichEnd = getAt(firstScoreSelectionList, ikChEnd)
  92.   set iFrameStart = getAt(firstScoreSelectionList, ikFrameStart)
  93.   set iFrameEnd = getAt(firstScoreSelectionList, ikFrameEnd)
  94.   set theGeneratedFrameEnd = iFrameStart + nFramesNeeded - 1
  95.   
  96.   --check to see if the ending frame is the last frame and put in a tempo setting if it is.
  97.   set theEnd to max(theGeneratedFrameEnd, iFrameEnd)
  98.   if theEnd >= iLastFrame then
  99.     set iNeedClean = true
  100.     tell the stage
  101.       beginRecording
  102.         go to frame (theEnd + 5)
  103.         set the frameTempo to 5
  104.       endrecording
  105.     end tell
  106.   else 
  107.     set iNeedClean = false
  108.   end if
  109.   
  110.   set iChannelAvailList = []
  111.   if (ichStart = -5) and (ichEnd = 48) then -- user selected a whole frame
  112.     -- Make a list saying all 48 channels are available
  113.     repeat with ch = 1 to 48
  114.       add iChannelAvailList, ch
  115.     end repeat
  116.     
  117.     -- If the user selected a range of full frames, delete these frames.
  118.     -- This will simulate an insertion cursor
  119.     if iFrameEnd >= iFrameStart then 
  120.       tell the stage
  121.         go to frame iFrameStart
  122.         beginRecording
  123.           repeat with theFrameNum = iFrameStart to iFrameEnd
  124.             -- The following line deletes any frame marker
  125.             set the frameLabel = 0
  126.             deleteFrame
  127.           end repeat 
  128.         endRecording
  129.       end tell
  130.     end if
  131.     
  132.     -- Now we basically have an insertion cursor in the score
  133.     -- So, here we insert frames
  134.     tell the stage
  135.       if iFrameStart = 1 then
  136.         go to frame 1
  137.       else
  138.         go to frame iFrameStart - 1
  139.       end if
  140.       
  141.       beginRecording
  142.         repeat with i = 1 to nFramesNeeded
  143.           insertFrame
  144.         end repeat
  145.       endRecording
  146.       
  147.       if iFrameStart = 1 then
  148.         go to frame 1
  149.       else
  150.         go to frame iFrameStart - 1
  151.       end if
  152.     end tell
  153.     
  154.     set iGeneratedScoreSelection = [[-5, 48, iFrameStart, theGeneratedFrameEnd]]
  155.     
  156.     
  157.     
  158.     -- Otherwise, the user has selected  one or more channels  
  159.   else    
  160.     --  Build a list of channels that the user has selected.    
  161.     set iGeneratedScoreSelection  = []
  162.     set nItems = count(iUsersScoreSelection)
  163.     repeat with thisSelection = 1 to nItems
  164.       set thisScoreSelectionList = getAt(iUsersScoreSelection, thisSelection)
  165.       set thisChStart = getAt(thisScoreSelectionList, ikChStart)
  166.       if thisChStart <= 0 then
  167.         alert("Please make your score selection in channels 1 through 48")
  168.         mClean me
  169.         return FALSE
  170.       end if
  171.       set thisChEnd = getAt(thisScoreSelectionList, ikChEnd)
  172.       -- add this to the Generated score selection
  173.       set thisScoreSelection = [thisChStart, thisChEnd, iFrameStart, theGeneratedFrameEnd]
  174.       addAt(iGeneratedScoreSelection, thisScoreSelection)
  175.       
  176.       -- add each of the user's selected channels to the channel available list
  177.       repeat with thisCh = thisChStart to thisChEnd
  178.         add(iChannelAvailList, thisCh)
  179.       end repeat
  180.       
  181.     end repeat
  182.     set nChannelsAvail = count(iChannelAvailList)
  183.     if nChannelsNeeded > nChannelsAvail then
  184.       alert("Your animation requires" && nChannelsNeeded && "channels, " & ¼
  185.                 "but you have only selected" && nChannelsAvail && "channels.  " & ¼
  186.                  "Please select more and try again.")
  187.       mClean me
  188.       return FALSE
  189.     end if
  190.     
  191.     -- If we don't have enough frames in the selection,
  192.     -- duplicate the last frame until we have enough
  193.     --but make sure we don't duplicate the tempo channel
  194.     set nFramesSelected = iFrameEnd - iFrameStart + 1   
  195.     if nFramesSelected < nFramesNeeded then
  196.       set nFramesToAdd = nFramesNeeded - nFramesSelected
  197.       tell the stage
  198.         go to frame iFrameEnd
  199.         beginRecording
  200.           repeat with i = 1 to nFramesToAdd
  201.             duplicateFrame
  202.             set the frameTempo = 0
  203.           end repeat
  204.         endRecording
  205.         go to frame iFrameStart
  206.       end tell     
  207.     end if
  208.   end if
  209.   
  210.   -- Finally, clear out all user selected cells in the generated score
  211.   --  and clear out the tempo channel, in case of reselection
  212.   
  213.   tell the stage
  214.     beginRecording
  215.       go to frame iFrameStart
  216.       repeat with thisFrame = iFrameStart to iFrameEnd
  217.         repeat with chIndex = 1 to nChannelsAvail
  218.           set thisCh = getAt(iChannelAvailList, chIndex)
  219.           if the castNum of sprite thisCh <> 0 then
  220.             set the type of sprite thisCh = 0  --  delete anything that's there
  221.           end if
  222.         end repeat
  223.         set the frameTempo = 0
  224.         updateFrame
  225.       end repeat
  226.     endRecording
  227.   end tell
  228.   
  229.   
  230.   
  231.   --put "Channels that are available are :" && iChannelAvailList
  232.   --put "The Generated score selection is:" && iGeneratedScoreSelection
  233.   updateStage
  234.   
  235.   return TRUE  
  236. end mInit
  237.  
  238. on mShowReselect me
  239.   set the scoreSelection = iUsersScoreSelection
  240.   set the loc of sprite ichReselect = iLocReselect
  241.   set the castNum of sprite ichReselect = the number of cast "ReselectButton"
  242.   updateStage
  243. end mShowReselect
  244.  
  245.  
  246. on mForceSelection me  
  247.   -- This ensures that we don't overwrite stuff in the MIAW
  248.   -- when we are using it as a development movie (not a MIAW)
  249.   -- If I goofed and forgot to select a testing area of the score,
  250.   -- make believe I selected frames 101 to 125
  251.   
  252.   set nItems = count(iUsersScoreSelection)
  253.   repeat with thisSelectionNum = 1 to nItems
  254.     set thisScoreSelectionList = getAt(iUsersScoreSelection, thisSelectionNum)
  255.     set thisStart = getAt(thisScoreSelectionList, ikFrameStart)
  256.     set thisEnd = getAt(thisScoreSelectionList, ikFrameEnd)
  257.     
  258.     if (thisStart < 101) or (thisEnd < 101) then
  259.       setAt(thisScoreSelectionList, ikFrameStart, 101)
  260.       setAt(thisScoreSelectionList, ikFrameEnd, 125)
  261.       setAt(iUsersScoreSelection, thisSelectionNum, thisScoreSelectionList)
  262.     end if
  263.   end repeat
  264.   
  265. end mForceSelection
  266.  
  267. on mReselect me
  268.   if iGeneratedScoreSelection = [] then
  269.     alert("Internal error, mReselect - there is nothing to reselect.")
  270.     return
  271.   end if
  272.   tell the stage
  273.     set the scoreSelection = iGeneratedScoreSelection
  274.   end tell
  275. end mReselect
  276.  
  277. on mGetGeneratedScoreSelection me
  278.   return iGeneratedScoreSelection
  279. end mGetGeneratedScoreSelection
  280.  
  281.  
  282.  
  283. on mGetStartFrame me
  284.   return iFrameStart
  285. end mGetStartFrame
  286.  
  287. on mGetNextSelectedChannel me
  288.   -- Get the first in the list of users selected channels set up in mInit, 
  289.   -- return it, and eliminate it from the list of available channels
  290.   
  291.   if iChannelAvailList = [] then
  292.     alert("Internal error, mGetNextSelectedChannel is out of available channels")
  293.     return -99
  294.   end if
  295.   set theCh = getAt(iChannelAvailList, 1)
  296.   deleteAt(iChannelAvailList, 1)
  297.   
  298.   return theCh
  299. end mGetNextSelectedChannel
  300.  
  301.  
  302. on mWriteSprite me, f, ch, cm, theForeColor, theBackColor, x, y, w, h
  303.   global gkTransparentInk
  304.   
  305.   tell the stage
  306.     go frame ( f )
  307.     beginRecording 
  308.       -- sprite properties
  309.       set the castNum of sprite ch = cm
  310.       set the foreColor of sprite ch = theForeColor
  311.       set the backColor of sprite ch = theBackColor
  312.       set the locH  of sprite ch = x
  313.       set the locV  of sprite ch = y
  314.       set the ink of sprite ch = gkTransparentInk
  315.       
  316.       -- last two are primarily to support Zoom effect
  317.       if w <> 0 then 
  318.         set the width  of sprite ch = w
  319.       end if
  320.       if h <> 0 then 
  321.         set the height of sprite ch = h
  322.       end if
  323.       updateFrame
  324.       -- debug( "Writing Sprite:" && s && the type of sprite s && the castNum of sprite s && ¼
  325.              the foreColor of sprite s && the backColor of sprite s && ¼
  326.              the locH of sprite s && the locV of sprite s && ¼
  327.              the width of sprite s && the height of sprite s )
  328.     endRecording
  329.   end tell
  330. end mWriteScore
  331.  
  332. --to be called when score recording has already begun, from within a repeat loop recording a range of frames.
  333. on mWriteSpriteRange me, f,ch,cm, theForeColor, theBackColor,x,y,w,h
  334.   global gkTransparentInk
  335.   
  336.   go frame ( f )
  337.   -- sprite properties
  338.   set the castNum of sprite ch = cm
  339.   set the foreColor of sprite ch = theForeColor
  340.   set the backColor of sprite ch = theBackColor
  341.   set the locH  of sprite ch = x
  342.   set the locV  of sprite ch = y
  343.   set the ink of sprite ch = gkTransparentInk
  344.   
  345.   if w <> 0 then 
  346.     set the width  of sprite ch = w
  347.   end if
  348.   if h <> 0 then 
  349.     set the height of sprite ch = h
  350.   end if
  351.   updateFrame
  352. end mWriteSpriteRange
  353.  
  354.  
  355. on mWriteFrameControl me, theFrame, theControl, theValue
  356.   if theControl = #Transition then -- copy a known transition
  357.     copyToClipBoard member (the number of member theValue)    
  358.     --  Create a cast member in the stage movie  
  359.     set castNumTransTarget = mFindFreeCastRun(goCastMgr, 1, 1)
  360.   end if
  361.   tell the stage
  362.     go frame theFrame
  363.     beginRecording 
  364.       case theControl of
  365.         #Label:  set the frameLabel = theValue
  366.         #Tempo: set the frameTempo = theValue
  367.         #Transition:   -- Copied transition to clipboard already (above)
  368.           pasteClipboardInto member castNumTransTarget
  369.           set the name of member castNumTransTarget  = "Transition" && string(the ticks)
  370.           set the frameTransition = castNumTransTarget
  371.         #Sound1:  set the frameSound1 = theValue
  372.         #Sound2:  set the frameSound2 = theValue
  373.         otherwise  alert("Bad control value passed to mWriteFrameControl" & theControl)
  374.       end case   
  375.       updateFrame
  376.     endRecording
  377.   end tell  
  378. end mWriteFrameControl
  379.  
  380.  
  381. on mWriteFrameLabel me, theFrame, theLabel
  382.   mWriteFrameControl(me, theFrame, #Label, theLabel)
  383. end mWriteFrameLabel
  384.  
  385. -- Writing a frame delay is painful. Unfortunately, there is no
  386. -- easy way to just set this property.  So, we have to write 1
  387. -- frame for each second delay, and set the frame tempo
  388. -- of that frame to 1 frame per second.
  389. --on mWriteFrameDelay me, theFrame, nSeconds
  390. --  if nSeconds > 0 then
  391. --    repeat with thisFrame = 1 to nSeconds
  392. --      mWriteFrameControl(me, (theFrame + thisFrame - 1), #Tempo, 1)
  393. --    end repeat    
  394. --  end if  
  395. --end mWriteFrameDelay
  396.  
  397. --undocumented lingo: setting the frameTempo to a negative number sets it to wait for that many seconds.
  398. on mWriteFrameDelay me, theFrame, nSeconds
  399.   mWriteFrameControl(me,theFrame, #Tempo, -nSeconds )
  400. end mWriteFrameDelay
  401.  
  402. on mWriteFrameTempo me, theFrame, theTempo
  403.   mWriteFrameControl(me, theFrame, #Tempo, theTempo)
  404. end mWriteFrameTempo
  405.  
  406. on mWriteFrameTransition me, theFrame, theTransition
  407.   mWriteFrameControl(me, theFrame, #Transition, theTransition)
  408. end mWriteFrameTransition
  409.  
  410. on mWriteFrameSound1 me, theFrame, theSound1
  411.   mWriteFrameControl(me, theFrame, #Sound1, theSound1)
  412. end mWriteFrameSound1
  413.  
  414. on mWriteFrameSound2 me, theFrame, theSound2
  415.   mWriteFrameControl(me, theFrame, #Sound2, theSound2)
  416. end mWriteSound2
  417.  
  418.  
  419. -- Old code not used anymore
  420. on mWriteFrame me, f, f_label, f_tempo, f_palette, f_trans, f_sound1, ¼
  421.             f_sound2, f_script, f_clone
  422.   global AwScript_ids
  423.   
  424.   tell the stage
  425.     go frame ( f )
  426.     beginRecording 
  427.       -- supports "insert" mode that clones existing content 
  428.       if f_clone > 0 then 
  429.         debug( "duplicating current frame"  )
  430.         duplicateFrame
  431.       end if
  432.       -- frame properties
  433.       if ( f_label   <> 0 ) then set the frameLabel       = f_label
  434.       if ( f_tempo   <> 0 ) then set the frameTempo       = f_tempo
  435.       if ( f_palette <> 0 ) then set the framePalette     = f_palette
  436.       if ( f_trans   <> 0 ) then set the frameTransition  = f_trans
  437.       if ( f_sound1  <> 0 ) then set the frameSound1      = f_sound1
  438.       if ( f_sound2  <> 0 ) then set the frameSound2      = f_sound2
  439.       
  440.       -- f_script is name in global property list storing script indexes from stage cast   
  441.       if ( symbolP( f_script )) then
  442.         put "got symbol for script"
  443.         put value( f_script )
  444.         if ( NOT voidP( getAProp( AwScript_ids, f_script ))) then
  445.           -- requested script already in list
  446.           put "setting frame script to :" && f_script 
  447.           put AwScript_ids
  448.           set the frameScript = getProp( AwScript_ids, f_script )
  449.         else
  450.           put "f_script not a symbol value"
  451.           -- requested script needs to be added
  452.           raise_exception( 1, "Requested script not present" )
  453.         end if
  454.       end if    
  455.       updateFrame
  456.       -- debug( "Writing:" && the frameLabel && the frameTempo && the framePalette && ¼
  457.             the frameTransition && the frameSound1 && the frameSound2 )
  458.     endRecording
  459.   end tell
  460. end mWriteFrame
  461.  
  462. --gets rid of the extra tempo setting, if we set it. 
  463. on mClean me
  464.   if iNeedClean = true then
  465.     tell the stage
  466.       set iLastFrame = the lastFrame
  467.       beginRecording
  468.         go to frame iLastFrame
  469.         set the frameTempo to  0
  470.       endrecording
  471.     end tell
  472.   end if
  473. end mClean
  474.