home *** CD-ROM | disk | FTP | other *** search
/ Boot Disc 2 / boot-disc-1996-10.iso / resources.dir / 00001_Script_resourcesClass next >
Text File  |  1996-08-03  |  14KB  |  430 lines

  1. -- ResourcesClass
  2. -- Resources Class,a Director Object for handling demo file access
  3. -- by Kurt Cagle, Imagine Publishing, copyright 1996
  4. -- To get a help file description of this class, type:
  5. --     describe (script "ResourcesClass")
  6.  
  7. property resList,IDName,demofield,categoryfield,activerec,defaultcatphrase
  8. property browser,defaultprotocol,defaultURL
  9. property shortinterval,longinterval,targetticks
  10.  
  11. on new me,mydemofield,mycategoryfield,loadflag
  12.   global resources
  13.   if getpos(the actorlist,resources)>0 then
  14.     set pos=getpos(the actorlist,resources)
  15.     deleteat the actorlist,pos
  16.   end if
  17.   set IDName="ResourcesClass"
  18.   if loadflag then
  19.     loadfile me
  20.   else
  21.     loadcast me
  22.   end if
  23.   set resources=me
  24.   set browser=#undefined
  25.   set defaultprotocol="http://"
  26.   set defaultURL="www.bootnet.com"
  27.   getBrowserPath me
  28.   set defaultCatPhrase="All Demos"
  29.   set activerec=0
  30.   set shortinterval=5*60
  31.   set longinterval=40*60
  32.   set targetticks=0
  33.   assigndemofield me,mydemofield
  34.   assigncategoryfield me,mycategoryfield
  35.   return me
  36. end
  37.  
  38. on loadcast me
  39.   set systemlist=value(the text of member "SystemInfoList")
  40.   if not voidP(systemlist) then
  41.     set restextlist=getprop(systemlist,IDName)
  42.     set reslist=the reslist of restextlist
  43.     -- set IDName=the IDName of restextlist
  44.   else
  45.     alert "The list in ""e&"ResourcesList"&" has become corrupt. Please reload from the source file."
  46.     halt
  47.   end if
  48. end  
  49.  
  50. on loadfile me
  51.   set file=fileIO(mNew,"?read","rsc")
  52.   if objectP(file) then
  53.     set restext=file(mReadfile)
  54.     file(mDispose)
  55.     repeat with index=1 to the number of lines in restext
  56.       if chartonum(char 1 of line index of restext)=10 then
  57.         delete char 1 of line index of restext
  58.       end if
  59.       if chartonum(char 1 of line index of restext)=10 then
  60.         delete line index of restext
  61.       end if
  62.     end repeat
  63.   else
  64.     alert ("No file was selected.")
  65.     halt
  66.   end if
  67.   parsefile me,restext
  68. end
  69.  
  70. on parsefile me,restext
  71.   set reslist=[:]
  72.   set reclist=[:]
  73.   set olddelimiter=the itemdelimiter
  74.   set the itemdelimiter=tab
  75.   set baseline=line 1 of restext
  76.   repeat with index=1 to the number of items in baseline
  77.     addprop reclist,value(item index of baseline),0
  78.   end repeat
  79.   repeat with curlineindex=2 to the number of lines in restext
  80.     if the number of items in line curlineindex of restext=count(reclist) then  
  81.       set newlist=duplicate(reclist)
  82.       set curline=line curlineindex of restext
  83.       repeat with index=1 to the number of items in curline
  84.         if item index of curline=#none then
  85.           setprop newlist,getpropat(newlist,index),#none
  86.         else
  87.           setprop newlist,getpropat(newlist,index),item index of curline
  88.         end if
  89.       end repeat
  90.       addprop reslist,getat(newlist,1),newlist
  91.     end if      
  92.   end repeat
  93.   put "File parsed"
  94.   set the itemdelimiter=olddelimiter
  95.   updateSystemInfoList me
  96.   -- put reslist
  97. end
  98.  
  99. on assignDemoField me,demofieldname
  100.   set demofield=demofieldname
  101.   set the textstyle of member demofield to "plain"
  102.   set rt=RETURN
  103.   set buffer="on mouseDown"&rt
  104.   set buffer=buffer&"  set curline=the mouseline"&rt
  105.   set buffer=buffer&"  set demotext=the text of field ""e&demofield"e&rt
  106.   set buffer=buffer&"  if curline>0 and curline<=the number of lines in demotext then"&rt
  107.   set buffer=buffer&"    global resources"&rt
  108.   set buffer=buffer&"    set obj=resources"&rt
  109.   set buffer=buffer&"    set rec=getrecord(obj,line curline of demotext)"&rt
  110.   set buffer=buffer&"    set the fontstyle of member ""e&demofield"e&" to ""e&"plain""e&rt
  111.   set buffer=buffer&"    set the fontstyle of line curline of field ""e&demofield"e&" to ""e&"bold""e&rt
  112.   set buffer=buffer&"    showRecord obj,rec"&rt
  113.   set buffer=buffer&"    set the targetticks of obj=the ticks+the longinterval of obj"&rt
  114.   set buffer=buffer&"   end if"&rt
  115.   set buffer=buffer&"end"
  116.   set the scripttext of member demofield to buffer
  117. end
  118.  
  119. on assignCategoryField me,categoryfieldname
  120.   set categoryfield=categoryfieldname
  121.   set the textstyle of member categoryfield to "plain"
  122.   set rt=RETURN
  123.   global resources
  124.   getCategories me
  125.   set buffer="on mouseDown"&rt
  126.   set buffer=buffer&"  set curline=the mouseline"&rt
  127.   set buffer=buffer&"  set cattext=the text of field ""e&categoryfield"e&rt
  128.   set buffer=buffer&"  if curline>0 and curline<=the number of lines in cattext then"&rt
  129.   set buffer=buffer&"    global resources"&rt
  130.   set buffer=buffer&"    set obj=resources"&rt
  131.   set buffer=buffer&"    set the fontstyle of member ""e&categoryfield"e&" to ""e&"plain""e&rt
  132.   set buffer=buffer&"    set the fontstyle of line curline of field ""e&categoryfield"e&" to ""e&"bold""e&rt
  133.   set buffer=buffer&"    getbycategory(obj,line curline of cattext)"&rt
  134.   set buffer=buffer&"    set the targetticks of obj=the ticks+the shortinterval of obj"&rt
  135.   set buffer=buffer&"   end if"&rt
  136.   set buffer=buffer&"end"
  137.   set the scripttext of member categoryfield to buffer
  138.   set the textstyle of member categoryfield to "plain"
  139.   set the textstyle of line 1 of member categoryfield to "bold"
  140.   getall(me)
  141. end
  142.  
  143. on getBrowserPath me
  144.   if browser=#undefined then
  145.     set file=fileIO(mNew,"read","c:\windows\bootcd.ini")
  146.     if (objectP(file)) then
  147.       set myline="temp"
  148.       repeat while myline<>""
  149.         set myline=file(mReadLine)
  150.         if offset("browser=",myline)>0 then
  151.           set browser=char 9 to length(myline) of myline
  152.           exit repeat
  153.         end if
  154.       end repeat
  155.       file(mDispose)
  156.       if browser=#undefined then
  157.         alert("You have not yet specified a browser for your use. Could you locate the browser you wish to use?")
  158.         set file=fileIO(mNew,"?read","exe")
  159.         if objectP(file) then
  160.           set browser=file(mFileName)
  161.           file(mDispose)
  162.           set file=fileIO(mNew,"write","c:\windows\bootcd.ini")
  163.           file(mWriteString,"browser="&browser)
  164.           file(mDispose)
  165.         else
  166.           alert("You have opted not to choose a browser this session.  If you change your mind, you can set the browser path in the bootNet section of this application.")
  167.           set browser=#none
  168.         end if
  169.       end if
  170.     else
  171.       alert("You have not yet specified a browser for your use. Could you locate the browser you wish to use?")
  172.       set file=fileIO(mNew,"?read","exe")
  173.       if objectP(file) then
  174.         set browser=file(mFileName)
  175.         file(mDispose)
  176.         set file=fileIO(mNew,"write","c:\windows\bootcd.ini")
  177.         file(mWriteString,"browser="&browser)
  178.         file(mDispose)
  179.       else
  180.         alert("You have opted not to choose a browser this session.  If you change your mind, you can set the browser path in the bootNet section of this application.")
  181.         set browser=#none
  182.       end if
  183.     end if
  184.   end if
  185.   return browser
  186. end
  187.  
  188. on getrecord me,myAppname
  189.   set activeRec=getprop(the reslist of me,myAppName)
  190.   return activeRec
  191. end
  192.  
  193. on getexepath me,myAppname
  194.   set rec=getrecord(me,myAppname)
  195.   if the platform of rec="Mac" then
  196.     set path=the moviepath&":"&(the appfolder of rec)&":"&(the exename of rec)
  197.   else
  198.     set path=the moviepath &(the appfolder of rec)&"\"&(the exename of rec)
  199.   end if
  200.   return path
  201. end
  202.  
  203. on getreadmepath me,myAppname
  204.   set rec=getrecord(me,myAppname)
  205.   if the platform of rec="Mac" then
  206.     set path=the moviepath&":"&(the appfolder of rec)&":"&(the readmename of rec)
  207.   else
  208.     set path=the moviepath &(the appfolder of rec)&"\"&(the readmename of rec)
  209.   end if
  210.   return path
  211. end
  212.  
  213. on getAll me
  214.   set buffer=""
  215.   set templist=[]
  216.   sort templist
  217.   repeat with recindex=1 to count(reslist)
  218.     set rec=getat(reslist,recindex)
  219.     add templist,the appname of rec
  220.   end repeat
  221.   repeat with recname in templist
  222.     set buffer=buffer&(recname)&return
  223.   end repeat
  224.   delete char(length(buffer)) of buffer
  225.   if demofield="" then
  226.     put buffer
  227.   else
  228.     put buffer into field demofield
  229.   end if
  230.   return buffer
  231. end  
  232.  
  233. on getByCategory me,whichcategory
  234.   set buffer=""
  235.   set templist=[]
  236.   sort templist
  237.   repeat with recindex=1 to count(reslist)
  238.     set rec=getat(reslist,recindex)
  239.     if offset(whichcategory,the category of rec)>0 then
  240.       repeat with itemindex=1 to the number of items in the category of rec
  241.         if item itemindex of the category of rec=whichcategory then
  242.           add templist,the appname of rec
  243.           set itemindex=the number of items in the category of rec+2
  244.         end if
  245.       end repeat
  246.     else
  247.       if whichcategory=defaultcatphrase then
  248.         add templist,the appname of rec
  249.       end if
  250.     end if
  251.   end repeat
  252.   repeat with recname in templist
  253.     set buffer=buffer&(recname)&return
  254.   end repeat
  255.   delete char(length(buffer)) of buffer
  256.   if demofield="" then
  257.     put buffer
  258.   else
  259.     set the textstyle of member demofield to "plain"
  260.     set the text of member demofield to buffer
  261.     set the textstyle of line 1 of member demofield to "bold"
  262.     getrecord me,line 1 of field demofield
  263.     showrecord me
  264.   end if
  265.   return buffer
  266. end  
  267.  
  268. on getCategories me
  269.   set buffer=""
  270.   set catlist=[]
  271.   add catlist,defaultcatphrase
  272.   repeat with recindex=1 to count(reslist)
  273.     set rec=getat(reslist,recindex)
  274.     repeat with index=1 to the number of items in the category of rec
  275.       if getpos(catlist,item index of the category of rec)=0 then
  276.         add catlist,item index of the category of rec
  277.       end if
  278.     end repeat
  279.   end repeat
  280.   repeat with index=1 to count(catlist)
  281.     set buffer=buffer&getat(catlist,index)&return
  282.   end repeat
  283.   delete char(length(buffer)) of buffer
  284.   if categoryfield="" then
  285.     put buffer
  286.   else
  287.     set the textstyle of member categoryfield to "plain"
  288.     set the text of member categoryfield to buffer
  289.   end if
  290.   return buffer
  291. end  
  292.  
  293. on describe me
  294.   put "ResourcesClass"
  295.   put "Resources Class,a Director Object for handling demo file access"
  296.   put "by Kurt Cagle, Imagine Publishing, copyright 1996"
  297. end
  298.  
  299. on updateSystemInfoList me
  300.   set systemlist=[:]
  301.   if the number of member "SystemInfoList"<1 then
  302.     set systemlist=[:]
  303.     set sysmember=findEmpty(member 1)
  304.     repeat with index=1 to the maxInteger
  305.       if the type of member index=#field then
  306.         duplicate member index, sysmember
  307.         exit repeat
  308.       end if
  309.     end repeat
  310.     set the name of member sysmember to "SystemInfoList"
  311.     set the text of member sysmember to  "[:]"
  312.   else
  313.     set sysmember=the number of member ("SystemInfoList")
  314.     set systemlist=value(the text of member sysmember)
  315.     if systemlist=0 then
  316.       set systemlist=[:]
  317.     end if
  318.   end if
  319.   set proplist=[:]
  320.   repeat with index=1 to count(me)
  321.     set prop=getpropat(me,index)
  322.     set entry=getprop(me,prop)
  323.     if voidP(entry) then set entry=0
  324.     addprop proplist,prop,entry
  325.   end repeat
  326.   if voidP(getaprop(systemlist,IDName)) then
  327.     addprop systemlist,IDName,proplist
  328.   else
  329.     setprop systemlist,IDName,proplist
  330.   end if
  331.   set the text of member sysmember to string(systemlist)  
  332. end
  333.  
  334. on launchURL me,URL
  335.   if browser<>#none then
  336.     if voidP(URL) then
  337.       if activerec=0 then
  338.         set URL=defaultprotocol&defaultURL
  339.       else
  340.         set URL=defaultprotocol&the URL of activerec
  341.       end if
  342.     end if
  343.     open browser&&URL
  344.   else
  345.     alert "No browser has been defined for use."
  346.   end if
  347. end
  348.  
  349. on cycle me
  350.   if activerec=0 then
  351.     getrecord me,line (the number of lines in field demofield) of field demofield
  352.   end if
  353.   set app=the appname of activerec
  354.   set curtext=the text of field demofield
  355.   repeat with index=1 to the number of lines in field demofield
  356.     set curline=line index of curtext
  357.     if app=curline then
  358.       set cycleIndex=index
  359.       exit repeat
  360.     end if
  361.   end repeat
  362.   if cycleindex=the number of lines in curtext then
  363.     set cycleindex=1
  364.   else
  365.     set cycleindex=cycleindex+1
  366.   end if
  367.   set app=line cycleindex of curtext
  368.   set the fontstyle of member demofield to "plain"
  369.   set the fontstyle of line cycleindex of field demofield to "bold"
  370.   getrecord me,app
  371.   showrecord me,app
  372.   set targetticks=the ticks+shortinterval
  373. end
  374.  
  375. on showrecord me
  376.   updateTitle me
  377. end
  378.  
  379. on startCycle me
  380.   if getpos(the actorlist,me)=0 then
  381.     add the actorlist me
  382.     set interval=shortinterval
  383.   end if
  384. end
  385.  
  386. on stepframe me
  387.   if the ticks>targetticks then
  388.     cycle me
  389.   end if
  390. end stepframe me
  391.  
  392. on endCycle me
  393.   set pos=getpos(the actorlist,me)
  394.   if pos>0 then
  395.     deleteat the actorlist,pos
  396.   end if
  397. end
  398.  
  399. on castsprite me,whichcast
  400.   set curcast=the number of member whichcast
  401.   set spritenum=0
  402.   if curcast>0 then
  403.     repeat with index=1 to 48
  404.       if the membernum of sprite index=curcast then
  405.         set spritenum=index
  406.         exit repeat
  407.       end if
  408.     end repeat
  409.   end if
  410.   return spritenum
  411. end
  412.  
  413. on updateTitle me
  414.   -- exit
  415.   set spritelist=[]
  416.   add spritelist,castsprite(me,"Title")
  417.   add spritelist,castsprite(me,"TitleLight")
  418.   add spritelist,castsprite(me,"TitleDark")
  419.   repeat with index=1 to count(spritelist)
  420.     set the visible of sprite getat(spritelist,index) to false
  421.   end repeat
  422.   repeat with index=1 to count(spritelist)
  423.     set the text of member (the membernum of sprite getat(spritelist,index)) to the appname of activerec
  424.   end repeat
  425.   repeat with index=1 to count(spritelist)
  426.     set the visible of sprite getat(spritelist,index) to true
  427.   end repeat
  428. end
  429.  
  430.