diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index d2a6f20cfc..2b96963d48 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -192,6 +192,10 @@ public class Control extends Module{ respawntime = -1; hiscore = false; + for(Block block : Block.getAllBlocks()){ + block.onReset(); + } + ui.updateItems(); ui.updateWeapons(); } diff --git a/core/src/io/anuke/mindustry/io/SaveIO.java b/core/src/io/anuke/mindustry/io/SaveIO.java index 5d087d919e..d812253195 100644 --- a/core/src/io/anuke/mindustry/io/SaveIO.java +++ b/core/src/io/anuke/mindustry/io/SaveIO.java @@ -82,7 +82,7 @@ import io.anuke.ucore.entities.Entities; */ public class SaveIO{ /**Save file version ID. Should be incremented every breaking release.*/ - private static final int fileVersionID = 11; + private static final int fileVersionID = 12; //TODO automatic registration of types? private static final Array> enemyIDs = Array.with( diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index 8c78332778..abf6d2fa63 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -91,6 +91,10 @@ public class Block{ return name; } + public void onReset(){ + + } + public boolean isSolidFor(Tile tile){ return false; } diff --git a/core/src/io/anuke/mindustry/world/blocks/types/defense/Door.java b/core/src/io/anuke/mindustry/world/blocks/types/defense/Door.java index 6bfcd2ce38..b3237a52d8 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/defense/Door.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/defense/Door.java @@ -2,11 +2,15 @@ package io.anuke.mindustry.world.blocks.types.defense; import static io.anuke.mindustry.Vars.*; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; -import com.badlogic.gdx.utils.ObjectMap; import io.anuke.mindustry.Vars; +import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.effect.Fx; import io.anuke.mindustry.entities.enemies.Enemy; import io.anuke.mindustry.world.Block; @@ -22,8 +26,6 @@ import io.anuke.ucore.scene.ui.layout.Table; import io.anuke.ucore.util.Tmp; public class Door extends Wall implements Configurable{ - private ObjectMap open = new ObjectMap<>(); - protected Effect openfx = Fx.dooropen; protected Effect closefx = Fx.doorclose; @@ -34,7 +36,9 @@ public class Door extends Wall implements Configurable{ @Override public void draw(Tile tile){ - if(open.get(tile, true)){ + DoorEntity entity = tile.entity(); + + if(!entity.open){ Draw.rect(name, tile.worldx(), tile.worldy()); }else{ Draw.rect(name + "-open", tile.worldx(), tile.worldy()); @@ -43,20 +47,25 @@ public class Door extends Wall implements Configurable{ @Override public boolean isSolidFor(Tile tile){ - return open.get(tile, true); + DoorEntity entity = tile.entity(); + return !entity.open; } @Override public void buildTable(Tile tile, Table table){ - if(anyEntities(tile) && !open.get(tile, true)){ + DoorEntity entity = tile.entity(); + + if(anyEntities(tile) && !entity.open){ return; } - open.put(tile, !open.get(tile, true)); - if(open.get(tile)){ - Effects.effect(closefx, tile.worldx(), tile.worldy()); + Vector2 offset = getPlaceOffset(); + + entity.open = !entity.open; + if(!entity.open){ + Effects.effect(closefx, tile.worldx() + offset.x, tile.worldy() + offset.y); }else{ - Effects.effect(openfx, tile.worldx(), tile.worldy()); + Effects.effect(openfx, tile.worldx() + offset.x, tile.worldy() + offset.y); } } @@ -81,5 +90,26 @@ public class Door extends Wall implements Configurable{ return false; } + + @Override + public TileEntity getEntity(){ + return new DoorEntity(); + } + + public class DoorEntity extends TileEntity{ + public boolean open = false; + + @Override + public void write(DataOutputStream stream) throws IOException{ + super.write(stream); + stream.writeBoolean(open); + } + + @Override + public void read(DataInputStream stream) throws IOException{ + super.read(stream); + open = stream.readBoolean(); + } + } } diff --git a/desktop/mindustry-saves/0.mins b/desktop/mindustry-saves/0.mins index 0345804f15..2badafeb22 100644 Binary files a/desktop/mindustry-saves/0.mins and b/desktop/mindustry-saves/0.mins differ diff --git a/desktop/mindustry-saves/2.mins b/desktop/mindustry-saves/2.mins index 32124eec4b..e8eda1212d 100644 Binary files a/desktop/mindustry-saves/2.mins and b/desktop/mindustry-saves/2.mins differ