Advertisement
IcarusLives

canvas, showCanvas, saveCanvas, updateCanvas functions

Feb 18th, 2017
1,167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.25 KB | None | 0 0
  1. :canvas
  2.         if "%~2" neq "" ( set /a "width=%~1 - 1", "height=%~2 - 1" ) else ( goto :eof )
  3.         call:cursorpos 2>nul
  4.         if "%~3" neq "" ( set "canvasChar=%~3" ) else ( set "canvasChar=#" )
  5.         if "%~4" neq "" ( set "title=%~4" ) else ( set "title=CANVAS" )
  6.         if "%~7" neq "" ( if /i "%~5" equ "/c" (
  7.                 set "CAM=/c"
  8.                 set /a "CAM_Y=0", "CAM_X=0", "maxX=%~6", "winMaxY=%~7","cols=maxX + 5", "rows=winMaxY + 5"
  9.                 if not defined outerBuffer ( for /l %%a in (-1,1,!maxX!) do (
  10.                     set "outerBuffer=!outerBuffer!%canvasChar%") )
  11.                 if !maxX!    geq %width%  set /a "maxX=width"
  12.                 if !winMaxY! geq %height% set /a "winMaxY=height"
  13.             )
  14.         ) else (
  15.             set /a "cols=width + 5", "rows=height + 5"
  16.             if not defined outerBuffer ( for /l %%a in (-2,1,%width%) do (
  17.                 set "outerBuffer=!outerBuffer!%canvasChar%") )
  18.         )
  19.         for /l %%a in (0,1,%width%)  do set "widthBuffer=!widthBuffer! "
  20.         call:updateCanvas
  21.         if exist "%temp%\cursorpos.exe" (
  22.             set "cls="%temp%\cursorpos.exe" 0 1" ) else ( set "cls=cls" )
  23.         mode con: cols=%cols% lines=%rows%
  24.         title %title%
  25.     goto :eof
  26.    
  27.     :saveCanvas
  28.         if "%~2" neq "" ( if /i "%~1" equ "/f" (
  29.                 if exist "%tmp%\Canvas_%~2.txt" ( del /f /q "%tmp%\Canvas_%~2.txt" 2>nul )
  30.                 for /l %%a in (0,1,%height%) do ( echo="!_[%%a]!">>"%tmp%\Canvas_%~2.txt")
  31.                 <nul set /p ".=::.%width%.%height%.%canvasChar%.%title%.%CAM%.%maxX%.%winMaxY% ">>"%tmp%\Canvas_%~2.txt"  
  32.             ) else if /i "%~1" equ "/v" ( for /l %%a in (0,1,%height%) do ( set "tmp_%~2_[%%a]=!_[%%a]!")
  33.         ) else if /i "%~1" equ "/d" ( if exist "%tmp%\Canvas_%~2.txt" ( del /f /q "%tmp%\Canvas_%~2.txt" 2>nul ) ) )
  34.     :updateCanvas
  35.         if "%~2" neq "" ( if /i "%~1" equ "/f" ( if exist "%tmp%\Canvas_%~2.txt" (
  36.                     set "_=-1"
  37.                     for /f "tokens=*" %%a in (%tmp%\Canvas_%~2.txt) do (
  38.                         set /a "_+=1" & set "tmp_%~2_[!_!]=%%~a"
  39.                         call set "expanded_=%%tmp_%~2_[!_!]%%"
  40.                         if "!expanded_:~0,2!" equ "::" set "parse=!expanded_:~3!"
  41.                     )
  42.                     for /f "tokens=1-7 delims=." %%a in ("!parse!") do (
  43.                         call:canvas "%%a + 1" "%%b + 1" "%%c" "%%d" "%%e" "%%f" "%%g"
  44.                     )
  45.                     call:updateCanvas /v %~2
  46.                 )
  47.             ) else if /i "%~1" equ "/v" ( for /l %%a in (0,1,%height%) do ( set "_[%%a]=!tmp_%~2_[%%a]!" ) )
  48.         ) else ( for /l %%a in (0,1,%height%) do ( set "_[%%a]=%widthBuffer%" ) )
  49.     goto :eof
  50.  
  51.     :showCanvas
  52.         %cls%
  53.         echo= %outerBuffer%
  54.         if /i "%CAM%" neq "/c" (
  55.             for /l %%a in (0,1,%height%) do ( echo= %canvasChar:~0,1%!_[%%a]!%canvasChar:~0,1%)
  56.         ) else if "%~3" neq "" (
  57.             set /a "maxY=CAM_Y + winMaxY", "_line=%~1 + 1" & if !maxY! gtr %height% set /a "maxY=height"
  58.             for /l %%a in (!CAM_Y!,1,!maxY!) do (
  59.                 set "line=!_[%%a]!"
  60.                 if "%%a" equ "%~2" set "line=!line:~0,%~1!%~3!line:~%_line%!"
  61.                 echo= !canvasChar:~0,1!!line:~%CAM_X%,%maxX%!!canvasChar:~0,1!
  62.             )
  63.         )
  64.         echo= %outerBuffer%
  65.     goto :eof
  66.    
  67.     :adjustCamera
  68.         set /a "CAM_X=%~1 - (maxX / 2)", "CAM_Y=%~2 - (winMaxY / 2)"
  69.         if %CAM_X% leq 0 set CAM_X=0
  70.         if %CAM_Y% leq 0 set CAM_Y=0
  71.     goto :eof
  72. goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement