Let any block have variants. (#5372)

This commit is contained in:
MEEP of Faith
2021-06-10 12:42:01 -07:00
committed by GitHub
parent e4bd3fab7c
commit af2830602d
5 changed files with 27 additions and 40 deletions

View File

@@ -907,7 +907,11 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
} }
public void draw(){ public void draw(){
Draw.rect(block.region, x, y, block.rotate ? rotdeg() : 0); if(block.variants == 0){
Draw.rect(block.region, x, y, block.rotate ? rotdeg() : 0);
}else{
Draw.rect(block.variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, block.variantRegions.length - 1))], x, y, block.rotate ? rotdeg() : 0);
}
drawTeamTop(); drawTeamTop();
} }

View File

@@ -78,6 +78,8 @@ public class Block extends UnlockableContent{
public boolean solidifes; public boolean solidifes;
/** whether this is rotateable */ /** whether this is rotateable */
public boolean rotate; public boolean rotate;
/** number of different variant regions to use */
public int variants = 0;
/** whether to draw a rotation arrow - this does not apply to lines of blocks */ /** whether to draw a rotation arrow - this does not apply to lines of blocks */
public boolean drawArrow = true; public boolean drawArrow = true;
/** for static blocks only: if true, tile data() is saved in world data. */ /** for static blocks only: if true, tile data() is saved in world data. */
@@ -240,11 +242,11 @@ public class Block extends UnlockableContent{
public ObjectMap<Class<?>, Cons2> configurations = new ObjectMap<>(); public ObjectMap<Class<?>, Cons2> configurations = new ObjectMap<>();
protected TextureRegion[] generatedIcons; protected TextureRegion[] generatedIcons;
protected TextureRegion[] variantRegions, editorVariantRegions; protected TextureRegion[] editorVariantRegions;
public TextureRegion region, editorIcon; public TextureRegion region, editorIcon;
public @Load("@-team") TextureRegion teamRegion; public @Load("@-team") TextureRegion teamRegion;
public TextureRegion[] teamRegions; public TextureRegion[] teamRegions, variantRegions;
protected static final Seq<Tile> tempTiles = new Seq<>(); protected static final Seq<Tile> tempTiles = new Seq<>();
protected static final Seq<Building> tempTileEnts = new Seq<>(); protected static final Seq<Building> tempTileEnts = new Seq<>();
@@ -264,7 +266,11 @@ public class Block extends UnlockableContent{
if(tile.build != null){ if(tile.build != null){
tile.build.draw(); tile.build.draw();
}else{ }else{
Draw.rect(region, tile.drawx(), tile.drawy()); if(variants == 0){
Draw.rect(region, tile.drawx(), tile.drawy());
}else{
Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], tile.drawx(), tile.drawy());
}
} }
} }
@@ -588,7 +594,8 @@ public class Block extends UnlockableContent{
protected TextureRegion[] icons(){ protected TextureRegion[] icons(){
//use team region in vanilla team blocks //use team region in vanilla team blocks
return teamRegion.found() && minfo.mod == null ? new TextureRegion[]{region, teamRegions[Team.sharded.id]} : new TextureRegion[]{region}; TextureRegion r = variants > 0 ? Core.atlas.find(name + "1") : region;
return teamRegion.found() && minfo.mod == null ? new TextureRegion[]{r, teamRegions[Team.sharded.id]} : new TextureRegion[]{r};
} }
public TextureRegion[] getGeneratedIcons(){ public TextureRegion[] getGeneratedIcons(){
@@ -831,6 +838,15 @@ public class Block extends UnlockableContent{
for(Team team : Team.all){ for(Team team : Team.all){
teamRegions[team.id] = teamRegion.found() ? Core.atlas.find(name + "-team-" + team.name, teamRegion) : teamRegion; teamRegions[team.id] = teamRegion.found() ? Core.atlas.find(name + "-team-" + team.name, teamRegion) : teamRegion;
} }
if(variants != 0){
variantRegions = new TextureRegion[variants];
for(int i = 0; i < variants; i++){
variantRegions[i] = Core.atlas.find(name + (i + 1));
}
region = variantRegions[0];
}
} }
@Override @Override

View File

@@ -15,8 +15,6 @@ import mindustry.world.meta.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
public class Wall extends Block{ public class Wall extends Block{
public int variants = 0;
/** Lighting chance. -1 to disable */ /** Lighting chance. -1 to disable */
public float lightningChance = -1f; public float lightningChance = -1f;
public float lightningDamage = 20f; public float lightningDamage = 20f;
@@ -51,20 +49,6 @@ public class Wall extends Block{
} }
} }
@Override
public void load(){
super.load();
if(variants != 0){
variantRegions = new TextureRegion[variants];
for(int i = 0; i < variants; i++){
variantRegions[i] = Core.atlas.find(name + (i + 1));
}
region = variantRegions[0];
}
}
@Override @Override
public TextureRegion[] icons(){ public TextureRegion[] icons(){
return new TextureRegion[]{Core.atlas.find(Core.atlas.has(name) ? name : name + "1")}; return new TextureRegion[]{Core.atlas.find(Core.atlas.has(name) ? name : name + "1")};

View File

@@ -20,8 +20,6 @@ import mindustry.world.blocks.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
public class Floor extends Block{ public class Floor extends Block{
/** number of different variant regions to use */
public int variants = 3;
/** edge fallback, used mainly for ores */ /** edge fallback, used mainly for ores */
public String edge = "stone"; public String edge = "stone";
/** Multiplies unit velocity by this when walked on. */ /** Multiplies unit velocity by this when walked on. */
@@ -76,6 +74,8 @@ public class Floor extends Block{
public Floor(String name){ public Floor(String name){
super(name); super(name);
variants = 3;
} }
public Floor(String name, int variants){ public Floor(String name, int variants){
@@ -90,7 +90,6 @@ public class Floor extends Block{
//load variant regions for drawing //load variant regions for drawing
if(variants > 0){ if(variants > 0){
variantRegions = new TextureRegion[variants]; variantRegions = new TextureRegion[variants];
for(int i = 0; i < variants; i++){ for(int i = 0; i < variants; i++){
variantRegions[i] = Core.atlas.find(name + (i + 1)); variantRegions[i] = Core.atlas.find(name + (i + 1));
} }
@@ -98,7 +97,6 @@ public class Floor extends Block{
variantRegions = new TextureRegion[1]; variantRegions = new TextureRegion[1];
variantRegions[0] = Core.atlas.find(name); variantRegions[0] = Core.atlas.find(name);
} }
int size = (int)(tilesize / Draw.scl); int size = (int)(tilesize / Draw.scl);
if(Core.atlas.has(name + "-edge")){ if(Core.atlas.has(name + "-edge")){
edges = Core.atlas.find(name + "-edge").split(size, size); edges = Core.atlas.find(name + "-edge").split(size, size);

View File

@@ -7,8 +7,6 @@ import mindustry.content.*;
import mindustry.world.*; import mindustry.world.*;
public class Prop extends Block{ public class Prop extends Block{
public int variants;
public Prop(String name){ public Prop(String name){
super(name); super(name);
breakable = true; breakable = true;
@@ -28,17 +26,4 @@ public class Prop extends Block{
public TextureRegion[] icons(){ public TextureRegion[] icons(){
return variants == 0 ? super.icons() : new TextureRegion[]{Core.atlas.find(name + "1")}; return variants == 0 ? super.icons() : new TextureRegion[]{Core.atlas.find(name + "1")};
} }
@Override
public void load(){
super.load();
if(variants > 0){
variantRegions = new TextureRegion[variants];
for(int i = 0; i < variants; i++){
variantRegions[i] = Core.atlas.find(name + (i + 1));
}
}
}
} }