summaryrefslogtreecommitdiff
path: root/src/main/java/tlIItools/Effect.java
diff options
context:
space:
mode:
authorBen Culkin <scorpress@gmail.com>2020-06-24 20:12:42 -0400
committerBen Culkin <scorpress@gmail.com>2020-06-24 20:12:42 -0400
commit4d1f759a298b3f7d2c908c90b4d7bcf03b3b111b (patch)
tree55c8751cf4a1316e43abfde7fcc2139c70481662 /src/main/java/tlIItools/Effect.java
parentc2e7530edb3b9a380fbf3d21a0ef1a2530db65a1 (diff)
Move reading of effect details to new class
This pulls out the reading of effect details from our data files to a new class that is referenced by Effect, EffectRepo
Diffstat (limited to 'src/main/java/tlIItools/Effect.java')
-rw-r--r--src/main/java/tlIItools/Effect.java135
1 files changed, 6 insertions, 129 deletions
diff --git a/src/main/java/tlIItools/Effect.java b/src/main/java/tlIItools/Effect.java
index 12e2765a..9075b490 100644
--- a/src/main/java/tlIItools/Effect.java
+++ b/src/main/java/tlIItools/Effect.java
@@ -1,13 +1,8 @@
package tlIItools;
-import java.io.FileReader;
-import java.io.IOException;
-
import java.util.ArrayList;
import java.util.List;
-import java.util.HashMap;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Scanner;
/**
@@ -26,124 +21,6 @@ public class Effect {
public static boolean doTiming;
/**
- * The list of detail strings for skills.
- */
- private static Map<String, String> detals;
- /**
- * The list of detail strings for timed skills.
- */
- private static Map<String, String> timeDetals;
-
- /**
- * The list of replacements for detail strings.
- */
- private static List<ReplPair> replList;
-
- /*
- * Init. lists from files.
- */
- static {
- try (FileReader detalReader = new FileReader("data/affix-detals.txt")) {
- detals = readDetails(new Scanner(detalReader));
- } catch (IOException ioex) {
- AffixLister.errOut.println("Error loading affix detail text");
- }
-
- try (FileReader timedDetalReader = new FileReader("data/timed-affix-detals.txt")) {
- timeDetals = readDetails(new Scanner(timedDetalReader));
- } catch (IOException ioex) {
- AffixLister.errOut.println("Error loading timed affix detail text");
- }
-
- try (FileReader replListReader = new FileReader("data/replace-list.txt")) {
- replList = ReplPair.readList(new Scanner(replListReader));
- } catch (IOException ioex) {
- AffixLister.errOut.println("Error loading replacement lists");
- }
- }
-
- /**
- * Read effect detail strings from an input source.
- *
- * @param scn
- * The source to read from.
- * @return
- * The map of effect details to use.
- */
- public static Map<String, String> readDetails(Scanner scn) {
- Map<String, String> detals = new HashMap<>();
-
- return readDetails(detals, scn);
- }
-
- /**
- * Read effect detail strings from an input source, adding to an
- * existing set.
- *
- * @param detals
- * The details to add to.
- * @param scn
- * The source to read from.
- * @return
- * The map of effect details to use.
- */
- public static Map<String, String> readDetails(Map<String, String> detals, Scanner scn) {
- while (scn.hasNextLine()) {
- String name = scn.nextLine().trim();
- if (name.equals("")) continue;
- if (name.startsWith("#")) continue;
-
- String body;
- do {
- body = scn.nextLine().trim();
- } while (body.startsWith("#"));
-
- detals.put(name, body);
- }
-
- return detals;
- }
-
- /**
- * Sanity check the loaded format strings.
- */
- public static void sanityCheckFormats() {
- for (Entry<String, String> detal : detals.entrySet()) {
- String fmt = detal.getValue();
-
- AffixLister.errOut.printf("\tTRACE: Applying replacements for %s\n", detal.getKey());
- for (ReplPair repl : replList) {
- String tmp = fmt;
- fmt = fmt.replaceAll(repl.find, repl.replace);
- if (!fmt.equals(tmp)) {
- String outFmt = "\t\tTRACE: Replaced %s with %s: \n\t\t%s\n\t\t%s\n";
-
- AffixLister.errOut.printf(outFmt, repl.find, repl.replace, tmp, fmt);
- }
- }
-
- if (fmt.contains("<") || fmt.contains(">")) {
- String warnFmt = "WARN: Details for effect %s are malformated (contains < or >):\n\t%s\n";
-
- AffixLister.errOut.printf(warnFmt, detal.getKey(), fmt);
- }
- }
-
- for (Entry<String, String> detal : timeDetals.entrySet()) {
- String fmt = detal.getValue();
-
- for (ReplPair repl : replList) {
- fmt = fmt.replaceAll(repl.find, repl.replace);
- }
-
- if (fmt.contains("<") || fmt.contains(">")) {
- String warnFmt = "WARN: Details for timed effect %s are malformatted (contains < or >):\n\t%s\n";
- AffixLister.errOut.printf(warnFmt, detal.getKey(), fmt);
- }
- }
- }
-
- /**
* The file name this effect came from.
*/
public String fName;
@@ -278,20 +155,20 @@ public class Effect {
sb.append("Inflict on Hit: ");
}
- Map<String, String> detMap = hasDuration ? timeDetals : detals;
+ Map<String, String> detMap = hasDuration ? EffectRepo.timeDetals : EffectRepo.detals;
- if (detMap.containsKey(type) || (hasDuration && !timeDetals.containsKey(type) && detals.containsKey(type))) {
+ if (detMap.containsKey(type) || (hasDuration && !EffectRepo.timeDetals.containsKey(type) && EffectRepo.detals.containsKey(type))) {
String fmt;
- if (hasDuration && !timeDetals.containsKey(type) && detals.containsKey(type)) {
+ if (hasDuration && !EffectRepo.timeDetals.containsKey(type) && EffectRepo.detals.containsKey(type)) {
AffixLister.errOut.printf("Improvised details for timed %s\n", type);
- fmt = detals.get(type) + "for <DUR> seconds";
+ fmt = EffectRepo.detals.get(type) + "for <DUR> seconds";
} else {
fmt = detMap.get(type);
}
// Expand aliases first.
- for (ReplPair repl : replList) {
+ for (ReplPair repl : EffectRepo.replList) {
fmt = fmt.replaceAll(repl.find, repl.replace);
}
@@ -573,7 +450,7 @@ public class Effect {
if (doTiming) {
String fmt = "\t\tProcessed effect %s from %s in %d nanoseconds (%.2f seconds)\n";
- double seconds = ((double)((endTime - startTime) / 1000000000));
+ double seconds = (((endTime - startTime) / 1000000000));
errs.add(String.format(fmt, efct.name, scnSource, endTime - startTime, seconds));
}