Merge + update

This commit is contained in:
Anuken
2019-06-30 14:13:13 -04:00
214 changed files with 11773 additions and 8613 deletions

View File

@@ -12,7 +12,6 @@ import javax.imageio.ImageIO
import java.awt.Graphics2D
import java.awt.image.BufferedImage
def outFolder = "../core/assets-raw/sprites_out/"
def genFolder = "../core/assets-raw/sprites_out/generated/"
def doAntialias = !project.hasProperty("disableAntialias")
def colorMap = new IntMap<List<Color>>(), colorIndexMap = new IntIntMap()
@@ -185,7 +184,6 @@ def scaleImage = { File file ->
def tileImage = { File file ->
def image = ImageIO.read(file)
def color = new Color()
def result = new BufferedImage(image.width * 2, image.height * 2, image.getType())
Graphics2D graphics = result.createGraphics()
@@ -248,28 +246,6 @@ task swapColors(){
}
}
task scaleSprites4x(){
doLast{
fileTree(dir: '../core/assets-raw/sprites_out/', include: "**/*.png").visit{ file ->
if(file.isDirectory() || file.toString().replace("\\", "/").contains("/ui/")) return
scaleImage(file.file)
antialias(file.file)
}
}
}
task scaleSprites(){
finalizedBy 'genSprites'
doLast{
copy{
from "../core/assets-raw/sprites/"
into "../core/assets-raw/sprites_out/"
}
}
}
task scaleImages(){
doLast{
for(def img : project.getProperty("images").split(",")){
@@ -288,66 +264,68 @@ task tileImages(){
}
}
task pack(){
dependsOn 'cleanSprites', 'scaleSprites'
//finalizedBy 'cleanup'
doLast{
fileTree(dir: '../core/assets-raw/sprites_out/', include: "**/*.png").visit{ file ->
if(file.isDirectory() || file.toString().replace("\\", "/").contains("/ui/")) return
antialias(file.file)
}
TexturePacker.process("core/assets-raw/sprites_out/", "core/assets/sprites/", "sprites.atlas")
delete{
delete fileTree(dir: '../core/assets-raw/sprites_out/', include: '**/pack.json')
}
copy{
from '../core/assets-raw/sprites_out/'
into '../core/assets-raw/sprites_out/'
include '**/*.json'
rename 'pack_fallback.json', "pack.json"
}
TexturePacker.process("core/assets-raw/sprites_out/", "core/assets/sprites/", "sprites_fallback.atlas")
}
}
task cleanup(){
doLast{
delete{
delete genFolder
delete outFolder
}
}
}
task cleanSprites(){
task pack(dependsOn: classes){
doLast{
//cleanup old sprites
delete{
delete "../core/assets-raw/sprites_out/"
}
//copy in new sprites
copy{
from "../core/assets-raw/sprites/"
into "../core/assets-raw/sprites_out/"
}
//run generation task; generate all needed sprites
file(genFolder).mkdirs()
}
}
javaexec{
main = "io.anuke.mindustry.ImagePacker"
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = genFolder
}
//upscale icon sprites using different method, which requires an OpenGL context
javaexec{
if(System.getProperty("os.name").toLowerCase().contains("mac")){
jvmArgs "-XstartOnFirstThread"
}
jvmArgs("-Djava.awt.headless=true")
main = "io.anuke.mindustry.Upscaler"
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = "../core/assets-raw/sprites_out/ui/icons"
}
//antialias everything except UI elements (...for some reason)
fileTree(dir: '../core/assets-raw/sprites_out/', include: "**/*.png").visit{ file ->
if(file.isDirectory() || (file.toString().replace("\\", "/").contains("/ui/") && !file.toString().replace("\\", "/").contains("/icons/"))) return
task antialiasGen(){
doLast{
fileTree(dir: '../core/assets-raw/sprites_out/generated/', include: "**/*.png").visit{ file ->
antialias(file.file)
}
//pack normal sprites
TexturePacker.process("core/assets-raw/sprites_out/", "core/assets/sprites/", "sprites.atlas")
//delete old pack defintions
delete{
delete fileTree(dir: '../core/assets-raw/sprites_out/', include: '**/pack.json')
}
if(false){
//rename pack definitions, generate fallback 1024x sprites
copy{
from '../core/assets-raw/sprites_out/'
into '../core/assets-raw/sprites_out/'
include "**/*.json"
rename 'pack_fallback.json', "pack.json"
}
TexturePacker.process("core/assets-raw/sprites_out/", "core/assets/sprites/", "sprites_fallback.atlas")
}
}
}
@@ -356,6 +334,7 @@ task genSprites(dependsOn: classes, type: JavaExec){
main = "io.anuke.mindustry.ImagePacker"
classpath = sourceSets.main.runtimeClasspath
jvmArgs("-Djava.awt.headless=true")
standardInput = System.in
workingDir = genFolder
}

View File

@@ -0,0 +1,212 @@
package io.anuke.mindustry;
import io.anuke.arc.Core;
import io.anuke.arc.files.FileHandle;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.Pixmap;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.Fill;
import io.anuke.arc.graphics.glutils.FrameBuffer;
import io.anuke.arc.util.ScreenUtils;
import io.anuke.arc.util.Tmp;
public class SquareMarcher{
final int resolution;
FrameBuffer buffer;
SquareMarcher(int resolution){
this.resolution = resolution;
this.buffer = new FrameBuffer(resolution, resolution);
}
void render(Pixmap pixmap, FileHandle file){
boolean[][] grid = new boolean[pixmap.getWidth()][pixmap.getHeight()];
for(int x = 0; x < pixmap.getWidth(); x++){
for(int y = 0; y < pixmap.getHeight(); y++){
Tmp.c1.set(pixmap.getPixel(x, y));
grid[x][pixmap.getHeight() - 1 - y] = Tmp.c1.a > 0.01f;
}
}
float xscl = resolution / (float)pixmap.getWidth(), yscl = resolution / (float)pixmap.getHeight();
float scl = xscl;
Draw.flush();
Draw.proj().setOrtho(-xscl / 2f, -yscl / 2f, resolution, resolution);
buffer.begin();
Core.graphics.clear(Color.CLEAR);
Draw.color(Color.WHITE);
for(int x = -1; x < pixmap.getWidth(); x++){
for(int y = -1; y < pixmap.getHeight(); y++){
int index = index(x, y, pixmap.getWidth(), pixmap.getHeight(), grid);
float leftx = x * xscl, boty = y * yscl, rightx = x * xscl + xscl, topy = y * xscl + yscl,
midx = x * xscl + xscl / 2f, midy = y * yscl + yscl / 2f;
switch(index){
case 0:
break;
case 1:
Fill.tri(
leftx, midy,
leftx, topy,
midx, topy
);
break;
case 2:
Fill.tri(
midx, topy,
rightx, topy,
rightx, midy
);
break;
case 3:
Fill.crect(leftx, midy, scl, scl / 2f);
break;
case 4:
Fill.tri(
midx, boty,
rightx, boty,
rightx, midy
);
break;
case 5:
//ambiguous
//7
Fill.tri(
leftx, midy,
midx, midy,
midx, boty
);
//13
Fill.tri(
midx, topy,
midx, midy,
rightx, midy
);
Fill.crect(leftx, midy, scl / 2f, scl / 2f);
Fill.crect(midx, boty, scl / 2f, scl / 2f);
break;
case 6:
Fill.crect(midx, boty, scl / 2f, scl);
break;
case 7:
//invert triangle
Fill.tri(
leftx, midy,
midx, midy,
midx, boty
);
//3
Fill.crect(leftx, midy, scl, scl / 2f);
Fill.crect(midx, boty, scl / 2f, scl / 2f);
break;
case 8:
Fill.tri(
leftx, boty,
leftx, midy,
midx, boty
);
break;
case 9:
Fill.crect(leftx, boty, scl / 2f, scl);
break;
case 10:
//ambiguous
//11
Fill.tri(
midx, boty,
midx, midy,
rightx, midy
);
//14
Fill.tri(
leftx, midy,
midx, midy,
midx, topy
);
Fill.crect(midx, midy, scl / 2f, scl / 2f);
Fill.crect(leftx, boty, scl / 2f, scl / 2f);
break;
case 11:
//invert triangle
Fill.tri(
midx, boty,
midx, midy,
rightx, midy
);
//3
Fill.crect(leftx, midy, scl, scl / 2f);
Fill.crect(leftx, boty, scl / 2f, scl / 2f);
break;
case 12:
Fill.crect(leftx, boty, scl, scl / 2f);
break;
case 13:
//invert triangle
Fill.tri(
midx, topy,
midx, midy,
rightx, midy
);
//12
Fill.crect(leftx, boty, scl, scl / 2f);
Fill.crect(leftx, midy, scl / 2f, scl / 2f);
break;
case 14:
//invert triangle
Fill.tri(
leftx, midy,
midx, midy,
midx, topy
);
//12
Fill.crect(leftx, boty, scl, scl / 2f);
Fill.crect(midx, midy, scl / 2f, scl / 2f);
break;
case 15:
Fill.square(midx, midy, scl / 2f);
break;
}
}
}
Draw.flush();
ScreenUtils.saveScreenshot(file, 0, 0, resolution, resolution);
buffer.end();
}
int index(int x, int y, int w, int h, boolean[][] grid){
int botleft = sample(grid, x, y);
int botright = sample(grid, x + 1, y);
int topright = sample(grid, x + 1, y + 1);
int topleft = sample(grid, x, y + 1);
return (botleft << 3) | (botright << 2) | (topright << 1) | topleft;
}
int sample(boolean[][] grid, int x, int y){
return (x < 0 || y < 0 || x >= grid.length || y >= grid.length) ? 0 : grid[x][y] ? 1 : 0;
}
}

View File

@@ -0,0 +1,66 @@
package io.anuke.mindustry;
import io.anuke.arc.ApplicationListener;
import io.anuke.arc.Core;
import io.anuke.arc.backends.lwjgl3.Lwjgl3Application;
import io.anuke.arc.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import io.anuke.arc.files.FileHandle;
import io.anuke.arc.graphics.Pixmap;
import io.anuke.arc.graphics.Pixmaps;
import io.anuke.arc.graphics.g2d.SpriteBatch;
import io.anuke.arc.graphics.g2d.TextureAtlas;
import io.anuke.arc.util.Log;
import io.anuke.arc.util.Time;
public class Upscaler{
static Res[] resolutions = {
new Res(Vars.iconsizesmall, "-small"),
new Res(Vars.iconsizemed, "-med"),
new Res(Vars.iconsize, ""),
};
public static void main(String[] args){
new Lwjgl3Application(new ApplicationListener(){
@Override
public void init(){
scale();
}
}, new Lwjgl3ApplicationConfiguration(){{
setInitialVisible(false);
}});
}
static void scale(){
Core.batch = new SpriteBatch();
Core.atlas = new TextureAtlas();
Core.atlas.addRegion("white", Pixmaps.blankTextureRegion());
FileHandle file = Core.files.local("");
Log.info("Upscaling icons...");
Time.mark();
FileHandle[] list = file.list();
for(Res res : resolutions){
SquareMarcher marcher = new SquareMarcher(res.size);
for(FileHandle img : list){
if(img.extension().equals("png")){
marcher.render(new Pixmap(img), img.sibling(img.nameWithoutExtension() + res.suffix + ".png"));
}
}
}
Log.info("Done upscaling icons in &lm{0}&lgs.", Time.elapsed()/1000f);
Core.app.exit();
}
static class Res{
final int size;
final String suffix;
public Res(int size, String suffix){
this.size = size;
this.suffix = suffix;
}
}
}