Editor variant regions for wall blocks

This commit is contained in:
Anuken 2021-06-10 15:52:33 -04:00
parent af2830602d
commit 8d9d6385f9
5 changed files with 20 additions and 18 deletions

View file

@ -18,6 +18,7 @@ public class MapRenderer implements Disposable{
private IndexedRenderer[][] chunks;
private IntSet updates = new IntSet();
private IntSet delayedUpdates = new IntSet();
private TextureRegion clearEditor;
private int width, height;
public void resize(int width, int height){
@ -45,6 +46,7 @@ public class MapRenderer implements Disposable{
public void draw(float tx, float ty, float tw, float th){
Draw.flush();
clearEditor = Core.atlas.find("clear-editor");
updates.each(i -> render(i % width, i / width));
updates.clear();
@ -80,6 +82,7 @@ public class MapRenderer implements Disposable{
}
public void updateAll(){
clearEditor = Core.atlas.find("clear-editor");
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
render(x, y);
@ -103,7 +106,7 @@ public class MapRenderer implements Disposable{
boolean center = tile.isCenter();
if(wall != Blocks.air && wall.synthetic()){
region = !Core.atlas.isFound(wall.editorIcon()) || !center ? Core.atlas.find("clear-editor") : wall.editorIcon();
region = !wall.editorIcon().found() || !center ? clearEditor : wall.editorIcon();
float width = region.width * Draw.scl, height = region.height * Draw.scl;
@ -124,13 +127,17 @@ public class MapRenderer implements Disposable{
mesh.setColor(team.color);
region = Core.atlas.find("block-border-editor");
}else if(!wall.synthetic() && wall != Blocks.air && center){
region = !Core.atlas.isFound(wall.editorIcon()) ? Core.atlas.find("clear-editor") : wall.editorIcon();
region = !wall.editorIcon().found() ?
clearEditor : wall.variants > 0 ?
wall.editorVariantRegions()[Mathf.randomSeed(idxWall, 0, wall.editorVariantRegions().length - 1)] :
wall.editorIcon();
offsetX = tilesize / 2f - region.width / 2f * Draw.scl;
offsetY = tilesize / 2f - region.height / 2f * Draw.scl;
}else if(wall == Blocks.air && !tile.overlay().isAir()){
region = tile.overlay().editorVariantRegions()[Mathf.randomSeed(idxWall, 0, tile.overlay().editorVariantRegions().length - 1)];
}else{
region = Core.atlas.find("clear-editor");
region = clearEditor;
}
float width = region.width * Draw.scl, height = region.height * Draw.scl;

View file

@ -863,6 +863,13 @@ public class Block extends UnlockableContent{
mapColor.set(image.get(image.width/2, image.height/2));
}
if(variants > 0){
for(int i = 0; i < variants; i++){
String rname = name + (i + 1);
packer.add(PageType.editor, "editor-" + rname, Core.atlas.getPixmap(rname));
}
}
Pixmap last = null;
var gen = icons();

View file

@ -59,11 +59,7 @@ public class Wall extends Block{
@Override
public void draw(){
if(variants == 0){
Draw.rect(region, x, y);
}else{
Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], x, y);
}
super.draw();
//draw flashing white overlay if enabled
if(flashHit){

View file

@ -74,7 +74,6 @@ public class Floor extends Block{
public Floor(String name){
super(name);
variants = 3;
}
@ -133,19 +132,12 @@ public class Floor extends Block{
@Override
public void createIcons(MultiPacker packer){
super.createIcons(packer);
packer.add(PageType.editor, "editor-" + name, Core.atlas.getPixmap(fullIcon).crop());
packer.add(PageType.editor, "editor-" + name, Core.atlas.getPixmap(fullIcon));
if(blendGroup != this){
return;
}
if(variants > 0){
for(int i = 0; i < variants; i++){
String rname = name + (i + 1);
packer.add(PageType.editor, "editor-" + rname, Core.atlas.getPixmap(rname).crop());
}
}
PixmapRegion image = Core.atlas.getPixmap(icons()[0]);
PixmapRegion edge = Core.atlas.getPixmap("edge-stencil");
Pixmap result = new Pixmap(edge.width, edge.height);

View file

@ -220,7 +220,7 @@ public class Generators{
TextureRegion[] regions = block.getGeneratedIcons();
if(block instanceof Floor){
if(block.variants > 0){
for(TextureRegion region : block.variantRegions()){
GenRegion gen = (GenRegion)region;
if(gen.path == null) continue;