Static wall autotile support
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package mindustry.world.blocks;
|
||||
|
||||
import arc.*;
|
||||
import arc.graphics.g2d.*;
|
||||
|
||||
public class TileBitmask{
|
||||
/** Autotile bitmasks for 8-directional sprites (see <a href="https://github.com/GglLfr/tile-gen">tile-gen</a>)*/
|
||||
public static final int[] values = {
|
||||
@@ -20,4 +23,12 @@ public class TileBitmask{
|
||||
3, 0, 3, 0, 15, 42, 15, 12, 3, 0, 3, 0, 15, 42, 15, 12,
|
||||
2, 1, 2, 1, 9, 45, 9, 19, 2, 1, 2, 1, 14, 18, 14, 13,
|
||||
};
|
||||
|
||||
public static TextureRegion[] load(String name){
|
||||
var regions = new TextureRegion[47];
|
||||
for(int i = 0; i < 47; i++){
|
||||
regions[i] = Core.atlas.find(name + "-" + i);
|
||||
}
|
||||
return regions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,10 +141,7 @@ public class Floor extends Block{
|
||||
}
|
||||
|
||||
if(autotile){
|
||||
autotileRegions = new TextureRegion[47];
|
||||
for(int i = 0; i < 47; i++){
|
||||
autotileRegions[i] = Core.atlas.find(name + "-" + i);
|
||||
}
|
||||
autotileRegions = TileBitmask.load(name);
|
||||
}
|
||||
|
||||
if(Core.atlas.has(name + "-edge")){
|
||||
|
||||
@@ -8,12 +8,17 @@ import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class StaticWall extends Prop{
|
||||
public @Load("@-large") TextureRegion large;
|
||||
public TextureRegion[][] split;
|
||||
/** If true, this wall uses autotiling; variants are not supported. See https://github.com/GglLfr/tile-gen*/
|
||||
public boolean autotile;
|
||||
|
||||
protected TextureRegion[] autotileRegions;
|
||||
|
||||
public StaticWall(String name){
|
||||
super(name);
|
||||
@@ -30,15 +35,28 @@ public class StaticWall extends Prop{
|
||||
|
||||
@Override
|
||||
public void drawBase(Tile tile){
|
||||
int rx = tile.x / 2 * 2;
|
||||
int ry = tile.y / 2 * 2;
|
||||
if(autotile){
|
||||
int bits = 0;
|
||||
|
||||
if(Core.atlas.isFound(large) && eq(rx, ry) && Mathf.randomSeed(Point2.pack(rx, ry)) < 0.5 && split.length >= 2 && split[0].length >= 2){
|
||||
Draw.rect(split[tile.x % 2][1 - tile.y % 2], tile.worldx(), tile.worldy());
|
||||
}else if(variants > 0){
|
||||
Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], tile.worldx(), tile.worldy());
|
||||
for(int i = 0; i < 8; i++){
|
||||
Tile other = tile.nearby(Geometry.d8[i]);
|
||||
if(other != null && other.block() == this){
|
||||
bits |= (1 << i);
|
||||
}
|
||||
}
|
||||
|
||||
Draw.rect(autotileRegions[TileBitmask.values[bits]], tile.worldx(), tile.worldy());
|
||||
}else{
|
||||
Draw.rect(region, tile.worldx(), tile.worldy());
|
||||
int rx = tile.x / 2 * 2;
|
||||
int ry = tile.y / 2 * 2;
|
||||
|
||||
if(Core.atlas.isFound(large) && eq(rx, ry) && Mathf.randomSeed(Point2.pack(rx, ry)) < 0.5 && split.length >= 2 && split[0].length >= 2){
|
||||
Draw.rect(split[tile.x % 2][1 - tile.y % 2], tile.worldx(), tile.worldy());
|
||||
}else if(variants > 0){
|
||||
Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], tile.worldx(), tile.worldy());
|
||||
}else{
|
||||
Draw.rect(region, tile.worldx(), tile.worldy());
|
||||
}
|
||||
}
|
||||
|
||||
//draw ore on top
|
||||
@@ -59,6 +77,10 @@ public class StaticWall extends Prop{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(autotile){
|
||||
autotileRegions = TileBitmask.load(name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,6 +32,7 @@ import static mindustry.Vars.*;
|
||||
|
||||
public class LogicBlock extends Block{
|
||||
private static final int maxByteLen = 1024 * 100;
|
||||
private static final int maxLinks = 6000;
|
||||
public static final int maxNameLength = 32;
|
||||
|
||||
public int maxInstructionScale = 5;
|
||||
@@ -198,7 +199,7 @@ public class LogicBlock extends Block{
|
||||
byte[] bytes = new byte[bytelen];
|
||||
stream.readFully(bytes);
|
||||
|
||||
int total = stream.readInt();
|
||||
int total = Math.min(stream.readInt(), maxLinks);
|
||||
|
||||
Seq<LogicLink> links = new Seq<>();
|
||||
|
||||
@@ -274,7 +275,7 @@ public class LogicBlock extends Block{
|
||||
|
||||
links.clear();
|
||||
|
||||
int total = stream.readInt();
|
||||
int total = Math.min(stream.readInt(), maxLinks);
|
||||
|
||||
if(version == 0){
|
||||
//old version just had links, ignore those
|
||||
|
||||
Reference in New Issue
Block a user