home *** CD-ROM | disk | FTP | other *** search
/ Boot Disc 2 / boot-disc-1996-10.iso / Demo.dir / 00004_Script_resourcesClass < prev    next >
Text File  |  1996-08-09  |  19KB  |  587 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,imagemember,activerec
  8. property defaultcatphrase,catlist,spritelist,imagesprite
  9. property browser,defaultprotocol,defaultURL,videosprite
  10. property shortinterval,longinterval,targetticks,IsCycling
  11.  
  12. on new me,mydemofield,mycategoryfield,myImageMember,myVideoSprite,loadflag
  13.   global resources
  14.   set videoSprite=myVideoSprite
  15.   set imageMember=the number of member(myImageMember)
  16.   set imageSprite=castsprite(me,myImageMember)
  17.   puppetsprite imageSprite,true
  18.   if getpos(the actorlist,resources)>0 then
  19.     set pos=getpos(the actorlist,resources)
  20.     deleteat the actorlist,pos
  21.   end if
  22.   set IDName="ResourcesClass"
  23.   if loadflag then
  24.     loadfile me
  25.   else
  26.     loadcast me
  27.   end if
  28.   set resources=me
  29.   set browser=#undefined
  30.   set catlist=[]
  31.   set defaultprotocol="http://"
  32.   set defaultURL="www.bootnet.com"
  33.   getBrowserPath me
  34.   set defaultCatPhrase="All Demos"
  35.   set activerec=0
  36.   set shortinterval=5*60
  37.   set longinterval=40*60
  38.   set targetticks=0
  39.   set IsCycling=false
  40.   if not voidP(myDemoField) then
  41.     assigndemofield me,mydemofield
  42.     assigncategoryfield me,mycategoryfield
  43.   end if
  44.   return me
  45. end
  46.  
  47. on loadcast me
  48.   set systemlist=value(the text of member "SystemInfoList")
  49.   if not voidP(systemlist) then
  50.     set restextlist=getprop(systemlist,IDName)
  51.     set reslist=the reslist of restextlist
  52.     -- set IDName=the IDName of restextlist
  53.   else
  54.     alert "The list in ""e&"ResourcesList"&" has become corrupt. Please reload from the source file."
  55.     halt
  56.   end if
  57. end  
  58.  
  59. on loadfile me
  60.   set file=fileIO(mNew,"?read","rsc")
  61.   if objectP(file) then
  62.     set restext=file(mReadfile)
  63.     file(mDispose)
  64.     repeat with index=1 to the number of lines in restext
  65.       if chartonum(char 1 of line index of restext)=10 then
  66.         delete char 1 of line index of restext
  67.       end if
  68.       if chartonum(char 1 of line index of restext)=10 then
  69.         delete line index of restext
  70.       end if
  71.     end repeat
  72.   else
  73.     alert ("No file was selected.")
  74.     halt
  75.   end if
  76.   parsefile me,restext
  77. end
  78.  
  79. on parsefile me,restext
  80.   set reslist=[:]
  81.   set reclist=[:]
  82.   set olddelimiter=the itemdelimiter
  83.   set the itemdelimiter=tab
  84.   set baseline=line 1 of restext
  85.   repeat with index=1 to the number of items in baseline
  86.     addprop reclist,value(item index of baseline),0
  87.   end repeat
  88.   repeat with curlineindex=2 to the number of lines in restext
  89.     if the number of items in line curlineindex of restext=count(reclist) then  
  90.       set newlist=duplicate(reclist)
  91.       set curline=line curlineindex of restext
  92.       repeat with index=1 to the number of items in curline
  93.         if item index of curline=#none then
  94.           setprop newlist,getpropat(newlist,index),#none
  95.         else
  96.           setprop newlist,getpropat(newlist,index),item index of curline
  97.         end if
  98.       end repeat
  99.       addprop reslist,getat(newlist,1),newlist
  100.     end if      
  101.   end repeat
  102.   put "File parsed"
  103.   set the itemdelimiter=olddelimiter
  104.   updateSystemInfoList me
  105.   -- put reslist
  106. end
  107.  
  108. on assignDemoField me,demofieldname
  109.   set demofield=demofieldname
  110.   set the textstyle of member demofield to "plain"
  111.   set rt=RETURN
  112.   set buffer="on mouseDown"&rt
  113.   set buffer=buffer&"  set curline=the mouseline"&rt
  114.   set buffer=buffer&"  set demotext=the text of field ""e&demofield"e&rt
  115.   set buffer=buffer&"  if curline>0 and curline<=the number of lines in demotext then"&rt
  116.   set buffer=buffer&"    global resources"&rt
  117.   set buffer=buffer&"    set obj=resources"&rt
  118.   set buffer=buffer&"    set rec=getrecord(obj,line curline of demotext)"&rt
  119.   set buffer=buffer&"    set the fontstyle of member ""e&demofield"e&" to ""e&"plain""e&rt
  120.   set buffer=buffer&"    set the fontstyle of line curline of field ""e&demofield"e&" to ""e&"bold""e&rt
  121.   set buffer=buffer&"    showRecord obj,rec"&rt
  122.   set buffer=buffer&"    set the targetticks of obj=the ticks+the longinterval of obj"&rt
  123.   set buffer=buffer&"   end if"&rt
  124.   set buffer=buffer&"end"
  125.   set the scripttext of member demofield to buffer
  126. end
  127.  
  128. on assignCategoryField me,categoryfieldname
  129.   set categoryfield=categoryfieldname
  130.   set the textstyle of member categoryfield to "plain"
  131.   set rt=RETURN
  132.   global resources
  133.   getCategories me
  134.   set buffer="on mouseDown"&rt
  135.   set buffer=buffer&"  set curline=the mouseline"&rt
  136.   set buffer=buffer&"  set cattext=the text of field ""e&categoryfield"e&rt
  137.   set buffer=buffer&"  if curline>0 and curline<=the number of lines in cattext then"&rt
  138.   set buffer=buffer&"    global resources"&rt
  139.   set buffer=buffer&"    set obj=resources"&rt
  140.   set buffer=buffer&"    set the fontstyle of member ""e&categoryfield"e&" to ""e&"plain""e&rt
  141.   set buffer=buffer&"    set the fontstyle of line curline of field ""e&categoryfield"e&" to ""e&"bold""e&rt
  142.   set buffer=buffer&"    getbycategory(obj,line curline of cattext)"&rt
  143.   set buffer=buffer&"    set the targetticks of obj=the ticks+the shortinterval of obj"&rt
  144.   set buffer=buffer&"   end if"&rt
  145.   set buffer=buffer&"end"
  146.   set the scripttext of member categoryfield to buffer
  147.   set the textstyle of member categoryfield to "plain"
  148.   set the textstyle of line 1 of member categoryfield to "bold"
  149.   getall(me)
  150. end
  151.  
  152. on getBrowserPath me
  153.   if browser=#undefined then
  154.     set file=fileIO(mNew,"read","c:\windows\bootcd.ini")
  155.     if (objectP(file)) then
  156.       set myline="temp"
  157.       repeat while myline<>""
  158.         set myline=file(mReadLine)
  159.         if offset("browser=",myline)>0 then
  160.           set browser=char 9 to length(myline) of myline
  161.           exit repeat
  162.         end if
  163.       end repeat
  164.       file(mDispose)
  165.       if browser=#undefined then
  166.         alert("You have not yet specified a browser for your use. Could you locate the browser you wish to use?")
  167.         set file=fileIO(mNew,"?read","exe")
  168.         if objectP(file) then
  169.           set browser=file(mFileName)
  170.           file(mDispose)
  171.           set file=fileIO(mNew,"write","c:\windows\bootcd.ini")
  172.           file(mWriteString,"browser="&browser)
  173.           file(mDispose)
  174.         else
  175.           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.")
  176.           set browser=#none
  177.         end if
  178.       end if
  179.     else
  180.       alert("You have not yet specified a browser for your use. Could you locate the browser you wish to use?")
  181.       set file=fileIO(mNew,"?read","exe")
  182.       if objectP(file) then
  183.         set browser=file(mFileName)
  184.         file(mDispose)
  185.         set file=fileIO(mNew,"write","c:\windows\bootcd.ini")
  186.         file(mWriteString,"browser="&browser)
  187.         file(mDispose)
  188.       else
  189.         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.")
  190.         set browser=#none
  191.       end if
  192.     end if
  193.   end if
  194.   return browser
  195. end
  196.  
  197. on getrecord me,myAppname
  198.   set activeRec=getprop(the reslist of me,myAppName)
  199.   return activeRec
  200. end
  201.  
  202. on getexepath me,myAppname
  203.   set rec=getrecord(me,myAppname)
  204.   if the platform of rec="Mac" then
  205.     set path=the moviepath&":"&(the appfolder of rec)&":"&(the exename of rec)
  206.   else
  207.     set path=the moviepath &(the appfolder of rec)&"\"&(the exename of rec)
  208.   end if
  209.   return path
  210. end
  211.  
  212. on getreadmepath me,myAppname
  213.   set rec=getrecord(me,myAppname)
  214.   if the platform of rec="Mac" then
  215.     set path=the moviepath&":"&(the appfolder of rec)&":"&(the readmename of rec)
  216.   else
  217.     set path=the moviepath &(the appfolder of rec)&"\"&(the readmename of rec)
  218.   end if
  219.   return path
  220. end
  221.  
  222. on getAll me
  223.   set buffer=""
  224.   set templist=[]
  225.   sort templist
  226.   repeat with recindex=1 to count(reslist)
  227.     set rec=getat(reslist,recindex)
  228.     add templist,the appname of rec
  229.   end repeat
  230.   repeat with recname in templist
  231.     set buffer=buffer&(recname)&return
  232.   end repeat
  233.   delete char(length(buffer)) of buffer
  234.   if demofield="" then
  235.     put buffer
  236.   else
  237.     put buffer into field demofield
  238.   end if
  239.   return buffer
  240. end  
  241.  
  242. on getByCategory me,whichcategory
  243.   set buffer=""
  244.   set templist=[]
  245.   sort templist
  246.   repeat with recindex=1 to count(reslist)
  247.     set rec=getat(reslist,recindex)
  248.     if offset(whichcategory,the category of rec)>0 then
  249.       repeat with itemindex=1 to the number of items in the category of rec
  250.         if item itemindex of the category of rec=whichcategory then
  251.           add templist,the appname of rec
  252.           set itemindex=the number of items in the category of rec+2
  253.         end if
  254.       end repeat
  255.     else
  256.       if whichcategory=defaultcatphrase then
  257.         add templist,the appname of rec
  258.       end if
  259.     end if
  260.   end repeat
  261.   repeat with recname in templist
  262.     set buffer=buffer&(recname)&return
  263.   end repeat
  264.   delete char(length(buffer)) of buffer
  265.   if demofield="" then
  266.     put buffer
  267.   else
  268.     set the textstyle of member demofield to "plain"
  269.     set the text of member demofield to buffer
  270.     set the textstyle of line 1 of member demofield to "bold"
  271.     getrecord me,line 1 of field demofield
  272.     showrecord me
  273.   end if
  274.   return buffer
  275. end  
  276.  
  277. on getCategories me
  278.   set buffer=""
  279.   set catlist=[]
  280.   add catlist,defaultcatphrase
  281.   repeat with recindex=1 to count(reslist)
  282.     set rec=getat(reslist,recindex)
  283.     repeat with index=1 to the number of items in the category of rec
  284.       if getpos(catlist,item index of the category of rec)=0 then
  285.         add catlist,item index of the category of rec
  286.       end if
  287.     end repeat
  288.   end repeat
  289.   repeat with index=1 to count(catlist)
  290.     set buffer=buffer&getat(catlist,index)&return
  291.   end repeat
  292.   delete char(length(buffer)) of buffer
  293.   if categoryfield="" then
  294.     put buffer
  295.   else
  296.     set the textstyle of member categoryfield to "plain"
  297.     set the text of member categoryfield to buffer
  298.   end if
  299.   return buffer
  300. end  
  301.  
  302. on describe me
  303.   put "ResourcesClass"
  304.   put "Resources Class,a Director Object for handling demo file access"
  305.   put "by Kurt Cagle, Imagine Publishing, copyright 1996"
  306. end
  307.  
  308. on updateSystemInfoList me
  309.   set systemlist=[:]
  310.   if the number of member "SystemInfoList"<1 then
  311.     set systemlist=[:]
  312.     set sysmember=findEmpty(member 1)
  313.     repeat with index=1 to the maxInteger
  314.       if the type of member index=#field then
  315.         duplicate member index, sysmember
  316.         exit repeat
  317.       end if
  318.     end repeat
  319.     set the name of member sysmember to "SystemInfoList"
  320.     set the text of member sysmember to  "[:]"
  321.   else
  322.     set sysmember=the number of member ("SystemInfoList")
  323.     set systemlist=value(the text of member sysmember)
  324.     if systemlist=0 then
  325.       set systemlist=[:]
  326.     end if
  327.   end if
  328.   set proplist=[:]
  329.   repeat with index=1 to count(me)
  330.     set prop=getpropat(me,index)
  331.     set entry=getprop(me,prop)
  332.     if voidP(entry) then set entry=0
  333.     addprop proplist,prop,entry
  334.   end repeat
  335.   if voidP(getaprop(systemlist,IDName)) then
  336.     addprop systemlist,IDName,proplist
  337.   else
  338.     setprop systemlist,IDName,proplist
  339.   end if
  340.   set the text of member sysmember to string(systemlist)  
  341. end
  342.  
  343. on launchURL me,URL
  344.   if browser<>#none then
  345.     puppetsound 0
  346.     puppetsound "PULSE0"&string(random(5))&".AIF"
  347.     if voidP(URL) then
  348.       if activerec=0 then
  349.         set URL=defaultprotocol&defaultURL
  350.       else
  351.         set URL=defaultprotocol&the URL of activerec
  352.       end if
  353.     end if
  354.     open browser&&URL
  355.     if the freeblock<500000 then
  356.       alert "There is insufficient memory to keep both the boot Disc and your browser open, so bootDisc will quit.  Double click on the bootDisc icon to relaunch."
  357.       halt
  358.     end if
  359.   else
  360.     alert "No browser has been defined for use."
  361.   end if
  362. end
  363.  
  364. on launchApp me
  365.   if activerec=0 then
  366.     alert("You must select an application to launch.")
  367.   end if
  368.   repeat with index=3 to 27
  369.     set drive=numtochar(64+index)
  370.     if fileExists(me,drive&":\bootcd\keylock.rsc") then
  371.       exit repeat
  372.     end if
  373.   end repeat
  374.   if drive=numtochar(91) then
  375.     alert("The bootCD was not found.  Please insert it into your disk drive to launch any applications.")
  376.     exit
  377.   end if
  378.   puppetsound 0
  379.   puppetsound "PULSE0"&string(random(5))&".AIF"
  380.   if the platform of activerec="DOS" then
  381.     set basepath="explorer.exe "&drive&":\bootcd\apps\"&(the appfolder of activerec)
  382.   else
  383.     set basepath=drive&":\bootcd\apps\"&(the appfolder of activerec)&"\"&(the exename of activerec)
  384.   end if
  385.   -- alert basepath
  386.   open basepath   
  387.   if the freeblock<500000 then
  388.     alert "There is insufficient memory to keep both the boot Disc and your browser open, so bootDisc will quit.  Double click on the bootDisc icon to relaunch."
  389.     halt
  390.   end if
  391.   
  392. end
  393.  
  394. on fileExists me,filename
  395.   set file=fileIO(mNew,"read",filename)
  396.   if objectP(file) then
  397.     file(mDispose)
  398.     return true
  399.   else
  400.     return false
  401.   end if
  402. end
  403.  
  404. on getBasePath me
  405.   if activerec=0 then
  406.     alert("You must select an application to launch.")
  407.   end if
  408.   repeat with index=3 to 27
  409.     set drive=numtochar(64+index)
  410.     if fileExists(me,drive&":\bootcd\keylock.rsc") then
  411.       exit repeat
  412.     end if
  413.   end repeat
  414.   if drive=numtochar(91) then
  415.     alert("The bootCD was not found.  Please insert it into your disk drive to launch any applications.")
  416.     exit
  417.   end if
  418.   set basepath=drive&":\bootcd\apps\"&(the appfolder of activerec)&"\"
  419.   return basepath
  420. end
  421.  
  422.  
  423. on cycle me
  424.   if activerec=0 then
  425.     getrecord me,line (the number of lines in field demofield) of field demofield
  426.   end if
  427.   set app=the appname of activerec
  428.   set curtext=the text of field demofield
  429.   repeat with index=1 to the number of lines in field demofield
  430.     set curline=line index of curtext
  431.     if app=curline then
  432.       set cycleIndex=index
  433.       exit repeat
  434.     end if
  435.   end repeat
  436.   if cycleindex=the number of lines in curtext then
  437.     set cycleindex=1
  438.   else
  439.     set cycleindex=cycleindex+1
  440.   end if
  441.   set app=line cycleindex of curtext
  442.   set the fontstyle of member demofield to "plain"
  443.   set the fontstyle of line cycleindex of field demofield to "bold"
  444.   getrecord me,app
  445.   showrecord me,app
  446.   showTitle me
  447.   set targetticks=the ticks+shortinterval
  448. end
  449.  
  450. on showrecord me
  451.   set rt=RETURN
  452.   puppetsound 0
  453.   puppetsound "LED0"&string(random(5))&".AIF"
  454.   if not IsCycling then showTitle me
  455.   set the fontstyle of member "Description" to "plain"
  456.   set the text of member "Description" to (the description of activerec)&rt&"System Requirements"&rt&(the system of activerec)&rt&"Special Instructions"&rt&(the instructions of activerec) 
  457.   showTitle me
  458.   global videoBtns
  459.   set the membernum of sprite imagesprite to the number of member (strip(me,the imagepath of activerec,".bmp"))
  460.   updateStage
  461.   playVideo videoBtns
  462.   setstate videoBtns,not(the dvpath of activerec="#none")
  463. end
  464.  
  465. on strip me,imagename,extension
  466.   set pos=offset(extension,imagename)
  467.   if pos>0 then
  468.     delete char pos to pos+length(extension)-1 of imagename
  469.   end if
  470.   -- alert(imagename)
  471.   return imagename
  472. end
  473.  
  474.  
  475. on startCycle me
  476.   if getpos(the actorlist,me)=0 then
  477.     add the actorlist me
  478.     set interval=shortinterval
  479.     set IsCycling=true
  480.   end if
  481. end
  482.  
  483. on stepframe me
  484.   if the ticks>targetticks then
  485.     cycle me
  486.   end if
  487. end stepframe me
  488.  
  489. on endCycle me
  490.   set pos=getpos(the actorlist,me)
  491.   if pos>0 then
  492.     deleteat the actorlist,pos
  493.   end if
  494.   set IsCycling=false
  495. end
  496.  
  497. on castsprite me,whichcast
  498.   set curcast=the number of member whichcast
  499.   set spritenum=0
  500.   if curcast>0 then
  501.     repeat with index=1 to 48
  502.       if the membernum of sprite index=curcast then
  503.         set spritenum=index
  504.         exit repeat
  505.       end if
  506.     end repeat
  507.   end if
  508.   return spritenum
  509. end
  510.  
  511. on hideTitle me
  512.   -- if the text of member "Title"=the appname of activerec then exit
  513.   -- exit
  514.   if spritelist=0 then
  515.     set spritelist=[]
  516.     add spritelist,castsprite(me,"Title")
  517.     add spritelist,castsprite(me,"TitleLight")
  518.     add spritelist,castsprite(me,"TitleDark")
  519.   end if
  520.   repeat with index=1 to count(spritelist)
  521.     set the visible of sprite getat(spritelist,index) to false
  522.   end repeat
  523. end
  524.  
  525. on showTitle me
  526.   -- if the text of member "Title"=the appname of activerec then exit
  527.   -- exit
  528.   if spritelist=0 then
  529.     set spritelist=[]
  530.     add spritelist,castsprite(me,"Title")
  531.     add spritelist,castsprite(me,"TitleLight")
  532.     add spritelist,castsprite(me,"TitleDark")
  533.   end if
  534.   repeat with index=1 to count(spritelist)
  535.     set the text of member (the membernum of sprite getat(spritelist,index)) to the appname of activerec
  536.   end repeat
  537.   repeat with index=1 to count(spritelist)
  538.     set the visible of sprite getat(spritelist,index) to true
  539.   end repeat
  540. end
  541.  
  542.  
  543. on getNextCategory me
  544.   hidetitle me
  545.   repeat while the frame<>label("doorsclosed")
  546.     go to the frame+1
  547.   end repeat
  548.   set whichcategory=line 1 of the text of member categoryfield
  549.   set pos=getpos(catlist,whichcategory)
  550.   set pos=pos+1
  551.   if pos>count(catlist) then
  552.     set pos=1
  553.   end if
  554.   set the text of member categoryfield to getat(catlist,pos)
  555.   getByCategory me,getat(catlist,pos)
  556.   set targetticks=the ticks+1*60
  557.   set activerec=0
  558.   global videobtns
  559.   setstate videobtns,false  
  560. end
  561.  
  562. on getPreviousCategory me
  563.   hidetitle me
  564.   repeat while the frame<>label("doorsclosed")
  565.     go to the frame+1
  566.   end repeat
  567.   set whichcategory=line 1 of the text of member categoryfield
  568.   set pos=getpos(catlist,whichcategory)
  569.   set pos=pos-1
  570.   if pos=0 then
  571.     set pos=count(catlist)
  572.   end if
  573.   set the text of member categoryfield to getat(catlist,pos)
  574.   getByCategory me,getat(catlist,pos)
  575.   set targetticks=the ticks+1*60
  576.   set activerec=0
  577.   global videobtns
  578.   setstate videobtns,false
  579. end
  580.  
  581. on dispose me
  582.   showtitle me
  583.   repeat with spritenum=1 to 48
  584.     set the visible of sprite spritenum to true
  585.   end repeat
  586. end
  587.