Browse Source

Class cleanup

feature-config-parsing
MagicBot 4 months ago
parent
commit
6854fad222
  1. 156
      src/engine/ConfigParsing/EffectsParser.java

156
src/engine/ConfigParsing/EffectsParser.java

@ -8,144 +8,132 @@
package engine.ConfigParsing; package engine.ConfigParsing;
import engine.ConfigParsing.EffectsData.Condition; import engine.ConfigParsing.EffectsData.Condition;
import engine.ConfigParsing.EffectsData.EffectData; import engine.ConfigParsing.EffectsData.EffectData;
import engine.ConfigParsing.EffectsData.Mod; import engine.ConfigParsing.EffectsData.Mod;
import engine.gameManager.ConfigManager; import engine.gameManager.ConfigManager;
import engine.mbEnums; import engine.mbEnums;
import org.pmw.tinylog.Logger;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
public class EffectsParser { 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<String,EffectData> effect_data = new HashMap<>(); public static HashMap<String, EffectData> effect_data = new HashMap<>();
public static void init() throws IOException { public static void init() throws IOException {
ArrayList<ArrayList<String>> compiledData = new ArrayList<>(); ArrayList<ArrayList<String>> compiledData = new ArrayList<>();
String[] lines = readLines(EffectsPath); List<String> fileData = Files.readAllLines(Paths.get(EffectsPath));
ArrayList<String> data = new ArrayList<>(); ArrayList<String> modData = new ArrayList<>();
for(String line : lines)
{ for (String line : fileData) {
if (line.contains("EFFECTBEGIN"))
{ if (line.contains("EFFECTBEGIN")) {
data = new ArrayList<>(); modData = new ArrayList<>();
} else if(!line.contains("EFFECTEND")) continue;
{
data.add(line);
}
else if (line.contains("EFFECTEND"))
{
compiledData.add(data);
} }
if (line.contains("EFFECTEND"))
compiledData.add(modData);
else
modData.add(line);
} }
CreateBlocks(compiledData); CreateBlocks(compiledData);
} }
public static String[] readLines(String filename) throws IOException {
FileReader fileReader = new FileReader(filename);
BufferedReader bufferedReader = new BufferedReader(fileReader);
List<String> lines = new ArrayList<>();
String line;
while ((line = bufferedReader.readLine()) != null) {
lines.add(line);
}
bufferedReader.close();
return lines.toArray(new String[0]);
}
public static void CreateBlocks(ArrayList<ArrayList<String>> compiledData)
{
for (ArrayList<String> lines : compiledData)
{
EffectData data = new EffectData();
data.id = lines.get(1).replace(" ", "").split(" ")[0];
try
{
data.name = lines.get(1).replace(" ", "").replace("\"", "").split(" ")[1];
}
catch(Exception e)
{
} public static void CreateBlocks(ArrayList<ArrayList<String>> compiledData) {
try
{ for (ArrayList<String> compiledLines : compiledData) {
data.icon = Integer.parseInt(lines.get(1).replace(" ", "").split(" ")[2]);
}
catch(Exception e)
{
EffectData effectData = new EffectData();
effectData.id = compiledLines.get(1).replace(" ", "").split(" ")[0];
effectData.sources = new ArrayList<>();
effectData.mods = new ArrayList<>();
effectData.conditions = new ArrayList<>();
try {
effectData.name = compiledLines.get(1).replace(" ", "").replace("\"", "").split(" ")[1];
effectData.icon = Integer.parseInt(compiledLines.get(1).replace(" ", "").split(" ")[2]);
} catch (Exception e) {
Logger.error(e);
} }
//log all sources
data.sources = new ArrayList<>();
int index = 0; int index = 0;
for(String line : lines) {
//log all sources
for (String line : compiledLines) {
if (line.contains("SOURCEBEGIN")) if (line.contains("SOURCEBEGIN"))
{ effectData.sources.add(mbEnums.EffectSourceType.valueOf(compiledLines.get(index + 1).replace(" ", "")));
data.sources.add(mbEnums.EffectSourceType.valueOf(lines.get(index + 1).replace(" ", "")));
}
index++; index++;
} }
//log all mods //log all mods
data.mods = new ArrayList<>();
index = 0; index = 0;
for (String line : compiledLines) {
if (line.contains("MODSBEGIN")) {
for (String line : lines)
{
if (line.contains("MODSBEGIN"))
{
int extra = 1; int extra = 1;
Mod mod = new Mod(); Mod mod = new Mod();
while(!lines.get(index + extra).contains("MODSEND"))
{ while (!compiledLines.get(index + extra).contains("MODSEND")) {
//data.mods.add(lines[index + extra].Replace(" ", "")); //data.mods.add(lines[index + extra].Replace(" ", ""));
mod.type = mbEnums.ModType.valueOf(lines.get(index + extra).replace(" ", "").split(" ")[0]); mod.type = mbEnums.ModType.valueOf(compiledLines.get(index + extra).replace(" ", "").split(" ")[0]);
GenerateModValues(mod, lines.get(index + extra).replace(" ", "").replace(" ", "").split(" ")); GenerateModValues(mod, compiledLines.get(index + extra).replace(" ", "").replace(" ", "").split(" "));
extra++; extra++;
} }
data.mods.add(mod); effectData.mods.add(mod);
} }
index++; index++;
} }
//log all conditions //log all conditions
data.conditions = new ArrayList<>();
index = 0; index = 0;
for (String line : lines) for (String line : compiledLines) {
{
if (line.contains("CONDITIONBEGIN")) if (line.contains("CONDITIONBEGIN")) {
{
int extra = 1; int extra = 1;
while (!lines.get(index + extra).contains("CONDITIONEND"))
{ while (!compiledLines.get(index + extra).contains("CONDITIONEND")) {
if (!lines.get(index + extra).contains("#"))
{ if (!compiledLines.get(index + extra).contains("#")) {
//data.conditions.add(lines[index + extra].Replace(" ", "")); //data.conditions.add(lines[index + extra].Replace(" ", ""));
Condition condition = new Condition(); Condition condition = new Condition();
condition.type = lines.get(index + extra).replace(" ", "").split(" ")[0]; condition.type = compiledLines.get(index + extra).replace(" ", "").split(" ")[0];
condition.value = lines.get(index + extra).replace(" ", "").split(" ")[1]; condition.value = compiledLines.get(index + extra).replace(" ", "").split(" ")[1];
} }
extra++; extra++;
} }
} }
index++; index++;
} }
effect_data.put(data.id,data); effect_data.put(effectData.id, effectData);
} }
} }
public static void GenerateModValues(Mod inMod, String[] data)
{ public static void GenerateModValues(Mod inMod, String[] data) {
inMod.values = new ArrayList<>(); inMod.values = new ArrayList<>();
for(int i = 1; i < data.length; i++)
{ for (int i = 1; i < data.length; i++)
if(data[i].length() != 0) if (!data[i].isEmpty())
{
inMod.values.add(data[i]); inMod.values.add(data[i]);
}
}
} }
} }
Loading…
Cancel
Save