Source reformat

This commit is contained in:
Anuken
2019-04-08 09:03:18 -04:00
parent 4a96b9bb00
commit b40beb0d1d
331 changed files with 2822 additions and 3274 deletions
+44 -44
View File
@@ -1,19 +1,19 @@
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
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 antialias = {File file ->
def antialias = { File file ->
if(!doAntialias || file.lastModified() <= 1000) return
def image = ImageIO.read(file)
@@ -28,7 +28,7 @@ def antialias = {File file ->
def sum = new Color()
def suma = new Color()
for (int x = 0; x < image.getWidth(); x++){
for(int x = 0; x < image.getWidth(); x++){
for(int y = 0; y < image.getHeight(); y++){
int A =
getRGB(x - 1, y + 1),
@@ -41,28 +41,28 @@ def antialias = {File file ->
H = getRGB(x, y - 1),
I = getRGB(x + 1, y - 1)
int p1=E, p2=E, p3=E, p4=E, p5=E, p6=E, p7=E, p8=E, p9=E
if (D==B && D!=H && B!=F) p1=D
if ((D==B && D!=H && B!=F && E!=C) || (B==F && B!=D && F!=H && E!=A)) p2=B
if (B==F && B!=D && F!=H) p3=F
if ((H==D && H!=F && D!=B && E!=A) || (D==B && D!=H && B!=F && E!=G)) p4=D
p5=E
if ((B==F && B!=D && F!=H && E!=I) || (F==H && F!=B && H!=D && E!=C)) p6=F
if (H==D && H!=F && D!=B) p7=D
if ((F==H && F!=B && H!=D && E!=G) || (H==D && H!=F && D!=B && E!=I)) p8=H
if (F==H && F!=B && H!=D) p9=F
int p1 = E, p2 = E, p3 = E, p4 = E, p5 = E, p6 = E, p7 = E, p8 = E, p9 = E
if(D == B && D != H && B != F) p1 = D
if((D == B && D != H && B != F && E != C) || (B == F && B != D && F != H && E != A)) p2 = B
if(B == F && B != D && F != H) p3 = F
if((H == D && H != F && D != B && E != A) || (D == B && D != H && B != F && E != G)) p4 = D
p5 = E
if((B == F && B != D && F != H && E != I) || (F == H && F != B && H != D && E != C)) p6 = F
if(H == D && H != F && D != B) p7 = D
if((F == H && F != B && H != D && E != G) || (H == D && H != F && D != B && E != I)) p8 = H
if(F == H && F != B && H != D) p9 = F
suma.set(0)
[p1, p2, p3, p4, p5, p6, p7, p8, p9].each{ val ->
Color.argb8888ToColor(color, val)
suma.r += color.r*color.a
suma.g += color.g*color.a
suma.b += color.b*color.a
suma.r += color.r * color.a
suma.g += color.g * color.a
suma.b += color.b * color.a
suma.a += color.a
}
suma.mul(suma.a <= 0.001f ? 0f : (float)(1f / suma.a))
suma.mul(suma.a <= 0.001f ? 0f : (float) (1f / suma.a))
float total = 0
sum.set(0)
@@ -70,7 +70,7 @@ def antialias = {File file ->
[p1, p2, p3, p4, p5, p6, p7, p8, p9].each{ val ->
Color.argb8888ToColor(color, val)
float a = color.a
color.lerp(suma, (float)(1f - a))
color.lerp(suma, (float) (1f - a))
sum.r += color.r
sum.g += color.g
sum.b += color.b
@@ -78,7 +78,7 @@ def antialias = {File file ->
total += 1f
}
sum.mul((float)(1f / total))
sum.mul((float) (1f / total))
int result = Color.argb8888(sum)
out.setRGB(x, y, result)
sum.set(0)
@@ -90,25 +90,25 @@ def antialias = {File file ->
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))
}
}
}
@@ -123,10 +123,10 @@ task swapColors(){
task scaleSprites4x(){
doLast{
fileTree(dir: '../core/assets-raw/sprites_out/', include: "**/*.png").visit { file ->
fileTree(dir: '../core/assets-raw/sprites_out/', include: "**/*.png").visit{ file ->
if(file.isDirectory() || file.toString().contains("/ui/")) return
for(int iteration in 0..1) {
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)
@@ -135,8 +135,8 @@ task scaleSprites4x(){
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++) {
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
@@ -148,16 +148,16 @@ task scaleSprites4x(){
F = getRGB(x + 1, y),
G = getRGB(x - 1, y - 1),
H = getRGB(x, y - 1),
I = getRGB(x + 1, 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
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)
@@ -183,7 +183,7 @@ task scaleSprites(){
into "../core/assets-raw/sprites_out/"
}
}
dependsOn 'scaleSprites4x'
}
@@ -202,7 +202,7 @@ task pack(){
TexturePacker.process("core/assets-raw/sprites_out/", "core/assets/sprites/", "sprites.atlas")
delete{
delete fileTree(dir: '../core/assets-raw/sprites_out/' , include: '**/pack.json')
delete fileTree(dir: '../core/assets-raw/sprites_out/', include: '**/pack.json')
}
copy{
@@ -214,12 +214,12 @@ task pack(){
TexturePacker.process("core/assets-raw/sprites_out/", "core/assets/sprites/", "sprites_fallback.atlas")
}
}
task cleanup(){
doLast {
delete {
doLast{
delete{
delete genFolder
delete outFolder
}
@@ -250,16 +250,16 @@ task antialiasGen(){
}
}
task genSprites(dependsOn: classes, type: JavaExec) {
task genSprites(dependsOn: classes, type: JavaExec){
finalizedBy 'antialiasGen'
main = "io.anuke.mindustry.ImagePacker"
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = genFolder
}
task updateBundles(dependsOn: classes, type: JavaExec) {
task updateBundles(dependsOn: classes, type: JavaExec){
file(genFolder).mkdirs()
main = "io.anuke.mindustry.BundleLauncher"
@@ -7,15 +7,10 @@ import io.anuke.arc.util.Log;
import io.anuke.arc.util.Strings;
import io.anuke.arc.util.io.PropertiesUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.io.*;
import java.nio.file.*;
public class BundleLauncher {
public class BundleLauncher{
public static void main(String[] args) throws Exception{
File file = new File("bundle.properties");
@@ -24,8 +19,9 @@ public class BundleLauncher {
Array<String> removals = new Array<>();
Files.walk(Paths.get("")).forEach(child -> {
try {
if (child.getFileName().toString().equals("bundle.properties") || Files.isDirectory(child) || child.toString().contains("output")) return;
try{
if(child.getFileName().toString().equals("bundle.properties") || Files.isDirectory(child) || child.toString().contains("output"))
return;
Log.info("Parsing bundle: {0}", child);
@@ -49,7 +45,7 @@ public class BundleLauncher {
for(String key : base.orderedKeys()){
if(!other.containsKey(key) || other.get(key).trim().isEmpty()){
other.put(key, base.get(key));
added ++;
added++;
Log.info("&lc- Adding missing key '{0}'...", key);
}
}
@@ -70,7 +66,7 @@ public class BundleLauncher {
Files.write(child, result.toString().getBytes(Strings.utf8));
}catch (IOException e){
}catch(IOException e){
throw new RuntimeException(e);
}
});
+17 -19
View File
@@ -6,10 +6,7 @@ import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Log;
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.type.*;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Block.Icon;
import io.anuke.mindustry.world.blocks.Floor;
@@ -22,7 +19,7 @@ import java.nio.file.Paths;
import static io.anuke.mindustry.Vars.content;
import static io.anuke.mindustry.Vars.tilesize;
public class Generators {
public class Generators{
public static void generate(){
@@ -54,7 +51,7 @@ public class Generators {
Image last = null;
if(block.outlineIcon){
int radius = 3;
GenRegion region = (GenRegion)regions[regions.length-1];
GenRegion region = (GenRegion)regions[regions.length - 1];
Image base = ImagePacker.get(region);
Image out = last = new Image(region.getWidth(), region.getHeight());
for(int x = 0; x < out.width(); x++){
@@ -93,7 +90,7 @@ public class Generators {
int i = 0;
for(TextureRegion region : regions){
i ++;
i++;
if(i != regions.length || last == null){
image.draw(region);
}else{
@@ -163,7 +160,7 @@ public class Generators {
image.drawCenter(mech.region);
}
int off = image.width()/2 - mech.weapon.region.getWidth()/2;
int off = image.width() / 2 - mech.weapon.region.getWidth() / 2;
image.draw(mech.weapon.region, -(int)mech.weaponOffsetX + off, (int)mech.weaponOffsetY + off, false, false);
image.draw(mech.weapon.region, (int)mech.weaponOffsetX + off, (int)mech.weaponOffsetY + off, true, false);
@@ -189,8 +186,8 @@ public class Generators {
for(boolean b : Mathf.booleans){
image.draw(type.weapon.region,
(int)(Mathf.sign(b) * type.weapon.width / Draw.scl + image.width()/2 - type.weapon.region.getWidth()/2),
(int)(type.weaponOffsetY / Draw.scl + image.height()/2f - type.weapon.region.getHeight()/2f),
(int)(Mathf.sign(b) * type.weapon.width / Draw.scl + image.width() / 2 - type.weapon.region.getWidth() / 2),
(int)(type.weaponOffsetY / Draw.scl + image.height() / 2f - type.weapon.region.getHeight() / 2f),
b, false);
}
@@ -205,15 +202,15 @@ public class Generators {
OreBlock ore = (OreBlock)block;
Item item = ore.itemDrop;
for (int i = 0; i < 3; i++) {
for(int i = 0; i < 3; i++){
//get base image to draw on
Image image = new Image(32, 32);
Image shadow = ImagePacker.get(item.name + (i+1));
Image shadow = ImagePacker.get(item.name + (i + 1));
int offset = image.width()/tilesize;
int offset = image.width() / tilesize;
for (int x = 0; x < image.width(); x++) {
for (int y = offset; y < image.height(); y++) {
for(int x = 0; x < image.width(); x++){
for(int y = offset; y < image.height(); y++){
Color color = shadow.getColor(x, y - offset);
//draw semi transparent background
@@ -224,9 +221,9 @@ public class Generators {
}
}
image.draw(ImagePacker.get(item.name + (i+1)));
image.save("../blocks/environment/ore-" + item.name + (i+1));
image.save("../editor/editor-ore-" + item.name + (i+1));
image.draw(ImagePacker.get(item.name + (i + 1)));
image.save("../blocks/environment/ore-" + item.name + (i + 1));
image.save("../editor/editor-ore-" + item.name + (i + 1));
//save icons
image.save(block.name + "-icon-full");
@@ -263,7 +260,8 @@ public class Generators {
result.save("../blocks/environment/" + floor.name + "-edge");
}catch(Exception ignored){}
}catch(Exception ignored){
}
}
});
}
+19 -19
View File
@@ -12,7 +12,7 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
class Image {
class Image{
private static ArrayList<Image> toDispose = new ArrayList<>();
private BufferedImage image;
@@ -63,31 +63,31 @@ class Image {
graphics.fillRect(x, y, 1, 1);
}
/**Draws a region at the top left corner.*/
/** Draws a region at the top left corner. */
void draw(TextureRegion region){
draw(region, 0, 0, false, false);
}
/**Draws a region at the center.*/
/** Draws a region at the center. */
void drawCenter(TextureRegion region){
draw(region, (width() - region.getWidth())/2, (height() - region.getHeight())/2, false, false);
draw(region, (width() - region.getWidth()) / 2, (height() - region.getHeight()) / 2, false, false);
}
/**Draws a region at the center.*/
/** Draws a region at the center. */
void drawCenter(TextureRegion region, boolean flipx, boolean flipy){
draw(region, (width() - region.getWidth())/2, (height() - region.getHeight())/2, flipx, flipy);
draw(region, (width() - region.getWidth()) / 2, (height() - region.getHeight()) / 2, flipx, flipy);
}
void drawScaled(Image image){
graphics.drawImage(image.image.getScaledInstance(width(), height(), java.awt.Image.SCALE_AREA_AVERAGING), 0, 0, width(), height(), null);
}
/**Draws an image at the top left corner.*/
/** Draws an image at the top left corner. */
void draw(Image image){
draw(image, 0, 0);
}
/**Draws an image at the coordinates specified.*/
/** Draws an image at the coordinates specified. */
void draw(Image image, int x, int y){
graphics.drawImage(image.image, x, y, null);
}
@@ -102,21 +102,21 @@ class Image {
int ofx = 0, ofy = 0;
graphics.drawImage(ImagePacker.get(region).image,
x, y,
x + region.getWidth(),
y + region.getHeight(),
(flipx ? region.getWidth() : 0) + ofx,
(flipy ? region.getHeight() : 0) + ofy,
(flipx ? 0 : region.getWidth()) + ofx,
(flipy ? 0 : region.getHeight()) + ofy,
null);
x, y,
x + region.getWidth(),
y + region.getHeight(),
(flipx ? region.getWidth() : 0) + ofx,
(flipy ? region.getHeight() : 0) + ofy,
(flipx ? 0 : region.getWidth()) + ofx,
(flipy ? 0 : region.getHeight()) + ofy,
null);
}
/** @param name Name of texture file name to create, without any extensions.*/
/** @param name Name of texture file name to create, without any extensions. */
void save(String name){
try {
try{
ImageIO.write(image, "png", new File(name + ".png"));
}catch (IOException e){
}catch(IOException e){
throw new RuntimeException(e);
}
}
+5 -11
View File
@@ -2,23 +2,17 @@ package io.anuke.mindustry;
import io.anuke.arc.Core;
import io.anuke.arc.collection.ObjectMap;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.TextureAtlas;
import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.graphics.g2d.TextureAtlas.AtlasRegion;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.util.Log;
import io.anuke.arc.util.*;
import io.anuke.arc.util.Log.LogHandler;
import io.anuke.arc.util.Log.NoopLogHandler;
import io.anuke.arc.util.Strings;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.core.ContentLoader;
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;
import java.nio.file.*;
public class ImagePacker{
static ObjectMap<String, TextureRegion> regionCache = new ObjectMap<>();
@@ -91,12 +85,12 @@ public class ImagePacker{
}
@Override
public boolean has(String s) {
public boolean has(String s){
return regionCache.containsKey(s);
}
};
Draw.scl = 1f/Core.atlas.find("scale_marker").getWidth();
Draw.scl = 1f / Core.atlas.find("scale_marker").getWidth();
Time.mark();
Generators.generate();