Made doors save state properly
This commit is contained in:
@@ -192,6 +192,10 @@ public class Control extends Module{
|
|||||||
respawntime = -1;
|
respawntime = -1;
|
||||||
hiscore = false;
|
hiscore = false;
|
||||||
|
|
||||||
|
for(Block block : Block.getAllBlocks()){
|
||||||
|
block.onReset();
|
||||||
|
}
|
||||||
|
|
||||||
ui.updateItems();
|
ui.updateItems();
|
||||||
ui.updateWeapons();
|
ui.updateWeapons();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ import io.anuke.ucore.entities.Entities;
|
|||||||
*/
|
*/
|
||||||
public class SaveIO{
|
public class SaveIO{
|
||||||
/**Save file version ID. Should be incremented every breaking release.*/
|
/**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?
|
//TODO automatic registration of types?
|
||||||
private static final Array<Class<? extends Enemy>> enemyIDs = Array.with(
|
private static final Array<Class<? extends Enemy>> enemyIDs = Array.with(
|
||||||
|
|||||||
@@ -91,6 +91,10 @@ public class Block{
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onReset(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isSolidFor(Tile tile){
|
public boolean isSolidFor(Tile tile){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,15 @@ package io.anuke.mindustry.world.blocks.types.defense;
|
|||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
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.Rectangle;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.utils.ObjectMap;
|
|
||||||
|
|
||||||
import io.anuke.mindustry.Vars;
|
import io.anuke.mindustry.Vars;
|
||||||
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
import io.anuke.mindustry.entities.effect.Fx;
|
import io.anuke.mindustry.entities.effect.Fx;
|
||||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
@@ -22,8 +26,6 @@ import io.anuke.ucore.scene.ui.layout.Table;
|
|||||||
import io.anuke.ucore.util.Tmp;
|
import io.anuke.ucore.util.Tmp;
|
||||||
|
|
||||||
public class Door extends Wall implements Configurable{
|
public class Door extends Wall implements Configurable{
|
||||||
private ObjectMap<Tile, Boolean> open = new ObjectMap<>();
|
|
||||||
|
|
||||||
protected Effect openfx = Fx.dooropen;
|
protected Effect openfx = Fx.dooropen;
|
||||||
protected Effect closefx = Fx.doorclose;
|
protected Effect closefx = Fx.doorclose;
|
||||||
|
|
||||||
@@ -34,7 +36,9 @@ public class Door extends Wall implements Configurable{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Tile tile){
|
public void draw(Tile tile){
|
||||||
if(open.get(tile, true)){
|
DoorEntity entity = tile.entity();
|
||||||
|
|
||||||
|
if(!entity.open){
|
||||||
Draw.rect(name, tile.worldx(), tile.worldy());
|
Draw.rect(name, tile.worldx(), tile.worldy());
|
||||||
}else{
|
}else{
|
||||||
Draw.rect(name + "-open", tile.worldx(), tile.worldy());
|
Draw.rect(name + "-open", tile.worldx(), tile.worldy());
|
||||||
@@ -43,20 +47,25 @@ public class Door extends Wall implements Configurable{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSolidFor(Tile tile){
|
public boolean isSolidFor(Tile tile){
|
||||||
return open.get(tile, true);
|
DoorEntity entity = tile.entity();
|
||||||
|
return !entity.open;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void buildTable(Tile tile, Table table){
|
public void buildTable(Tile tile, Table table){
|
||||||
if(anyEntities(tile) && !open.get(tile, true)){
|
DoorEntity entity = tile.entity();
|
||||||
|
|
||||||
|
if(anyEntities(tile) && !entity.open){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
open.put(tile, !open.get(tile, true));
|
Vector2 offset = getPlaceOffset();
|
||||||
if(open.get(tile)){
|
|
||||||
Effects.effect(closefx, tile.worldx(), tile.worldy());
|
entity.open = !entity.open;
|
||||||
|
if(!entity.open){
|
||||||
|
Effects.effect(closefx, tile.worldx() + offset.x, tile.worldy() + offset.y);
|
||||||
}else{
|
}else{
|
||||||
Effects.effect(openfx, tile.worldx(), tile.worldy());
|
Effects.effect(openfx, tile.worldx() + offset.x, tile.worldy() + offset.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,4 +91,25 @@ public class Door extends Wall implements Configurable{
|
|||||||
return false;
|
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.
Reference in New Issue
Block a user