|
|
|
@ -8,10 +8,55 @@
@@ -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<String> 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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|