From 10d98f32b62751cf4cf91b365957055ca7ab703e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 19 Aug 2024 05:28:23 -0400 Subject: [PATCH] More PowerEntry work. --- src/engine/wpak/PowersParser.java | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/engine/wpak/PowersParser.java b/src/engine/wpak/PowersParser.java index 81732ca7..37c01392 100644 --- a/src/engine/wpak/PowersParser.java +++ b/src/engine/wpak/PowersParser.java @@ -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 { 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 powerHeader = new ArrayList<>(); // Parse header @@ -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());