Merged 4x graphics

This commit is contained in:
Anuken
2018-12-28 23:46:09 -05:00
137 changed files with 2985 additions and 3045 deletions
Binary file not shown.
+115 -27
View File
@@ -1,36 +1,40 @@
apply plugin: "java"
sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = ["src/"]
sourceSets.main.java.srcDirs = [ "src/" ]
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.tools.texturepacker.TexturePacker
import javax.imageio.ImageIO
import java.awt.image.BufferedImage
def textureFolder = "../core/assets-raw/sprites/generated/"
def outFolder = "../core/assets-raw/sprites_out/"
def genFolder = "../core/assets-raw/sprites_out/generated/"
def scaling = "XBRZ 4x"
def do4 = true
task swapColors(){
doLast{
if(project.hasProperty("colors")){
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])) }
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 ->
fileTree(dir: '../core/assets-raw/sprites', include: "**/*.png").visit { file ->
if(file.isDirectory()) return
swaps++
swaps ++
def img = ImageIO.read(file.file)
for(x in (0..img.getWidth() - 1)){
for(y in (0..img.getHeight() - 1)){
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))
img.setRGB(x, y, (int)map.get(c))
}
}
}
@@ -43,45 +47,129 @@ task swapColors(){
}
}
task pack(){
dependsOn 'prePack'
task scaleSprites4x(){
doLast{
TexturePacker.process("core/assets-raw/sprites/", "core/assets/sprites/", "sprites.atlas")
fileTree(dir: '../core/assets-raw/sprites_out/', include: "**/*.png").visit { file ->
if(file.isDirectory() || file.toString().contains("/ui/")) return;
delete{
delete textureFolder
for(int iteration in 0..1) {
def image = ImageIO.read(file.file)
def scaled = new BufferedImage(image.getWidth() * 2, image.getHeight() * 2, BufferedImage.TYPE_INT_ARGB)
def getRGB = { int ix, int iy ->
return image.getRGB(Math.max(Math.min(ix, image.width - 1), 0), Math.max(Math.min(iy, image.height - 1), 0))
}
for (int x = 0; x < image.getWidth(); x++) {
for (int y = 0; y < image.getHeight(); y++) {
int p = image.getRGB(x, y)
int p1 = p, p2 = p, p3 = p, p4 = p
int A = getRGB(x - 1, y + 1),
B = getRGB(x, y + 1),
C = getRGB(x + 1, y + 1),
D = getRGB(x - 1, y),
E = getRGB(x, y),
F = getRGB(x + 1, y),
G = getRGB(x - 1, y - 1),
H = getRGB(x, y - 1),
I = getRGB(x + 1, y - 1),
J = getRGB(x, y + 2),
K = getRGB(x - 2, y),
L = getRGB(x + 2, y),
M = getRGB(x, y - 2);
if (B==D && B!=F && D!=H && (E!=A || E==C || E==G || A==J || A==K)) p1 = B
if (B==F & B!=D & F!=H && (E!=C || E==A || E==I || C==J || C==L)) p2 = F
if (D==H & B!=D & F!=H && (E!=G || E==A || E==I || G==K || G==M)) p3 = D
if (F==H & B!=F & D!=H && (E!=I || E==C || E==G || I==L || I==M)) p4 = H
scaled.setRGB(x * 2, y * 2 + 1, p1)
scaled.setRGB(x * 2 + 1, y * 2 + 1, p2)
scaled.setRGB(x * 2, y * 2, p3)
scaled.setRGB(x * 2 + 1, y * 2, p4)
}
}
ImageIO.write(scaled, "png", file.file)
}
}
}
}
task prePack(){
dependsOn "cleanup"
task scaleSprites(){
finalizedBy 'genSprites'
if(do4){
dependsOn 'scaleSprites4x'
}else{
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'
finalizedBy 'cleanup'
doLast{
TexturePacker.process("core/assets-raw/sprites/", "core/assets/sprites/", "sprites.atlas")
}
finalizedBy 'generateSprites'
copy{
from "../core/assets-raw/sprites_replacement/"
into "../core/assets-raw/sprites_out/"
}
TexturePacker.process("core/assets-raw/sprites_out/", "core/assets/sprites/", "sprites.atlas")
}
}
task cleanup(){
delete{
delete textureFolder
doLast {
delete {
delete genFolder
delete outFolder
}
}
}
task generateSprites(dependsOn: classes, type: JavaExec){
file(textureFolder).mkdirs()
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 = textureFolder
workingDir = genFolder
}
task updateBundles(dependsOn: classes, type: JavaExec){
file(textureFolder).mkdirs()
task updateBundles(dependsOn: classes, type: JavaExec) {
file(genFolder).mkdirs()
main = "io.anuke.mindustry.BundleLauncher"
classpath = sourceSets.main.runtimeClasspath
+5 -2
View File
@@ -6,11 +6,14 @@ import io.anuke.arc.graphics.g2d.TextureRegion;
public class GenRegion extends AtlasRegion{
public String name;
public boolean invalid;
public ImageContext context;
public GenRegion(String name){
this.name = name;
}
public static void validate(TextureRegion region){
if(((GenRegion)region).invalid){
((GenRegion) region).context.err("Region does not exist: {0}", ((GenRegion)region).name);
ImageContext.err("Region does not exist: {0}", ((GenRegion)region).name);
}
}
}
+22 -41
View File
@@ -19,7 +19,7 @@ public class Generators {
public static void generate(ImageContext context){
context.generate("block-icons", () -> {
ImageContext.generate("block-icons", () -> {
for(Block block : content.blocks()){
TextureRegion[] regions = block.getBlockIcon();
@@ -28,41 +28,20 @@ public class Generators {
}
if(block.turretIcon){
Color color = Color.ROYAL;
Image image = context.get(block.name);
Image image = ImageContext.get(block.name);
Image read = context.create(image.width(), image.height());
Image read = ImageContext.create(image.width(), image.height());
read.draw(image);
for (int x = 0; x < image.width(); x++) {
for (int y = 0; y < image.height(); y++) {
if(read.isEmpty(x, y) &&
(!read.isEmpty(x, y + 1) || !read.isEmpty(x, y - 1) || !read.isEmpty(x + 1, y) || !read.isEmpty(x - 1, y))){
image.draw(x, y, color);
}
}
}
Image base = context.get("block-" + block.size);
Image top = context.get("block-" + block.size + "-top");
for (int x = 0; x < base.width(); x++) {
for (int y = 0; y < base.height(); y++) {
Color result = top.getColor(x, y);
if(result.a > 0.01f){
result.lerp(color, 0.45f);
base.draw(x, y, result);
}
}
}
Image base = ImageContext.get("block-" + block.size);
base.draw(image);
base.save("block-icon-" + block.name);
}else {
Image image = context.get(regions[0]);
Image image = ImageContext.get(regions[0]);
for (TextureRegion region : regions) {
image.draw(region);
@@ -73,13 +52,13 @@ public class Generators {
}
});
context.generate("mech-icons", () -> {
ImageContext.generate("mech-icons", () -> {
for(Mech mech : content.<Mech>getBy(ContentType.mech)){
mech.load();
mech.weapon.load();
Image image = context.get(mech.region);
Image image = ImageContext.get(mech.region);
if(!mech.flying){
image.drawCenter(mech.baseRegion);
@@ -98,13 +77,13 @@ public class Generators {
}
});
context.generate("unit-icons", () -> {
ImageContext.generate("unit-icons", () -> {
for(UnitType type : content.<UnitType>getBy(ContentType.unit)){
type.load();
type.weapon.load();
Image image = context.get(type.region);
Image image = ImageContext.get(type.region);
if(!type.isFlying){
image.draw(type.baseRegion);
@@ -126,9 +105,9 @@ public class Generators {
}
});
context.generate("liquid-icons", () -> {
ImageContext.generate("liquid-icons", () -> {
for(Liquid liquid : content.liquids()){
Image image = context.get("liquid-icon");
Image image = ImageContext.get("liquid-icon");
for (int x = 0; x < image.width(); x++) {
for (int y = 0; y < image.height(); y++) {
Color color = image.getColor(x, y);
@@ -141,17 +120,17 @@ public class Generators {
}
});
context.generate("block-edges", () -> {
ImageContext.generate("block-edges", () -> {
for(Block block : content.blocks()){
if(!(block instanceof Floor)) continue;
Floor floor = (Floor)block;
if(floor.getIcon().length > 0 && !Core.atlas.has(floor.name + "-cliff-side")){
Image floori = context.get(floor.getIcon()[0]);
Image floori = ImageContext.get(floor.getIcon()[0]);
Color color = floori.getColor(0, 0).mul(1.3f, 1.3f, 1.3f, 1f);
String[] names = {"cliff-edge-2", "cliff-edge", "cliff-edge-1", "cliff-side"};
for(String str : names){
Image image = context.get("generic-" + str);
Image image = ImageContext.get("generic-" + str);
for(int x = 0; x < image.width(); x++){
for(int y = 0; y < image.height(); y++){
@@ -168,7 +147,7 @@ public class Generators {
}
});
context.generate("ore-icons", () -> {
ImageContext.generate("ore-icons", () -> {
for(Block block : content.blocks()){
if(!(block instanceof OreBlock)) continue;
@@ -178,12 +157,14 @@ public class Generators {
for (int i = 0; i < 3; i++) {
//get base image to draw on
Image image = context.get(base.name + (i+1));
Image shadow = context.get(item.name + (i+1));
Image image = ImageContext.get(base.name + (i+1));
Image shadow = ImageContext.get(item.name + (i+1));
int offset = 3;
for (int x = 0; x < image.width(); x++) {
for (int y = 1; y < image.height(); y++) {
Color color = shadow.getColor(x, y - 1);
for (int y = offset; y < image.height(); y++) {
Color color = shadow.getColor(x, y - offset);
//draw semi transparent background
if(color.a > 0.001f){
@@ -193,7 +174,7 @@ public class Generators {
}
}
image.draw(context.get(item.name + (i+1)));
image.draw(ImageContext.get(item.name + (i+1)));
image.save("ore-" + item.name + "-" + base.name + (i+1));
}
+14 -15
View File
@@ -14,27 +14,26 @@ import java.util.ArrayList;
public class Image {
private static ArrayList<Image> toDispose = new ArrayList<>();
private BufferedImage atlas;
private BufferedImage image;
private Graphics2D graphics;
private Color color = new Color();
public Image(BufferedImage atlas, TextureRegion region){
this(atlas, region.getWidth(), region.getHeight());
draw(region);
public Image(TextureRegion region){
this(ImageContext.buf(region));
}
public Image(BufferedImage atlas, int width, int height){
this.atlas = atlas;
this.image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
public Image(BufferedImage src){
this.image = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB);
this.graphics = image.createGraphics();
this.graphics.drawImage(src, 0, 0, null);
toDispose.add(this);
}
public Image(int width, int height){
this(new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB));
}
public int width(){
return image.getWidth();
}
@@ -106,14 +105,14 @@ public class Image {
y = 0;
}
graphics.drawImage(atlas,
graphics.drawImage(ImageContext.get(region).image,
x, y,
x + region.getWidth(),
y + region.getHeight(),
(flipx ? region.getX() + region.getWidth() : region.getX()) + ofx,
(flipy ? region.getY() + region.getHeight() : region.getY()) + ofy,
(flipx ? region.getX() : region.getX() + region.getWidth()) + ofx,
(flipy ? region.getY() : region.getY() + region.getHeight()) + ofy,
(flipx ? region.getWidth() : 0) + ofx,
(flipy ? region.getHeight() : 0) + ofy,
(flipx ? 0 : region.getWidth()) + ofx,
(flipy ? 0 : region.getHeight()) + ofy,
null);
}
+50 -45
View File
@@ -12,70 +12,73 @@ import io.anuke.arc.util.Log;
import io.anuke.arc.util.Log.LogHandler;
import io.anuke.arc.util.Log.NoopLogHandler;
import io.anuke.arc.util.Time;
import io.anuke.arc.Core;
import io.anuke.mindustry.core.ContentLoader;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class ImageContext {
private BufferedImage image;
static ObjectMap<String, TextureRegion> regionCache = new ObjectMap<>();
static ObjectMap<TextureRegion, BufferedImage> imageCache = new ObjectMap<>();
public void load() throws IOException{
static void load() throws IOException{
Log.setLogger(new NoopLogHandler());
Vars.content = new ContentLoader();
Vars.content.load();
Log.setLogger(new LogHandler());
String spritesFolder = new File("../../../assets/sprites").getAbsolutePath();
TextureAtlasData data = new TextureAtlasData(new FileHandle(spritesFolder + "/sprites.atlas"),
new FileHandle(spritesFolder), false);
Files.walk(Paths.get("../../../assets-raw/sprites_out")).forEach(path -> {
try{
if(Files.isDirectory(path)) return;
ObjectMap<String, AtlasRegion> regionCache = new ObjectMap<>();
String fname = path.getFileName().toString();
fname = fname.substring(0, fname.length() - 4);
for(Region region : data.getRegions()){
int x = region.left, y = region.top, width = region.width, height = region.height;
BufferedImage image = ImageIO.read(path.toFile());
GenRegion region = new GenRegion(fname){
regionCache.put(region.name, new GenRegion(){
{
name = region.name;
context = ImageContext.this;
}
@Override
public int getX(){
return 0;
}
@Override
public int getX(){
return x;
}
@Override
public int getY(){
return 0;
}
@Override
public int getY(){
return y;
}
@Override
public int getWidth(){
return image.getWidth();
}
@Override
public int getWidth(){
return width;
}
@Override
public int getHeight(){
return image.getHeight();
}
};
@Override
public int getHeight(){
return height;
}
});
}
regionCache.put(fname, region);
imageCache.put(region, image);
}catch(IOException e){
e.printStackTrace();
}
});
Core.atlas = new TextureAtlas(){
@Override
public AtlasRegion find(String name){
if(!regionCache.containsKey(name)){
GenRegion region = new GenRegion();
region.name = name;
region.context = ImageContext.this;
GenRegion region = new GenRegion(name);
region.invalid = true;
return region;
}
return regionCache.get(name);
return (AtlasRegion)regionCache.get(name);
}
@Override
@@ -83,31 +86,33 @@ public class ImageContext {
return regionCache.containsKey(s);
}
};
image = ImageIO.read(new File(spritesFolder + "/sprites.png"));
}
public void generate(String name, Runnable run){
static void generate(String name, Runnable run){
Time.mark();
run.run();
Log.info("&ly[Generator]&lc Time to generate &lm{0}&lc: &lg{1}&lcms", name, Time.elapsed());
}
public Image create(int width, int height){
return new Image(image, width, height);
static BufferedImage buf(TextureRegion region){
return imageCache.get(region);
}
public Image get(String name){
static Image create(int width, int height){
return new Image(width, height);
}
static Image get(String name){
return get(Core.atlas.find(name));
}
public Image get(TextureRegion region){
static Image get(TextureRegion region){
GenRegion.validate(region);
return new Image(image, region);
return new Image(imageCache.get(region));
}
public void err(String message, Object... args){
static void err(String message, Object... args){
Log.err(message, args);
System.exit(-1);
}