Skip to content

Commit

Permalink
Check for invalid eu4 tag
Browse files Browse the repository at this point in the history
  • Loading branch information
crschnick committed Jan 14, 2023
1 parent 97827ec commit e13c707
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pdxu-model/src/main/java/com/crschnick/pdxu/model/eu4/Eu4Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public final class Eu4Tag {
public Eu4Tag() {
}

public Eu4Tag(FlagType flagType, String tag, GameColor mapColor, GameColor countryColor, String name, ColonialFlagData colonialFlagData, CustomFlagData customFlagData) {
public Eu4Tag(
FlagType flagType, String tag, GameColor mapColor, GameColor countryColor, String name, ColonialFlagData colonialFlagData,
CustomFlagData customFlagData
) {
this.flagType = flagType;
this.tag = tag;
this.mapColor = mapColor;
Expand Down Expand Up @@ -57,7 +60,8 @@ public static Eu4Tag fromNode(String tag, Node n) {
col.getNodeForKey("symbol_index").getInteger(),
col.getNodeForKey("flag_colors").getNodeArray().stream()
.map(Node::getInteger)
.collect(Collectors.toList()));
.collect(Collectors.toList())
);
} else if (OBSERVER_FLAG_TAG_PATTERN.matcher(tag).matches() || tag.equals(INVALID_TAG_ID)) {
t = FlagType.NO_FLAG;
} else {
Expand All @@ -68,7 +72,10 @@ public static Eu4Tag fromNode(String tag, Node n) {
}

public static Eu4Tag getTag(List<Eu4Tag> tags, String name) {
return tags.stream().filter(t -> t.tag.equals(name)).findFirst().get();
return tags.stream()
.filter(t -> t.tag.equals(name))
.findFirst()
.orElse(new Eu4Tag(FlagType.NO_FLAG, "REB", GameColor.BLACK, GameColor.BLACK, "Unknown", null, null));
}

public String getTag() {
Expand Down

0 comments on commit e13c707

Please sign in to comment.