[#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 {
|
||||
public boolean active = true;
|
||||
//public int prev = -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.stageId = stageId;
|
||||
this.active = _active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StageFlags clone(){
|
||||
return new StageFlags( this.stageNumber, true);
|
||||
return new StageFlags(this.stageNumber, this.stageId, true);
|
||||
}
|
||||
}
|
||||
|
||||
/* 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 private Collection<MotorConfiguration> activeMotors = new ConcurrentLinkedQueue<MotorConfiguration>();
|
||||
final private InstanceMap activeInstances = new InstanceMap();
|
||||
@ -130,7 +131,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
|
||||
public void copyStages(FlightConfiguration other) {
|
||||
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();
|
||||
updateActiveInstances();
|
||||
}
|
||||
@ -370,7 +371,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
public List<AxialStage> getAllStages() {
|
||||
List<AxialStage> stages = new ArrayList<>();
|
||||
for (StageFlags flags : this.stages.values()) {
|
||||
stages.add( rocket.getStage(flags.stageNumber));
|
||||
stages.add( rocket.getStage(flags.stageId));
|
||||
}
|
||||
return stages;
|
||||
}
|
||||
@ -380,7 +381,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
|
||||
for (StageFlags flags : this.stages.values()) {
|
||||
if (flags.active) {
|
||||
AxialStage stage = rocket.getStage(flags.stageNumber);
|
||||
AxialStage stage = rocket.getStage(flags.stageId);
|
||||
if (stage == null) {
|
||||
continue;
|
||||
}
|
||||
@ -408,7 +409,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
AxialStage bottomStage = null;
|
||||
for (StageFlags curFlags : this.stages.values()) {
|
||||
if (curFlags.active) {
|
||||
bottomStage = rocket.getStage( curFlags.stageNumber);
|
||||
bottomStage = rocket.getStage(curFlags.stageId);
|
||||
}
|
||||
}
|
||||
return bottomStage;
|
||||
@ -458,14 +459,18 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
}
|
||||
|
||||
private void updateStages() {
|
||||
if (this.rocket.getStageCount() == this.stages.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<Integer, FlightConfiguration.StageFlags> stagesBackup = new HashMap<>(this.stages);
|
||||
this.stages.clear();
|
||||
for (AxialStage curStage : this.rocket.getStageList()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -850,8 +855,8 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
||||
final String fmt = " [%-2s][%4s]: %6s \n";
|
||||
buf.append(String.format(fmt, "#", "?actv", "Name"));
|
||||
for (StageFlags flags : stages.values()) {
|
||||
final int stageNumber = flags.stageNumber;
|
||||
buf.append(String.format(fmt, stageNumber, (flags.active?" on": "off"), rocket.getStage( stageNumber).getName()));
|
||||
final FlightConfigurationId stageId = flags.stageId;
|
||||
buf.append(String.format(fmt, stageId, (flags.active?" on": "off"), rocket.getStage(stageId).getName()));
|
||||
}
|
||||
buf.append("\n");
|
||||
return buf.toString();
|
||||
|
Loading…
x
Reference in New Issue
Block a user