Balancing / Bugfixes / Badly antialiased turret outlines
This commit is contained in:
@@ -2,16 +2,21 @@ package io.anuke.mindustry;
|
||||
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Log;
|
||||
import io.anuke.mindustry.type.UnitType;
|
||||
import io.anuke.mindustry.ImagePacker.GenRegion;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.Mech;
|
||||
import io.anuke.mindustry.type.UnitType;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Block.Icon;
|
||||
import io.anuke.mindustry.world.blocks.Floor;
|
||||
import io.anuke.mindustry.world.blocks.OreBlock;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
@@ -21,6 +26,7 @@ public class Generators {
|
||||
|
||||
ImagePacker.generate("block-icons", () -> {
|
||||
Image colors = new Image(256, 1);
|
||||
Color outlineColor = new Color(0, 0, 0, 0.3f);
|
||||
|
||||
for(Block block : content.blocks()){
|
||||
TextureRegion[] regions = block.getGeneratedIcons();
|
||||
@@ -47,6 +53,45 @@ public class Generators {
|
||||
scaled.save(block.name + "-icon-" + icon.name());
|
||||
}
|
||||
|
||||
if(block.outlineIcon){
|
||||
int radius = 3;
|
||||
GenRegion region = (GenRegion)regions[regions.length-1];
|
||||
Image base = ImagePacker.get(region);
|
||||
Image out = new Image(region.getWidth(), region.getHeight());
|
||||
for(int x = 0; x < out.width(); x++){
|
||||
for(int y = 0; y < out.height(); y++){
|
||||
|
||||
Color color = base.getColor(x, y);
|
||||
if(color.a >= 0.01f){
|
||||
out.draw(x, y, color);
|
||||
}else{
|
||||
boolean found = false;
|
||||
outer:
|
||||
for(int rx = -radius; rx <= radius; rx++){
|
||||
for(int ry = -radius; ry <= radius; ry++){
|
||||
if(Mathf.dst(rx, ry) <= radius && base.getColor(rx + x, ry + y).a > 0.01f){
|
||||
found = true;
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(found){
|
||||
out.draw(x, y, outlineColor);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
Files.delete(region.path);
|
||||
}catch(IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
out.save(block.name);
|
||||
}
|
||||
|
||||
Color average = new Color();
|
||||
for(int x = 0; x < image.width(); x++){
|
||||
for(int y = 0; y < image.height(); y++){
|
||||
|
||||
@@ -52,6 +52,7 @@ class Image {
|
||||
}
|
||||
|
||||
Color getColor(int x, int y){
|
||||
if(!Structs.inBounds(x, y, width(), height())) return color.set(0, 0, 0, 0);
|
||||
int i = image.getRGB(x, y);
|
||||
Color.argb8888ToColor(color, i);
|
||||
return color;
|
||||
|
||||
@@ -16,6 +16,7 @@ import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class ImagePacker{
|
||||
@@ -38,7 +39,7 @@ public class ImagePacker{
|
||||
fname = fname.substring(0, fname.length() - 4);
|
||||
|
||||
BufferedImage image = ImageIO.read(path.toFile());
|
||||
GenRegion region = new GenRegion(fname){
|
||||
GenRegion region = new GenRegion(fname, path){
|
||||
|
||||
@Override
|
||||
public int getX(){
|
||||
@@ -73,7 +74,7 @@ public class ImagePacker{
|
||||
@Override
|
||||
public AtlasRegion find(String name){
|
||||
if(!regionCache.containsKey(name)){
|
||||
GenRegion region = new GenRegion(name);
|
||||
GenRegion region = new GenRegion(name, null);
|
||||
region.invalid = true;
|
||||
return region;
|
||||
}
|
||||
@@ -136,9 +137,11 @@ public class ImagePacker{
|
||||
static class GenRegion extends AtlasRegion{
|
||||
String name;
|
||||
boolean invalid;
|
||||
Path path;
|
||||
|
||||
GenRegion(String name){
|
||||
GenRegion(String name, Path path){
|
||||
this.name = name;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
static void validate(TextureRegion region){
|
||||
|
||||
Reference in New Issue
Block a user