mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-08 01:43:59 +07:00
Allow JSON Mods To Use TeamEntry Content Type (#10089)
* for mods * tem enry * screw it, its GOING to be necessary for absolutely no reason * screw it * skill issue i have skill issue * dumb dumb i need an ide * explode * hello my name is stupid
This commit is contained in:
parent
2241ebaff8
commit
942069e89a
@ -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<TeamEntry>)(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;
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user