home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 February / macformat-047.iso / Demos / Simpsons Cartoon Studio™ Demo / Simpdata / simpmain / 00007_layerManager parent.ls < prev    next >
Encoding:
Text File  |  1996-09-06  |  3.7 KB  |  167 lines

  1. property maxSlots, slotAddedP
  2. global dispatchTable, scoreData
  3.  
  4. on birth me
  5.   init(me)
  6.   set slotAddedP to 0
  7.   return me
  8. end
  9.  
  10. on init me
  11.   set maxSlots to 12
  12.   clear(me)
  13. end
  14.  
  15. on clear me
  16.   set dispatchTable to []
  17. end
  18.  
  19. on isEmptyP me
  20.   if dispatchTable = 0 then
  21.     return 1
  22.   else
  23.     return 0
  24.   end if
  25. end
  26.  
  27. on isFullP me
  28.   if count(dispatchTable) >= maxSlots then
  29.     return 1
  30.   else
  31.     return 0
  32.   end if
  33. end
  34.  
  35. on findDuplicateCategory me, theGroup
  36.   set found to 0
  37.   set slotNum to 1
  38.   repeat with curSlot in dispatchTable
  39.     if theGroup = getAt(curSlot, 2) then
  40.       set curDataChannel to getAt(curSlot, 3)
  41.       set found to 1
  42.       exit repeat
  43.     end if
  44.     set slotNum to slotNum + 1
  45.   end repeat
  46.   if found then
  47.     set slotAddedP to 0
  48.     return curDataChannel
  49.   else
  50.     return found
  51.   end if
  52. end
  53.  
  54. on addNewSlot me, theType, theCategory, clipDataField
  55.   set curClipType to theType
  56.   set curClipGroup to theCategory
  57.   set junkList to []
  58.   repeat with curSlot in dispatchTable
  59.     add(junkList, getAt(curSlot, 3))
  60.   end repeat
  61.   sort(junkList)
  62.   set curDataChannel to 1
  63.   repeat with slot in junkList
  64.     if slot <> curDataChannel then
  65.       exit repeat
  66.     end if
  67.     set curDataChannel to curDataChannel + 1
  68.   end repeat
  69.   append(dispatchTable, [curClipType, curClipGroup, curDataChannel, clipDataField])
  70.   set slotAddedP to 1
  71.   return curDataChannel
  72. end
  73.  
  74. on insertProp me, theType, theCategory
  75.   set tempDispatchTable to []
  76.   set thePropSlot to getLast(dispatchTable)
  77.   deleteAt(dispatchTable, count(dispatchTable))
  78.   repeat with count = 1 to count(dispatchTable)
  79.     set theSearchType to getAt(getAt(dispatchTable, count), 1)
  80.     if (theSearchType <> "S") and (theSearchType <> "P") then
  81.       exit repeat
  82.     end if
  83.   end repeat
  84.   if count > 1 then
  85.     repeat with theSlotNumber = 1 to count - 1
  86.       append(tempDispatchTable, getAt(dispatchTable, theSlotNumber))
  87.     end repeat
  88.     append(tempDispatchTable, thePropSlot)
  89.     repeat with theSlotNumber = count to count(dispatchTable)
  90.       append(tempDispatchTable, getAt(dispatchTable, theSlotNumber))
  91.     end repeat
  92.   else
  93.     append(tempDispatchTable, thePropSlot)
  94.     repeat with theSlot in dispatchTable
  95.       append(tempDispatchTable, theSlot)
  96.     end repeat
  97.   end if
  98.   set dispatchTable to tempDispatchTable
  99.   set slotAddedP to 1
  100. end
  101.  
  102. on getLayer me, theGroup
  103.   set found to 0
  104.   set slotNum to 1
  105.   repeat with curSlot in dispatchTable
  106.     if theGroup = getAt(curSlot, 2) then
  107.       set curDataChannel to getAt(curSlot, 3)
  108.       set found to 1
  109.       exit repeat
  110.     end if
  111.     set slotNum to slotNum + 1
  112.   end repeat
  113.   if found then
  114.     return slotNum
  115.   else
  116.     return found
  117.   end if
  118. end
  119.  
  120. on updateStackPanel me
  121.   update(stackMgr)
  122. end
  123.  
  124. on deleteLastSlot me, theGroup
  125.   if slotAddedP then
  126.     set found to 0
  127.     set slotNum to 1
  128.     repeat with curSlot in dispatchTable
  129.       if theGroup = getAt(curSlot, 2) then
  130.         set curDataChannel to getAt(curSlot, 3)
  131.         set found to 1
  132.         exit repeat
  133.       end if
  134.       set slotNum to slotNum + 1
  135.     end repeat
  136.     if found then
  137.       deleteAt(dispatchTable, slotNum)
  138.     end if
  139.   end if
  140. end
  141.  
  142. on updateDispatchTable me
  143.   set dispatchMap to []
  144.   repeat with theSlot in dispatchTable
  145.     set channelNumber to getAt(theSlot, 3)
  146.     set found to 0
  147.     repeat with theFrame in scoreData
  148.       if getAt(theFrame, channelNumber) <> EMPTY then
  149.         set found to 1
  150.         exit repeat
  151.       end if
  152.     end repeat
  153.     if found = 1 then
  154.       add(dispatchMap, 1)
  155.       next repeat
  156.     end if
  157.     add(dispatchMap, 0)
  158.   end repeat
  159.   set numberOfSlots to count(dispatchTable)
  160.   repeat with theSlot = 1 to numberOfSlots
  161.     if getAt(dispatchMap, theSlot) = 0 then
  162.       deleteAt(dispatchTable, theSlot)
  163.     end if
  164.   end repeat
  165.   updateStackPanel(me)
  166. end
  167.