Archived
0

use laden ship mass in profile model

This commit is contained in:
iMoHax
2016-04-01 14:16:21 +03:00
parent 51428a3dfd
commit 156171b679

View File

@@ -60,7 +60,7 @@ public class ProfileModel {
LOG.debug("Change docked, old: {}, new: {}", o, n); LOG.debug("Change docked, old: {}, new: {}", o, n);
if (!n && route.getValue() != null) {getRoute().updateCurrentEntry(getSystem(), getStation(), true);} if (!n && route.getValue() != null) {getRoute().updateCurrentEntry(getSystem(), getStation(), true);}
}); });
shipMass.addListener((ov, o, n) -> LOG.debug("Change ship mass, old: {}, new: {}", o, n)); shipMass.addListener((ov, o, n) -> LOG.debug("Change ship laden mass, old: {}, new: {}", o, n));
shipTank.addListener((ov, o, n) -> LOG.debug("Change ship tank, old: {}, new: {}", o, n)); shipTank.addListener((ov, o, n) -> LOG.debug("Change ship tank, old: {}, new: {}", o, n));
shipCargo.addListener((ov, o, n) -> LOG.debug("Change ship cargo, old: {}, new: {}", o, n)); shipCargo.addListener((ov, o, n) -> LOG.debug("Change ship cargo, old: {}, new: {}", o, n));
shipEngine.addListener((ov, o, n) -> LOG.debug("Change ship engine, old: {}, new: {}", o, n)); shipEngine.addListener((ov, o, n) -> LOG.debug("Change ship engine, old: {}, new: {}", o, n));
@@ -152,25 +152,25 @@ public class ProfileModel {
return shipMass.get(); return shipMass.get();
} }
public DoubleProperty shipMassProperty() { public ReadOnlyDoubleProperty shipMassProperty() {
return shipMass; return shipMass;
} }
public void setShipMass(double shipMass) { public void setShipMass(double shipMass) {
profile.getShip().setMass(shipMass); updateUnladenMass(shipMass);
this.shipMass.set(shipMass);
} }
public double getShipTank() { public double getShipTank() {
return shipTank.get(); return shipTank.get();
} }
public DoubleProperty shipTankProperty() { public ReadOnlyDoubleProperty shipTankProperty() {
return shipTank; return shipTank;
} }
public void setShipTank(double shipTank) { public void setShipTank(double shipTank) {
profile.getShip().setTank(shipTank); profile.getShip().setTank(shipTank);
updateUnladenMass(getShipMass());
this.shipTank.set(shipTank); this.shipTank.set(shipTank);
} }
@@ -178,12 +178,13 @@ public class ProfileModel {
return shipCargo.get(); return shipCargo.get();
} }
public IntegerProperty shipCargoProperty() { public ReadOnlyIntegerProperty shipCargoProperty() {
return shipCargo; return shipCargo;
} }
public void setShipCargo(int shipCargo) { public void setShipCargo(int shipCargo) {
profile.getShip().setCargo(shipCargo); profile.getShip().setCargo(shipCargo);
updateUnladenMass(getShipMass());
this.shipCargo.set(shipCargo); this.shipCargo.set(shipCargo);
} }
@@ -228,6 +229,12 @@ public class ProfileModel {
route.setValue(null); route.setValue(null);
} }
private void updateUnladenMass(double ladenMass){
double unladenMass = ladenMass - profile.getShip().getTank() - profile.getShip().getCargo();
profile.getShip().setMass(unladenMass);
this.shipMass.set(profile.getShip().getLadenMass());
}
private void refresh(){ private void refresh(){
name.setValue(profile.getName()); name.setValue(profile.getName());
balance.setValue(profile.getBalance()); balance.setValue(profile.getBalance());
@@ -235,7 +242,7 @@ public class ProfileModel {
station.setValue(market.getModeler().get(profile.getStation())); station.setValue(market.getModeler().get(profile.getStation()));
docked.setValue(profile.isDocked()); docked.setValue(profile.isDocked());
Ship ship = profile.getShip(); Ship ship = profile.getShip();
shipMass.setValue(ship.getMass()); shipMass.setValue(ship.getLadenMass());
shipTank.setValue(ship.getTank()); shipTank.setValue(ship.getTank());
shipCargo.setValue(ship.getCargo()); shipCargo.setValue(ship.getCargo());
shipEngine.setValue(ship.getEngine()); shipEngine.setValue(ship.getEngine());