Process an iteration of a FOR loop. @param node The node being processed @param output The writer output is to be sent to. @param aPC The character being processed. @param index The current value of the loop index @return true if the loop should be stopped.
(FORNode node, BufferedWriter output, PlayerCharacter aPC, int index)
| 841 | * @return true if the loop should be stopped. |
| 842 | */ |
| 843 | private boolean processLoop(FORNode node, BufferedWriter output, PlayerCharacter aPC, int index) |
| 844 | { |
| 845 | loopVariables.put(node.var(), index); |
| 846 | int numberOfChildrenNodes = node.children().size(); |
| 847 | for (int y = 0; y < numberOfChildrenNodes; ++y) |
| 848 | { |
| 849 | if (node.children().get(y) instanceof FORNode nextFor) |
| 850 | { |
| 851 | loopVariables.put(nextFor.var(), 0); |
| 852 | existsOnly = nextFor.exists(); |
| 853 | |
| 854 | String minString = nextFor.min(); |
| 855 | String maxString = nextFor.max(); |
| 856 | String stepString = nextFor.step(); |
| 857 | |
| 858 | minString = replaceVariables(minString, loopParameters); |
| 859 | minString = replaceVariables(minString, loopVariables); |
| 860 | maxString = replaceVariables(maxString, loopParameters); |
| 861 | maxString = replaceVariables(maxString, loopVariables); |
| 862 | stepString = replaceVariables(stepString, loopParameters); |
| 863 | stepString = replaceVariables(stepString, loopVariables); |
| 864 | |
| 865 | final int varMin = getVarValue(minString, aPC); |
| 866 | final int varMax = getVarValue(maxString, aPC); |
| 867 | final int varStep = getVarValue(stepString, aPC); |
| 868 | String var = nextFor.var(); |
| 869 | loopParameters.put(var + "!MIN", varMin); |
| 870 | loopParameters.put(var + "!MAX", varMax); |
| 871 | loopParameters.put(var + "!STEP", varMax); |
| 872 | |
| 873 | loopFOR(nextFor, varMin, varMax, varStep, output, aPC); |
| 874 | loopParameters.remove(var + "!MIN"); |
| 875 | loopParameters.remove(var + "!MAX"); |
| 876 | loopParameters.remove(var + "!STEP"); |
| 877 | |
| 878 | existsOnly = node.exists(); |
| 879 | loopVariables.remove(nextFor.var()); |
| 880 | } |
| 881 | else if (node.children().get(y) instanceof IIFNode) |
| 882 | { |
| 883 | evaluateIIF((IIFNode) node.children().get(y), output, aPC); |
| 884 | } |
| 885 | else |
| 886 | { |
| 887 | String lineString = (String) node.children().get(y); |
| 888 | lineString = replaceVariables(lineString, loopParameters); |
| 889 | lineString = replaceVariables(lineString, loopVariables); |
| 890 | |
| 891 | noMoreItems = false; |
| 892 | replaceLine(lineString, output, aPC); |
| 893 | |
| 894 | // If the output sheet author has no control |
| 895 | // over the whitespace then print a newline. |
| 896 | if (canWrite && !manualWhitespace) |
| 897 | { |
| 898 | FileAccess.newLine(output); |
| 899 | } |
| 900 |
no test coverage detected