From 4537b6f1e7d9e9ed59ae264bb231ec5f5d3ce89b Mon Sep 17 00:00:00 2001 From: Christopher Schnick Date: Fri, 3 May 2024 22:25:32 +0200 Subject: [PATCH] Deduplicate mods --- .../main/java/com/crschnick/pdxu/app/info/SavegameData.java | 5 +++-- .../com/crschnick/pdxu/app/info/ck3/Ck3SavegameData.java | 3 ++- .../com/crschnick/pdxu/app/info/eu4/Eu4SavegameData.java | 5 +++-- .../com/crschnick/pdxu/app/info/hoi4/Hoi4SavegameData.java | 3 ++- .../com/crschnick/pdxu/app/info/vic3/Vic3SavegameData.java | 3 ++- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/SavegameData.java b/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/SavegameData.java index a6bb1d00..4382aa72 100644 --- a/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/SavegameData.java +++ b/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/SavegameData.java @@ -16,6 +16,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo; import lombok.Setter; +import java.util.LinkedHashSet; import java.util.List; import java.util.UUID; @@ -38,7 +39,7 @@ public abstract class SavegameData { protected GameDate date; protected UUID campaignHeuristic; - protected List mods; + protected LinkedHashSet mods; protected List dlcs; protected boolean ironman; @Setter @@ -96,7 +97,7 @@ public UUID getCampaignHeuristic() { return campaignHeuristic; } - public List getMods() { + public LinkedHashSet getMods() { return mods; } diff --git a/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/ck3/Ck3SavegameData.java b/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/ck3/Ck3SavegameData.java index 69c4e80a..bf7b2906 100644 --- a/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/ck3/Ck3SavegameData.java +++ b/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/ck3/Ck3SavegameData.java @@ -9,6 +9,7 @@ import com.crschnick.pdxu.model.ck3.Ck3Tag; import com.fasterxml.jackson.annotation.JsonTypeName; +import java.util.LinkedHashSet; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -51,7 +52,7 @@ protected void init(SavegameContent content) { mods = content.get().getNodeForKey("meta_data").getNodeForKeyIfExistent("mods") .map(Node::getNodeArray).orElse(List.of()) .stream().map(Node::getString) - .collect(Collectors.toList()); + .collect(Collectors.toCollection(LinkedHashSet::new)); dlcs = content.get().getNodeForKey("meta_data").getNodeForKeyIfExistent("dlcs") .map(Node::getNodeArray).orElse(List.of()) .stream().map(Node::getString) diff --git a/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/eu4/Eu4SavegameData.java b/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/eu4/Eu4SavegameData.java index 38d77986..5478ae51 100644 --- a/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/eu4/Eu4SavegameData.java +++ b/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/eu4/Eu4SavegameData.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; @@ -74,7 +75,7 @@ protected void init(SavegameContent content) { private void queryMods(Node n) { // Mod data has changed in 1.31 if (version.compareTo(new GameVersion(1, 31, 0, 0)) >= 0) { - var list = new ArrayList(); + var list = new LinkedHashSet(); n.getNodeForKeyIfExistent("mods_enabled_names").ifPresent(me -> me.forEach((k, v) -> { list.add(v.getNodeForKey("filename").getString()); }, true)); @@ -82,7 +83,7 @@ private void queryMods(Node n) { } else { mods = n.getNodeForKeyIfExistent("mod_enabled").map(Node::getNodeArray).orElse(List.of()) .stream().map(Node::getString) - .collect(Collectors.toList()); + .collect(Collectors.toCollection(LinkedHashSet::new)); } } diff --git a/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/hoi4/Hoi4SavegameData.java b/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/hoi4/Hoi4SavegameData.java index 2df16dd4..81adf1ac 100644 --- a/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/hoi4/Hoi4SavegameData.java +++ b/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/hoi4/Hoi4SavegameData.java @@ -9,6 +9,7 @@ import com.crschnick.pdxu.model.hoi4.Hoi4Tag; import com.fasterxml.jackson.annotation.JsonTypeName; +import java.util.LinkedHashSet; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -46,7 +47,7 @@ protected void init(SavegameContent content) { mods = content.get().getNodeForKeyIfExistent("mods") .map(Node::getNodeArray).orElse(List.of()) .stream().map(Node::getString) - .collect(Collectors.toList()); + .collect(Collectors.toCollection(LinkedHashSet::new)); dlcs = null; initVersion(content.get()); } diff --git a/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/vic3/Vic3SavegameData.java b/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/vic3/Vic3SavegameData.java index a3461cd7..99cbaf46 100644 --- a/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/vic3/Vic3SavegameData.java +++ b/pdxu-app/src/main/java/com/crschnick/pdxu/app/info/vic3/Vic3SavegameData.java @@ -11,6 +11,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import lombok.Getter; +import java.util.LinkedHashSet; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -58,7 +59,7 @@ protected void init(SavegameContent content) { mods = content.get().getNodeForKey("meta_data").getNodeForKeyIfExistent("mods") .map(Node::getNodeArray).orElse(List.of()) .stream().map(Node::getString) - .collect(Collectors.toList()); + .collect(Collectors.toCollection(LinkedHashSet::new)); dlcs = content.get().getNodeForKey("meta_data").getNodeForKeyIfExistent("dlcs") .map(Node::getNodeArray).orElse(List.of()) .stream().map(Node::getString)