Implemented saving of conveyor belt contents and turret ammo
This commit is contained in:
@@ -276,8 +276,6 @@ public class Control extends RendererModule{
|
|||||||
public void update(){
|
public void update(){
|
||||||
|
|
||||||
if(debug){
|
if(debug){
|
||||||
if(Inputs.keyUp(Keys.ESCAPE))
|
|
||||||
Gdx.app.exit();
|
|
||||||
|
|
||||||
if(Inputs.keyUp(Keys.SPACE))
|
if(Inputs.keyUp(Keys.SPACE))
|
||||||
Effects.sound("shoot", World.core.worldx(), World.core.worldy());
|
Effects.sound("shoot", World.core.worldx(), World.core.worldy());
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class Vars{
|
|||||||
//how much the zoom changes every zoom button press
|
//how much the zoom changes every zoom button press
|
||||||
public static final int zoomScale = Math.round(Unit.dp.inPixels(1));
|
public static final int zoomScale = Math.round(Unit.dp.inPixels(1));
|
||||||
//if true, player speed will be increased, massive amounts of resources will be given on start, and other debug options will be available
|
//if true, player speed will be increased, massive amounts of resources will be given on start, and other debug options will be available
|
||||||
public static boolean debug = true;
|
public static boolean debug = false;
|
||||||
//number of save slots-- increasing may lead to layout issues
|
//number of save slots-- increasing may lead to layout issues
|
||||||
public static final int saveSlots = 4;
|
public static final int saveSlots = 4;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.entities;
|
|||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.badlogic.gdx.utils.ObjectMap;
|
import com.badlogic.gdx.utils.ObjectMap;
|
||||||
|
|
||||||
@@ -32,11 +33,11 @@ public class TileEntity extends Entity{
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(DataOutputStream stream){
|
public void write(DataOutputStream stream) throws IOException{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read(TileEntity entity, DataInputStream stream){
|
public void read(DataInputStream stream) throws IOException{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,20 +9,18 @@ import java.util.Date;
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.ObjectMap;
|
import com.badlogic.gdx.utils.ObjectMap;
|
||||||
import com.badlogic.gdx.utils.TimeUtils;
|
import com.badlogic.gdx.utils.TimeUtils;
|
||||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||||
|
|
||||||
import io.anuke.mindustry.*;
|
import io.anuke.mindustry.*;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
|
||||||
import io.anuke.mindustry.entities.Weapon;
|
import io.anuke.mindustry.entities.Weapon;
|
||||||
import io.anuke.mindustry.entities.enemies.*;
|
import io.anuke.mindustry.entities.enemies.*;
|
||||||
import io.anuke.mindustry.resource.Item;
|
import io.anuke.mindustry.resource.Item;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.blocks.Blocks;
|
import io.anuke.mindustry.world.blocks.Blocks;
|
||||||
import io.anuke.mindustry.world.blocks.Conveyor.ConveyorEntity;
|
|
||||||
import io.anuke.mindustry.world.blocks.Turret.TurretEntity;
|
|
||||||
import io.anuke.ucore.entities.Entities;
|
import io.anuke.ucore.entities.Entities;
|
||||||
import io.anuke.ucore.entities.Entity;
|
import io.anuke.ucore.entities.Entity;
|
||||||
|
|
||||||
@@ -76,6 +74,7 @@ import io.anuke.ucore.entities.Entity;
|
|||||||
* (item list)
|
* (item list)
|
||||||
* Item ID (byte)
|
* Item ID (byte)
|
||||||
* Item amount (int)
|
* Item amount (int)
|
||||||
|
* Additional tile entity data (varies, check the TileEntity classes)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class SaveIO{
|
public class SaveIO{
|
||||||
@@ -97,17 +96,6 @@ public class SaveIO{
|
|||||||
put(enemyIDs.get(value), value);
|
put(enemyIDs.get(value), value);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
private static final ObjectMap<Class<? extends TileEntity>, Byte> tileIDs = new ObjectMap<Class<? extends TileEntity>, Byte>(){{
|
|
||||||
put(TileEntity.class, (byte)0);
|
|
||||||
put(TurretEntity.class, (byte)1);
|
|
||||||
put(ConveyorEntity.class, (byte)2);
|
|
||||||
}};
|
|
||||||
|
|
||||||
private static final ObjectMap<Byte, Class<? extends TileEntity>> idTiles = new ObjectMap<Byte, Class<? extends TileEntity>>(){{
|
|
||||||
for(Class<? extends TileEntity> value : tileIDs.keys())
|
|
||||||
put(tileIDs.get(value), value);
|
|
||||||
}};
|
|
||||||
|
|
||||||
public static void saveToSlot(int slot){
|
public static void saveToSlot(int slot){
|
||||||
write(fileFor(slot));
|
write(fileFor(slot));
|
||||||
}
|
}
|
||||||
@@ -232,18 +220,16 @@ public class SaveIO{
|
|||||||
stream.writeInt(tile.block().id); //block ID
|
stream.writeInt(tile.block().id); //block ID
|
||||||
|
|
||||||
if(tile.entity != null){
|
if(tile.entity != null){
|
||||||
stream.writeByte(tile.rotation);
|
stream.writeByte(tile.rotation); //rotation
|
||||||
stream.writeInt(tile.entity.health); //health
|
stream.writeInt(tile.entity.health); //health
|
||||||
stream.writeByte(tile.entity.items.size); //amount of items
|
stream.writeByte(tile.entity.items.size); //amount of items
|
||||||
|
|
||||||
//if(strea){
|
|
||||||
// stream.writeInt(tile.entity.);
|
|
||||||
//}
|
|
||||||
|
|
||||||
for(Item item : tile.entity.items.keys()){
|
for(Item item : tile.entity.items.keys()){
|
||||||
stream.writeByte(item.ordinal()); //item ID
|
stream.writeByte(item.ordinal()); //item ID
|
||||||
stream.writeInt(tile.entity.items.get(item)); //item amount
|
stream.writeInt(tile.entity.items.get(item)); //item amount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tile.entity.write(stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -311,6 +297,8 @@ public class SaveIO{
|
|||||||
|
|
||||||
int enemies = stream.readInt();
|
int enemies = stream.readInt();
|
||||||
|
|
||||||
|
Array<Enemy> enemiesToUpdate = new Array<>();
|
||||||
|
|
||||||
for(int i = 0; i < enemies; i ++){
|
for(int i = 0; i < enemies; i ++){
|
||||||
byte type = stream.readByte();
|
byte type = stream.readByte();
|
||||||
int lane = stream.readByte();
|
int lane = stream.readByte();
|
||||||
@@ -320,11 +308,11 @@ public class SaveIO{
|
|||||||
|
|
||||||
try{
|
try{
|
||||||
Enemy enemy = (Enemy)ClassReflection.getConstructor(idEnemies.get(type), int.class).newInstance(lane);
|
Enemy enemy = (Enemy)ClassReflection.getConstructor(idEnemies.get(type), int.class).newInstance(lane);
|
||||||
enemy.findClosestNode();
|
|
||||||
enemy.health = health;
|
enemy.health = health;
|
||||||
enemy.x = x;
|
enemy.x = x;
|
||||||
enemy.y = y;
|
enemy.y = y;
|
||||||
enemy.add();
|
enemy.add();
|
||||||
|
enemiesToUpdate.add(enemy);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -344,6 +332,10 @@ public class SaveIO{
|
|||||||
World.loadMap(mapid, seed);
|
World.loadMap(mapid, seed);
|
||||||
Renderer.clearTiles();
|
Renderer.clearTiles();
|
||||||
|
|
||||||
|
for(Enemy enemy : enemiesToUpdate){
|
||||||
|
enemy.findClosestNode();
|
||||||
|
}
|
||||||
|
|
||||||
for(int x = 0; x < World.width(); x ++){
|
for(int x = 0; x < World.width(); x ++){
|
||||||
for(int y = 0; y < World.height(); y ++){
|
for(int y = 0; y < World.height(); y ++){
|
||||||
Tile tile = World.tile(x, y);
|
Tile tile = World.tile(x, y);
|
||||||
@@ -376,6 +368,8 @@ public class SaveIO{
|
|||||||
int itemamount = stream.readInt();
|
int itemamount = stream.readInt();
|
||||||
tile.entity.items.put(itemEnums[itemid], itemamount);
|
tile.entity.items.put(itemEnums[itemid], itemamount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tile.entity.read(stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ package io.anuke.mindustry.world.blocks;
|
|||||||
|
|
||||||
import static io.anuke.mindustry.Vars.tilesize;
|
import static io.anuke.mindustry.Vars.tilesize;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import com.badlogic.gdx.utils.DelayedRemovalArray;
|
import com.badlogic.gdx.utils.DelayedRemovalArray;
|
||||||
|
|
||||||
@@ -88,6 +92,31 @@ public class Conveyor extends Block{
|
|||||||
|
|
||||||
public static class ConveyorEntity extends TileEntity{
|
public static class ConveyorEntity extends TileEntity{
|
||||||
DelayedRemovalArray<ItemPos> convey = new DelayedRemovalArray<>();
|
DelayedRemovalArray<ItemPos> convey = new DelayedRemovalArray<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(DataOutputStream stream) throws IOException{
|
||||||
|
stream.writeInt(convey.size);
|
||||||
|
|
||||||
|
for(ItemPos pos : convey){
|
||||||
|
stream.writeByte(pos.item.ordinal());
|
||||||
|
stream.writeByte((int)(pos.pos*255-128));
|
||||||
|
stream.writeByte((int)(pos.y*255-128));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(DataInputStream stream) throws IOException{
|
||||||
|
int amount = stream.readInt();
|
||||||
|
|
||||||
|
for(int i = 0; i < amount; i ++){
|
||||||
|
Item item = Item.values()[stream.readByte()];
|
||||||
|
float pos = ((int)stream.readByte()+128)/255f;
|
||||||
|
float y = ((int)stream.readByte()+128)/255f;
|
||||||
|
|
||||||
|
ItemPos out = new ItemPos(item, pos, y);
|
||||||
|
convey.add(out);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ItemPos{
|
static class ItemPos{
|
||||||
@@ -99,5 +128,6 @@ public class Conveyor extends Block{
|
|||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package io.anuke.mindustry.world.blocks;
|
package io.anuke.mindustry.world.blocks;
|
||||||
import static io.anuke.mindustry.Vars.tilesize;
|
import static io.anuke.mindustry.Vars.tilesize;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
|
|
||||||
@@ -125,5 +129,15 @@ public class Turret extends Block{
|
|||||||
public TileEntity target;
|
public TileEntity target;
|
||||||
public int ammo;
|
public int ammo;
|
||||||
public float rotation;
|
public float rotation;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(DataOutputStream stream) throws IOException{
|
||||||
|
stream.writeInt(ammo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(DataInputStream stream) throws IOException{
|
||||||
|
this.ammo = stream.readInt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user