--LINKED SCRIPTS UTILITIES----------------------------------- -- * SHARED SCRIPT * --version .9b by Robert Walch --Last updated 12/13/2000 --create/validate files and directories --convert director and file xtra date and time strings to date Objects --add leading zeros to strings and numbers --create and synchronize linked lingo scripts --commenting scripts with key words --list all scripts --fill empty member spaces for sorting casts shared accross movies ------------------------------------------------------------------------------- --------Protection Masking code------- --on handlers(me) -- return [#handlers] --end --FILE HANDLERS--------------------------------------------------- -- updated 12/13/2000 RW on dirchar if ((the platform) contains "Mac") then return ":" else return "\" end if end ------------------------------------------------------------------------------- --FILEXTRA HANDLERS--------------------------------------------------- -- updated 12/13/2000 RW on getfiletext tempfile ftext = "" -- ** fileX = Xtra("FileXtra3").new() fileIO = xtra("fileIO").new() if fileExists(tempfile) = 0 then fileIO.openFile(tempfile, 1) --fileIO.setPosition(1)-- < --- 1 or 0???? ftext = fileIO.readFile() end if return ftext end -- updated 12/13/2000 RW on validatetextfile (dirpath, thefilename, thetext) dirpath = validatedirectory (dirpath) if (thefilename <> 0) then fileX = Xtra("FileXtra3").new() if fileX.fx_FileExists(thefilename) then --Fix for long file names on Mac----------------------------------------- --max number of chars in a mac filename are 31 MaxChar = 31 if thefilename.length > MaxChar then put "member" && thefilename & "'s name is too long." the itemdelimiter = "." if thefilename.item.count = 1 then thefilename = thefilename.char[1..MaxChar-1] & "~" --24 else theextension = thefilename.item[thefilename.item.count] thefilename = thefilename.char[1..(MaxChar-(theextension.length+2))] & "~" & "." & theextension --24 end if end if ------------------------------------------------------------------------- thefilepath = dirpath & thefilename else thefilepath = dirpath & thefilename end if -- ** Check if the file Exists -- fileIO = xtra("fileIO").new() -- if (thetext <> 0) then -- err = fileIO.createFile(thefilepath) -- if err then -- put "fileIO Error:" && err -- return err -- end if -- -------------------------- -- fileIO.openfile(thefilepath, 2) -- fileIO.writeString(thetext) -- fileIO.closefile() -- end if --fileIO = 0 return thefilepath end if end -- updated 12/13/2000 RW on validatedirectory dirpath dchar = dirchar() the itemdelimiter = dchar dircount = dirpath.item.count FileX = xtra("filextra3").new() repeat with x = 2 to dircount if (dirpath.item[x] <> "") then testpath = dirpath.item[1..x] & dchar if FileX.fx_FolderExists(testpath) = 0 then --Fix for long directory names on Mac --max number of chars in a mac filename are 31 --CreateDirectory wil return -17 if folder name is too long thefoldername = testpath.item[x] if thefoldername.length > 31 then put "the folder" && thefoldername & "'s name is too long." thefoldername = thefoldername.char[1..30] & "~" put thefoldername into dirpath.item[dircount] put thefoldername into testpath.item[dircount] end if --fx_FolderCreate err = FileX.fx_FolderCreate(testpath) if err < 0 then --fx_ErrorNumber --fx_ErrorString put FileX.fx_ErrorString() return err end if end if end if end repeat FileX = 0 return dirpath end ------------------------------------------------------------------------------- --DIALOGS---------------------------------------------------------------------- on getDirectoryDialog --put xtra("fileIO").new().displayOpen() fileIO = xtra("fileIO").new() thedirectory = fileIO.displaySave("go to the folder you want","save to choose") fileIO = 0 dchar = dirchar() the itemdelimiter = dchar return thedirectory.item[1..thedirectory.item.count-1] & dchar end -- updated 12/13/2000 RW on yesnodialog displaytext -- Returns 1 for Yes and 2 for No --put xtra("MUI").interface() muix = xtra("MUI").new() -- ** add a Say Yes (or No) to All button answer = muix.alert([#buttons:#YesNo,#default:1,#title:"replace script?",#message:displaytext,#icon:#question,#movable:1]) muix = 0 return answer end --DATES------------------------------------------------------------------------ on getsystemdateObj dateObj = convertAbbreviatedDate(the abbreviated date) dateObj.seconds = convertTimetoSeconds(the long time) return dateObj end on convertTimetoSeconds ttime--from (the long time) -- "3:34:19 PM" the itemdelimiter = ":" Hours = value(ttime.item[1]) if (ttime contains "AM") then if Hours = 12 then Hours = 0 end if else if (ttime contains "PM") and Hours <> 12 then Hours = Hours+12 end if if Hours = 24 then Hours = 0 end if HourSec = Hours * 3600 MinuteSec = value(ttime.item[2]) * 60 SecondSec = value(ttime.item[3].char[1..2]) tseconds = HourSec + MinuteSec + SecondSec return tseconds end on convertSecondstoTime tseconds return framesToHMS(tseconds, 1, 0, 0) end --This must be tested with different system clock setting on US & International systems on convertAbbreviatedDate tdate --from (the abbreviated date) --Tue, Oct 17, 2000 monthlist = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"] tyear = value(tdate.word[4])--filedate.word.count tmonth = findpos(monthlist,tdate.word[2]) tday = value(tdate.word[3]) dateObj = date( tyear, tmonth, tday ) return dateObj end on convertShortDate tdate --from (the abbreviated date) --10/17/2000 the itemdelimiter = "/" tmonth = value(tdate.item[1]) tday = value(tdate.item[2]) tyear = value(tdate.item[3]) dateObj = date( tyear, tmonth, tday ) return dateObj end on convertfiledate tdate --from file xtra date --Thu Aug 17 05:47:09 2000 monthlist = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"] tyear = value(tdate.word[5])--filedate.word.count tmonth = findpos(monthlist,tdate.word[2]) tday = value(tdate.word[3]) tseconds = convertTimetoSeconds(tdate.word[4]) dateObj = date( tyear, tmonth, tday ) dateObj.seconds = tseconds return dateObj end on convertdirdate dirdate --to file xtra date --Thu Aug 17 05:47:09 2000 monthlist = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"] ttime = getdateObjecttime(dirdate,1) filedate = "---" && monthlist[dirdate.month] && dirdate.day && ttime && dirdate.year return filedate end on getdateObjectshortdate dirdate,twocharyear --to short date US --10/17/2000 if twocharyear = 0 then tdate = dirdate.month & "/" & dirdate.day & "/" & dirdate.year else tdate = dirdate.month & "/" & dirdate.day & "/" & dirdate.year.char[3..4] end if return tdate end on getdateObjecttime dirdate,NoAMPM,Pseconds --to time US --05:47:09 2000 if Pseconds = 0 then dirseconds = dirdate.seconds else dirseconds = Pseconds end if Hours = dirseconds/3600 Minutes = (dirseconds mod 3600)/60 SecondsN = dirseconds mod 60 Minutes = leadingzeros(Minutes, 2) SecondsN = leadingzeros(SecondsN, 2) if Hours = 24 then Hours = 0 end if if Noampm = 0 then if Hours = 0 then ampm = "AM" Hours = 12 else if Hours < 12 then ampm = "AM" else ampm = "PM" if Hours <> 12 then Hours = Hours-12 end if end if ttime = leadingzeros(Hours, 2) & ":" & Minutes & ":" & SecondsN && ampm else ttime = leadingzeros(Hours, 2) & ":" & Minutes & ":" & SecondsN end if return ttime end on isnewer date1,date2--testing if date1 is newer daysapart = date1-date2 if daysapart = 0 then --same day. check time secondsapart = date1.seconds-date2.seconds if secondsapart = 0 then --Same Time return 0 else if secondsapart > 0 then --date1 seconds newer return 1 else --date1 seconds older return -1 end if else if daysapart > 0 then --date1 days newer return 1 else --date1 days older return -1 end if end --FORMAT TEXT------------------------------------------------------------------ on leadingzeros (numstring, totalchars)--,leadingcharacter numstring = string(numstring) charsneeded = totalchars-numstring.char.count if charsneeded > 0 then repeat with x = 1 to charsneeded numstring = "0" & numstring-- = leadingcharacter & numstring end repeat end if return numstring end --SCRIPTS--LINK---------------------------------------------------------------- --------LINK ALL SCRIPTS --To specify a directory use: --put makeallscriptslinked(getDirectoryDialog()) -- updated 12/14/2000 RW on linkallscripts (dir, dontUseShare) --don't Look for "SHARED SCRIPT" in script text -- if no directory is passed provide default directory if voidP(dir) then dir = the moviepath & "lingo" & dirchar() cstcount = the number of castlibs repeat with z = 1 to cstcount memcount = the number of members of castLib z repeat with x = 1 to memcount err = makescriptlinked(x, z, dir, dontUseShare) if err then return err end if end repeat end repeat return 0 end --------LINK A SCRIPT -- updated 12/14/2000 RW on makescriptlinked (membern, castlibn, dir, dontUseShare) dchar = dirchar() -- if no directory is passed provide default directory if voidP(dir) then dir = (the moviepath) & "lingo" & dchar -- accept member number if integerP(membern) then if castlibn = 0 then castlibn = 1 m=member(membern,castlibn) -- accept member name else if stringP(membern) then m=member(membern) castlibn=m.castlibnum -- accept member reference else if ilk(membern) = #member then m = membern -- report bad parameter else put "bad parameter: membern" return -1 end if if m.type=#script then st=m.scripttype if not m.linked then theScriptText = m.scripttext -- add comment to Script to identify author m.comments=convertdirdate(m.modifieddate) & RETURN & m.modifiedby -- Look for "SHARED SCRIPT" in script text if (theScriptText contains "SHARED SCRIPT") and (dontUseShare = 0) then -- If there save it in a special shared folder thefolderpath = getPref( "Shared_Script_Folder.txt" ) -- save a pref of the shared folder for later use -- hold down option to modify an existing pref if ((thefolderpath = 0) or (the optiondown)) then thefolderpath = getDirectoryDialog() if (thefolderpath <> "") then setPref( "Shared_Script_Folder" , thefolderpath ) else -- save in a folder named after the castlib name -- or moviename if the cast is "Internal" thefolderpath = dir & SubGetCastMovieName(castlibN) & dchar end if end if else -- save in a folder named after the castlib name -- or moviename if the cast is "Internal" thefolderpath = dir & SubGetCastMovieName(castlibN) & dchar end if tempfile = validatetextfile( thefolderpath , m.name & ".ls" , theScriptText ) --Method 1 -- m.filename=tempfile -- m.scripttype=st --Method 2 m.linkas(tempfile) else put "member" && m.name && "is already linked." end if end if return 0 end -- makescriptlinked() subroutine -- created 12/14/2000 on SubGetCastMovieName(castlibN) thefolderpath = castLib(castlibn).name if thefolderpath = "Internal" then the itemdelimiter="." thefolderpath = (the moviename).item[1] end if return thefolderpath end --------UNLINK on unlinkallscripts cstcount = the number of castlibs repeat with z = 1 to cstcount memcount = the number of members of castLib z repeat with x = 1 to memcount if member(x, z).type = #script then member(x, z).linked = 0 end if end repeat end repeat end --------MODIFIED on listmodifiedscripts cstcount = the number of castlibs repeat with z = 1 to cstcount memcount = the number of members of castLib z repeat with x = 1 to memcount if member(x,z).modified then put member(x,z).name end repeat end repeat end --------REVERT TO TEXT FILE on revertlinkedscriptstofile cstcount = the number of castlibs repeat with z = 1 to cstcount memcount = the number of members of castLib z repeat with x = 1 to memcount if member(x, z).type = #script then if member(x, z).linked then tempfile = member(x, z).filename member(x, z).linked = 0 member(x, z).filename = tempfile end if end if end repeat end repeat end --SCRIPTS--COMMENTS------------------------------------------------------------ on stripcomments memtype cstcount = the number of castlibs repeat with z = 1 to cstcount memcount = the number of members of castLib z if voidP(memtype) then repeat with x = 1 to memcount member(x,z).comments = "" end repeat else repeat with x = 1 to memcount if memtype = member(x,z).type then member(x,z).comments = "" end if end repeat end if end repeat end on addscriptcomment containstxt,commenttxt cstcount = the number of castlibs repeat with z = 1 to cstcount memcount = the number of members of castLib z repeat with x = 1 to memcount mem = member(x,z) if mem.type = #script then if (mem.scripttext contains containstxt) and not (mem.comments contains commenttxt)then mem.comments = mem.comments & commenttxt & " "--append end if end if end repeat end repeat end on listscriptcomments --sort scripts by comment clist = [:] clist.sort() cstcount = the number of castlibs repeat with z = 1 to cstcount memcount = the number of members of castLib z repeat with x = 1 to memcount mem = member(x,z) if mem.type = #script then clist.addprop(mem.comments & TAB & castlib(z).name && mem.membernum,mem.name) end if end repeat end repeat --list scripts by name sorted by comment clistcount = clist.count cstring = "" repeat with x = 1 to clistcount n = clist.getat(x)--name m = clist.getpropat(x)--comment repeat while n.char.count < 40 n = n & SPACE end repeat cstring = cstring & n & TAB & m & RETURN end repeat tempfile = getRootPath() & dirchar() & "ScriptList.txt" writetofile(tempfile,cstring,1) put cstring end on commentourscripts stripcomments #script--careful --Events addscriptcomment "on mouse","Mouse_Event" --Custom addscriptcomment "--obsolete","Obsolete" addscriptcomment "draw", "DRAW" addscriptcomment "SHADOW", "SHADOW" addscriptcomment "ancestor", "ancestor" addscriptcomment "Object", "Object" --Berlitz addscriptcomment "score", "Score" addscriptcomment "correct", "Score_Track" addscriptcomment "points", "Score_Track" addscriptcomment "Jump","Jump_Nav" addscriptcomment "branch","Jump_Nav" addscriptcomment "SRI","SRI_Xtra" addscriptcomment "SRI_StateChange","SRI_StateChange" addscriptcomment "RCNavOK","Speech_Nav" addscriptcomment "startintrecognize","Speech_Nav" addscriptcomment "intstartrec","Speech_Nav" addscriptcomment "intrecognize","Speech_Nav" listscriptcomments end --SCRIPTS--SEARCH-------------------------------------------------------------- on FindScriptsWith containstxt cstcount = the number of castlibs cstring = "" repeat with z = 1 to cstcount memcount = the number of members of castLib z repeat with x = 1 to memcount mem = member( x , z ) if mem.type = #script then stext = mem.scripttext if ( stext contains containstxt ) then cstring = cstring & "Script :" && mem.name & RETURN cstring = cstring & "Handlers :" && mem.script.handlers() & RETURN varnhandlist = [] wordcount = stext.word.count repeat with n = 1 to wordcount theword = stext.word[n] if ( theword contains containstxt ) then if varnhandlist.findpos( theword ) = 0 then varnhandlist.add( theword ) cstring = cstring && theword & RETURN end if end if end repeat cstring = cstring & RETURN end if end if end repeat end repeat -- tempfile = getRootPath( ) & dirchar( ) & "Scriptswith_" & containstxt & ".txt" -- writetofile( tempfile , cstring , 1 ) return cstring end --MEMBER--FIND LINK DIR MEMBERS------------------------------------------------ on findlinkedfrom dirtext cstcount = the number of castlibs repeat with z = 1 to cstcount memcount = the number of members of castLib z repeat with x = 1 to memcount if (member(x,z).filename contains dirtext) then put "member" && member(x,z).name && member(x,z).membernum && "of castlib" && castlib(z).anme end if end repeat end repeat end --MEMBER--FILL EMPTY CAST------------------------------------------------------ on fillemptyMembers whichCast namelist = [] repeat with x = 1 to the number of members of castLib whichCast themem = member(x,whichCast) if themem.type = #empty then tempmem = new(#field,castlib whichCast) tempmem.name = "_empty_member" && x && "of" && whichCast else if themem.name = "" then themem.name = "member" && x && "of" && whichCast end if end if if namelist.findpos(themem.name) then themem.name = themem.name && x put "name dup" && themem.name end if namelist.add(themem.name) end repeat end on clearemptyMembers whichCast repeat with x = 1 to the number of members of castLib whichCast themem = member(x,whichCast) if (themem.name contains "_empty_member") then themem.erase() end if end repeat end --------------------------------------------------------- on listScriptXtras () nc = the number of xtras repeat with n = 1 to nc put xtra(n).name end repeat end