Better save validation

This commit is contained in:
Anuken
2020-10-29 19:03:58 -04:00
parent cd6516786b
commit 1663497e6c
4 changed files with 17 additions and 8 deletions

View File

@@ -875,6 +875,7 @@ public class UnitTypes implements ContentList{
health = 75;
engineOffset = 5.5f;
range = 140f;
targetAir = false;
weapons.add(new Weapon(){{
y = 0f;

View File

@@ -13,7 +13,7 @@ public class DrawOperation{
private MapEditor editor;
private LongSeq array = new LongSeq();
public DrawOperation(MapEditor editor) {
public DrawOperation(MapEditor editor){
this.editor = editor;
}
@@ -37,7 +37,7 @@ public class DrawOperation{
}
}
private void updateTile(int i) {
private void updateTile(int i){
long l = array.get(i);
array.set(i, TileOp.get(TileOp.x(l), TileOp.y(l), TileOp.type(l), getTile(editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l))));
setTile(editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l), TileOp.value(l));

View File

@@ -79,8 +79,10 @@ public abstract class BulletType extends Content{
public boolean backMove = true;
/** Bullet range override. */
public float range = -1f;
/** Heal Bullet Percent **/
/** % of block health healed **/
public float healPercent = 0f;
/** whether to make fire on impact */
public boolean makeFire = false;
//additional effects
@@ -158,7 +160,7 @@ public abstract class BulletType extends Content{
}
public void hitTile(Bullet b, Building tile, float initialHealth){
if(status == StatusEffects.burning) {
if(makeFire) {
Fires.create(tile.tile);
}
hit(b);
@@ -209,14 +211,14 @@ public abstract class BulletType extends Content{
Damage.status(b.team, x, y, splashDamageRadius, status, statusDuration, collidesAir, collidesGround);
}
if(healPercent > 0f) {
if(healPercent > 0f){
indexer.eachBlock(b.team, x, y, splashDamageRadius, other -> other.damaged(), other -> {
Fx.healBlockFull.at(other.x, other.y, other.block.size, Pal.heal);
other.heal(healPercent / 100f * other.maxHealth());
});
}
if(status == StatusEffects.burning) {
if(makeFire){
indexer.eachBlock(null, x, y, splashDamageRadius, other -> other.team != b.team, other -> {
Fires.create(other.tile);
});

View File

@@ -2,6 +2,7 @@ package mindustry.io;
import arc.struct.*;
import arc.struct.ObjectMap.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.world.*;
@@ -60,9 +61,11 @@ public abstract class SaveFileReader{
protected final DataOutputStream dataBytesSmall = new DataOutputStream(byteOutputSmall);
protected int lastRegionLength;
protected @Nullable CounterInputStream currCounter;
protected void region(String name, DataInput stream, CounterInputStream counter, IORunner<DataInput> cons) throws IOException{
counter.resetCount();
this.currCounter = counter;
int length;
try{
length = readChunk(stream, cons);
@@ -70,8 +73,8 @@ public abstract class SaveFileReader{
throw new IOException("Error reading region \"" + name + "\".", e);
}
if(length != counter.count() - 4){
throw new IOException("Error reading region \"" + name + "\": read length mismatch. Expected: " + length + "; Actual: " + (counter.count() - 4));
if(length != counter.count - 4){
throw new IOException("Error reading region \"" + name + "\": read length mismatch. Expected: " + length + "; Actual: " + (counter.count - 4));
}
}
@@ -114,8 +117,11 @@ public abstract class SaveFileReader{
/** Reads a chunk of some length. Use the runner for reading to catch more descriptive errors. */
public int readChunk(DataInput input, boolean isShort, IORunner<DataInput> runner) throws IOException{
int length = isShort ? input.readUnsignedShort() : input.readInt();
int pos = currCounter.count;
lastRegionLength = length;
runner.accept(input);
if(pos + length != currCounter.count) throw new IOException("Read length mismatch. Expected: " + length + ", Actual: " + (currCounter.count - pos));
return length;
}