1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-10-26 09:13:28 +03: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:
Mythril382 2024-08-06 10:34:28 +08:00 committed by GitHub
parent 2241ebaff8
commit 942069e89a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 2 deletions

View File

@ -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;
}
);

View File

@ -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();