Changeset 215 for trunk/lingosource/castlib1/alexUtilities.ls
- Timestamp:
- 12/15/08 13:00:15 (3 years ago)
- File:
-
- 1 edited
-
trunk/lingosource/castlib1/alexUtilities.ls (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lingosource/castlib1/alexUtilities.ls
r202 r215 1 -- Some of my Authoring Utility Handlers -- ©06 Alex da Franca -- alex@farbflash.de 2 ----------------------------------------------------------------------------------- 1 -- alexUtilities 2 ----------------------------------- 3 -- CREATED: 4 -- 14.12.2008 5 -- PROPERTIES: 6 --!memberProperties: [#name: "alexUtilities", #scripttype: #parent, #scriptSyntax: #lingo, #comments: "~/Documents/Scripts/lingo/commonMovieScript.ls"] 7 -- 8 -- DESCRIPTION: 9 -- Some of my Authoring Utility Handlers -- c06 Alex da Franca -- alex@farbflash.de 10 -- 11 -- REQUIRES: 12 -- script "PseudoXMLPS" -> parse xml 13 -- although it does not really REQUIRE shell xtra and buddyApi xtra 14 -- still much of the functionality will gracefully fail, if those are not present 15 -- In order to export images, the sharp image exporter is required 16 -- if missing those functions fail gracefully 17 -- 18 -- USAGE: 19 -- This script is instantiated and used in the "tell the stage" block and one of the functions 20 -- which are defined in script "OSCmenu_Utilities" and which was selected by the user 21 -- will be executed in "stage scope". That means, that references are made form within the stage context 22 -- e.g. member("foo") will refer to a member in one of the stages castlibs 23 -- sprite(x) will refere to sprite(x) in the stages score and so on 24 -- 25 -- Please see the descriptions of many of those handlers at: http://www.farbflash.org/trac/HandlerMenu/wiki/utilityHandlers 26 -- (Although I started to comment each handler, I didn't reach far until now...) 27 ----------------------------------- 3 28 4 29 property ancestor … … 14 39 on new me 15 40 ancestor = new(script "PseudoXMLPS") -- we need this script later 16 -- and as we may already be in the scope of the stage, we have it as ancestor17 41 -- and as we may already be in the scope of the stage, we use it as ancestor 42 -- because once in another scope, it will not be available as member 18 43 return me 19 44 end … … 24 49 25 50 on Authoring_ExchangeScriptListColorsToRGBs me 51 ----------------------------------- 52 -- ACTION: fix the score data which has #color instead of #rgb when authored with D10 53 -- which fails with the older player (AUTHORING ONLY!) 54 -- INPUT: - 55 -- RETURNS: - 56 ----------------------------------- 57 26 58 theLastFrame = the lastFrame 27 59 theLastChannel = the lastChannel … … 62 94 63 95 on mOpenContainingFolder me 96 ----------------------------------- 97 -- ACTION: Open the folder, where the current movie is inside in the Finder/Explorer 98 -- INPUT: - 99 -- RETURNS: - 100 ----------------------------------- 101 64 102 if length(the moviepath) < 1 then 65 103 alert "The movie must be saved first!" … … 78 116 79 117 on mReadXML_2_List me, pfad 118 ----------------------------------- 119 -- ACTION: Read xml text from file and parse into lingo list using pseudoXMLPS script 120 -- INPUT: <pfad> ; string ; full pathname ; optional => default "" => show file selection dialog 121 -- RETURNS: lingo list or property list ; [:] in case of invalid xml file 122 ----------------------------------- 123 80 124 theResult = [:] 81 125 dertext = mGetTextFromFile(me, pfad) … … 91 135 92 136 on mSaveList_2_XML me, theList, thePath 137 ----------------------------------- 138 -- ACTION: Convert a lingo list or property list to xml and write xml string to file 139 -- INPUT: <theList> ; #list or #proplist ; required 140 -- <thePath> ; string ; full pathname ; optional => default "" => show file save dialog 141 -- RETURNS: string => full pathname of newly created file or "", if user cancelled process 142 ----------------------------------- 143 93 144 if not(list(theList)) then 94 145 global gRetVal … … 111 162 112 163 on mGetTextFromFile me, pfad 164 ----------------------------------- 165 -- ACTION: Read contents of textfile 166 -- INPUT: <pfad> ; string ; full pathname ; optional => default "" => show file selection dialog 167 -- RETURNS: string => contents of textfile or "", if user cancelled process 168 ----------------------------------- 169 113 170 retval = "" 114 171 … … 141 198 142 199 on mSaveToTextFile me, theText, pfad, theTitle, theDefaultName, startfolder 200 ----------------------------------- 201 -- ACTION: Save text to textfile 202 -- INPUT: <theText> ; string ; string to save 203 -- <pfad> ; string ; full pathname ; optional => default "" => show file save dialog 204 -- <theTitle> ; string ; caption of the save dialog (if any => pfad == "") 205 -- <theDefaultName> ; string ; default filename provided in the save dialog (if any => pfad == "") 206 -- <startfolder> ; string ; startfolder of the save dialog (if any => pfad == "") 207 -- RETURNS: string => full pathname of newly created file or "", if user cancelled process 208 ----------------------------------- 209 210 143 211 retval = 0 144 212 … … 215 283 216 284 on mSaveTextToTempFile me, theText, pfad 285 ----------------------------------- 286 -- ACTION: Write text out to a temporary file 287 -- (helper for the bbdiff and svn handler) 288 -- INPUT: <theText> ; string ; string to save 289 -- <pfad> ; string ; full pathname ; optional => default "tmpfile.txt" in temporary files folder 290 -- RETURNS: string => full pathname of newly created file or "", if user cancelled process 291 ----------------------------------- 217 292 218 293 pfad = string(pfad) … … 231 306 232 307 on mAppendTextToFile me, theText, pfad 308 ----------------------------------- 309 -- ACTION: Write text out to a temporary file 310 -- (helper for the bbdiff and svn handler) 311 -- INPUT: <theText> ; string ; string to append to file <pfad> 312 -- <pfad> ; string ; full pathname ; optional => default "" => show file selection dialog 313 -- RETURNS: string => full pathname of newly created file or "", if user cancelled process 314 ----------------------------------- 315 233 316 retval = 0 234 317 … … 312 395 313 396 if length(theType) < 1 then 314 if offset(".", theDefaultName) > 1 then 315 theType = theDefaultName.char[offset(".", theDefaultName) + 1 .. length(theDefaultName)] 397 splitpath = mSplitPath(me, theDefaultName) 398 -- if offset(".", theDefaultName) > 1 then 399 -- theType = theDefaultName.char[offset(".", theDefaultName) + 1 .. length(theDefaultName)] 400 -- end if 401 if length(splitpath[#extension]) > 0 then 402 theType = splitpath[#extension] 403 delete char 1 of theType 316 404 end if 317 405 forceType = 0 … … 359 447 len = length(pfad) 360 448 if len < 1 then exit 361 basename = pfad 362 ext = "" 363 repeat with n = len down to 1 364 c = char n of pfad 365 if c = "." then exit repeat 366 put c before ext 367 if length(ext) > 4 then exit repeat 368 end repeat 369 if ["txt", "rtf", "htm", "html"].getPos(ext) > 0 then theType = ext 449 -- basename = pfad 450 -- ext = "" 451 -- repeat with n = len down to 1 452 -- c = char n of pfad 453 -- if c = "." then exit repeat 454 -- put c before ext 455 -- if length(ext) > 4 then exit repeat 456 -- end repeat 457 -- if ["txt", "rtf", "htm", "html"].getPos(ext) > 0 then theType = ext 458 splitpath = mSplitPath(me, pfad) 459 ext = splitpath[#extension] 460 if length(ext) > 0 then 461 if ".txt.rtf.htm.html" contains ext then 462 delete char 1 of ext 463 theType = ext 464 end if 465 end if 370 466 end if 371 467 … … 630 726 if (not(mac) and (theType = "pct")) then theType = "bmp" 631 727 632 theDot = offset(".", thePath) 633 if theDot then thePath = thePath.char[1 .. (theDot - 1)] 728 -- theDot = offset(".", thePath) 729 -- if theDot then thePath = thePath.char[1 .. (theDot - 1)] 730 splitpath = mSplitPath(me, thePath) 731 thePath = splitpath[#basedir] & splitpath[#basename] 634 732 635 733 if not(["jpg", "png", "bmp", "pct"].getPos(theType)) then exit … … 755 853 if (not(mac) and (theType = "pct")) then theType = "bmp" 756 854 757 -- ensure the right file extension: 758 theDot = offset(".", thePath) 759 if theDot = 0 then thePath = thePath&"."&theType 855 -- -- ensure the right file extension: 856 857 -- theDot = offset(".", thePath) 858 -- if theDot = 0 then thePath = thePath&"."&theType 859 860 splitpath = mSplitPath(me, thePath) 861 if length(splitpath[#extension]) < 1 then splitpath[#extension] = "." & theType 862 thePath = splitpath[#basedir] & splitpath[#basename] & splitpath[#extension] 863 760 864 -- else thePath = thePath.char[1 .. theDot]&theType 761 865 … … 2137 2241 mp = the moviepath 2138 2242 delim = the last char of mp 2139 od = the itemdelimiter 2140 the itemdelimiter = delim 2141 fname = the last item of pfad 2142 the itemdelimiter = od 2143 len = fname.length 2144 if fname.char[len - 3] = "." then 2145 fnameW = fname.char[1 .. len - 4] 2146 ext = fname.char[len - 2 .. len] 2147 else if fname.char[len - 4] = "." then 2148 fnameW = fname.char[1 .. len - 5] 2149 ext = fname.char[len - 3 .. len] 2150 else 2151 fnameW = fname 2152 ext = "" 2153 end if 2243 -- od = the itemdelimiter 2244 -- the itemdelimiter = delim 2245 -- fname = the last item of pfad 2246 -- the itemdelimiter = od 2247 -- len = fname.length 2248 -- if fname.char[len - 3] = "." then 2249 -- fnameW = fname.char[1 .. len - 4] 2250 -- ext = fname.char[len - 2 .. len] 2251 -- else if fname.char[len - 4] = "." then 2252 -- fnameW = fname.char[1 .. len - 5] 2253 -- ext = fname.char[len - 3 .. len] 2254 -- else 2255 -- fnameW = fname 2256 -- ext = "" 2257 -- end if 2258 splitpath = mSplitPath(me, pfad) 2259 fnameW = splitpath[#basename] 2260 ext = splitpath[#extension] 2261 fname = fnameW & ext 2262 if length(ext) > 0 then delete char 1 of ext 2154 2263 2155 2264 -- in case of field we always use the plain text: … … 2586 2695 RETURN & " -- CREATED:"&\ 2587 2696 RETURN & " -- <currentDate>"&\ 2697 RETURN & " -- PROPERTIES:"&\ 2698 RETURN & " --!memberProperties: [#name: ""E&"<scriptname>""E&", #scripttype: #<scripttype>, #scriptSyntax: #<scriptSyntax>, #comments: ""E&"<comments>""E&"]"&\ 2588 2699 RETURN & " --"&\ 2589 2700 RETURN & " -- DESCRIPTION:"&\ … … 2592 2703 RETURN & " -- REQUIRES:"&\ 2593 2704 RETURN & " -- (Prerequisites)"&\ 2594 RETURN & " --"&\2705 RETURN & " --"&\ 2595 2706 RETURN & " -- USAGE:"&\ 2596 2707 RETURN & " -- -"&\ … … 2662 2773 --------------------------------- for the current scriptname, which we only "know" here in this script 2663 2774 if replacePlaceHolder = 1 then 2664 placeholders = [["<currentDate>", the short date], ["<scriptname>", theMem.name] ]2775 placeholders = [["<currentDate>", the short date], ["<scriptname>", theMem.name], ["<scripttype>", theMem.scripttype], ["<scriptSyntax>", theMem.scriptSyntax], ["<comments>", theMem.comments]] 2665 2776 2666 2777 repeat with repl in placeholders … … 2901 3012 end 2902 3013 -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 3014 3015 -- the following handlers are mostly duplicates from the script "commonMovieScript", 3016 -- because we are running in the scope of the stage here, we can not use it directly 3017 -- and therefore this script shall be completely self contained. 2903 3018 2904 3019 -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx … … 3038 3153 return memref.type 3039 3154 end 3155 3156 -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 3157 3158 -- split a path into its three elements => base directory, basename and extension: 3159 3160 on mSplitPath me, fname, delim -- delim optional: default = the systems pathdelimiter 3161 3162 olddelim = the itemdelimiter 3163 delim = string(delim) 3164 if length(delim) < 1 then 3165 delim = the last char of the moviepath 3166 if length(delim) < 1 then 3167 3168 if the runmode contains "plug" then 3169 delim = "/" 3170 else 3171 delim = the last char of the applicationpath 3172 end if 3173 3174 3175 if length(delim) < 1 then delim = "/" 3176 end if 3177 end if 3178 the itemdelimiter = delim 3179 dateiname = the last item of fname 3180 delete the last item of fname 3181 put delim after fname 3182 the itemdelimiter = olddelim 3183 3184 3185 len = length(dateiname) 3186 ext = "" 3187 until = max(1, len-8) -- let's pretend, that a file extension is not langer than 8 chars 3188 3189 repeat with n = len down to until 3190 this = dateiname.char[n] 3191 put this before ext 3192 delete char n of dateiname 3193 if this = "." then exit repeat 3194 end repeat 3195 3196 if char 1 of ext <> "." then -- no extension 3197 put ext after dateiname 3198 ext = "" 3199 end if 3200 3201 return [#basedir:fname, #basename:dateiname, #extension:ext] 3202 3203 end
Note: See TracChangeset
for help on using the changeset viewer.
