diff --git a/core/src/mindustry/io/MapIO.java b/core/src/mindustry/io/MapIO.java index 8dc8088681..18f6a712bd 100644 --- a/core/src/mindustry/io/MapIO.java +++ b/core/src/mindustry/io/MapIO.java @@ -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); diff --git a/core/src/mindustry/io/SaveVersion.java b/core/src/mindustry/io/SaveVersion.java index ab243b0823..76e3b1cc5c 100644 --- a/core/src/mindustry/io/SaveVersion.java +++ b/core/src/mindustry/io/SaveVersion.java @@ -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); diff --git a/core/src/mindustry/io/legacy/LegacySaveVersion.java b/core/src/mindustry/io/legacy/LegacySaveVersion.java index a511868356..f533ebd27d 100644 --- a/core/src/mindustry/io/legacy/LegacySaveVersion.java +++ b/core/src/mindustry/io/legacy/LegacySaveVersion.java @@ -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(); diff --git a/core/src/mindustry/maps/Map.java b/core/src/mindustry/maps/Map.java index 0bed8f0408..1f9ab65cdd 100644 --- a/core/src/mindustry/maps/Map.java +++ b/core/src/mindustry/maps/Map.java @@ -70,7 +70,7 @@ public class Map implements Comparable, 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(){ diff --git a/core/src/mindustry/world/WorldContext.java b/core/src/mindustry/world/WorldContext.java index 760aa0938f..498e4e587b 100644 --- a/core/src/mindustry/world/WorldContext.java +++ b/core/src/mindustry/world/WorldContext.java @@ -20,4 +20,7 @@ public interface WorldContext{ /** End generating, prepares tiles.*/ void end(); + /** Called when a building is finished reading. */ + default void onReadBuilding(){} + }