From 97c118ae1ac163007e47d5e06541aca4bf0c0c18 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Tue, 13 Aug 2024 12:20:27 -0400 Subject: [PATCH] PowerEntry parsing work --- src/engine/wpak/EffectsParser.java | 4 +-- src/engine/wpak/PowersParser.java | 47 +++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/engine/wpak/EffectsParser.java b/src/engine/wpak/EffectsParser.java index d6800cd9..78ff2db2 100644 --- a/src/engine/wpak/EffectsParser.java +++ b/src/engine/wpak/EffectsParser.java @@ -22,7 +22,7 @@ import java.util.regex.Pattern; public class EffectsParser { - public static String EffectsPath = ConfigManager.DEFAULT_DATA_DIR + "wpak/Effects.cfg"; + public static String effectsPath = ConfigManager.DEFAULT_DATA_DIR + "wpak/Effects.cfg"; public static HashMap effect_data = new HashMap<>(); private static final Pattern EFFECT_REGEX = Pattern.compile("(?<=EFFECTBEGIN)(.+?)(?=EFFECTEND)", Pattern.DOTALL); private static final Pattern SOURCE_REGEX = Pattern.compile("(?<=SOURCEBEGIN)(.+?)(?=SOURCEEND)", Pattern.DOTALL); @@ -34,7 +34,7 @@ public class EffectsParser { // Read .wpak file from disk - byte[] fileData = Files.readAllBytes(Paths.get(EffectsPath)); + byte[] fileData = Files.readAllBytes(Paths.get(effectsPath)); String fileContents = new String(fileData); // Iterate over effect entries from .wpak data diff --git a/src/engine/wpak/PowersParser.java b/src/engine/wpak/PowersParser.java index 11ab9060..dd8c4077 100644 --- a/src/engine/wpak/PowersParser.java +++ b/src/engine/wpak/PowersParser.java @@ -8,10 +8,55 @@ package engine.wpak; +import engine.gameManager.ConfigManager; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.regex.Matcher; import java.util.regex.Pattern; public class PowersParser { + public static String powersPath = ConfigManager.DEFAULT_DATA_DIR + "wpak/Effects.cfg"; private static final Pattern POWER_REGEX = Pattern.compile("(?<=POWERBEGIN)(.+?)(?=POWEREND)", Pattern.DOTALL); - + private static final Pattern STRSPLIT_REGEX = Pattern.compile("([^\"]\\S*|\"[^\"]*\")\\s*"); + + public static void parseWpakFile() throws IOException { + + // Read .wpak file from disk + + byte[] fileData = Files.readAllBytes(Paths.get(powersPath)); + String fileContents = new String(fileData); + + // Iterate over effect entries from .wpak data + + Matcher matcher = POWER_REGEX.matcher(fileContents); + + while (matcher.find()) { + + PowerEntry powerEntry = parsePowerEntry(matcher.group(1).trim()); + + } + } + + private static PowerEntry parsePowerEntry(String powerData) { + + PowerEntry powerEntry = new PowerEntry(); + ArrayList powerValues = new ArrayList<>(); + String[] powerEntries = powerData.trim().split("\n"); + + for (String powerString : powerEntries) { + + Matcher matcher = STRSPLIT_REGEX.matcher(powerString.trim()); + + while (matcher.find()) + powerValues.add(matcher.group(1).trim()); + + } + return powerEntry; + } + } +