-- @Version: 2.0.1 -- @Author Luke Wigley -- @Description -- Function to trawl through all your scripts looking for occurances -- of 'global functions' that require an Xtra, as well as all 'named' Xtras --@ History -- 2.0.1 Added check for the moviename to force the re-scan if you change movies -- -- @Notes -- To find unnamed Xtras (eg BuddyAPI which provides 'global functions' and -- does not need to be instantiated), this script relies on a Director quirk -- which puts a string representation of the Xtra providing the global -- functions when you attempt to 'put' the function into a variable. Therefore, -- the script will not be able to find any attempts to call a missing Xtra -- To find 'named' xtras (ie xtras that are instantiated - eg FileXtra), -- this script simply looks for the 'xtra' keyword followed by optional -- parenthesis, and then the name in quotes. Therefore, it will not find -- xtras instantiated by using a variable name such as obj = xtra(myvar).new() -- Also note, when looking for 'used' Xtras, this script will try and -- ignored any commented out lingo. However, when looking for named -- xtras, it will also look in comments -- @Requires xtra "PregEx" from OpenXtras.org --- STATIC SCRIPT PROPERTIES -------------------------------------- property FoundXtras, WhoUsesFoundXtras, IgnoreWordList, CurrentMovie --- GLOBAL FUNCTIONS -------------------------------------- on GetUsedXtras() -- returns a list of all the Xtras the current movie appears to use. this = script("FlightChecker.Xtraslib") put "Scanning... this may take a few moments..." --tell the stage if voidP(this.FoundXtras) then this.__ScanForXtraFunctions() else if this.CurrentMovie <> (the moviePath & the movieName) then this.__ScanForXtraFunctions() -- end tell return this.FoundXtras end on WhoUsesXtra(xtraName) -- returns a list of all the scripts that appear to use the named Xtra this = script("FlightChecker.Xtraslib") put "Scanning... this may take a few moments..." --tell the stage if voidP(this.FoundXtras) then this.__ScanForXtraFunctions() else if this.CurrentMovie <> (the moviePath & the movieName) then this.__ScanForXtraFunctions() --end tell return this.WhoUsesFoundXtras[xtraName] end --- PRIVATE METHODS ----------------------------------------------- on __ScanForXtraFunctions (this) this.CurrentMovie = (the moviePath & the movieName) this.IgnoreWordList = [#and, #case, #char, #contains, #else, #field, #if, #item, #line, #member, #mod, #not, #on, #or, #repeat, #script, #sprite, #starts, #the, #then, #to, #with, #word] XtrasBeingUsed = [] WhoIsUsingThem = [:] repeat with c = 1 to the number of castlibs repeat with n = 1 to the number of members of castlib c if member(n,c).type = #script then this.__FindXtrasBeingUsed(member(n,c), XtrasBeingUsed, whoIsUsingThem) -- find xtras by seeing if any of their 'global functions' are being used this.__FindXtrasByName(member(n,c), XtrasBeingUsed, whoIsUsingThem) -- find if any instantiated xtras are used by looking for the Xtra keyword end if end repeat end repeat this.FoundXtras = XtrasBeingUsed this.WhoUsesFoundXtras = WhoIsUsingThem end on __FindXtrasBeingUsed(this, memberRef, XtrasBeingUsed, whoIsUsingThem) whatScriptLong = (memberRef) -- "script (" & QUOTE & memberRef.name"E & ") "& memberRef scriptToSearch = memberRef.scriptText statements = PRegEx_Split([scriptToSearch], "(?:--[^\n]*)|\n", "gm") -- get everything before comments or end of line statements = PRegEx_Grep(statements, #length) -- remove the empties repeat with aStatement in statements bits = PRegEx_Split([aStatement],"\""E&"[^\""E&"]*\""E&"" , "g") -- remove stuff inside quotes repeat with bit in bits wrds = PRegEx_Split([bit], "\W+", "g") -- break into words wrds = PRegEx_Grep(wrds, #length) -- remove the empties repeat with wrd in wrds if this.IgnoreWordList.getOne(symbol(wrd)) then next repeat t = void -- put wrd do "put " & wrd & " into t" -- do ("t = " & wrd) ts = string(t) if length(ts) > 0 then if (PRegEx_Search([ts], " 0) then whatXtra = string(symbol(PRegEx_GetMatchString(1))) -- put wrd & " = " & whatXtra if not(XtrasBeingUsed.getOne(whatXtra)) then XtrasBeingUsed.append(whatXtra) if voidP(whoIsUsingThem.getAProp(whatXtra)) then whoIsUsingThem.addProp(whatXtra, []) if not(whoIsUsingThem[whatXtra].getOne(memberRef)) then whoIsUsingThem[whatXtra].append(memberRef) end if end if end repeat end repeat end repeat end on __FindXtrasByName (this, memberRef, XtrasBeingUsed, whoIsUsingThem) whatScriptLong = (memberRef) -- "script (" & QUOTE & memberRef.name"E & ") "& memberRef if (PRegEx_SearchBegin([memberRef.scriptText], "\bxtra\b(?:[ \(]*?)""E&"([^\r\n]+?)\""E, "gi") > 0) then repeat while (PRegEx_SearchContinue() > 0) whatXtra = PRegEx_GetMatchString(1) if stringP(whatXtra) then whatXtra = string(symbol(whatXtra)) -- a trick to keep all the names in the same 'case' if not(XtrasBeingUsed.getOne(whatXtra)) then XtrasBeingUsed.append(whatXtra) if voidP(whoIsUsingThem.getAProp(whatXtra)) then whoIsUsingThem.addProp(whatXtra, []) if not(whoIsUsingThem[whatXtra].getOne(memberRef)) then whoIsUsingThem[whatXtra].append(memberRef) end if end repeat end if end