Browse Source

Class cleanup

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

152
src/engine/ConfigParsing/EffectsParser.java

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