Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :canvas
- if "%~2" neq "" ( set /a "width=%~1 - 1", "height=%~2 - 1" ) else ( goto :eof )
- call:cursorpos 2>nul
- if "%~3" neq "" ( set "canvasChar=%~3" ) else ( set "canvasChar=#" )
- if "%~4" neq "" ( set "title=%~4" ) else ( set "title=CANVAS" )
- if "%~7" neq "" ( if /i "%~5" equ "/c" (
- set "CAM=/c"
- set /a "CAM_Y=0", "CAM_X=0", "maxX=%~6", "winMaxY=%~7","cols=maxX + 5", "rows=winMaxY + 5"
- if not defined outerBuffer ( for /l %%a in (-1,1,!maxX!) do (
- set "outerBuffer=!outerBuffer!%canvasChar%") )
- if !maxX! geq %width% set /a "maxX=width"
- if !winMaxY! geq %height% set /a "winMaxY=height"
- )
- ) else (
- set /a "cols=width + 5", "rows=height + 5"
- if not defined outerBuffer ( for /l %%a in (-2,1,%width%) do (
- set "outerBuffer=!outerBuffer!%canvasChar%") )
- )
- for /l %%a in (0,1,%width%) do set "widthBuffer=!widthBuffer! "
- call:updateCanvas
- if exist "%temp%\cursorpos.exe" (
- set "cls="%temp%\cursorpos.exe" 0 1" ) else ( set "cls=cls" )
- mode con: cols=%cols% lines=%rows%
- title %title%
- goto :eof
- :saveCanvas
- if "%~2" neq "" ( if /i "%~1" equ "/f" (
- if exist "%tmp%\Canvas_%~2.txt" ( del /f /q "%tmp%\Canvas_%~2.txt" 2>nul )
- for /l %%a in (0,1,%height%) do ( echo="!_[%%a]!">>"%tmp%\Canvas_%~2.txt")
- <nul set /p ".=::.%width%.%height%.%canvasChar%.%title%.%CAM%.%maxX%.%winMaxY% ">>"%tmp%\Canvas_%~2.txt"
- ) else if /i "%~1" equ "/v" ( for /l %%a in (0,1,%height%) do ( set "tmp_%~2_[%%a]=!_[%%a]!")
- ) else if /i "%~1" equ "/d" ( if exist "%tmp%\Canvas_%~2.txt" ( del /f /q "%tmp%\Canvas_%~2.txt" 2>nul ) ) )
- :updateCanvas
- if "%~2" neq "" ( if /i "%~1" equ "/f" ( if exist "%tmp%\Canvas_%~2.txt" (
- set "_=-1"
- for /f "tokens=*" %%a in (%tmp%\Canvas_%~2.txt) do (
- set /a "_+=1" & set "tmp_%~2_[!_!]=%%~a"
- call set "expanded_=%%tmp_%~2_[!_!]%%"
- if "!expanded_:~0,2!" equ "::" set "parse=!expanded_:~3!"
- )
- for /f "tokens=1-7 delims=." %%a in ("!parse!") do (
- call:canvas "%%a + 1" "%%b + 1" "%%c" "%%d" "%%e" "%%f" "%%g"
- )
- call:updateCanvas /v %~2
- )
- ) else if /i "%~1" equ "/v" ( for /l %%a in (0,1,%height%) do ( set "_[%%a]=!tmp_%~2_[%%a]!" ) )
- ) else ( for /l %%a in (0,1,%height%) do ( set "_[%%a]=%widthBuffer%" ) )
- goto :eof
- :showCanvas
- %cls%
- echo= %outerBuffer%
- if /i "%CAM%" neq "/c" (
- for /l %%a in (0,1,%height%) do ( echo= %canvasChar:~0,1%!_[%%a]!%canvasChar:~0,1%)
- ) else if "%~3" neq "" (
- set /a "maxY=CAM_Y + winMaxY", "_line=%~1 + 1" & if !maxY! gtr %height% set /a "maxY=height"
- for /l %%a in (!CAM_Y!,1,!maxY!) do (
- set "line=!_[%%a]!"
- if "%%a" equ "%~2" set "line=!line:~0,%~1!%~3!line:~%_line%!"
- echo= !canvasChar:~0,1!!line:~%CAM_X%,%maxX%!!canvasChar:~0,1!
- )
- )
- echo= %outerBuffer%
- goto :eof
- :adjustCamera
- set /a "CAM_X=%~1 - (maxX / 2)", "CAM_Y=%~2 - (winMaxY / 2)"
- if %CAM_X% leq 0 set CAM_X=0
- if %CAM_Y% leq 0 set CAM_Y=0
- goto :eof
- goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement