Correct team display on maps

This commit is contained in:
Anuken
2020-10-31 10:35:21 -04:00
parent 2c29a06eb5
commit 8d6ea6b197
5 changed files with 30 additions and 6 deletions

View File

@@ -79,12 +79,8 @@ public class MapIO{
CachedTile tile = new CachedTile(){
@Override
public void setBlock(Block type){
//previous state.
if(build != null && build.block instanceof CoreBlock){
map.teams.add(build.team.id);
}
super.setBlock(type);
int c = colorFor(block(), Blocks.air, Blocks.air, team());
if(c != black){
walls.draw(x, floors.getHeight() - 1 - y, c);
@@ -104,6 +100,27 @@ public class MapIO{
world.setGenerating(false);
}
@Override
public void onReadBuilding(){
//read team colors
if(tile.build != null){
int c = tile.build.team.color.rgba8888();
int size = tile.block().size;
int offsetx = -(size - 1) / 2;
int offsety = -(size - 1) / 2;
for(int dx = 0; dx < size; dx++){
for(int dy = 0; dy < size; dy++){
int drawx = tile.x + dx + offsetx, drawy = tile.y + dy + offsety;
walls.draw(drawx, floors.getHeight() - 1 - drawy, c);
}
}
if(tile.build.block instanceof CoreBlock){
map.teams.add(tile.build.team.id);
}
}
}
@Override
public Tile tile(int index){
tile.x = (short)(index % map.width);

View File

@@ -263,6 +263,8 @@ public abstract class SaveVersion extends SaveFileReader{
//skip the entity region, as the entity and its IO code are now gone
skipChunk(stream, true);
}
context.onReadBuilding();
}
}else if(hadData){
tile.setBlock(block);

View File

@@ -85,6 +85,8 @@ public abstract class LegacySaveVersion extends SaveVersion{
}catch(Throwable e){
throw new IOException("Failed to read tile entity of block: " + block, e);
}
context.onReadBuilding();
}else{
int consecutives = stream.readUnsignedByte();

View File

@@ -70,7 +70,7 @@ public class Map implements Comparable<Map>, Publishable{
}
public Fi previewFile(){
return Vars.mapPreviewDirectory.child((workshop ? file.parent().name() : file.nameWithoutExtension()) + ".png");
return Vars.mapPreviewDirectory.child((workshop ? file.parent().name() : file.nameWithoutExtension()) + "_v2.png");
}
public Fi cacheFile(){

View File

@@ -20,4 +20,7 @@ public interface WorldContext{
/** End generating, prepares tiles.*/
void end();
/** Called when a building is finished reading. */
default void onReadBuilding(){}
}