Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement Blitz title for older protos #1392

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 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,23 @@ public Component getStyledName(MapNameStyle style) {
.collect(StreamUtils.toImmutableList());
}

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

if (gamemode == null) {
for (Element title : XMLUtils.flattenElements(root, "blitz", "title")) {
if (this.getProto().isNoOlderThan(MapProtos.REMOVE_BLITZ_TITLE)) {
throw new InvalidXMLException(
"<title> inside <blitz> is no longer supported, use <map game=\"...\"> or <game>",
title);
}
return XMLUtils.parseFormattedText(new Node(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