Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--------------------------------------------------------------------------------------------//
- //------------------------------- Cube-Art Script Version: 1.4 -------------------------------//
- //--------------------------------------------------------------------------------------------//
- // //
- // What it does: //
- // //
- // This script will read a specified ".cfg" file that has stored within it a list of //
- // the RBGA values for each pixel in an image. Then, it allows the user to draw each row //
- // of pixels in the image semi-automatically to render a pixel image inside the game. //
- // //
- // //
- // //
- // How to use in-game: //
- // //
- // Place "cube_art.cfg" in the same folder as your "autoexec.cfg" and put the line //
- // "exec cube_art.cfg" inside your "autoexec.cfg". //
- // If this is the first script you've wanted to add to Sauerbraten, you won't have an //
- // "autoexec.cfg" file, so just make a blank one under "/Sauerbraten". //
- // //
- // Step 1. Type "/cubeart" to get started //
- // A nice GUI menu will pop up with all the Cube Art image files you have; select one. //
- // If the image loaded, you will be notified in the top left corner of your screen. //
- // //
- // Step 2. Select a cube to start drawing the image from and stand back. //
- // Be sure to stand back because the row will get cut-off if it goes outside of //
- // your view. If that happens, type "/prevrow" to try again afterwards //
- // //
- // Step 3. Type "/drawrow" to draw a row of pixels from the image. //
- // //
- // Step 4. Move down to the next row, select the next cube, and repeat steps 2-3 until //
- // the image is done. (You will be notified when it is complete too). //
- // //
- // //
- // //
- // General Notes: //
- // //
- // A good "rule of thumb" is to not try to render big pictures as it will take a //
- // long time to finish them, and they're also difficult due to stand-off distance. //
- // //
- // It's not our fault you have to stand far back but rather an engine limitation //
- // that prevents editing when the selection is out of view (aka your camera). //
- // //
- // Large images (or many of them in general) are likely to cause lag for you and //
- // others ingame. Try to be fair to others in that regard and don't be annoying. //
- // //
- // //
- // //
- // Developer Notes: //
- // //
- // Original script developed by "SomeDude" (stevenquack86vg@gmail.com) //
- // Remastered by "RaZgRiZ" circa 2011-2012 (and later in 2018) because he's bored AF //
- // //
- //--------------------------------------------------------------------------------------------//
- // Default keybind:
- // editbind N cubeart
- cubeart = [ showgui cubeart ]
- init = [ if (=s (getalias $arg1) "") [ $arg1 = $arg2 ] ]
- init imgdelay 1 // Defines the sleep amount in ms before drawing another pixel to avoid lag.
- init drawalpha 0 // Defines whether transparency is drawn in a pixel or substituted with black.
- clearimg = [
- imgwidth = 0 // The height is calculated automatically.
- imgheight = 0 // Set the height which will be calculated for each new image.
- imgdata = [] // This stores the actual image's data (it can get really big).
- imgindex = 0 // This keeps track of the current pixel.
- _cubeart = [] // Clear the list of configs found
- loopfiles f "cube-art" "cfg" [
- _cubeart = (concat $_cubeart $f)
- ]
- ]
- clearimg // Defining the variables for the first run too!
- // This function is the one drawing each "pixel" of your image.
- // It is not meant to be used manually, so please don't do it.
- _drawpixel = [
- vcolor (divf (pxcol 0) 255) (divf (pxcol 1) 255) (divf (pxcol 2) 255)
- if (&& $drawalpha [< (pxcol 3) 255]) [
- if (pxcol 3) [
- editmat alpha
- valpha (divf (pxcol 3) 255)
- ] editdel
- ]
- imgindex = (+ $imgindex 4)
- ]
- // This function is a shortcut for easy loading of image configs without worrying for the file
- // path or extension. It makes your life (and ours) much easier if you don't struggle.
- loadimg = [
- local path ; path = $arg1
- if (!=s (substr $arg1 (- (strlen $arg1) 4) 4) ".cfg") [
- path = [@[arg1].cfg]
- ]
- if (!=s (substr $path 0 9) "cube-art/") [
- path = [cube-art/@path]
- ]
- clearimg
- exec $path
- cond (mod (listlen $imgdata) $imgwidth) [
- error "^f3The file can't be found or is corrupted."
- clearimg
- ] $imgwidth [
- imgheight = (div (div (listlen $imgdata) $imgwidth) 4)
- echo "^f7This image is^f2" $imgheight "^f7pixels tall."
- ] [
- error "^f3The image width is incorrectly set."
- clearimg
- ]
- ]
- // This function is the one responsible for drawing each row of the image.
- // It only draws one each time, since you're required to reposition afterwards.
- drawrow = [
- local pxcol ; pxcol = [at $imgdata (+ $imgindex $arg1)]
- if $imgwidth [
- sleep (* $imgwidth (* $imgdelay 10)) [
- _drawpixel
- allfaces @allfaces
- nompedit @nompedit
- if (> $imgindex (listlen $imgdata)) [
- clearimg
- echo "^f0Image drawn successfully!"
- if (isconnected) [
- echo "^t^f7Type ^f2^"/sendmap^" ^f7so others may see your work!"
- ]
- ]
- ]
- allfaces 1
- nompedit 0
- loop p (- $imgwidth 1) [
- sleep (* $p (* $imgdelay 10)) [
- if (! (mod $imgindex (* $imgwidth 4))) [
- echo "^f7Drawing row^f2" (div $imgindex (* $imgwidth 4))
- ]
- _drawpixel
- editface -1 1
- ]
- ]
- ] [
- error "^f3No image has been loaded."
- echo "^f7To load an image, type ^f2^"/loadimg [name]^""
- ]
- ]
- // This function allows you to define the row you are about to draw.
- // Its index starts from 0, so don't get confused with it now!
- setrow = [
- if (&& $numargs $imgwidth) [
- imgindex = (* $imgwidth (* (min $imgheight (max 0 $arg1)) 4))
- echo "^f7Jumping to row^f2" (div $imgindex (* $imgwidth 4))
- ]
- ]
- // This function backtracks to the previous row, or X rows back if specified.
- // Useful for when something messes up your progress and you need a restart.
- prevrow = [
- if $imgwidth [
- imgindex = (max (- $imgindex (* (? $numargs (* $arg1 4) 4) $imgwidth)) 0)
- echo "^f7Going back to row^f2" (div $imgindex (* $imgwidth 4))
- ]
- ]
- // And last, this is the basic GUI. Should do the job just fine.
- newgui cubeart [
- guitext "^f2Pixel draw delay: (x10 ms)" 0
- guilistslider imgdelay "1 2 3 4 5 6 7 8 9 10 20"
- guistrut 1
- guilist [
- guilist [
- guistrut 20 1
- looplist i $_cubeart [
- guibutton $i [loadimg @i]
- ]
- ]
- guilist [
- guicheckbox "Draw Transparent Pixels" drawalpha
- guistrut (- (listlen $_cubeart) 2)
- guistayopen [
- guibutton "Reset Script" [
- echo "^f0Clearing image data and updating config database.."
- clearimg
- ]
- ]
- ]
- ]
- ] " Cube-Art "
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement