Disable stage when parent stage is inactive

This commit is contained in:
SiboVG 2022-06-25 13:59:57 +02:00
parent 88e343a30c
commit 4d1e6165a8
2 changed files with 23 additions and 0 deletions

View File

@ -193,6 +193,10 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
public void _setStageActive(final int stageNumber, final boolean _active ) {
if ((0 <= stageNumber) && (stages.containsKey(stageNumber))) {
stages.get(stageNumber).active = _active;
// Set the active state of all the sub-stages as well.
for (AxialStage stage : rocket.getStage(stageNumber).getSubStages()) {
stages.get(stage.getStageNumber()).active = _active;
}
fireChangeEvent();
return;
}
@ -204,6 +208,10 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
if ((0 <= stageNumber) && (stages.containsKey(stageNumber))) {
StageFlags flags = stages.get(stageNumber);
flags.active = !flags.active;
// Set the active state of all the sub-stages as well.
for (AxialStage stage : rocket.getStage(stageNumber).getSubStages()) {
stages.get(stage.getStageNumber()).active = flags.active;
}
updateMotors();
updateActiveInstances();

View File

@ -1749,6 +1749,21 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
}
throw new IllegalStateException("getStage() called on hierarchy without an AxialStage.");
}
/**
* Returns all the stages that are a child or sub-child of this component.
* @return all the stages that are a child or sub-child of this component.
*/
public final List<AxialStage> getSubStages() {
List<AxialStage> result = new LinkedList<>();
Iterator<RocketComponent> it = iterator(false);
while (it.hasNext()) {
RocketComponent c = it.next();
if (c instanceof AxialStage)
result.add((AxialStage) c);
}
return result;
}
/**
* Return the first component assembly component that this component belongs to.