Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////////////////////////////////////////
- //------------------------------- Cube-Art Script Version: 1.3 -------------------------------//
- // This Script and the "SauerImageConverter" originally made by SomeDude //
- // Script remastered by RaZgRiZ //
- //--------------------------------------------------------------------------------------------//
- // //
- // 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. (each row must still be selected manually) //
- // //
- // //
- // 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". //
- // NOTE: I recommend that you keybind the "cubeart" function to some key for ease. //
- // Eg: Put "editbind N cubeart" somewhere in your "autoexec.cfg" //
- // //
- // Step 1. Press the 'N' key. (Or type "/loadimg <image_name>") //
- // 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 your view) //
- // //
- // 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 3-4 until //
- // the image is done. (You will be notified when it is complete) //
- // //
- // //
- // General Notes: //
- // -A good "rule of thumb" is to shrink an image so it's around 40 pixels in height //
- // before converting it for in-game use. //
- // -The image will get cut-off if you do not stand back as each row is drawn, this is //
- // an unavoidable inconvenience due to the use of the "editface" command. //
- // -HUGE images tend to cause significant lag, try to avoid them. //
- // -Many medium-sized images can also cause lag, however, this can be reduced if //
- // only a few images can be viewed at any one time. (Ex: grouping them into rooms) //
- // //
- // Developer Notes: //
- // ****The file format for CubeArt images is the same ".cfg" as for scripts.**** //
- // This means cubescript can be fully utilized within CubeArt Images. //
- // This allows for customization of images you convert including but not limited to: //
- // -"Echo" commands crediting image authors, specifying instructions, or other info. //
- // -Enabling/Disabling the use of the alpha channel in the image. //
- // -Changing the format of the "imgdata" //
- // -Definition and use of custom user-defined functions //
- // //
- // //
- // My Contact Info: //
- // Email: "stevenquack86vg@gmail.com" //
- // Sauerbraten username: "SomeDude" //
- // //
- // //
- // **Special Thanks to MMC(Map Making Clan) and it's forum for hosting earlier versions.** //
- // //
- ////////////////////////////////////////////////////////////////////////////////////////////////
- // Default keybind:
- // editbind N cubeart
- cubeart = [showgui cubeart] // draw a line or select a picture for drawing.
- vcolorc = [vcolor (divf $arg1 255) (divf $arg2 255) (divf $arg3 255)] // shortcut of vcolor for RGB values.
- ca_col = [at $imgdata (+ $imgindex $arg1)] // 0 red, 1 green, 2 blue, 3 alpha.
- createine = [if (=s (getalias $arg1) "") [$arg1 = $arg2]]
- createine imgdelay 1 // Defines the sleep amount in ms before drawing another pixel to avoid lag.
- createine drawalpha 0 // This controls the use of the Alpha Material in place of the alpha channel in the image.
- 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 = [
- vcolorc (ca_col 0) (ca_col 1) (ca_col 2)
- if (&& $drawalpha [< (ca_col 3) 255]) [
- if (ca_col 3) [
- editmat alpha
- valpha (divf (ca_col 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 easier and is responsible for a few other things as well.
- loadimg = [
- ca_tmp = $arg1
- if (!=s (substr $arg1 (- (strlen $arg1) 4) 4) ".cfg") [
- ca_tmp = [@[arg1].cfg]
- ]
- if (!=s (substr $ca_tmp 0 9) "cube-art/") [
- ca_tmp = [cube-art/@ca_tmp]
- ]
- clearimg
- exec $ca_tmp
- cond (mod (listlen $imgdata) $imgwidth) [
- error "^f3The file in question is either missing or corrupt and cannot be loaded!"
- clearimg
- ] $imgwidth [
- imgheight = (div (div (listlen $imgdata) $imgwidth) 4)
- echo "^f7This image is^f2" $imgheight "^f7pixels tall"
- ] [
- error "^f3The image's width is incorrect and process cannot continue!"
- 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 = [
- 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 "^f3You have not loaded an image yet!"
- 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 "^f2Delay between pixels: (1/100 second)" 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 Alpha" drawalpha
- guistrut (- (listlen $_cubeart) 2)
- guistayopen [
- guibutton "Force Restart" [
- echo "^f0Clearing image data and updating config database.."
- clearimg
- ]
- ]
- ]
- ]
- ] " Cube-Art "
Add Comment
Please, Sign In to add comment