|
|
|
@ -25,9 +25,10 @@ import java.util.regex.Pattern;
@@ -25,9 +25,10 @@ import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
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 STRSPLIT_REGEX = Pattern.compile("([^\"]\\S*|\"[^\"]*\")\\s*"); |
|
|
|
|
private static final Pattern CONDITION_REGEX = Pattern.compile("(CONDITIONBEGIN.*?CONDITIONEND)"); |
|
|
|
|
|
|
|
|
|
public static void parseWpakFile() throws IOException { |
|
|
|
|
|
|
|
|
@ -53,7 +54,26 @@ public class PowersParser {
@@ -53,7 +54,26 @@ public class PowersParser {
|
|
|
|
|
|
|
|
|
|
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<>(); |
|
|
|
|
|
|
|
|
|
// Parse header
|
|
|
|
@ -61,7 +81,7 @@ public class PowersParser {
@@ -61,7 +81,7 @@ public class PowersParser {
|
|
|
|
|
String headerString = lineData[0]; |
|
|
|
|
headerString = headerString.replace("\n", " "); |
|
|
|
|
|
|
|
|
|
Matcher matcher = STRSPLIT_REGEX.matcher(headerString); |
|
|
|
|
matcher = STRSPLIT_REGEX.matcher(headerString); |
|
|
|
|
|
|
|
|
|
while (matcher.find()) |
|
|
|
|
powerHeader.add(matcher.group().trim()); |
|
|
|
|