mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-03 13:30:25 +07:00
Made doors save state properly
This commit is contained in:
parent
6e111f1e80
commit
704ee097f3
@ -192,6 +192,10 @@ public class Control extends Module{
|
||||
respawntime = -1;
|
||||
hiscore = false;
|
||||
|
||||
for(Block block : Block.getAllBlocks()){
|
||||
block.onReset();
|
||||
}
|
||||
|
||||
ui.updateItems();
|
||||
ui.updateWeapons();
|
||||
}
|
||||
|
@ -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<Class<? extends Enemy>> enemyIDs = Array.with(
|
||||
|
@ -91,6 +91,10 @@ public class Block{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void onReset(){
|
||||
|
||||
}
|
||||
|
||||
public boolean isSolidFor(Tile tile){
|
||||
return false;
|
||||
}
|
||||
|
@ -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<Tile, Boolean> 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user