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

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);
}
}
}

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));
}

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);
}

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);
}