diff options
| author | Ben Culkin <scorpress@gmail.com> | 2020-03-29 21:57:32 -0400 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2020-03-29 21:57:32 -0400 |
| commit | 0bca0d24a20ca713dd1c9ef042dcc64d3b795fef (patch) | |
| tree | 0728e3980702198590855466c3606c8fc71446dc | |
| parent | 4d059f250889cae60ecf82ccfbd159b546a89949 (diff) | |
Fix up ReplPair
There was something in ReplPair that was causing issues. Since we don't
need any of the fancy ReplPair functionality, I ripped it all out, since
it was causing issues (probably sorting-related, with a comparator or
something missing somewhere)
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | data/replace-list.txt | 2 | ||||
| -rw-r--r-- | src/main/java/tlIItools/Effect.java | 14 | ||||
| -rw-r--r-- | src/main/java/tlIItools/ReplPair.java | 327 |
4 files changed, 17 insertions, 329 deletions
@@ -5,3 +5,6 @@ tags synfiles basefiles target/ +/allafxs.err +/afxsocket.err +/afxsocket.out diff --git a/data/replace-list.txt b/data/replace-list.txt index 7d43d370..4c3a189a 100644 --- a/data/replace-list.txt +++ b/data/replace-list.txt @@ -80,4 +80,4 @@ # Max count <MAXC> -%10\$.0f +%10\$.0f
\ No newline at end of file diff --git a/src/main/java/tlIItools/Effect.java b/src/main/java/tlIItools/Effect.java index 3efec6de..5c8b203a 100644 --- a/src/main/java/tlIItools/Effect.java +++ b/src/main/java/tlIItools/Effect.java @@ -291,10 +291,10 @@ public class Effect { // Expand aliases first. - for (ReplPair repl : replList) { + for (ReplPair repl : replList) { fmt = fmt.replaceAll(repl.find, repl.replace); } - + if (minValue <= 0 && maxValue <= 0) { fmt = fmt.replaceAll("<C\\|([^|>]+)\\|([^|>]+)>", "$1"); } @@ -310,9 +310,9 @@ public class Effect { if (minPer >= 0 && maxPer >= 0) { fmt = fmt.replaceAll("<MC\\|([^|>]+)\\|([^|>]+)>", "$2"); } - + if (fmt.contains("<") || fmt.contains(">")) { - AffixLister.errOut.printf("WARN: Details for effect %s are malformated (contains < or >):\n\t%s\n", type, fmt); + AffixLister.errOut.printf("WARN: Details for effect %s are malformatted (contains < or >):\n\t%s\n", type, fmt); } sb.append(String.format(fmt, Math.abs(minValue), Math.abs(maxValue), duration, damageType.toLowerCase(), level, resist, name, Math.abs(minPer), Math.abs(maxPer), range, maxCount, pulse)); @@ -434,7 +434,11 @@ public class Effect { } else { efct.hasDuration = true; - efct.duration = Double.parseDouble(splits[1]); + if (splits[1].equalsIgnoreCase("instant")) { + efct.duration = -1; + } else { + efct.duration = Double.parseDouble(splits[1]); + } } } else if (ln.contains("<FLOAT>MIN:")) { efct.minValue = Double.parseDouble(splits[1]); diff --git a/src/main/java/tlIItools/ReplPair.java b/src/main/java/tlIItools/ReplPair.java index 5830db3f..74012716 100644 --- a/src/main/java/tlIItools/ReplPair.java +++ b/src/main/java/tlIItools/ReplPair.java @@ -66,25 +66,6 @@ public class ReplPair implements Comparable<ReplPair> { } /** - * Possible statuses of pairs with respect to exporting. - * @author Ben Culkin - */ - public static enum StageStatus { - /** - * Only use for staging pairs; don't export. - */ - INTERNAL, - /** - * Don't use for staging pairs; do export. - */ - EXTERNAL, - /** - * Use for staging pairs; do export. - */ - BOTH; - } - - /** * The priority for this replacement. */ public int priority; @@ -105,8 +86,6 @@ public class ReplPair implements Comparable<ReplPair> { */ public String replace; - private StageStatus stat = StageStatus.BOTH; - /** * Create a new blank replacement pair. */ @@ -231,15 +210,9 @@ public class ReplPair implements Comparable<ReplPair> { int pno = 0; int defPrior = 1; - int defStage = 1; - - boolean defMulti = false; - - StageStatus defStatus = StageStatus.BOTH; - - List<List<ReplPair>> stages = new ArrayList<>(); - stages.add(new ArrayList<>()); + List<ReplPair> resList = new ArrayList<>(); + // For every line in the source... while (scn.hasNextLine()) { String name = scn.nextLine().trim(); @@ -249,181 +222,8 @@ public class ReplPair implements Comparable<ReplPair> { if (name.equals("")) continue; if (name.startsWith("#")) continue; - // Global control. Process it. - if (name.startsWith("|//")) { - name = name.substring(3); - - // Split out each control - String[] bits = name.split(";"); - - for (String bit : bits) { - String bitHead = bit.toUpperCase(); - String bitBody = bit; - - int idx = bit.indexOf('/'); - if (idx != -1) { - bitHead = bit.substring(0, idx).toUpperCase(); - bitBody = bit.substring(idx + 1); - } - - switch (bitHead) { - case "P": - try { - defPrior = Integer.parseInt(bitBody); - } catch (NumberFormatException nfex) { - String errMsg = String.format("'%s' is not a valid priority (must be an integer)", bitBody); - errs.add(new ReplError(lno, pno, errMsg, name)); - } - break; - case "S": - try { - int tmpStage = Integer.parseInt(bitBody); - if (tmpStage < 0) { - String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)", bitBody); - errs.add(new ReplError(lno, pno, errMsg, name)); - - break; - } - defStage = tmpStage; - } catch (NumberFormatException nfex) { - String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)", bitBody); - errs.add(new ReplError(lno, pno, errMsg, name)); - } - break; - case "MT": - defMulti = true; - break; - case "MF": - defMulti = false; - break; - case "M": - defMulti = Boolean.parseBoolean(bitBody); - break; - case "I": - defStatus = StageStatus.INTERNAL; - break; - case "E": - defStatus = StageStatus.EXTERNAL; - break; - case "B": - defStatus = StageStatus.BOTH; - break; - default: - errs.add(new ReplError(lno, pno, String.format("Invalid control name '%s'", bitHead), name)); - break; - } - } - - continue; - } - ReplPair rp = new ReplPair(); rp.priority = defPrior; - rp.stat = defStatus; - - int stage = defStage; - - boolean isMulti = defMulti; - - // Name has attached controls, process them. - if (name.startsWith("//")) { - name = name.substring(2); - - int idx = name.indexOf("//"); - if (idx == -1) { - String msg = "Did not find control terminator (//) in name where it should be"; - - errs.add(new ReplError(lno, pno, msg, name)); - continue; - } - - String contName = name.substring(0, idx); - String actName = name.substring(idx + 2); - - // Split out each control - String[] bits = contName.split(";"); - - for (String bit : bits) { - String bitHead = bit.toUpperCase(); - String bitBody = bit; - - idx = bit.indexOf('/'); - if (idx != -1) { - bitHead = bit.substring(0, idx).toUpperCase(); - bitBody = bit.substring(idx + 1); - } - - switch (bitHead) { - case "N": - rp.name = bitBody; - break; - case "P": - try { - rp.priority = Integer.parseInt(bitBody); - } catch (NumberFormatException nfex) { - String errMsg = String.format("'%s' is not a valid priority (must be an integer)", bitBody); - errs.add(new ReplError(lno, pno, errMsg, name)); - } - break; - case "S": - try { - int tmpStage = Integer.parseInt(bitBody); - if (tmpStage < 0) { - String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)", bitBody); - errs.add(new ReplError(lno, pno, errMsg, name)); - - break; - } - stage = tmpStage; - } catch (NumberFormatException nfex) { - String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)", bitBody); - errs.add(new ReplError(lno, pno, errMsg, name)); - } - break; - case "MT": - isMulti = true; - break; - case "MF": - isMulti = false; - break; - case "M": - isMulti = Boolean.parseBoolean(bitBody); - break; - case "I": - rp.stat = StageStatus.INTERNAL; - break; - case "E": - rp.stat = StageStatus.EXTERNAL; - break; - case "B": - rp.stat = StageStatus.BOTH; - break; - default: - errs.add(new ReplError(lno, pno, String.format("Unknown control name '%s'", bitHead), name)); - break; - } - } - - // Multi-line name with a trailer - if (isMulti) { - String tmp = actName; - - while (tmp.endsWith("\\")) { - boolean incNL = tmp.endsWith("|\\"); - - if (!scn.hasNextLine()) break; - - tmp = scn.nextLine().trim(); - - if (tmp.equals("")) continue; - if (tmp.startsWith("#")) continue; - - actName = String.format("%s%s%s", actName, incNL ? "\n" : "", tmp); - } - } - - name = actName; - } rp.find = name; if (rp.name == null) rp.name = name; @@ -447,132 +247,13 @@ public class ReplPair implements Comparable<ReplPair> { lno += 1; } while (body.startsWith("#")); - isMulti = defMulti; - - // Body has attached controls, process them. - if (body.startsWith("//")) { - body = body.substring(2); - - int idx = body.indexOf("//"); - if (idx == -1) { - String msg = "Did not find control terminator (//) in body where it should be"; - - errs.add(new ReplError(lno, pno, msg, body)); - continue; - } - - String contBody = body.substring(0, idx); - String actBody = body.substring(idx + 2); - - // Split out each control - String[] bits = actBody.split(";"); - - for (String bit : bits) { - String bitHead = bit.toUpperCase(); - String bitBody = bit; - - idx = bit.indexOf('/'); - if (idx != -1) { - bitHead = bit.substring(0, idx).toUpperCase(); - bitBody = bit.substring(idx + 1); - } - - switch (bitHead) { - case "MT": - isMulti = true; - break; - case "MF": - isMulti = false; - break; - case "M": - isMulti = Boolean.parseBoolean(bitBody); - break; - default: - errs.add(new ReplError(lno, pno, String.format("Invalid control name '%s'", bitHead), body)); - break; - } - } - - // Multi-line name with a trailer - if (isMulti) { - String tmp = actBody; - - while (tmp.endsWith("\\")) { - boolean incNL = tmp.endsWith("|\\"); - - if (!scn.hasNextLine()) break; - - tmp = scn.nextLine().trim(); - - if (tmp.startsWith("#")) continue; - - actBody = String.format("%s%s%s", actBody, incNL ? "\n" : "", tmp); - } - } - - body = actBody; - } rp.replace = body; - List<ReplPair> stageList; - if (stages.size() < stage) { - stageList = stages.get(stage); - - if (stageList == null) { - stageList = new ArrayList<>(); - stages.set(stage, stageList); - } - } else { - stageList = new ArrayList<>(); - stages.add(stage, stageList); - } - - stageList.add(rp); - } - - // Special-case one-stage processing. - if (stages.size() == 1) { - detals.addAll(stages.iterator().next()); - - detals.sort(null); - - return detals; + resList.add(rp); } - // Handle stages - List<ReplPair> tmpList = new ArrayList<>(); - tmpList.addAll(detals); - - for (List<ReplPair> stageList : stages) { - List<ReplPair> curStage = new ArrayList<>(); - - for (ReplPair rp : stageList) { - // Process through every pair in the previous - // stages - for (ReplPair curPar : tmpList) { - rp.replace = rp.replace.replaceAll(curPar.find, curPar.replace); - } - - // If we're external; add straight to the output - if (rp.stat == StageStatus.EXTERNAL) detals.add(rp); - else curStage.add(rp); - } - - tmpList.addAll(curStage); - tmpList.sort(null); - } - - // Copy over to output, excluding internals - for (ReplPair rp : tmpList) { - if (rp.stat == StageStatus.INTERNAL) continue; - - detals.add(rp); - } - - detals.sort(null); - - return detals; + return resList; } @Override |
