SHOW:
|
|
- or go back to the newest paste.
| 1 | //////////////////////////////////////////////////////////////////////////////////////////////// | |
| 2 | - | //------------------------------- Cube-Art Script Version: 1.4 -------------------------------// |
| 2 | + | //------------------------------- Cube-Art Script Version: 1.3 -------------------------------// |
| 3 | // This Script and the "SauerImageConverter" originally made by SomeDude // | |
| 4 | // Script remastered by RaZgRiZ // | |
| 5 | //--------------------------------------------------------------------------------------------// | |
| 6 | // // | |
| 7 | - | // This script will read a specified ".cfg" file that has stored within it a list of // |
| 7 | + | |
| 8 | - | // the RBGA values for each pixel in an image. Then, it allows the user to draw each row // |
| 8 | + | // This script will read a specified ".cfg" file that has, stored within it, a list of // |
| 9 | - | // of pixels in the image semi-automatically to render a pixel image inside the game. // |
| 9 | + | // the RBGA values for each pixel in an image. Then, it allows the user to draw each row // |
| 10 | // of pixels in the image semi-automatically. (each row must still be selected manually) // | |
| 11 | // // | |
| 12 | // // | |
| 13 | // How to use in-game: // | |
| 14 | // Place "cube_art.cfg" in the same folder as your "autoexec.cfg" and put the line // | |
| 15 | // "exec cube_art.cfg" inside your "autoexec.cfg". // | |
| 16 | // If this is the first script you've wanted to add to Sauerbraten, you won't have an // | |
| 17 | // "autoexec.cfg" file, so just make a blank one under "/Sauerbraten". // | |
| 18 | // NOTE: I recommend that you keybind the "cubeart" function to some key for ease. // | |
| 19 | // Eg: Put "editbind N cubeart" somewhere in your "autoexec.cfg" // | |
| 20 | - | // Step 1. Type "/cubeart" to get started // |
| 20 | + | |
| 21 | // Step 1. Press the 'N' key. (Or type "/loadimg <image_name>") // | |
| 22 | // A nice GUI menu will pop up with all the Cube Art image files you have; select one. // | |
| 23 | // If the image loaded, you will be notified in the top left corner of your screen. // | |
| 24 | // // | |
| 25 | - | // Be sure to stand back because the row will get cut-off if it goes outside of // |
| 25 | + | |
| 26 | - | // your view. If that happens, type "/prevrow" to try again afterwards // |
| 26 | + | // (Be sure to stand back because the row will get cut-off if it goes outside your view) // |
| 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 // |
| 30 | + | // Step 4. Move down to the next row, select the next cube, and repeat steps 3-4 until // |
| 31 | - | // the image is done. (You will be notified when it is complete too). // |
| 31 | + | // the image is done. (You will be notified when it is complete) // |
| 32 | // // | |
| 33 | // // | |
| 34 | // General Notes: // | |
| 35 | // -A good "rule of thumb" is to shrink an image so it's around 40 pixels in height // | |
| 36 | // before converting it for in-game use. // | |
| 37 | - | // A good "rule of thumb" is to not try to render big pictures as it will take a // |
| 37 | + | // -The image will get cut-off if you do not stand back as each row is drawn, this is // |
| 38 | - | // long time to finish them, and they're also difficult due to stand-off distance. // |
| 38 | + | // an unavoidable inconvenience due to the use of the "editface" command. // |
| 39 | // -HUGE images tend to cause significant lag, try to avoid them. // | |
| 40 | - | // It's not our fault you have to stand far back but rather an engine limitation // |
| 40 | + | // -Many medium-sized images can also cause lag, however, this can be reduced if // |
| 41 | - | // that prevents editing when the selection is out of view (aka your camera). // |
| 41 | + | // only a few images can be viewed at any one time. (Ex: grouping them into rooms) // |
| 42 | // // | |
| 43 | - | // Large images (or many of them in general) are likely to cause lag for you and // |
| 43 | + | |
| 44 | - | // others ingame. Try to be fair to others in that regard and don't be annoying. // |
| 44 | + | // ****The file format for CubeArt images is the same ".cfg" as for scripts.**** // |
| 45 | // This means cubescript can be fully utilized within CubeArt Images. // | |
| 46 | // This allows for customization of images you convert including but not limited to: // | |
| 47 | // -"Echo" commands crediting image authors, specifying instructions, or other info. // | |
| 48 | // -Enabling/Disabling the use of the alpha channel in the image. // | |
| 49 | // -Changing the format of the "imgdata" // | |
| 50 | - | // Original script developed by "SomeDude" ([email protected]) // |
| 50 | + | // -Definition and use of custom user-defined functions // |
| 51 | - | // Remastered by "RaZgRiZ" circa 2011-2012 (and later in 2018) because he's bored AF // |
| 51 | + | |
| 52 | // // | |
| 53 | // My Contact Info: // | |
| 54 | // Email: "[email protected]" // | |
| 55 | // Sauerbraten username: "SomeDude" // | |
| 56 | // // | |
| 57 | // // | |
| 58 | // **Special Thanks to MMC(Map Making Clan) and it's forum for hosting earlier versions.** // | |
| 59 | - | cubeart = [ showgui cubeart ] |
| 59 | + | |
| 60 | //////////////////////////////////////////////////////////////////////////////////////////////// | |
| 61 | - | init = [ if (=s (getalias $arg1) "") [ $arg1 = $arg2 ] ] |
| 61 | + | |
| 62 | ||
| 63 | - | init imgdelay 1 // Defines the sleep amount in ms before drawing another pixel to avoid lag. |
| 63 | + | |
| 64 | - | init drawalpha 0 // Defines whether transparency is drawn in a pixel or substituted with black. |
| 64 | + | |
| 65 | ||
| 66 | cubeart = [showgui cubeart] // draw a line or select a picture for drawing. | |
| 67 | vcolorc = [vcolor (divf $arg1 255) (divf $arg2 255) (divf $arg3 255)] // shortcut of vcolor for RGB values. | |
| 68 | ca_col = [at $imgdata (+ $imgindex $arg1)] // 0 red, 1 green, 2 blue, 3 alpha. | |
| 69 | ||
| 70 | createine = [if (=s (getalias $arg1) "") [$arg1 = $arg2]] | |
| 71 | ||
| 72 | createine imgdelay 1 // Defines the sleep amount in ms before drawing another pixel to avoid lag. | |
| 73 | createine drawalpha 0 // This controls the use of the Alpha Material in place of the alpha channel in the image. | |
| 74 | ||
| 75 | clearimg = [ | |
| 76 | imgwidth = 0 // The height is calculated automatically. | |
| 77 | imgheight = 0 // Set the height which will be calculated for each new image. | |
| 78 | imgdata = [] // This stores the actual image's data (it can get really big). | |
| 79 | imgindex = 0 // This keeps track of the current pixel. | |
| 80 | _cubeart = [] // Clear the list of configs found | |
| 81 | loopfiles f "cube-art" "cfg" [ | |
| 82 | _cubeart = (concat $_cubeart $f) | |
| 83 | - | vcolor (divf (pxcol 0) 255) (divf (pxcol 1) 255) (divf (pxcol 2) 255) |
| 83 | + | |
| 84 | - | if (&& $drawalpha [< (pxcol 3) 255]) [ |
| 84 | + | |
| 85 | - | if (pxcol 3) [ |
| 85 | + | |
| 86 | clearimg // Defining the variables for the first run too! | |
| 87 | - | valpha (divf (pxcol 3) 255) |
| 87 | + | |
| 88 | ||
| 89 | // This function is the one drawing each "pixel" of your image. | |
| 90 | // It is not meant to be used manually, so please don't do it. | |
| 91 | _drawpixel = [ | |
| 92 | vcolorc (ca_col 0) (ca_col 1) (ca_col 2) | |
| 93 | if (&& $drawalpha [< (ca_col 3) 255]) [ | |
| 94 | - | // path or extension. It makes your life (and ours) much easier if you don't struggle. |
| 94 | + | if (ca_col 3) [ |
| 95 | editmat alpha | |
| 96 | - | local path ; path = $arg1 |
| 96 | + | valpha (divf (ca_col 3) 255) |
| 97 | ] editdel | |
| 98 | - | path = [@[arg1].cfg] |
| 98 | + | |
| 99 | imgindex = (+ $imgindex 4) | |
| 100 | - | if (!=s (substr $path 0 9) "cube-art/") [ |
| 100 | + | |
| 101 | - | path = [cube-art/@path] |
| 101 | + | |
| 102 | // This function is a shortcut for easy loading of image configs without worrying for the file | |
| 103 | // path or extension. It makes your life easier and is responsible for a few other things as well. | |
| 104 | - | exec $path |
| 104 | + | |
| 105 | ca_tmp = $arg1 | |
| 106 | - | error "^f3The file can't be found or is corrupted." |
| 106 | + | |
| 107 | ca_tmp = [@[arg1].cfg] | |
| 108 | ] | |
| 109 | if (!=s (substr $ca_tmp 0 9) "cube-art/") [ | |
| 110 | - | echo "^f7This image is^f2" $imgheight "^f7pixels tall." |
| 110 | + | ca_tmp = [cube-art/@ca_tmp] |
| 111 | ] | |
| 112 | - | error "^f3The image width is incorrectly set." |
| 112 | + | |
| 113 | exec $ca_tmp | |
| 114 | cond (mod (listlen $imgdata) $imgwidth) [ | |
| 115 | error "^f3The file in question is either missing or corrupt and cannot be loaded!" | |
| 116 | clearimg | |
| 117 | ] $imgwidth [ | |
| 118 | imgheight = (div (div (listlen $imgdata) $imgwidth) 4) | |
| 119 | echo "^f7This image is^f2" $imgheight "^f7pixels tall" | |
| 120 | - | local pxcol ; pxcol = [at $imgdata (+ $imgindex $arg1)] |
| 120 | + | |
| 121 | error "^f3The image's width is incorrect and process cannot continue!" | |
| 122 | clearimg | |
| 123 | ] | |
| 124 | ] | |
| 125 | ||
| 126 | // This function is the one responsible for drawing each row of the image. | |
| 127 | // It only draws one each time, since you're required to reposition afterwards. | |
| 128 | drawrow = [ | |
| 129 | if $imgwidth [ | |
| 130 | sleep (* $imgwidth (* $imgdelay 10)) [ | |
| 131 | _drawpixel | |
| 132 | allfaces @allfaces | |
| 133 | nompedit @nompedit | |
| 134 | if (> $imgindex (listlen $imgdata)) [ | |
| 135 | clearimg | |
| 136 | echo "^f0Image drawn successfully!" | |
| 137 | if (isconnected) [ | |
| 138 | echo "^t^f7Type ^f2^"/sendmap^" ^f7so others may see your work!" | |
| 139 | ] | |
| 140 | ] | |
| 141 | ] | |
| 142 | allfaces 1 | |
| 143 | nompedit 0 | |
| 144 | loop p (- $imgwidth 1) [ | |
| 145 | sleep (* $p (* $imgdelay 10)) [ | |
| 146 | - | error "^f3No image has been loaded." |
| 146 | + | |
| 147 | echo "^f7Drawing row^f2" (div $imgindex (* $imgwidth 4)) | |
| 148 | ] | |
| 149 | _drawpixel | |
| 150 | editface -1 1 | |
| 151 | ] | |
| 152 | ] | |
| 153 | ] [ | |
| 154 | error "^f3You have not loaded an image yet!" | |
| 155 | echo "^f7To load an image, type ^f2^"/loadimg [name]^"" | |
| 156 | ] | |
| 157 | ] | |
| 158 | ||
| 159 | // This function allows you to define the row you are about to draw. | |
| 160 | // Its index starts from 0, so don't get confused with it now! | |
| 161 | setrow = [ | |
| 162 | if (&& $numargs $imgwidth) [ | |
| 163 | imgindex = (* $imgwidth (* (min $imgheight (max 0 $arg1)) 4)) | |
| 164 | echo "^f7Jumping to row^f2" (div $imgindex (* $imgwidth 4)) | |
| 165 | ] | |
| 166 | ] | |
| 167 | ||
| 168 | // This function backtracks to the previous row, or X rows back if specified. | |
| 169 | // Useful for when something messes up your progress and you need a restart. | |
| 170 | prevrow = [ | |
| 171 | - | guitext "^f2Pixel draw delay: (x10 ms)" 0 |
| 171 | + | |
| 172 | imgindex = (max (- $imgindex (* (? $numargs (* $arg1 4) 4) $imgwidth)) 0) | |
| 173 | echo "^f7Going back to row^f2" (div $imgindex (* $imgwidth 4)) | |
| 174 | ] | |
| 175 | ] | |
| 176 | ||
| 177 | // And last, this is the basic GUI. Should do the job just fine. | |
| 178 | newgui cubeart [ | |
| 179 | guitext "^f2Delay between pixels: (1/100 second)" 0 | |
| 180 | guilistslider imgdelay "1 2 3 4 5 6 7 8 9 10 20" | |
| 181 | guistrut 1 | |
| 182 | - | guicheckbox "Draw Transparent Pixels" drawalpha |
| 182 | + | |
| 183 | guilist [ | |
| 184 | guistrut 20 1 | |
| 185 | - | guibutton "Reset Script" [ |
| 185 | + | |
| 186 | guibutton $i [loadimg @i] | |
| 187 | ] | |
| 188 | ] | |
| 189 | guilist [ | |
| 190 | guicheckbox "Draw Alpha" drawalpha | |
| 191 | guistrut (- (listlen $_cubeart) 2) | |
| 192 | guistayopen [ | |
| 193 | guibutton "Force Restart" [ | |
| 194 | echo "^f0Clearing image data and updating config database.." | |
| 195 | clearimg | |
| 196 | ] | |
| 197 | ] | |
| 198 | ] | |
| 199 | ] | |
| 200 | ] " Cube-Art " |