Mindustry/tools/build.gradle
2018-11-12 19:03:24 -05:00

115 lines
3.2 KiB
Groovy

apply plugin: "java"
sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = [ "src/" ]
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.tools.texturepacker.TexturePacker
import javax.imageio.ImageIO
def outFolder = "../core/assets-raw/sprites_out/"
def genFolder = "../core/assets-raw/sprites_out/generated/"
def scaling = "XBRZ 4x"
task swapColors(){
doLast{
if (project.hasProperty("colors")) {
def carr = new File(getProperty("colors")).text.split("\n")
def map = [:]
def swaps = 0
carr.each {str -> map[Color.argb8888(Color.valueOf(str.split("=")[0]))] = Color.argb8888(Color.valueOf(str.split("=")[1]))}
def tmpc = new Color()
fileTree(dir: '../core/assets-raw/sprites', include: "**/*.png").visit { file ->
if(file.isDirectory()) return
swaps ++
def img = ImageIO.read(file.file)
for (x in (0..img.getWidth()-1)) {
for (y in (0..img.getHeight()-1)) {
def c = img.getRGB(x, y)
Color.argb8888ToColor(tmpc, c)
if(tmpc.a < 0.1f) continue
if(map.containsKey(c)){
img.setRGB(x, y, (int)map.get(c))
}
}
}
ImageIO.write(img, "png", file.file)
}
println "Swapped $swaps images."
}else{
throw new InvalidUserDataException("No replacement colors specified. Use -Pcolors=\"<path to color file>\"")
}
}
}
task scaleSprites(){
finalizedBy 'genSprites'
doLast{
def arguments = ["mono", "ImageResizer.exe"]
fileTree(dir: '../core/assets-raw/sprites/', include: "**/*.png").visit { file ->
if(file.isDirectory() || file.toString().contains("/ui/")) return;
def write = new File(file.file.toString().replace("/sprites", "/sprites_out"))
arguments += ["/load", file.file.toString(), "/resize",
"auto", scaling, "/save", write.toString()]
}
exec{
commandLine arguments
}
}
}
task pack(){
dependsOn 'cleanSprites', 'scaleSprites'
doLast{
TexturePacker.process("core/assets-raw/sprites_out/", "core/assets/sprites/", "sprites.atlas")
delete{
delete outFolder
delete genFolder
}
}
}
task cleanSprites(){
doLast{
delete{
delete "../core/assets-raw/sprites_out/"
}
copy{
from "../core/assets-raw/sprites/"
into "../core/assets-raw/sprites_out/"
}
file(genFolder).mkdirs()
}
}
task genSprites(dependsOn: classes, type: JavaExec) {
main = "io.anuke.mindustry.PackerLauncher"
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = genFolder
}
task updateBundles(dependsOn: classes, type: JavaExec) {
file(genFolder).mkdirs()
main = "io.anuke.mindustry.BundleLauncher"
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = "../core/assets/bundles/"
}