[#1680] Update flight config stages based on stage ID
This commit is contained in:
parent
9cb57ae9c8
commit
8c7fb6b67f
@ -46,22 +46,23 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
|
|
||||||
private class StageFlags implements Cloneable {
|
private class StageFlags implements Cloneable {
|
||||||
public boolean active = true;
|
public boolean active = true;
|
||||||
//public int prev = -1;
|
|
||||||
public int stageNumber = -1;
|
public int stageNumber = -1;
|
||||||
|
public FlightConfigurationId stageId;
|
||||||
|
|
||||||
public StageFlags( int _num, boolean _active) {
|
public StageFlags(int _num, FlightConfigurationId stageId, boolean _active) {
|
||||||
this.stageNumber = _num;
|
this.stageNumber = _num;
|
||||||
|
this.stageId = stageId;
|
||||||
this.active = _active;
|
this.active = _active;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StageFlags clone(){
|
public StageFlags clone(){
|
||||||
return new StageFlags( this.stageNumber, true);
|
return new StageFlags(this.stageNumber, this.stageId, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cached data */
|
/* Cached data */
|
||||||
final protected Map<Integer, StageFlags> stages = new HashMap<Integer, StageFlags>(); // Map of stage number to StageFlags of the corresponding stage
|
final protected Map<Integer, StageFlags> stages = new HashMap<>(); // Map of stage number to StageFlags of the corresponding stage
|
||||||
final protected Map<MotorConfigurationId, MotorConfiguration> motors = new HashMap<MotorConfigurationId, MotorConfiguration>();
|
final protected Map<MotorConfigurationId, MotorConfiguration> motors = new HashMap<MotorConfigurationId, MotorConfiguration>();
|
||||||
final private Collection<MotorConfiguration> activeMotors = new ConcurrentLinkedQueue<MotorConfiguration>();
|
final private Collection<MotorConfiguration> activeMotors = new ConcurrentLinkedQueue<MotorConfiguration>();
|
||||||
final private InstanceMap activeInstances = new InstanceMap();
|
final private InstanceMap activeInstances = new InstanceMap();
|
||||||
@ -130,7 +131,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
|
|
||||||
public void copyStages(FlightConfiguration other) {
|
public void copyStages(FlightConfiguration other) {
|
||||||
for (StageFlags cur : other.stages.values())
|
for (StageFlags cur : other.stages.values())
|
||||||
stages.put(cur.stageNumber, new StageFlags(cur.stageNumber, cur.active));
|
stages.put(cur.stageNumber, new StageFlags(cur.stageNumber, cur.stageId, cur.active));
|
||||||
updateMotors();
|
updateMotors();
|
||||||
updateActiveInstances();
|
updateActiveInstances();
|
||||||
}
|
}
|
||||||
@ -370,7 +371,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
public List<AxialStage> getAllStages() {
|
public List<AxialStage> getAllStages() {
|
||||||
List<AxialStage> stages = new ArrayList<>();
|
List<AxialStage> stages = new ArrayList<>();
|
||||||
for (StageFlags flags : this.stages.values()) {
|
for (StageFlags flags : this.stages.values()) {
|
||||||
stages.add( rocket.getStage(flags.stageNumber));
|
stages.add( rocket.getStage(flags.stageId));
|
||||||
}
|
}
|
||||||
return stages;
|
return stages;
|
||||||
}
|
}
|
||||||
@ -380,7 +381,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
|
|
||||||
for (StageFlags flags : this.stages.values()) {
|
for (StageFlags flags : this.stages.values()) {
|
||||||
if (flags.active) {
|
if (flags.active) {
|
||||||
AxialStage stage = rocket.getStage(flags.stageNumber);
|
AxialStage stage = rocket.getStage(flags.stageId);
|
||||||
if (stage == null) {
|
if (stage == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -408,7 +409,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
AxialStage bottomStage = null;
|
AxialStage bottomStage = null;
|
||||||
for (StageFlags curFlags : this.stages.values()) {
|
for (StageFlags curFlags : this.stages.values()) {
|
||||||
if (curFlags.active) {
|
if (curFlags.active) {
|
||||||
bottomStage = rocket.getStage( curFlags.stageNumber);
|
bottomStage = rocket.getStage(curFlags.stageId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bottomStage;
|
return bottomStage;
|
||||||
@ -458,14 +459,18 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateStages() {
|
private void updateStages() {
|
||||||
if (this.rocket.getStageCount() == this.stages.size()) {
|
Map<Integer, FlightConfiguration.StageFlags> stagesBackup = new HashMap<>(this.stages);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.stages.clear();
|
this.stages.clear();
|
||||||
for (AxialStage curStage : this.rocket.getStageList()) {
|
for (AxialStage curStage : this.rocket.getStageList()) {
|
||||||
if (curStage == null) continue;
|
if (curStage == null) continue;
|
||||||
StageFlags flagsToAdd = new StageFlags( curStage.getStageNumber(), true);
|
boolean active = true;
|
||||||
|
for (FlightConfiguration.StageFlags flag : stagesBackup.values()) {
|
||||||
|
if (flag.stageId.equals(curStage.getStageId())) {
|
||||||
|
active = flag.active;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StageFlags flagsToAdd = new StageFlags(curStage.getStageNumber(), curStage.getStageId(), active);
|
||||||
this.stages.put(curStage.getStageNumber(), flagsToAdd);
|
this.stages.put(curStage.getStageNumber(), flagsToAdd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -850,8 +855,8 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
final String fmt = " [%-2s][%4s]: %6s \n";
|
final String fmt = " [%-2s][%4s]: %6s \n";
|
||||||
buf.append(String.format(fmt, "#", "?actv", "Name"));
|
buf.append(String.format(fmt, "#", "?actv", "Name"));
|
||||||
for (StageFlags flags : stages.values()) {
|
for (StageFlags flags : stages.values()) {
|
||||||
final int stageNumber = flags.stageNumber;
|
final FlightConfigurationId stageId = flags.stageId;
|
||||||
buf.append(String.format(fmt, stageNumber, (flags.active?" on": "off"), rocket.getStage( stageNumber).getName()));
|
buf.append(String.format(fmt, stageId, (flags.active?" on": "off"), rocket.getStage(stageId).getName()));
|
||||||
}
|
}
|
||||||
buf.append("\n");
|
buf.append("\n");
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user