Colored floor tile

This commit is contained in:
Anuken
2025-07-12 18:16:26 -04:00
parent 0939076b4d
commit e53201347f
8 changed files with 74 additions and 11 deletions

View File

@@ -311,6 +311,10 @@ public class Tile implements Position, QuadTreeObject, Displayable{
if(!world.isGenerating() && prev != type){
Events.fire(floorChange.set(this, prev, type));
}
if(this.floor != prev){
this.floor.floorChanged(this);
}
}
public boolean isEditorTile(){
@@ -564,6 +568,10 @@ public class Tile implements Position, QuadTreeObject, Displayable{
null : null;
}
public boolean shouldSaveData(){
return floor.saveData || overlay.saveData || block.saveData;
}
public int staticDarkness(){
return block.solid && block.fillsTile && !block.synthetic() ? data : 0;
}

View File

@@ -0,0 +1,47 @@
package mindustry.world.blocks.environment;
import arc.graphics.*;
import arc.graphics.g2d.*;
import mindustry.world.*;
public class ColoredFloor extends Floor{
public Color defaultColor = Color.white;
protected int defaultColorRgba;
public ColoredFloor(String name){
super(name);
saveData = true;
}
@Override
public void init(){
super.init();
defaultColorRgba = defaultColor.rgba();
}
@Override
public void drawBase(Tile tile){
//make sure to mask out the alpha channel - it's generally undesirable, and leads to invisible blocks when the data is not initialized
Draw.color(tile.extraData | 0xff);
super.drawBase(tile);
Draw.color();
}
@Override
public void drawOverlay(Tile tile){
//make sure color doesn't carry over
Draw.color();
super.drawOverlay(tile);
}
@Override
public void floorChanged(Tile tile){
//reset to white
tile.extraData = defaultColorRgba;
}
@Override
public int minimapColor(Tile tile){
return tile.extraData | 0xff;
}
}

View File

@@ -268,6 +268,9 @@ public class Floor extends Block{
return new TextureRegion[]{Core.atlas.find(Core.atlas.has(name) ? name : name + "1")};
}
/** Called when this floor is set on the specified tile. */
public void floorChanged(Tile tile){}
/** @return whether to index this floor by flag */
public boolean shouldIndex(Tile tile){
return true;