Advertisement
RaZgRiZ

Cube-Art 1.4

Jun 13th, 2012
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.66 KB | None | 0 0
  1. //--------------------------------------------------------------------------------------------//
  2. //------------------------------- Cube-Art Script Version: 1.4 -------------------------------//
  3. //--------------------------------------------------------------------------------------------//
  4. //                                                                                            //
  5. //  What it does:                                                                             //
  6. //                                                                                            //
  7. //    This script will read a specified ".cfg" file that has stored within it a list of       //
  8. //    the RBGA values for each pixel in an image. Then, it allows the user to draw each row   //
  9. //    of pixels in the image semi-automatically to render a pixel image inside the game.      //
  10. //                                                                                            //
  11. //                                                                                            //
  12. //                                                                                            //
  13. //  How to use in-game:                                                                       //
  14. //                                                                                            //
  15. //    Place "cube_art.cfg" in the same folder as your "autoexec.cfg" and put the line         //
  16. //      "exec cube_art.cfg" inside your "autoexec.cfg".                                       //
  17. //    If this is the first script you've wanted to add to Sauerbraten, you won't have an      //
  18. //      "autoexec.cfg" file, so just make a blank one under "/Sauerbraten".                   //
  19. //                                                                                            //
  20. //    Step 1. Type "/cubeart" to get started                                                  //
  21. //        A nice GUI menu will pop up with all the Cube Art image files you have; select one. //
  22. //        If the image loaded, you will be notified in the top left corner of your screen.    //
  23. //                                                                                            //
  24. //    Step 2. Select a cube to start drawing the image from and stand back.                   //
  25. //        Be sure to stand back because the row will get cut-off if it goes outside of        //
  26. //        your view. If that happens, type "/prevrow" to try again afterwards                 //
  27. //                                                                                            //
  28. //    Step 3. Type "/drawrow" to draw a row of pixels from the image.                         //
  29. //                                                                                            //
  30. //    Step 4. Move down to the next row, select the next cube, and repeat steps 2-3 until     //
  31. //            the image is done. (You will be notified when it is complete too).              //
  32. //                                                                                            //
  33. //                                                                                            //
  34. //                                                                                            //
  35. //  General Notes:                                                                            //
  36. //                                                                                            //
  37. //   A good "rule of thumb" is to not try to render big pictures as it will take a            //
  38. //     long time to finish them, and they're also difficult due to stand-off distance.        //
  39. //                                                                                            //
  40. //   It's not our fault you have to stand far back but rather an engine limitation            //
  41. //     that prevents editing when the selection is out of view (aka your camera).             //
  42. //                                                                                            //
  43. //   Large images (or many of them in general) are likely to cause lag for you and            //
  44. //     others ingame. Try to be fair to others in that regard and don't be annoying.          //
  45. //                                                                                            //
  46. //                                                                                            //
  47. //                                                                                            //
  48. //  Developer Notes:                                                                          //
  49. //                                                                                            //
  50. //    Original script developed by "SomeDude" (stevenquack86vg@gmail.com)                     //
  51. //    Remastered by "RaZgRiZ" circa 2011-2012 (and later in 2018) because he's bored AF       //
  52. //                                                                                            //
  53. //--------------------------------------------------------------------------------------------//
  54.  
  55.  
  56. // Default keybind:
  57. // editbind N cubeart
  58.  
  59. cubeart = [ showgui cubeart ]
  60.  
  61. init = [ if (=s (getalias $arg1) "") [ $arg1 = $arg2 ] ]
  62.  
  63. init imgdelay  1 // Defines the sleep amount in ms before drawing another pixel to avoid lag.
  64. init drawalpha 0 // Defines whether transparency is drawn in a pixel or substituted with black.
  65.  
  66. clearimg = [
  67.     imgwidth  = 0   // The height is calculated automatically.
  68.     imgheight = 0   // Set the height which will be calculated for each new image.
  69.     imgdata   = []  // This stores the actual image's data (it can get really big).
  70.     imgindex  = 0   // This keeps track of the current pixel.
  71.     _cubeart = []   // Clear the list of configs found
  72.     loopfiles f "cube-art" "cfg" [
  73.         _cubeart = (concat $_cubeart $f)
  74.     ]
  75. ]
  76.  
  77. clearimg // Defining the variables for the first run too!
  78.  
  79.  
  80. // This function is the one drawing each "pixel" of your image.
  81. // It is not meant to be used manually, so please don't do it.
  82. _drawpixel = [
  83.     vcolor (divf (pxcol 0) 255) (divf (pxcol 1) 255) (divf (pxcol 2) 255)
  84.     if (&& $drawalpha [< (pxcol 3) 255]) [
  85.         if (pxcol 3) [
  86.             editmat alpha
  87.             valpha (divf (pxcol 3) 255)
  88.         ] editdel
  89.     ]
  90.     imgindex = (+ $imgindex 4)
  91. ]
  92.  
  93. // This function is a shortcut for easy loading of image configs without worrying for the file
  94. // path or extension. It makes your life (and ours) much easier if you don't struggle.
  95. loadimg = [
  96.     local path ; path = $arg1
  97.     if (!=s (substr $arg1 (- (strlen $arg1) 4) 4) ".cfg") [
  98.         path = [@[arg1].cfg]
  99.     ]
  100.     if (!=s (substr $path 0 9) "cube-art/") [
  101.         path = [cube-art/@path]
  102.     ]
  103.     clearimg
  104.     exec $path
  105.     cond (mod (listlen $imgdata) $imgwidth) [
  106.         error "^f3The file can't be found or is corrupted."
  107.         clearimg
  108.     ] $imgwidth [
  109.         imgheight = (div (div (listlen $imgdata) $imgwidth) 4)
  110.         echo "^f7This image is^f2" $imgheight "^f7pixels tall."
  111.     ] [
  112.         error "^f3The image width is incorrectly set."
  113.         clearimg
  114.     ]
  115. ]
  116.  
  117. // This function is the one responsible for drawing each row of the image.
  118. // It only draws one each time, since you're required to reposition afterwards.
  119. drawrow = [
  120.     local pxcol ; pxcol = [at $imgdata (+ $imgindex $arg1)]
  121.     if $imgwidth [
  122.         sleep (* $imgwidth (* $imgdelay 10)) [
  123.             _drawpixel
  124.             allfaces @allfaces
  125.             nompedit @nompedit
  126.             if (> $imgindex (listlen $imgdata)) [
  127.                 clearimg
  128.                 echo "^f0Image drawn successfully!"
  129.                 if (isconnected) [
  130.                     echo "^t^f7Type ^f2^"/sendmap^" ^f7so others may see your work!"
  131.                 ]
  132.             ]
  133.         ]
  134.         allfaces 1
  135.         nompedit 0
  136.         loop p (- $imgwidth 1) [
  137.             sleep (* $p (* $imgdelay 10)) [
  138.                 if (! (mod $imgindex (* $imgwidth 4))) [
  139.                     echo "^f7Drawing row^f2" (div $imgindex (* $imgwidth 4))
  140.                 ]
  141.                 _drawpixel
  142.                 editface -1 1
  143.             ]
  144.         ]
  145.     ] [
  146.         error "^f3No image has been loaded."
  147.         echo "^f7To load an image, type ^f2^"/loadimg [name]^""
  148.     ]
  149. ]
  150.  
  151. // This function allows you to define the row you are about to draw.
  152. // Its index starts from 0, so don't get confused with it now!
  153. setrow = [
  154.     if (&& $numargs $imgwidth) [
  155.         imgindex = (* $imgwidth (* (min $imgheight (max 0 $arg1)) 4))
  156.         echo "^f7Jumping to row^f2" (div $imgindex (* $imgwidth 4))
  157.     ]
  158. ]
  159.  
  160. // This function backtracks to the previous row, or X rows back if specified.
  161. // Useful for when something messes up your progress and you need a restart.
  162. prevrow = [
  163.     if $imgwidth [
  164.         imgindex = (max (- $imgindex (* (? $numargs (* $arg1 4) 4) $imgwidth)) 0)
  165.         echo "^f7Going back to row^f2" (div $imgindex (* $imgwidth 4))
  166.     ]
  167. ]
  168.  
  169. // And last, this is the basic GUI. Should do the job just fine.
  170. newgui cubeart [
  171.     guitext "^f2Pixel draw delay: (x10 ms)" 0
  172.     guilistslider imgdelay "1 2 3 4 5 6 7 8 9 10 20"
  173.     guistrut 1
  174.     guilist [
  175.         guilist [
  176.             guistrut 20 1
  177.             looplist i $_cubeart [
  178.                 guibutton $i [loadimg @i]
  179.             ]
  180.         ]
  181.         guilist [
  182.             guicheckbox "Draw Transparent Pixels" drawalpha
  183.             guistrut (- (listlen $_cubeart) 2)
  184.             guistayopen [
  185.                 guibutton "Reset Script" [
  186.                     echo "^f0Clearing image data and updating config database.."
  187.                     clearimg
  188.                 ]
  189.             ]
  190.         ]
  191.     ]
  192. ] " Cube-Art "
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement