Skip to content

Commit

Permalink
Deduplicate mods
Browse files Browse the repository at this point in the history
  • Loading branch information
crschnick committed May 3, 2024
1 parent 26a8e51 commit 4537b6f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -38,7 +39,7 @@ public abstract class SavegameData<T> {

protected GameDate date;
protected UUID campaignHeuristic;
protected List<String> mods;
protected LinkedHashSet<String> mods;
protected List<String> dlcs;
protected boolean ironman;
@Setter
Expand Down Expand Up @@ -96,7 +97,7 @@ public UUID getCampaignHeuristic() {
return campaignHeuristic;
}

public List<String> getMods() {
public LinkedHashSet<String> getMods() {
return mods;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,15 +75,15 @@ 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<String>();
var list = new LinkedHashSet<String>();
n.getNodeForKeyIfExistent("mods_enabled_names").ifPresent(me -> me.forEach((k, v) -> {
list.add(v.getNodeForKey("filename").getString());
}, true));
mods = list;
} else {
mods = n.getNodeForKeyIfExistent("mod_enabled").map(Node::getNodeArray).orElse(List.of())
.stream().map(Node::getString)
.collect(Collectors.toList());
.collect(Collectors.toCollection(LinkedHashSet::new));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4537b6f

Please sign in to comment.