mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-13 12:16:53 +07:00
Packer reorganization
This commit is contained in:
parent
8b791b68d3
commit
1d8efe5f9d
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Before Width: | Height: | Size: 193 KiB After Width: | Height: | Size: 338 KiB |
@ -103,7 +103,7 @@ task scaleSprites(){
|
||||
|
||||
task pack(){
|
||||
dependsOn 'cleanSprites', 'scaleSprites'
|
||||
//finalizedBy 'cleanup'
|
||||
finalizedBy 'cleanup'
|
||||
|
||||
doLast{
|
||||
|
||||
@ -142,7 +142,7 @@ task cleanSprites(){
|
||||
}
|
||||
|
||||
task genSprites(dependsOn: classes, type: JavaExec) {
|
||||
main = "io.anuke.mindustry.PackerLauncher"
|
||||
main = "io.anuke.mindustry.ImagePacker"
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
standardInput = System.in
|
||||
workingDir = genFolder
|
||||
|
@ -1,19 +0,0 @@
|
||||
package io.anuke.mindustry;
|
||||
|
||||
import io.anuke.arc.graphics.g2d.TextureAtlas.AtlasRegion;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
|
||||
public class GenRegion extends AtlasRegion{
|
||||
public String name;
|
||||
public boolean invalid;
|
||||
|
||||
public GenRegion(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static void validate(TextureRegion region){
|
||||
if(((GenRegion)region).invalid){
|
||||
ImageContext.err("Region does not exist: {0}", ((GenRegion)region).name);
|
||||
}
|
||||
}
|
||||
}
|
@ -15,9 +15,9 @@ import static io.anuke.mindustry.Vars.content;
|
||||
|
||||
public class Generators {
|
||||
|
||||
public static void generate(ImageContext context){
|
||||
public static void generate(){
|
||||
|
||||
ImageContext.generate("block-icons", () -> {
|
||||
ImagePacker.generate("block-icons", () -> {
|
||||
for(Block block : content.blocks()){
|
||||
TextureRegion[] regions = block.getBlockIcon();
|
||||
|
||||
@ -27,19 +27,19 @@ public class Generators {
|
||||
|
||||
if(block.turretIcon){
|
||||
|
||||
Image image = ImageContext.get(block.name);
|
||||
Image image = ImagePacker.get(block.name);
|
||||
|
||||
Image read = ImageContext.create(image.width(), image.height());
|
||||
Image read = ImagePacker.create(image.width(), image.height());
|
||||
read.draw(image);
|
||||
|
||||
Image base = ImageContext.get("block-" + block.size);
|
||||
Image base = ImagePacker.get("block-" + block.size);
|
||||
|
||||
base.draw(image);
|
||||
|
||||
base.save("block-icon-" + block.name);
|
||||
}else {
|
||||
|
||||
Image image = ImageContext.get(regions[0]);
|
||||
Image image = ImagePacker.get(regions[0]);
|
||||
|
||||
for (TextureRegion region : regions) {
|
||||
image.draw(region);
|
||||
@ -50,13 +50,13 @@ public class Generators {
|
||||
}
|
||||
});
|
||||
|
||||
ImageContext.generate("mech-icons", () -> {
|
||||
ImagePacker.generate("mech-icons", () -> {
|
||||
for(Mech mech : content.<Mech>getBy(ContentType.mech)){
|
||||
|
||||
mech.load();
|
||||
mech.weapon.load();
|
||||
|
||||
Image image = ImageContext.get(mech.region);
|
||||
Image image = ImagePacker.get(mech.region);
|
||||
|
||||
if(!mech.flying){
|
||||
image.drawCenter(mech.baseRegion);
|
||||
@ -75,13 +75,13 @@ public class Generators {
|
||||
}
|
||||
});
|
||||
|
||||
ImageContext.generate("unit-icons", () -> {
|
||||
ImagePacker.generate("unit-icons", () -> {
|
||||
for(UnitType type : content.<UnitType>getBy(ContentType.unit)){
|
||||
|
||||
type.load();
|
||||
type.weapon.load();
|
||||
|
||||
Image image = ImageContext.get(type.region);
|
||||
Image image = ImagePacker.get(type.region);
|
||||
|
||||
if(!type.isFlying){
|
||||
image.draw(type.baseRegion);
|
||||
@ -103,17 +103,17 @@ public class Generators {
|
||||
}
|
||||
});
|
||||
|
||||
ImageContext.generate("block-edges", () -> {
|
||||
ImagePacker.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 = ImageContext.get(floor.getIcon()[0]);
|
||||
Image floori = ImagePacker.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 = ImageContext.get("generic-" + str);
|
||||
Image image = ImagePacker.get("generic-" + str);
|
||||
|
||||
for(int x = 0; x < image.width(); x++){
|
||||
for(int y = 0; y < image.height(); y++){
|
||||
@ -130,7 +130,7 @@ public class Generators {
|
||||
}
|
||||
});
|
||||
|
||||
ImageContext.generate("ore-icons", () -> {
|
||||
ImagePacker.generate("ore-icons", () -> {
|
||||
for(Block block : content.blocks()){
|
||||
if(!(block instanceof OreBlock)) continue;
|
||||
|
||||
@ -140,8 +140,8 @@ public class Generators {
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
//get base image to draw on
|
||||
Image image = ImageContext.get(base.name + (i+1));
|
||||
Image shadow = ImageContext.get(item.name + (i+1));
|
||||
Image image = ImagePacker.get(base.name + (i+1));
|
||||
Image shadow = ImagePacker.get(item.name + (i+1));
|
||||
|
||||
int offset = 3;
|
||||
|
||||
@ -157,7 +157,7 @@ public class Generators {
|
||||
}
|
||||
}
|
||||
|
||||
image.draw(ImageContext.get(item.name + (i+1)));
|
||||
image.draw(ImagePacker.get(item.name + (i+1)));
|
||||
image.save("ore-" + item.name + "-" + base.name + (i+1));
|
||||
}
|
||||
|
||||
|
@ -3,11 +3,12 @@ package io.anuke.mindustry;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.util.Structs;
|
||||
import io.anuke.mindustry.ImagePacker.GenRegion;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.awt.Graphics2D;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -19,7 +20,7 @@ public class Image {
|
||||
private Color color = new Color();
|
||||
|
||||
public Image(TextureRegion region){
|
||||
this(ImageContext.buf(region));
|
||||
this(ImagePacker.buf(region));
|
||||
}
|
||||
|
||||
public Image(BufferedImage src){
|
||||
@ -105,7 +106,7 @@ public class Image {
|
||||
y = 0;
|
||||
}
|
||||
|
||||
graphics.drawImage(ImageContext.get(region).image,
|
||||
graphics.drawImage(ImagePacker.get(region).image,
|
||||
x, y,
|
||||
x + region.getWidth(),
|
||||
y + region.getHeight(),
|
||||
|
@ -2,17 +2,13 @@ package io.anuke.mindustry;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.collection.ObjectMap;
|
||||
import io.anuke.arc.files.FileHandle;
|
||||
import io.anuke.arc.graphics.g2d.TextureAtlas;
|
||||
import io.anuke.arc.graphics.g2d.TextureAtlas.AtlasRegion;
|
||||
import io.anuke.arc.graphics.g2d.TextureAtlas.TextureAtlasData;
|
||||
import io.anuke.arc.graphics.g2d.TextureAtlas.TextureAtlasData.Region;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
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;
|
||||
@ -21,11 +17,13 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class ImageContext {
|
||||
public class ImagePacker{
|
||||
static ObjectMap<String, TextureRegion> regionCache = new ObjectMap<>();
|
||||
static ObjectMap<TextureRegion, BufferedImage> imageCache = new ObjectMap<>();
|
||||
|
||||
static void load() throws IOException{
|
||||
public static void main(String[] args) throws IOException{
|
||||
Vars.headless = true;
|
||||
|
||||
Log.setLogger(new NoopLogHandler());
|
||||
Vars.content = new ContentLoader();
|
||||
Vars.content.load();
|
||||
@ -86,6 +84,12 @@ public class ImageContext {
|
||||
return regionCache.containsKey(s);
|
||||
}
|
||||
};
|
||||
|
||||
Time.mark();
|
||||
Generators.generate();
|
||||
Log.info("&ly[Generator]&lc Total time to generate: &lg{0}&lcms", Time.elapsed());
|
||||
Log.info("&ly[Generator]&lc Total images created: &lg{0}", Image.total());
|
||||
Image.dispose();
|
||||
}
|
||||
|
||||
static void generate(String name, Runnable run){
|
||||
@ -116,4 +120,19 @@ public class ImageContext {
|
||||
Log.err(message, args);
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
static class GenRegion extends AtlasRegion{
|
||||
String name;
|
||||
boolean invalid;
|
||||
|
||||
GenRegion(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
static void validate(TextureRegion region){
|
||||
if(((GenRegion)region).invalid){
|
||||
ImagePacker.err("Region does not exist: {0}", ((GenRegion)region).name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package io.anuke.mindustry;
|
||||
|
||||
import io.anuke.arc.util.Log;
|
||||
import io.anuke.arc.util.Time;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class PackerLauncher {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
Vars.headless = true;
|
||||
ImageContext context = new ImageContext();
|
||||
context.load();
|
||||
Time.mark();
|
||||
Generators.generate(context);
|
||||
Log.info("&ly[Generator]&lc Total time to generate: &lg{0}&lcms", Time.elapsed());
|
||||
Log.info("&ly[Generator]&lc Total images created: &lg{0}", Image.total());
|
||||
Image.dispose();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user