Skip to content

Commit

Permalink
Reimplement Blitz title for older protos
Browse files Browse the repository at this point in the history
Signed-off-by: BT (calcastor/mame) <[email protected]>
  • Loading branch information
calcastor committed Aug 25, 2024
1 parent 8c0d064 commit af699f9
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion core/src/main/java/tc/oc/pgm/map/MapInfoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import tc.oc.pgm.api.map.MapContext;
import tc.oc.pgm.api.map.MapInfo;
import tc.oc.pgm.api.map.MapModule;
import tc.oc.pgm.api.map.MapProtos;
import tc.oc.pgm.api.map.MapSource;
import tc.oc.pgm.api.map.MapTag;
import tc.oc.pgm.api.map.Phase;
Expand Down Expand Up @@ -102,7 +103,7 @@ public MapInfoImpl(MapSource source, @Nullable Map<String, VariantInfo> variants
Node.fromLastChildOrAttr(root, "difficulty"), Difficulty.class, Difficulty.NORMAL)
.ordinal();
this.world = parseWorld(root);
this.gamemode = XMLUtils.parseFormattedText(Node.fromLastChildOrAttr(root, "game"));
this.gamemode = parseGamemode(root);
this.gamemodes = parseGamemodes(root);
this.phase =
XMLUtils.parseEnum(Node.fromLastChildOrAttr(root, "phase"), Phase.class, Phase.PRODUCTION);
Expand Down Expand Up @@ -265,6 +266,24 @@ public Component getStyledName(MapNameStyle style) {
.collect(StreamUtils.toImmutableList());
}

private Component parseGamemode(Element root) throws InvalidXMLException {
Component gamemode = XMLUtils.parseFormattedText(Node.fromLastChildOrAttr(root, "game"));

final Element blitz = root.getChild("blitz");
if (blitz != null) {
final Element title = blitz.getChild("title");
if (title != null) {
if (this.getProto().isNoOlderThan(MapProtos.REMOVE_BLITZ_TITLE)) {
throw new InvalidXMLException(
"<title> inside <blitz> is no longer supported, use <map game=\"...\">", title);
}
gamemode = XMLUtils.parseFormattedText(Node.fromNullable(title));
}
}

return gamemode;
}

private static @NotNull List<Gamemode> parseGamemodes(Element root) throws InvalidXMLException {
ImmutableList.Builder<Gamemode> gamemodes = ImmutableList.builder();
for (Element gamemodeEl : root.getChildren("gamemode")) {
Expand Down

0 comments on commit af699f9

Please sign in to comment.