|
|
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
|
|
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
|
|
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
|
|
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
|
|
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
|
|
|
// Magicbane Emulator Project © 2013 - 2024
|
|
|
|
// www.magicbane.com
|
|
|
|
|
|
|
|
package engine.ConfigParsing;
|
|
|
|
|
|
|
|
import engine.ConfigParsing.EffectEntry.EffectEntry;
|
|
|
|
import engine.ConfigParsing.EffectEntry.EffectModifier;
|
|
|
|
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.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);
|
|
|
|
private static final Pattern STRSPLIT_REGEX = Pattern.compile("([^\"]\\S*|\"[^\"]*\")\\s*");
|
|
|
|
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;
|
|
|
|
ArrayList<String> effectDescription = new ArrayList<>();
|
|
|
|
|
|
|
|
// Some effects exist without sources/mods or conditions
|
|
|
|
// (ACID "MOB" 0)
|
|
|
|
|
|
|
|
if (effectData.indexOf('\n') > 0)
|
|
|
|
firstLine = effectData.substring(0, effectData.indexOf('\n'));
|
|
|
|
else
|
|
|
|
firstLine = effectData;
|
|
|
|
|
|
|
|
// Regex ignores spaces within quotes
|
|
|
|
|
|
|
|
Matcher matcher = STRSPLIT_REGEX.matcher(firstLine);
|
|
|
|
|
|
|
|
while (matcher.find())
|
|
|
|
effectDescription.add(matcher.group(1).trim());
|
|
|
|
|
|
|
|
effectEntry.id = effectDescription.get(0);
|
|
|
|
effectEntry.name = effectDescription.get(1);
|
|
|
|
effectEntry.name = effectEntry.name.replaceAll("\"", "");
|
|
|
|
|
|
|
|
// Some effect mods have no icon
|
|
|
|
// (SEEINVIS-SHADE "See Invis")
|
|
|
|
|
|
|
|
if (effectDescription.size() == 3)
|
|
|
|
effectEntry.icon = Integer.parseInt(effectDescription.get(2));
|
|
|
|
else
|
|
|
|
effectEntry.icon = 0;
|
|
|
|
|
|
|
|
// Parse source entries
|
|
|
|
|
|
|
|
matcher = SOURCE_REGEX.matcher(effectData);
|
|
|
|
|
|
|
|
while (matcher.find())
|
|
|
|
effectEntry.sources.add(matcher.group().trim());
|
|
|
|
|
|
|
|
// Parse modifier entries
|
|
|
|
|
|
|
|
matcher = MODS_REGEX.matcher(effectData);
|
|
|
|
|
|
|
|
// Iterate effect entries from .wpak config data
|
|
|
|
|
|
|
|
while (matcher.find()) {
|
|
|
|
EffectModifier effectModifier = parseModEntry(matcher.group());
|
|
|
|
|
|
|
|
if (effectModifier != null)
|
|
|
|
effectEntry.mods.add(effectModifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
return effectEntry;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private static EffectModifier parseModEntry(String modData) {
|
|
|
|
|
|
|
|
EffectModifier effectModifier = new EffectModifier();
|
|
|
|
|
|
|
|
return effectModifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|