aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorKeebler408 <85420839+Keebler408@users.noreply.github.com>2021-12-18 03:48:38 -0600
committerGitHub <noreply@github.com>2021-12-18 10:48:38 +0100
commit844a99734bf7f2396904ce3996fddd3047c55355 (patch)
tree8b4accd512b6deb29e6102f7ec8f7c3bb2391943 /src/main
parent2756032ce923a86c1d3d90b6f6fc7ff05df6e177 (diff)
downloadNotEnoughUpdates-844a99734bf7f2396904ce3996fddd3047c55355.tar.gz
NotEnoughUpdates-844a99734bf7f2396904ce3996fddd3047c55355.tar.bz2
NotEnoughUpdates-844a99734bf7f2396904ce3996fddd3047c55355.zip
Fix per-profile fairy soul bug that wipes progress for all but one location (#32)
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java60
1 files changed, 16 insertions, 44 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java
index 968a9f95..8d611845 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FairySouls.java
@@ -135,60 +135,32 @@ public class FairySouls {
}
public static void load(File file, Gson gson) {
- HashMap<String, HashMap<String, Set<Integer>>> foundSoulsList;
- BufferedReader reader;
+ loadedFoundSouls = new HashMap<>();
+ String fileContent;
try {
- reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
+ fileContent = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))
+ .lines()
+ .collect(Collectors.joining(System.lineSeparator()));
} catch (FileNotFoundException e) {
- loadedFoundSouls = new HashMap<>();
return;
}
- String fileContent = reader
- .lines()
- .collect(Collectors.joining(System.lineSeparator()));
- if (file.exists()) {
+ try {
+ //noinspection UnstableApiUsage
+ Type multiProfileSoulsType = new TypeToken<HashMap<String, HashMap<String, Set<Integer>>>>() {
+ }.getType();
+ loadedFoundSouls = gson.fromJson(fileContent, multiProfileSoulsType);
+ } catch (JsonSyntaxException e) {
+ //The file is in the old format, convert it to the new one and set the profile to unknown
try {
//noinspection UnstableApiUsage
- Type type = new TypeToken<HashMap<String, HashMap<String, Set<Integer>>>>() {
+ Type singleProfileSoulsType = new TypeToken<HashMap<String, Set<Integer>>>() {
}.getType();
-
- foundSoulsList = gson.fromJson(fileContent, type);
- for (Map.Entry<String, HashMap<String, Set<Integer>>> soulsJson : foundSoulsList.entrySet()) {
- String profileName = soulsJson.getKey();
- for (Map.Entry<String, Set<Integer>> souls : soulsJson.getValue().entrySet()) {
- HashMap<String, Set<Integer>> map = new HashMap<>();
- map.put(souls.getKey(), souls.getValue());
- loadedFoundSouls.put(profileName, map);
- }
- }
- return;
- } catch (JsonSyntaxException e) {
- //The file is in the old format, convert it to the new one and set the profile to unknown
- try {
- //noinspection UnstableApiUsage
- Type type = new TypeToken<HashMap<String, Set<Integer>>>() {
- }.getType();
-
- HashMap<String, Set<Number>> foundSoulsListOldFormat = gson.fromJson(fileContent, type);
- HashMap<String, Set<Integer>> map = new HashMap<>();
- for (Map.Entry<String, Set<Number>> entry : foundSoulsListOldFormat.entrySet()) {
- HashSet<Integer> set = new HashSet<>();
- for (Number n : entry.getValue()) {
- set.add(n.intValue());
- }
- map.put(entry.getKey(), set);
- }
- loadedFoundSouls.put(unknownProfile, map);
- return;
- } catch (JsonSyntaxException e2) {
- System.err.println("Can't read file containing collected fairy souls, resetting.");
- loadedFoundSouls = new HashMap<>();
- return;
- }
+ loadedFoundSouls.put(unknownProfile, gson.fromJson(fileContent, singleProfileSoulsType));
+ } catch (JsonSyntaxException e2) {
+ System.err.println("Can't read file containing collected fairy souls, resetting.");
}
}
- loadedFoundSouls = new HashMap<>();
}
public static void save(File file, Gson gson) {