Unit weapon rework, titan and bomber enemies added, various fixes

This commit is contained in:
Anuken
2018-06-26 22:48:18 -04:00
parent 03277c69af
commit c89123b18a
48 changed files with 1154 additions and 879 deletions

View File

@@ -0,0 +1,15 @@
package io.anuke.mindustry;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
public class GenRegion extends TextureRegion {
public String name;
public boolean invalid;
public ImageContext context;
public static void validate(TextureRegion region){
if(((GenRegion)region).invalid){
((GenRegion) region).context.err("Region does not exist: {0}", ((GenRegion)region).name);
}
}
}

View File

@@ -2,6 +2,7 @@ package io.anuke.mindustry;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.entities.units.UnitType;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.Mech;
import io.anuke.mindustry.type.Upgrade;
@@ -63,6 +64,28 @@ public class Generators {
}
});
context.generate("unit-icons", () -> {
for(UnitType type : UnitType.all()){
type.load();
type.weapon.load();
Image image = context.get(type.region);
if(!type.isFlying){
image.draw(type.baseRegion);
image.draw(type.legRegion);
image.draw(type.legRegion, true, false);
image.draw(type.region);
image.draw(type.weapon.equipRegion, -(int)type.weaponOffsetX, (int)type.weaponOffsetY, false, false);
image.draw(type.weapon.equipRegion, (int)type.weaponOffsetX, (int)type.weaponOffsetY, true, false);
}
image.save("unit-icon-" + type.name);
}
});
context.generate("ore-icons", () -> {
for(Block block : Block.all()){
if(!(block instanceof OreBlock)) continue;

View File

@@ -64,6 +64,8 @@ public class Image {
}
public void draw(TextureRegion region, int x, int y, boolean flipx, boolean flipy){
GenRegion.validate(region);
int ofx = 0, ofy = 0;
if(x < 0){

View File

@@ -35,7 +35,11 @@ public class ImageContext {
for(Region region : data.getRegions()){
int x = region.left, y = region.top, width = region.width, height = region.height;
regionCache.put(region.name, new TextureRegion(){
regionCache.put(region.name, new GenRegion(){
{
name = region.name;
context = ImageContext.this;
}
@Override
public int getRegionX(){
@@ -62,6 +66,13 @@ public class ImageContext {
Core.atlas = new Atlas(){
@Override
public TextureRegion getRegion(String name){
if(!regionCache.containsKey(name)){
GenRegion region = new GenRegion();
region.name = name;
region.context = ImageContext.this;
region.invalid = true;
return region;
}
return regionCache.get(name);
}
@@ -87,6 +98,8 @@ public class ImageContext {
}
public Image get(TextureRegion region){
GenRegion.validate(region);
return new Image(image, region);
}