Skip to content

Commit

Permalink
Condition progwidgets can't have true/false branches *and* default flow
Browse files Browse the repository at this point in the history
It is now a programmer error to have this situation

#1353
  • Loading branch information
desht committed Oct 13, 2024
1 parent ec0afc6 commit 061af05
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,13 @@ public void getTooltip(List<Component> curTooltip) {
@Override
public void addErrors(List<Component> curInfo, List<IProgWidget> widgets) {
super.addErrors(curInfo, widgets);

IProgWidget textTrue = getConnectedParameters()[getParameters().size() - 1];
IProgWidget textFalse = getConnectedParameters()[getParameters().size() * 2 - 1];
if (getMeasureVar().isEmpty() && getConnectedParameters()[getParameters().size() - 1] == null && getConnectedParameters()[getParameters().size() * 2 - 1] == null) {
curInfo.add(xlate("pneumaticcraft.gui.progWidget.condition.error.noFlowControl"));
} else if (getOutputWidget() != null && textTrue != null && textFalse != null) {
curInfo.add(xlate("pneumaticcraft.gui.progWidget.condition.error.badFlowControl"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ public WidgetDifficulty getDifficulty() {
@Override
public void addErrors(List<Component> curInfo, List<IProgWidget> widgets) {
super.addErrors(curInfo, widgets);
IProgWidget widget = getConnectedParameters()[getParameters().size() - 1];
IProgWidget widget2 = getConnectedParameters()[getParameters().size() * 2 - 1];
IProgWidget textTrue = getConnectedParameters()[getParameters().size() - 1];
IProgWidget textFalse = getConnectedParameters()[getParameters().size() * 2 - 1];
boolean hasMeasureVar = this instanceof ICondition cond && !cond.getMeasureVar().isEmpty();
if (widget == null && widget2 == null && !hasMeasureVar) {
if (textTrue == null && textFalse == null && !hasMeasureVar) {
curInfo.add(xlate("pneumaticcraft.gui.progWidget.condition.error.noFlowControl"));
} else if (widget != null && !(widget instanceof ProgWidgetText) || widget2 != null && !(widget2 instanceof ProgWidgetText)) {
} else if (textTrue != null && !(textTrue instanceof ProgWidgetText) || textFalse != null && !(textFalse instanceof ProgWidgetText)) {
curInfo.add(xlate("pneumaticcraft.gui.progWidget.condition.error.shouldConnectTextPieces"));
} else if (getOutputWidget() != null && textTrue != null && textFalse != null) {
curInfo.add(xlate("pneumaticcraft.gui.progWidget.condition.error.badFlowControl"));
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/pneumaticcraft/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,7 @@
"pneumaticcraft.gui.progWidget.conditionBlock.checkForLiquids" : "Check for Liquids",
"pneumaticcraft.gui.progWidget.conditionBlock.checkForLiquids.tooltip" : "Special condition. When checked, a block passes the filter when it's a liquid.",
"pneumaticcraft.gui.progWidget.conditionCoordinate.error.noAxisSelected" : "No checking axis selected. You need to check at least one condition for its value for the condition to work.",
"pneumaticcraft.gui.progWidget.condition.error.badFlowControl" : "With branch labels on both right (true) and left (false), the widget below is never used!",
"pneumaticcraft.gui.progWidget.condition.error.noFlowControl" : "No output label selected. The flow will continue downwards, regardless of the outcome of the condition.",
"pneumaticcraft.gui.progWidget.condition.error.shouldConnectTextPieces" : "You should only connect Text puzzle pieces that reference a Label puzzle piece with a text piece.",
"pneumaticcraft.gui.progWidget.condition.anyBlock" : "Any Block",
Expand Down

0 comments on commit 061af05

Please sign in to comment.