Browse Source

Regex used for strsplit

feature-config-parsing2
MagicBot 5 months ago
parent
commit
c7b4404c36
  1. 18
      src/engine/ConfigParsing/EffectsParser.java

18
src/engine/ConfigParsing/EffectsParser.java

@ -14,6 +14,7 @@ import engine.gameManager.ConfigManager; @@ -14,6 +14,7 @@ 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;
@ -25,7 +26,7 @@ public class EffectsParser { @@ -25,7 +26,7 @@ public class EffectsParser {
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));
@ -53,15 +54,20 @@ public class EffectsParser { @@ -53,15 +54,20 @@ public class EffectsParser {
// Parse effect entry description
String firstLine = effectData.substring(0, effectData.indexOf('\n'));
String[] effectDescription = firstLine.split(" ");
ArrayList<String> effectDescription = new ArrayList<>();
Matcher matcher = STRSPLIT_REGEX.matcher(firstLine);
while (matcher.find())
effectDescription.add(matcher.group(1));
effectEntry.id = effectDescription[0];
effectEntry.name = effectDescription[1];
effectEntry.icon = Integer.parseInt(effectDescription[2]);
effectEntry.id = effectDescription.get(0);
effectEntry.name = effectDescription.get(1);
effectEntry.icon = Integer.parseInt(effectDescription.get(2));
// Parse source entries
Matcher matcher = SOURCE_REGEX.matcher(effectData);
matcher = SOURCE_REGEX.matcher(effectData);
while (matcher.find())
effectEntry.sources.add(matcher.group().trim());

Loading…
Cancel
Save