Archived
0

fix parse fuel in ED 2.0

This commit is contained in:
Mo
2015-12-27 13:43:01 +03:00
parent e4f8886018
commit 2a99db0ce3
7 changed files with 6578 additions and 26 deletions

View File

@@ -4,7 +4,7 @@ import java.util.Objects;
public class Fuel { public class Fuel {
private double capacity; private double capacity;
private double lvl; private double level;
public double getCapacity() { public double getCapacity() {
return capacity; return capacity;
@@ -14,12 +14,12 @@ public class Fuel {
this.capacity = capacity; this.capacity = capacity;
} }
public double getLvl() { public double getLevel() {
return lvl; return level;
} }
public void setLvl(double lvl) { public void setLevel(double level) {
this.lvl = lvl; this.level = level;
} }
@Override @Override
@@ -28,7 +28,7 @@ public class Fuel {
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
Fuel fuel = (Fuel) o; Fuel fuel = (Fuel) o;
return Objects.equals(capacity, fuel.capacity) && return Objects.equals(capacity, fuel.capacity) &&
Objects.equals(lvl, fuel.lvl); Objects.equals(level, fuel.level);
} }
@Override @Override

View File

@@ -0,0 +1,39 @@
package ru.trader.edce.entities;
import java.util.Objects;
public class FuelTanks {
private Fuel main;
private Fuel reserve;
public Fuel getMain() {
return main;
}
public void setMain(Fuel main) {
this.main = main;
}
public Fuel getReserve() {
return reserve;
}
public void setReserve(Fuel reserve) {
this.reserve = reserve;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FuelTanks fuelTanks = (FuelTanks) o;
return Objects.equals(main, fuelTanks.main) &&
Objects.equals(reserve, fuelTanks.reserve);
}
@Override
public int hashCode() {
return Objects.hash(main, reserve);
}
}

View File

@@ -2,11 +2,14 @@ package ru.trader.edce.entities;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.*; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class Ship { public class Ship {
private String name; private String name;
private Fuel fuel; private FuelTanks fuel;
private Cargo cargo; private Cargo cargo;
private Map<String, List<Slot>> modules = new LinkedHashMap<>(); private Map<String, List<Slot>> modules = new LinkedHashMap<>();
@@ -18,11 +21,11 @@ public class Ship {
this.name = name; this.name = name;
} }
public Fuel getFuel() { public FuelTanks getFuel() {
return fuel; return fuel;
} }
public void setFuel(Fuel fuel) { public void setFuel(FuelTanks fuel) {
this.fuel = fuel; this.fuel = fuel;
} }
@@ -43,13 +46,13 @@ public class Ship {
} }
@JsonIgnore @JsonIgnore
public double getFuelLvl(){ public double getFuelLevel(){
return fuel != null ? fuel.getLvl() : 0; return fuel != null ? fuel.getMain().getLevel() : 0;
} }
@JsonIgnore @JsonIgnore
public double getFuelCapacity(){ public double getFuelCapacity(){
return fuel != null ? fuel.getCapacity() : 0; return fuel != null ? fuel.getMain().getCapacity() : 0;
} }
@JsonIgnore @JsonIgnore

View File

@@ -7,7 +7,10 @@ import org.slf4j.LoggerFactory;
import ru.trader.edce.entities.*; import ru.trader.edce.entities.*;
import ru.trader.edce.entities.System; import ru.trader.edce.entities.System;
import java.io.*; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List; import java.util.List;
public class ParseTest extends Assert { public class ParseTest extends Assert {
@@ -68,7 +71,7 @@ public class ParseTest extends Assert {
assertNotNull(ship); assertNotNull(ship);
assertEquals("CobraMkIII", ship.getName()); assertEquals("CobraMkIII", ship.getName());
assertEquals(16, ship.getFuelCapacity(), 0.0001); assertEquals(16, ship.getFuelCapacity(), 0.0001);
assertEquals(16, ship.getFuelLvl(), 0.0001); assertEquals(16, ship.getFuelLevel(), 0.0001);
assertEquals(12, ship.getCargoCapacity()); assertEquals(12, ship.getCargoCapacity());
assertEquals(8, ship.getCargoLimit()); assertEquals(8, ship.getCargoLimit());
Module fsd = ship.getFSD(); Module fsd = ship.getFSD();
@@ -159,7 +162,7 @@ public class ParseTest extends Assert {
assertNotNull(ship); assertNotNull(ship);
assertEquals("CobraMkIII", ship.getName()); assertEquals("CobraMkIII", ship.getName());
assertEquals(16, ship.getFuelCapacity(), 0.0001); assertEquals(16, ship.getFuelCapacity(), 0.0001);
assertEquals(12.47372, ship.getFuelLvl(), 0.0001); assertEquals(12.47372, ship.getFuelLevel(), 0.0001);
assertEquals(0, ship.getCargoCapacity()); assertEquals(0, ship.getCargoCapacity());
assertEquals(0, ship.getCargoLimit()); assertEquals(0, ship.getCargoLimit());
Module fsd = ship.getFSD(); Module fsd = ship.getFSD();

View File

@@ -6710,11 +6710,14 @@
"cockpitBreached": false, "cockpitBreached": false,
"oxygenRemaining": 450000, "oxygenRemaining": 450000,
"fuel": { "fuel": {
"capacity": 16, "main": {
"lvl": 16 "level": 16,
"capacity": 16
}, },
"reserve": { "reserve": {
"lvl": 1 "level": 1,
"capacity": 1
}
}, },
"cargo": { "cargo": {
"capacity": 12, "capacity": 12,

View File

@@ -2448,11 +2448,14 @@
"cockpitBreached": false, "cockpitBreached": false,
"oxygenRemaining": 450000, "oxygenRemaining": 450000,
"fuel": { "fuel": {
"capacity": 16, "main": {
"lvl": 12.47372 "level": 12.47372,
"capacity": 16
}, },
"reserve": { "reserve": {
"lvl": 0.587228 "level": 0.587228,
"capacity": 1
}
}, },
"cargo": { "cargo": {
"capacity": 0, "capacity": 0,

File diff suppressed because it is too large Load Diff