Browse Source

More PowerEntry work.

feature-config-parsing2
MagicBot 3 months ago
parent
commit
10d98f32b6
  1. 26
      src/engine/wpak/PowersParser.java

26
src/engine/wpak/PowersParser.java

@ -25,9 +25,10 @@ import java.util.regex.Pattern;
public class PowersParser { public class PowersParser {
public static String powersPath = ConfigManager.DEFAULT_DATA_DIR + "wpak/Powers.cfg"; private static String powersPath = ConfigManager.DEFAULT_DATA_DIR + "wpak/Powers.cfg";
private static final Pattern POWER_REGEX = Pattern.compile("(?<=POWERBEGIN)(.+?)(?=POWEREND)", Pattern.DOTALL); private static final Pattern POWER_REGEX = Pattern.compile("(?<=POWERBEGIN)(.+?)(?=POWEREND)", Pattern.DOTALL);
private static final Pattern STRSPLIT_REGEX = Pattern.compile("([^\"]\\S*|\"[^\"]*\")\\s*"); private static final Pattern STRSPLIT_REGEX = Pattern.compile("([^\"]\\S*|\"[^\"]*\")\\s*");
private static final Pattern CONDITION_REGEX = Pattern.compile("(CONDITIONBEGIN.*?CONDITIONEND)");
public static void parseWpakFile() throws IOException { public static void parseWpakFile() throws IOException {
@ -53,7 +54,26 @@ public class PowersParser {
try { try {
String[] lineData = powerData.trim().split("\n"); // Remove all lines that contain a # and leading/trailing blank lines
powerData = powerData.replaceAll("(?m)^.*#.*\r?\n?", "");
StringBuilder conditionString = new StringBuilder();
StringBuilder powerString = new StringBuilder();
int endPos = 0;
Matcher matcher = CONDITION_REGEX.matcher(powerData);
while (matcher.find()) {
conditionString.append(matcher.group());
powerString.append(matcher.start());
endPos = matcher.end();
}
powerString.append(powerData.substring(endPos));
String[] lineData = powerString.toString().trim().split("\n");
ArrayList<String> powerHeader = new ArrayList<>(); ArrayList<String> powerHeader = new ArrayList<>();
// Parse header // Parse header
@ -61,7 +81,7 @@ public class PowersParser {
String headerString = lineData[0]; String headerString = lineData[0];
headerString = headerString.replace("\n", " "); headerString = headerString.replace("\n", " ");
Matcher matcher = STRSPLIT_REGEX.matcher(headerString); matcher = STRSPLIT_REGEX.matcher(headerString);
while (matcher.find()) while (matcher.find())
powerHeader.add(matcher.group().trim()); powerHeader.add(matcher.group().trim());

Loading…
Cancel
Save