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
+10 -3
View File
@@ -18,6 +18,7 @@ public class MapRenderer implements Disposable{
private IndexedRenderer[][] chunks; private IndexedRenderer[][] chunks;
private IntSet updates = new IntSet(); private IntSet updates = new IntSet();
private IntSet delayedUpdates = new IntSet(); private IntSet delayedUpdates = new IntSet();
private TextureRegion clearEditor;
private int width, height; private int width, height;
public void resize(int width, int 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){ public void draw(float tx, float ty, float tw, float th){
Draw.flush(); Draw.flush();
clearEditor = Core.atlas.find("clear-editor");
updates.each(i -> render(i % width, i / width)); updates.each(i -> render(i % width, i / width));
updates.clear(); updates.clear();
@@ -80,6 +82,7 @@ public class MapRenderer implements Disposable{
} }
public void updateAll(){ public void updateAll(){
clearEditor = Core.atlas.find("clear-editor");
for(int x = 0; x < width; x++){ for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){ for(int y = 0; y < height; y++){
render(x, y); render(x, y);
@@ -103,7 +106,7 @@ public class MapRenderer implements Disposable{
boolean center = tile.isCenter(); boolean center = tile.isCenter();
if(wall != Blocks.air && wall.synthetic()){ 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; float width = region.width * Draw.scl, height = region.height * Draw.scl;
@@ -124,13 +127,17 @@ public class MapRenderer implements Disposable{
mesh.setColor(team.color); mesh.setColor(team.color);
region = Core.atlas.find("block-border-editor"); region = Core.atlas.find("block-border-editor");
}else if(!wall.synthetic() && wall != Blocks.air && center){ }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; offsetX = tilesize / 2f - region.width / 2f * Draw.scl;
offsetY = tilesize / 2f - region.height / 2f * Draw.scl; offsetY = tilesize / 2f - region.height / 2f * Draw.scl;
}else if(wall == Blocks.air && !tile.overlay().isAir()){ }else if(wall == Blocks.air && !tile.overlay().isAir()){
region = tile.overlay().editorVariantRegions()[Mathf.randomSeed(idxWall, 0, tile.overlay().editorVariantRegions().length - 1)]; region = tile.overlay().editorVariantRegions()[Mathf.randomSeed(idxWall, 0, tile.overlay().editorVariantRegions().length - 1)];
}else{ }else{
region = Core.atlas.find("clear-editor"); region = clearEditor;
} }
float width = region.width * Draw.scl, height = region.height * Draw.scl; float width = region.width * Draw.scl, height = region.height * Draw.scl;
+7
View File
@@ -863,6 +863,13 @@ public class Block extends UnlockableContent{
mapColor.set(image.get(image.width/2, image.height/2)); 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; Pixmap last = null;
var gen = icons(); var gen = icons();
@@ -59,11 +59,7 @@ public class Wall extends Block{
@Override @Override
public void draw(){ public void draw(){
if(variants == 0){ super.draw();
Draw.rect(region, x, y);
}else{
Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], x, y);
}
//draw flashing white overlay if enabled //draw flashing white overlay if enabled
if(flashHit){ if(flashHit){
@@ -74,7 +74,6 @@ public class Floor extends Block{
public Floor(String name){ public Floor(String name){
super(name); super(name);
variants = 3; variants = 3;
} }
@@ -133,19 +132,12 @@ public class Floor extends Block{
@Override @Override
public void createIcons(MultiPacker packer){ public void createIcons(MultiPacker packer){
super.createIcons(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){ if(blendGroup != this){
return; 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 image = Core.atlas.getPixmap(icons()[0]);
PixmapRegion edge = Core.atlas.getPixmap("edge-stencil"); PixmapRegion edge = Core.atlas.getPixmap("edge-stencil");
Pixmap result = new Pixmap(edge.width, edge.height); Pixmap result = new Pixmap(edge.width, edge.height);
+1 -1
View File
@@ -220,7 +220,7 @@ public class Generators{
TextureRegion[] regions = block.getGeneratedIcons(); TextureRegion[] regions = block.getGeneratedIcons();
if(block instanceof Floor){ if(block.variants > 0){
for(TextureRegion region : block.variantRegions()){ for(TextureRegion region : block.variantRegions()){
GenRegion gen = (GenRegion)region; GenRegion gen = (GenRegion)region;
if(gen.path == null) continue; if(gen.path == null) continue;