diff --git a/core/src/mindustry/mod/ContentParser.java b/core/src/mindustry/mod/ContentParser.java index 05198c401e..19d033b01c 100644 --- a/core/src/mindustry/mod/ContentParser.java +++ b/core/src/mindustry/mod/ContentParser.java @@ -327,6 +327,20 @@ public class ContentParser{ readFields(consume, data); return consume; }); + put(Team.class, (type, data) -> { + if(data.isString()){ + Team out = Structs.find(Team.baseTeams, t -> t.name.equals(data.asString())); + if(out == null) throw new IllegalArgumentException("Unknown team: " + data.asString()); + return out; + }else if(data.isNumber()){ + if(data.asInt() >= Team.all.length || data.asInt() < 0){ + throw new IllegalArgumentException("Unknown team: " + data.asString()); + } + return Team.get(data.asInt()); + }else{ + throw new IllegalArgumentException("Unknown team: " + data.asString() + ". Team must either be a string or a number."); + } + }); }}; /** Stores things that need to be parsed fully, e.g. reading fields of content. * This is done to accommodate binding of content names first.*/ @@ -674,6 +688,27 @@ public class ContentParser{ currentContent = planet; read(() -> readFields(planet, value)); return planet; + }, + ContentType.team, (TypeParser)(mod, name, value) -> { + TeamEntry entry; + Team team; + if(value.has("team")){ + team = (Team)classParsers.get(Team.class).parse(Team.class, value.get("team")); + }else{ + throw new RuntimeException("Team field missing."); + } + value.remove("team"); + + if(locate(ContentType.team, name) != null){ + entry = locate(ContentType.team, name); + readBundle(ContentType.team, name, value); + }else{ + readBundle(ContentType.team, name, value); + entry = new TeamEntry(mod + "-" + name, team); + } + currentContent = entry; + read(() -> readFields(entry, value)); + return entry; } ); diff --git a/core/src/mindustry/type/TeamEntry.java b/core/src/mindustry/type/TeamEntry.java index e3f1d42868..3d4f9880c3 100644 --- a/core/src/mindustry/type/TeamEntry.java +++ b/core/src/mindustry/type/TeamEntry.java @@ -9,11 +9,15 @@ import mindustry.game.*; public class TeamEntry extends UnlockableContent{ public final Team team; - public TeamEntry(Team team){ - super(team.name); + public TeamEntry(String name, Team team){ + super(name); this.team = team; } + public TeamEntry(Team team){ + this(team.name, team); + } + @Override public void displayExtra(Table table){ table.add("@team." + name + ".log").pad(6).padTop(20).width(400f).wrap().fillX();