home *** CD-ROM | disk | FTP | other *** search
/ Stickerpedia Stickerbook / Stickerbook.iso / pc / DATA / objects.cxt / 00022_Script_oMarvin < prev    next >
Text File  |  2003-03-19  |  9KB  |  396 lines

  1. --¨
  2. oMarvin
  3.  
  4.  
  5.  
  6.  
  7.  
  8. global oHQ, oMarvin
  9.  
  10.  
  11. on new me
  12.   -- addObject me
  13.   -- updateProgressBar ("Object loading", oMarvin && "status #ok")
  14.   return me
  15. end
  16.  
  17.  
  18.  
  19. on showProps me
  20.   showProps oHQ, me
  21. end
  22.  
  23.  
  24.  
  25. on convertTextToField me
  26.   
  27. end
  28.  
  29.  
  30.  
  31.  
  32. on getName me, theName, optionalDelimiter
  33.   set retVal = #noString
  34.   if stringP(theName) then
  35.     saveDelim = the itemDelimiter
  36.     if voidP(optionalDelimiter) then
  37.       the itemDelimiter = "."
  38.     else
  39.       the itemDelimiter = optionalDelimiter
  40.     end if
  41.     
  42.     set retVal = item 1 of theName
  43.     itemDelimiter = saveDelim
  44.   end if
  45.   return retVal
  46. end
  47.  
  48.  
  49. on fadeSprite me, spriteNum, startBlend, endBlend, repeats
  50.   
  51.   sprite(spriteNum).blend = startBlend 
  52.   sprite(spriteNum).visible = 1 
  53.   increment = 100/repeats
  54.   if startBlend > endBlend then increment = increment*-1
  55.   
  56.   
  57.   repeat with n = 1 to repeats
  58.     sprite(spriteNum).blend = sprite(spriteNum).blend + increment
  59.     updatestage
  60.   end repeat
  61.   
  62.   sprite(spriteNum).blend = endBlend
  63.   updatestage
  64.   
  65. end
  66.  
  67.  
  68.  
  69.  
  70. on pad me, x
  71.   -- insert "0" chars for single digit values of x
  72.   if x < 10 then
  73.     return "0" & string(x)
  74.   else
  75.     return x
  76.   end if
  77. end
  78.  
  79. on doublePad me, x
  80.   -- insert "00" chars for single digit values of x
  81.   -- and "0" for doubleDigit characters
  82.   
  83.   if x < 10 then
  84.     return "00" & string(x)
  85.   else if x < 100 then
  86.     return "0" & string(x)
  87.   else
  88.     return string(x)
  89.   end if
  90. end
  91.  
  92.  
  93.  
  94. on triplePad me, x
  95.   -- insert "000" chars for single digit values of x
  96.   -- and insert "00" chars for double digit values of x
  97.   -- and "0" for triple characters
  98.   
  99.   if x < 10 then
  100.     return "000" & string(x)
  101.   else if x < 100 then
  102.     return "00" & string(x)
  103.   else if x < 1000 then
  104.     return "0" & string(x)
  105.   else
  106.     return string(x)
  107.   end if
  108. end
  109.  
  110.  
  111. on doStage me
  112.   set the stageColor = the stageColor  
  113. end
  114.  
  115.  
  116.  
  117. on joinPropLists me, originalListOfLists
  118.   
  119.   -- some deleting will be done, so make a copy of original lists
  120.   set listOfLists = duplicate(originalListOfLists)
  121.   
  122.   -- newList will contain all passed lists, make it a property list: 
  123.   set newList = [:]  
  124.   
  125.   set numOfLists = count(listOfLists)
  126.   
  127.   -- two nested repeat loops: 
  128.   -- first loop iterates through listOfLists
  129.   -- second loop iterate through current list and extracts data and adds it to newList
  130.   
  131.   repeat with listIndex = 1 to numOfLists
  132.     
  133.     set curList = getAt(listOfLists, ListIndex)
  134.     set lastIndex = count(curList)
  135.     
  136.     repeat with curIndex = 1 to lastIndex
  137.       
  138.       -- get the first value:
  139.       set nextValue = getAt(curList,1)
  140.       
  141.       -- get the property assigned to it
  142.       set nextProp = getOne(curList,nextValue)
  143.       
  144.       -- add the fellows to newList
  145.       addProp newList, nextProp, nextValue
  146.       
  147.       -- because getOne() only retrieves the first occurence of a value,
  148.       -- delete the just retrieved entry from curList in case there are properties
  149.       -- with the same values
  150.       deleteAt curList,1 
  151.       
  152.     end repeat
  153.   end repeat
  154.   return newList 
  155. end
  156.  
  157.  
  158. on splitPropLists me, propertyList
  159.   -- this handler splits a property list into a linear list that contains an entry per property as a string
  160.   
  161.   set newList = []
  162.   -- some deleting will be done, so make a copy of original list
  163.   set damnLongPropertyList = duplicate(propertyList)
  164.   
  165.   set numofProps = count(damnLongPropertyList)
  166.   repeat with n = 1 to numofProps
  167.     
  168.     -- get the first value:
  169.     set nextValue = getAt(damnLongPropertyList,1)
  170.     
  171.     -- get the property assigned to it
  172.     set nextProp = getOne(damnLongPropertyList,nextValue)
  173.     
  174.     
  175.     -- because getOne() only retrieves the first occurence of a value,
  176.     -- delete the just retrieved entry from curList in case there are properties
  177.     -- with the same values
  178.     deleteAt damnLongPropertyList,1 
  179.     
  180.     set tempList = [:]
  181.     addProp tempList, nextProp, nextValue
  182.     add newList, tempList
  183.     
  184.     
  185.   end repeat
  186.   return newList
  187. end
  188.  
  189.  
  190.  
  191.  
  192. on checkListForDuplicates me, aList
  193.   retVal = []
  194.   numOfEntries = aList.count
  195.   
  196.   repeat with pointer = 1 to numOfEntries
  197.     checkThisEntry = aList[pointer]
  198.     -- updateProgressBar ("object Marvin checks asset lists for duplicates", string(pointer))
  199.     
  200.     repeat with pointer2 = 1 to numOfEntries
  201.       if pointer = pointer2 then next repeat
  202.       compareTo = aList[pointer2]
  203.       if (checkThisEntry = compareTo) and not getOne(retVal, compareTo) then retVal.add(checkThisEntry)  
  204.       
  205.     end repeat
  206.     
  207.   end repeat
  208.   
  209.   return retVal
  210. end
  211.  
  212.  
  213.  
  214.  
  215.  
  216. on eliminateDuplicatesInList me, originalList
  217.   
  218.   startTimer
  219.   
  220.   duplicatetInfoList =[:]
  221.   listOfDuplicates   = []
  222.   retVal             = originalList.duplicate()
  223.   deletePositionList = []
  224.   
  225.   numOfEntries = originalList.count
  226.   
  227.   repeat with pointer = 1 to numOfEntries
  228.     
  229.     checkThisEntry = originalList[pointer]
  230.     tempList = []
  231.     
  232.     repeat with pointer2 = 1 to numOfEntries
  233.       compareTo = originalList[pointer2]
  234.       if (checkThisEntry = compareTo) and not getOne(listOfDuplicates, compareTo) then tempList.add(pointer2)
  235.     end repeat
  236.     tempList.deleteAt(1)
  237.     if tempList.count then duplicatetInfoList.setAProp(checkThisEntry, tempList)  
  238.   end repeat
  239.   
  240.   
  241.   
  242.   -- put "duplicatetInfoList" && duplicatetInfoList
  243.   repeat with curPointerList in duplicatetInfoList
  244.     repeat with curPosition in curPointerList
  245.       deletePositionList.add(curPosition)
  246.     end repeat
  247.   end repeat
  248.   
  249.   sort deletePositionList
  250.   --put "deletePositionList" && deletePositionList
  251.   
  252.   numOfEntriesToDelete = deletePositionList.count
  253.   
  254.   repeat with pointer = numOfEntriesToDelete down to 1
  255.     retVal.deleteAt(deletePositionList[pointer])  
  256.   end repeat
  257.   put "eliminateDuplicatesInList" && the timer && "ticks"
  258.   return retVal
  259.   
  260. end
  261.  
  262.  
  263.  
  264.  
  265.  
  266. on invertPropertyListSortOrder me, aList
  267.   sort aList
  268.   retVal = [:]
  269.   numOfEntries = aList.count
  270.   repeat with pointer = numOfEntries down to 1
  271.     curValue = aList[pointer]
  272.     curProp = aList.getPropAt(pointer)
  273.     retVal.addProp(curProp, curValue)
  274.   end repeat
  275.   return retVal
  276. end
  277.  
  278.  
  279. on textToList me, theText
  280.   retVal = []
  281.   numOfEntries = theText.lines.count
  282.   
  283.   repeat with pointer = 1 to numOfEntries 
  284.     theValue = theText.line[pointer]
  285.     retVal.add(theValue)
  286.   end repeat
  287.   return retVal
  288. end
  289.  
  290.  
  291.  
  292. on listToText me, aList
  293.   retVal = ""
  294.   if ilk(aList) = #propList then propList = 1
  295.   numOfEntries = aList.count
  296.   
  297.   repeat with pointer = 1 to numOfEntries 
  298.     theValue = aList[pointer]
  299.     if propList then
  300.       theProp = aList.getPropAt(pointer)
  301.       retVal = retVal & theProp && "=" && theValue & RETURN
  302.     else
  303.       retVal = retVal & theValue & RETURN
  304.     end if
  305.   end repeat
  306.   return retVal
  307. end
  308.  
  309.  
  310. --
  311. --on switchListPosition me, aList, oldPos, newPos
  312. --  -- switches the position of a value in a list from oldPos to newPos
  313. --  retVal = []
  314. --  numOfEntries = aList.count
  315. --  if aList.ilk = #propList then customAlert "Not a property list"
  316. --  
  317. --  oldValue = aList[oldPos]
  318. --  aList.deleteAt(oldPos)
  319. --  
  320. --  -- create a new value at the end of the list
  321. --  -- move all values
  322. --  
  323. --end
  324.  
  325.  
  326.  
  327.  
  328.  
  329. on letterToNumber me, aLetter
  330.   set retVal = -1
  331.   if not stringP(aLetter) then
  332.     handleError oHQ, "object Marvin's method 'letterToNumber' can't translate" && aLetter && "into a number"
  333.     exit
  334.     return retVal
  335.   end if
  336.   if the number of chars in aLetter > 1 then
  337.     handleError oHQ, "object Marvin's method 'letterToNumber' can't translate" && aLetter && "into a number"
  338.     exit
  339.     return retVal
  340.   end if
  341.   
  342.   set theNumber = charToNum(aLetter)-96
  343.   if theNumber >=1 and theNumber <= 26 then
  344.     set retVal = theNumber
  345.   end if
  346.   return retVal
  347. end
  348.  
  349.  
  350. on switchCapitalLowerCase me, aLetter
  351.   set retVal = -1
  352.   set theNumber = charToNum(aLetter)
  353.   if theNumber >= 65 and theNumber <= 90 then
  354.     set retVal =  numToChar(theNumber+32) 
  355.   else
  356.     set retVal =  numToChar(theNumber-32) 
  357.   end if
  358.   return retVal
  359. end
  360.  
  361.  
  362. on eliminateSpaces me, aString
  363.   
  364.   
  365.   repeat while aString.char[1] = " "
  366.     delete aString.char[1]
  367.   end repeat
  368.   
  369.   repeat while aString.char[(aString.length)] = " "
  370.     delete aString.char[(aString.length)]
  371.   end repeat
  372.   
  373.   
  374.   return aString
  375.   
  376. end
  377.  
  378.  
  379.  
  380.  
  381. on pointWithInRect me, aPoint, aRect
  382.   if (getAt(aPoint,1) > getAt(aRect,1) ) and (getAt(aPoint,1) < getAt(aRect,3)) and  (getAt(aPoint,2) > getAt(aRect,2) ) and (getAt(aPoint,2) < getAt(aRect,4)) then return 1
  383.   else return 0
  384. end
  385.  
  386.  
  387. on getAllRollovers me
  388.   set sprList = []
  389.   repeat with n = 1 to 120
  390.     if rollover(n) then add sprList, n  
  391.   end repeat
  392.   return sprList
  393. end
  394.  
  395.  
  396.