mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-04 15:27:19 +07:00
Improved texture gen system, mech icon generation
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 254 B After Width: | Height: | Size: 314 B |
BIN
core/assets-raw/sprites/weapons/generic-weapon.png
Normal file
BIN
core/assets-raw/sprites/weapons/generic-weapon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 281 B |
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 118 KiB |
@ -77,7 +77,6 @@ public class Recipes implements ContentList{
|
||||
new Recipe(crafting, CraftingBlocks.stoneFormer, new ItemStack(Items.steel, 10), new ItemStack(Items.iron, 10));
|
||||
new Recipe(crafting, CraftingBlocks.melter, new ItemStack(Items.steel, 30), new ItemStack(Items.titanium, 15));
|
||||
new Recipe(crafting, CraftingBlocks.incinerator, new ItemStack(Items.steel, 60), new ItemStack(Items.iron, 60));
|
||||
new Recipe(crafting, CraftingBlocks.weaponFactory, new ItemStack(Items.steel, 1), new ItemStack(Items.iron, 1)).setDesktop();
|
||||
|
||||
new Recipe(production, ProductionBlocks.ironDrill, new ItemStack(Items.iron, 25));
|
||||
new Recipe(production, ProductionBlocks.reinforcedDrill, new ItemStack(Items.iron, 25));
|
||||
|
@ -11,7 +11,7 @@ import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.production.*;
|
||||
|
||||
public class CraftingBlocks extends BlockList implements ContentList {
|
||||
public static Block smelter, arcsmelter, siliconsmelter, plasteelcompressor, phaseweaver, alloysmelter, alloyfuser, cryofluidmixer, melter, separator, centrifuge, biomatterCompressor, pulverizer, oilRefinery, stoneFormer, weaponFactory, incinerator;
|
||||
public static Block smelter, arcsmelter, siliconsmelter, plasteelcompressor, phaseweaver, alloysmelter, alloyfuser, cryofluidmixer, melter, separator, centrifuge, biomatterCompressor, pulverizer, oilRefinery, stoneFormer, incinerator;
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
@ -215,11 +215,6 @@ public class CraftingBlocks extends BlockList implements ContentList {
|
||||
hasLiquids = hasItems = true;
|
||||
}};
|
||||
|
||||
weaponFactory = new MechFactory("weaponfactory") {{
|
||||
size = 2;
|
||||
health = 250;
|
||||
}};
|
||||
|
||||
incinerator = new Incinerator("incinerator") {{
|
||||
health = 90;
|
||||
}};
|
||||
|
@ -282,12 +282,11 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
Draw.rect(mech.region, x, y, rotation -90);
|
||||
|
||||
for (int i : Mathf.signs) {
|
||||
float tra = rotation - 90,
|
||||
trX = 4*i, trY = 3 - mech.weapon.getRecoil(this, i > 0)*1.5f;
|
||||
float w = i > 0 ? -8 : 8;
|
||||
float tra = rotation - 90, trY = - mech.weapon.getRecoil(this, i > 0)*1.5f;
|
||||
float w = i > 0 ? -12 : 12;
|
||||
Draw.rect(mech.weapon.equipRegion,
|
||||
x + Angles.trnsx(tra, trX, trY),
|
||||
y + Angles.trnsy(tra, trX, trY), w, 8, rotation - 90);
|
||||
x + Angles.trnsx(tra, 0, trY),
|
||||
y + Angles.trnsy(tra, 0, trY), w, 12, rotation - 90);
|
||||
}
|
||||
|
||||
float backTrns = 4f, itemSize = 5f;
|
||||
|
@ -14,7 +14,7 @@ public class Mech extends Upgrade {
|
||||
public float armor = 1f;
|
||||
public Weapon weapon = Weapons.blaster;
|
||||
|
||||
public TextureRegion baseRegion, legRegion, region;
|
||||
public TextureRegion baseRegion, legRegion, region, iconRegion;
|
||||
|
||||
public Mech(String name, boolean flying){
|
||||
super(name);
|
||||
@ -29,5 +29,6 @@ public class Mech extends Upgrade {
|
||||
}
|
||||
|
||||
region = Draw.region(name);
|
||||
iconRegion = Draw.optional("mech-icon-"+ name);
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ public class CoreBlock extends StorageBlock {
|
||||
if(entity.currentPlayer != null) {
|
||||
Player player = entity.currentPlayer;
|
||||
|
||||
TextureRegion region = Draw.region(player.mech.name);
|
||||
TextureRegion region = player.mech.iconRegion;
|
||||
|
||||
Shaders.build.region = region;
|
||||
Shaders.build.progress = entity.progress;
|
||||
|
@ -112,7 +112,7 @@ public class Reconstructor extends Block{
|
||||
|
||||
Player player = entity.current;
|
||||
|
||||
TextureRegion region = Draw.region(player.mech.name);
|
||||
TextureRegion region = player.mech.iconRegion;
|
||||
|
||||
Shaders.build.region = region;
|
||||
Shaders.build.progress = progress;
|
||||
@ -253,6 +253,8 @@ public class Reconstructor extends Block{
|
||||
entity.power.amount -= ((Reconstructor)tile.block()).powerPerTeleport;
|
||||
entity.updateTime = 1f;
|
||||
entity.set(tile.drawx(), tile.drawy());
|
||||
player.rotation = 90f;
|
||||
player.baseRotation = 90f;
|
||||
player.setDead(true);
|
||||
player.setRespawning(true);
|
||||
player.setRespawning();
|
||||
|
@ -38,7 +38,7 @@ task cleanup(){
|
||||
task generateSprites(dependsOn: classes, type: JavaExec) {
|
||||
file(textureFolder).mkdirs()
|
||||
|
||||
main = "io.anuke.mindustry.TextureGenerator"
|
||||
main = "io.anuke.mindustry.PackerLauncher"
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
standardInput = System.in
|
||||
workingDir = textureFolder
|
||||
|
61
packer/src/io/anuke/mindustry/Generators.java
Normal file
61
packer/src/io/anuke/mindustry/Generators.java
Normal file
@ -0,0 +1,61 @@
|
||||
package io.anuke.mindustry;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import io.anuke.mindustry.type.Mech;
|
||||
import io.anuke.mindustry.type.Upgrade;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
|
||||
public class Generators {
|
||||
|
||||
public static void generate(ImageContext context){
|
||||
|
||||
context.generate("block-icons", () -> {
|
||||
for(Block block : Block.all()){
|
||||
TextureRegion[] regions = block.getBlockIcon();
|
||||
|
||||
if(regions.length == 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
if(regions[0] == null){
|
||||
context.err("Error in block \"{0}\": null region!", block.name);
|
||||
}
|
||||
|
||||
Image image = context.get(regions[0]);
|
||||
|
||||
for(TextureRegion region : regions){
|
||||
image.draw(region);
|
||||
}
|
||||
|
||||
image.save("block-icon-" + block.name);
|
||||
}
|
||||
});
|
||||
|
||||
context.generate("mech-icons", () -> {
|
||||
for(Upgrade upgrade : Upgrade.all()){
|
||||
if(!(upgrade instanceof Mech)) continue;
|
||||
|
||||
Mech mech = (Mech)upgrade;
|
||||
|
||||
mech.load();
|
||||
mech.weapon.load();
|
||||
|
||||
Image image = context.get(mech.region);
|
||||
|
||||
if(!mech.flying){
|
||||
image.draw(mech.baseRegion);
|
||||
image.draw(mech.legRegion);
|
||||
image.draw(mech.legRegion, true, false);
|
||||
image.draw(mech.region);
|
||||
}
|
||||
|
||||
image.draw(mech.weapon.equipRegion, false, false);
|
||||
image.draw(mech.weapon.equipRegion, true, false);
|
||||
|
||||
|
||||
image.save("mech-icon-" + mech.name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
88
packer/src/io/anuke/mindustry/Image.java
Normal file
88
packer/src/io/anuke/mindustry/Image.java
Normal file
@ -0,0 +1,88 @@
|
||||
package io.anuke.mindustry;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Image {
|
||||
private static ArrayList<Image> toDispose = new ArrayList<>();
|
||||
|
||||
private BufferedImage atlas;
|
||||
|
||||
private BufferedImage image;
|
||||
private Graphics2D graphics;
|
||||
|
||||
public Image(BufferedImage atlas, TextureRegion region){
|
||||
this.atlas = atlas;
|
||||
|
||||
this.image = new BufferedImage(region.getRegionWidth(), region.getRegionHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
this.graphics = image.createGraphics();
|
||||
|
||||
draw(region);
|
||||
|
||||
toDispose.add(this);
|
||||
}
|
||||
|
||||
/**Draws a region at the top left corner.*/
|
||||
public void draw(TextureRegion region){
|
||||
draw(region, 0, 0, false, false);
|
||||
}
|
||||
|
||||
/**Draws an image at the top left corner.*/
|
||||
public void draw(Image image){
|
||||
graphics.drawImage(image.image, 0, 0, null);
|
||||
}
|
||||
|
||||
public void draw(TextureRegion region, boolean flipx, boolean flipy){
|
||||
draw(region, 0, 0, flipx, flipy);
|
||||
}
|
||||
|
||||
public void draw(TextureRegion region, int x, int y, boolean flipx, boolean flipy){
|
||||
int ofx = 0, ofy = 0;
|
||||
|
||||
if(x < 0){
|
||||
ofx = x;
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if(y < 0){
|
||||
ofy = y;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
graphics.drawImage(atlas,
|
||||
x, y,
|
||||
x + region.getRegionWidth(),
|
||||
y + region.getRegionHeight(),
|
||||
(flipx ? region.getRegionX() + region.getRegionWidth() : region.getRegionX()) + ofx,
|
||||
(flipy ? region.getRegionY() + region.getRegionHeight() : region.getRegionY()) + ofy,
|
||||
(flipx ? region.getRegionX() : region.getRegionX() + region.getRegionWidth()) + ofx,
|
||||
(flipy ? region.getRegionY() : region.getRegionY() + region.getRegionHeight()) + ofy,
|
||||
null);
|
||||
}
|
||||
|
||||
/** @param name Name of texture file name to create, without any extensions.*/
|
||||
public void save(String name){
|
||||
try {
|
||||
ImageIO.write(image, "png", new File(name + ".png"));
|
||||
}catch (IOException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static int total(){
|
||||
return toDispose.size();
|
||||
}
|
||||
|
||||
public static void dispose(){
|
||||
for(Image image : toDispose){
|
||||
image.graphics.dispose();
|
||||
}
|
||||
toDispose.clear();
|
||||
}
|
||||
}
|
@ -6,30 +6,27 @@ import com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import io.anuke.mindustry.core.ContentLoader;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Atlas;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Log.LogHandler;
|
||||
import io.anuke.ucore.util.Log.NoopLogHandler;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**Used for generating extra textures before packing.*/
|
||||
public class TextureGenerator {
|
||||
static BufferedImage image;
|
||||
static Graphics2D graphics;
|
||||
public class ImageContext {
|
||||
private BufferedImage image;
|
||||
|
||||
public static void main(String[] args) throws Exception{
|
||||
public void load() throws IOException{
|
||||
Log.setLogger(new NoopLogHandler());
|
||||
|
||||
ContentLoader.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);
|
||||
|
||||
@ -77,45 +74,24 @@ public class TextureGenerator {
|
||||
Core.atlas.setErrorRegion("error");
|
||||
|
||||
image = ImageIO.read(new File(spritesFolder + "/sprites.png"));
|
||||
graphics = image.createGraphics();
|
||||
|
||||
generateBlocks();
|
||||
}
|
||||
|
||||
/**Generates full block icons for use in the editor.*/
|
||||
static void generateBlocks() throws IOException {
|
||||
public void generate(String name, Runnable run){
|
||||
Timers.mark();
|
||||
run.run();
|
||||
Log.info("&ly[Generator]&lc Time to generate &lm{0}&lc: &lg{1}&lcms", name, Timers.elapsed());
|
||||
}
|
||||
|
||||
for(Block block : Block.all()){
|
||||
TextureRegion[] regions = block.getBlockIcon();
|
||||
public Image get(String name){
|
||||
return get(Core.atlas.getRegion(name));
|
||||
}
|
||||
|
||||
if(regions.length == 0){
|
||||
continue;
|
||||
}
|
||||
public Image get(TextureRegion region){
|
||||
return new Image(image, region);
|
||||
}
|
||||
|
||||
if(regions[0] == null){
|
||||
System.err.println("Error in block \"" + block.name + "\": null region!");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
BufferedImage target = new BufferedImage(regions[0].getRegionWidth(), regions[0].getRegionHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D tg = target.createGraphics();
|
||||
|
||||
for(TextureRegion region : regions){
|
||||
|
||||
tg.drawImage(image,
|
||||
0, 0,
|
||||
region.getRegionWidth(),
|
||||
region.getRegionHeight(),
|
||||
region.getRegionX(),
|
||||
region.getRegionY(),
|
||||
region.getRegionX() + region.getRegionWidth(),
|
||||
region.getRegionY() + region.getRegionHeight(),
|
||||
null);
|
||||
}
|
||||
|
||||
tg.dispose();
|
||||
|
||||
ImageIO.write(target, "png", new File("block-icon-" + block.name + ".png"));
|
||||
}
|
||||
public void err(String message, Object... args){
|
||||
Log.err(message, args);
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
20
packer/src/io/anuke/mindustry/PackerLauncher.java
Normal file
20
packer/src/io/anuke/mindustry/PackerLauncher.java
Normal file
@ -0,0 +1,20 @@
|
||||
package io.anuke.mindustry;
|
||||
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class PackerLauncher {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
ImageContext context = new ImageContext();
|
||||
context.load();
|
||||
Timers.mark();
|
||||
Generators.generate(context);
|
||||
Log.info("&ly[Generator]&lc Total time to generate: &lg{0}&lcms", Timers.elapsed());
|
||||
Log.info("&ly[Generator]&lc Total images created: &lg{0}", Image.total());
|
||||
Image.dispose();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user