|
|
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
|
|
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
|
|
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
|
|
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
|
|
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
|
|
|
// Magicbane Emulator Project © 2013 - 2024
|
|
|
|
// www.magicbane.com
|
|
|
|
|
|
|
|
package engine.ConfigParsing;
|
|
|
|
|
|
|
|
import engine.ConfigParsing.EffectEntry.EffectEntry;
|
|
|
|
import engine.gameManager.ConfigManager;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
public class EffectsParser {
|
|
|
|
|
|
|
|
public static String EffectsPath = ConfigManager.DEFAULT_DATA_DIR + "wpak/Effects.cfg";
|
|
|
|
public static HashMap<String, EffectEntry> 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);
|
|
|
|
private static final Pattern MODS_REGEX = Pattern.compile("(?<=MODSBEGIN)(.+?)(?=MODSEEND)", Pattern.DOTALL);
|
|
|
|
|
|
|
|
public static void init() throws IOException {
|
|
|
|
|
|
|
|
byte[] fileData = Files.readAllBytes(Paths.get(EffectsPath));
|
|
|
|
String fileContents = new String(fileData);
|
|
|
|
Matcher matcher = EFFECT_REGEX.matcher(fileContents);
|
|
|
|
|
|
|
|
// Iterate effect entries from .wpak config data
|
|
|
|
|
|
|
|
while (matcher.find()) {
|
|
|
|
EffectEntry effectEntry = parseEffectEntry(matcher.group());
|
|
|
|
|
|
|
|
if (effectEntry != null)
|
|
|
|
effect_data.put(effectEntry.id, effectEntry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static EffectEntry parseEffectEntry(String effectData) {
|
|
|
|
EffectEntry effectEntry = new EffectEntry();
|
|
|
|
|
|
|
|
// Remove all lines that contain a # and leading/trailing blanks
|
|
|
|
|
|
|
|
effectData = effectData.replaceAll("(?m)^.*#.*\r?\n?", "");
|
|
|
|
effectData = effectData.trim();
|
|
|
|
|
|
|
|
// Parse effect entry description
|
|
|
|
|
|
|
|
String firstLine = effectData.substring(0, effectData.indexOf('\n'));
|
|
|
|
String[] effectDescription = firstLine.split(" ");
|
|
|
|
|
|
|
|
effectEntry.id = effectDescription[0];
|
|
|
|
effectEntry.name = effectDescription[1];
|
|
|
|
effectEntry.icon = Integer.parseInt(effectDescription[2]);
|
|
|
|
|
|
|
|
// Parse source entries
|
|
|
|
|
|
|
|
Matcher matcher = SOURCE_REGEX.matcher(effectData);
|
|
|
|
|
|
|
|
while (matcher.find())
|
|
|
|
effectEntry.sources.add(matcher.group().trim());
|
|
|
|
|
|
|
|
// Parse modifier entries
|
|
|
|
|
|
|
|
return effectEntry;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|