1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-11-11 14:56:10 +03:00

Fixed save crash

This commit is contained in:
Anuken 2017-09-25 19:48:24 -04:00
parent 9f3d7be7b4
commit ce75be6204
10 changed files with 36 additions and 14 deletions

View File

@ -126,6 +126,12 @@ public class Renderer extends RendererModule{
//render the entire map
if(floorCache == null || floorCache.length != chunksx || floorCache[0].length != chunksy){
floorCache = new Cache[chunksx][chunksy];
for(int x = 0; x < chunksx; x ++){
for(int y = 0; y < chunksy; y ++){
renderCache(x, y);
}
}
}
OrthographicCamera camera = Core.camera;

View File

@ -435,7 +435,7 @@ public class UI extends SceneModule{
new table(){{
new table("pane"){{
new label(()->"Respawning in " + (int)(control.getRespawnTime()/60)).scale(0.75f).pad(10);
new label(()->"[orange]Respawning in " + (int)(control.getRespawnTime()/60)).scale(0.75f).pad(10);
visible(()->control.getRespawnTime() > 0 && !GameState.is(State.menu));

View File

@ -161,7 +161,6 @@ public class Enemy extends DestructibleEntity{
@Override
public void draw(){
Draw.color();
String region = ClassReflection.getSimpleName(getClass()).toLowerCase() + "-t" + Mathf.clamp(tier, 1, 3);
@ -170,6 +169,7 @@ public class Enemy extends DestructibleEntity{
Draw.getShader(Outline.class).region = Draw.region(region);
Draw.shader(Outline.class);
Draw.color();
Draw.rect(region, x, y, direction.angle()-90);
Draw.shader();
}

View File

@ -14,12 +14,13 @@ public class TankEnemy extends Enemy{
speed = 0.2f;
reload = 90f;
bullet = BulletType.small;
length = 3f;
}
void shoot(){
vector.set(length, 0).rotate(direction.angle());
Angles.shotgun(3, 4f, direction.angle(), f->{
Angles.shotgun(3, 8f, direction.angle(), f->{
Bullet out = new Bullet(bullet, this, x+vector.x, y+vector.y, f).add();
out.damage = (int)(damage*Vars.multiplier);
});

View File

@ -14,6 +14,7 @@ import io.anuke.mindustry.world.World;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.ucore.core.*;
import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.Mathf;
public class AndroidInput extends InputAdapter{
@ -101,7 +102,7 @@ public class AndroidInput extends InputAdapter{
public static void doInput(){
if(Gdx.input.isTouched(0)
&& Mathf.near2d(lmousex, lmousey, Gdx.input.getX(0), Gdx.input.getY(0), 50)
&& Mathf.near2d(lmousex, lmousey, Gdx.input.getX(0), Gdx.input.getY(0), Unit.dp.inPixels(50))
&& !ui.hasMouse() /*&& (player.recipe == null || mode == PlaceMode.touch)*/){
warmup += Timers.delta();
@ -127,8 +128,8 @@ public class AndroidInput extends InputAdapter{
mousey = ly;
}else{
warmup = 0;
lmousex = Gdx.input.getX(0);
lmousey = Gdx.input.getY(0);
//lmousex = Gdx.input.getX(0);
//lmousey = Gdx.input.getY(0);
player.breaktime = 0;
mousex = Mathf.clamp(mousex, 0, Gdx.graphics.getWidth());

View File

@ -59,6 +59,7 @@ import io.anuke.ucore.entities.Entity;
* spawn lane (byte)
* x (float)
* y (float)
* tier (byte)
* health (int)
*
*
@ -82,7 +83,7 @@ import io.anuke.ucore.entities.Entity;
*/
public class SaveIO{
/**Save file version ID. Should be incremented every breaking release.*/
private static final int fileVersionID = 6;
private static final int fileVersionID = 7;
private static FormatProvider provider = null;
@ -91,7 +92,11 @@ public class SaveIO{
Enemy.class,
FastEnemy.class,
RapidEnemy.class,
FlamerEnemy.class
FlamerEnemy.class,
TankEnemy.class,
BlastEnemy.class,
MortarEnemy.class,
TestEnemy.class
);
private static final ObjectMap<Class<? extends Enemy>, Byte> idEnemies = new ObjectMap<Class<? extends Enemy>, Byte>(){{
@ -186,6 +191,7 @@ public class SaveIO{
stream.writeByte(enemy.spawn); //lane
stream.writeFloat(enemy.x); //x
stream.writeFloat(enemy.y); //y
stream.writeByte(enemy.tier); //tier
stream.writeInt(enemy.health); //health
}
}
@ -308,6 +314,7 @@ public class SaveIO{
int lane = stream.readByte();
float x = stream.readFloat();
float y = stream.readFloat();
byte tier = stream.readByte();
int health = stream.readInt();
try{
@ -315,6 +322,7 @@ public class SaveIO{
enemy.health = health;
enemy.x = x;
enemy.y = y;
enemy.tier = tier;
enemy.add();
enemiesToUpdate.add(enemy);
}catch (Exception e){

View File

@ -2,6 +2,7 @@ package io.anuke.mindustry.ui;
import com.badlogic.gdx.utils.Timer;
import com.badlogic.gdx.utils.Timer.Task;
import com.badlogic.gdx.utils.reflect.ClassReflection;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.io.SaveIO;
@ -68,13 +69,17 @@ public class SaveDialog extends Dialog{
@Override
public void run(){
hide();
Vars.ui.hideLoading();
try{
SaveIO.saveToSlot(slot);
}catch (Exception e){
Vars.ui.showError("[orange]Failed to save game!");
return;
}catch (Throwable e){
e = (e.getCause() == null ? e : e.getCause());
Vars.ui.showError("[orange]Failed to save game!\n[white]" +
ClassReflection.getSimpleName(e.getClass()) + ": " + e.getMessage() + "\n" +
"at " + e.getStackTrace()[0].getFileName() + ":"+ e.getStackTrace()[0].getLineNumber());
}
Vars.ui.hideLoading();
}
}, 5f/60f);
}

View File

@ -21,8 +21,9 @@ public class Drill extends Block{
@Override
public void update(Tile tile){
if(tile.floor() == resource && Timers.get(tile, 60 * time)){
//drills can only hold up to 10 items at a time
if(tile.floor() == resource && Timers.get(tile, 60 * time) && tile.entity.totalItems() < 10){
offloadNear(tile, result);
Effects.effect("spark", tile.worldx(), tile.worldy());
}

Binary file not shown.

Binary file not shown.