Stewie410

padAnimationArgs

Apr 20th, 2018
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 5.44 KB | None | 0 0
  1. :: Pad Animation
  2. :: Author:      Stewie410 <[email protected]>
  3. :: Client:      user/kevin5609
  4. :: Desc:        Take any given animation with individual frames in a directory, and pad it out.
  5. ::              Each frame must have the same base name and extension
  6. ::              Now including CMD args, see :showHelp for more information
  7. :: Date:        2018-04-21
  8. :: Env:         Windows 7 x64 Professional
  9. :: Tested:      Win7x64 Pro
  10. ::              Win10x64 Pro
  11.  
  12. @echo off
  13. setlocal enableextensions
  14. set me=%~nx0
  15. set medir=%~dp0
  16.  
  17. :: ----------------------------------------- ::
  18. :: --       User Defined Vars             -- ::
  19. :: ----------------------------------------- ::
  20. :: Note: All path and name definitions are CASE-SENSITIVE
  21. :: Define the full path to your animation
  22. set pathToAnimation=%userprofile%\Desktop\Animation
  23.  
  24. :: Define the baseline name for your animation's files, eg back-button
  25. set animationBaselineName=menu-back
  26.  
  27. :: Define the type file, eg png
  28. set filetype=png
  29.  
  30. :: Define the number of frames to start with (count starts at 0, eg 0-16 == 17 frames)
  31. :: Ignore the non-numbered files
  32. set initialFileCount=20
  33.  
  34. :: Define the frame number to start counting at
  35. :: Example:     If you have 20 frames (file-name-0 to file-name-19), but you want to
  36. ::              start at the fifth frame, set startCountingAt=4
  37. set startCountingAt=0
  38.  
  39. :: Define the padding offset
  40. :: If you want 2x as many frames, paddingOffset==2
  41. set paddingOffset=2
  42. :: ----------------------------------------- ::
  43. :: --       End User Defined Vars         -- ::
  44. :: ----------------------------------------- ::
  45.  
  46. :: Argument Processing
  47. :argLoop
  48.     if not "%~1."=="." (
  49.         if /i "%~1"=="/f" if not "%~2."=="." set animationBaselineName=%~2
  50.         if /i "%~1"=="/t" if not "%~2."=="." set filetype=%~2
  51.         if /i "%~1"=="/d" if not "%~2."=="." set pathToAnimation=%~2
  52.         if /i "%~1"=="/n" if not "%~2."=="." set initialFileCount=%~2
  53.         if /i "%~1"=="/p" if not "%~2."=="." set paddingOffset=%~2
  54.         if /i "%~1"=="/h" set showHelp=1
  55.         if /i "%~1"=="/?" set showHelp=1
  56.         shift
  57.     goto :argLoop
  58.     )
  59. if defined showHelp goto :showHelp 
  60.    
  61. :: Other vars
  62. set hd=@2x
  63. set dir=%pathToAnimation:"=%
  64. set name=%animationBaselineName:"=%
  65. set ext=%filetype:"=%
  66. if "%ext:~0,1%"=="." set ext=%ext:~1%
  67. set /a "endCount=initialFileCount*paddingOffset"
  68. set /a "endCount=endCount-2"
  69. :: --
  70.  
  71. :: Run
  72. :: Error handles
  73. if "%paddingOffset%" leq "1" goto :eof
  74. if not exist "%pathToAnimation%" goto :eof
  75.  
  76. :: Space the files out
  77. cd "%pathToAnimation%"
  78. set cnt=%initialFileCount%
  79. :spaceLoop
  80.     if %cnt% gtr %startCountingAt% (
  81.         call :space %cnt%
  82.         set /a "cnt-=1"
  83.         goto :spaceLoop
  84.     )
  85.  
  86. :: Pad each frame
  87. set cnt=%startCountingAt%
  88. :padLoop
  89.     if %cnt% leq %endCount% (
  90.         call :dupe %cnt%
  91.         set /a "cnt=cnt+1"
  92.         goto :padLoop
  93.     )
  94.    
  95. :: Exit
  96. cd "%medir%"
  97. goto :eof
  98.  
  99. :: Subs
  100. :: Space out the frames based on the paddingOffset variable
  101. :space
  102.     if "%~1."=="." goto :eof
  103.     if %~1 leq 0 goto :eof
  104.     if %~1 gtr %initialFileCount% goto :eof
  105.    
  106.     if defined i set "i="
  107.     if defined o set "o="
  108.     set i=%~1
  109.     set /a "o=i*paddingOffset"
  110.    
  111.     if exist "%name%-%i%.%ext%" ren "%name%-%i%.%ext%" "%name%-%o%.%ext%"
  112.     if exist "%name%-%i%@2x.%ext%" ren "%name%-%i%@2x.%ext%" "%name%-%o%@2x.%ext%"
  113. goto :eof
  114.  
  115. :: Duplicate the files to make up the now empty space in the animation
  116. :dupe
  117.     if "%~1."=="." goto :eof
  118.     if %~1 lss 0 goto :eof
  119.     if %~1 gtr %endCount% goto :eof
  120.    
  121.     if defined i set "i="
  122.     if defined o set "o="
  123.     set i=%~1
  124.     set /a "o=i+1"
  125.    
  126.     if not exist "%name%-%i%.%ext%" if exist "%name%-%i%@2x.%ext%" goto :hd
  127.    
  128.     if not exist "%name%-%i%.%ext%" goto :eof
  129.     if exist "%name%-%o%.%ext%" goto :eof
  130.     copy /y "%name%-%i%.%ext%" "%name%-%o%.%ext%"
  131.    
  132.     :hd
  133.     if not exist "%name%-%i%@2x.%ext%" goto :eof
  134.     if exist "%name%-%o%@2x.%ext%" goto :eof
  135.     copy /y "%name%-%i%@2x.%ext%" "%name%-%o%@2x.%ext%"
  136. goto :eof
  137.  
  138. :remOuterQuotes
  139.     if "%~1."=="." goto :eof
  140.     set tmp=###%1###
  141.     set tmp=%tmp:###"=%
  142.     set tmp=%tmp:"###=%
  143.     set tmp=%tmp:###=%
  144. goto :eof
  145.  
  146. :showHelp
  147. echo padAnimation [/f name][/t type][/d path][/n int][/p int][/h][/?]
  148. echo.
  149. echo padAnimation aims to increase the length of a simple animation by duplicating each frame.
  150. echo This assumes that each frame is a separate file, and each frame shares a similar naming scheme:
  151. echo.
  152. echo    %animationBaselineName%-0.ext
  153. echo    %animationBaselineName%-1.ext
  154. echo    %animationBaselineName%-2.ext
  155. echo    [...]
  156. echo.
  157. echo This script was initially written to increase the animation length for skin animations within osu!
  158. echo As such, it will also look for and attempt to duplicate files with an "@2x" suffix.
  159. echo.
  160. echo.
  161. echo /f name        Define the name to be used in the given file.
  162. echo            Filename must be encapsulated in double-quotes if any non-alphanumeric characters are used
  163. echo            eg:     filename
  164. echo                    "%animationBaselineName%"
  165. echo.      
  166. if "%filetype:~0,1%"=="." set filetype=%filetype:~1%
  167. echo /t type        Define the filetype of each frame
  168. echo            Filetype must be encapsulated in double-quotes if a leading period (.) is included
  169. echo            eg:     %filetype%
  170. echo                    ".%filetype%"
  171. echo.
  172. echo /d path        Define the full path to your animation.
  173. echo            eg:     %pathToAnimation%
  174. echo.
  175. echo /n int         Define the initial count of frames, where the count starts at zero (0)
  176. echo.
  177. echo /p int         Define the number of offset for padding.
  178. echo            If you want duplicate each frame once, your offset will be 2.
  179. echo            eg:     in  = 10    (frame-0 to frame-9)
  180. echo                    out = 20    (frame-0 to frame-19)
  181. echo                    p   = 2
  182. echo.
  183. echo /h?        Display this help information
  184. goto :eof
Advertisement
Add Comment
Please, Sign In to add comment