JSON schema generation tweaks / Logic link name fixes

This commit is contained in:
Anuken
2026-08-10 22:38:45 -04:00
parent a5c6b9d240
commit e7d214d43b
2 changed files with 40 additions and 8 deletions
@@ -128,7 +128,7 @@ public class LogicBlock extends Block{
public static String getLinkName(Block block){ public static String getLinkName(Block block){
String name = block.name; String name = block.name;
if(name.contains("-")){ if(name.indexOf('-') != -1){
String[] split = name.split("-"); String[] split = name.split("-");
//filter out 'large' at the end of block names //filter out 'large' at the end of block names
if(split.length >= 2 && (split[split.length - 1].equals("large") || Strings.canParseFloat(split[split.length - 1]))){ if(split.length >= 2 && (split[split.length - 1].equals("large") || Strings.canParseFloat(split[split.length - 1]))){
@@ -259,7 +259,7 @@ public class LogicBlock extends Block{
public Seq<LogicLink> links = new Seq<>(); public Seq<LogicLink> links = new Seq<>();
public @Nullable ObjectIntMap<String> linkMap; public @Nullable ObjectIntMap<String> linkMap;
public boolean checkedDuplicates = false; public boolean checkedDuplicates = false;
public int ipt = instructionsPerTick; public int ipt = instructionsPerTick;
/** Display name, for convenience. This is currently only available for world processors. */ /** Display name, for convenience. This is currently only available for world processors. */
public @Nullable String tag; public @Nullable String tag;
@@ -521,7 +521,9 @@ public class LogicBlock extends Block{
if(valid){ if(valid){
if(lastBlock != null && cur.block != lastBlock){ if((lastBlock != null && cur.block != lastBlock) ||
//links don't store the type of block they used to be in saves, so when a link becomes valid, the only way to make sure the name is correct is an expensive string startsWith check
(lastBlock == null && !l.name.startsWith(getLinkName(cur.block)))){
l.logicVar = null; //name was reassigned because block type changed, the old cached logic var is no longer relevant l.logicVar = null; //name was reassigned because block type changed, the old cached logic var is no longer relevant
l.name = ""; l.name = "";
l.name = findLinkName(cur.block); l.name = findLinkName(cur.block);
@@ -548,7 +550,7 @@ public class LogicBlock extends Block{
if(changed){ if(changed){
updateLinks(); updateLinks();
} }
if(state.rules.disableWorldProcessors && privileged) return; if(state.rules.disableWorldProcessors && privileged) return;
if(enabled && executor.initialized()){ if(enabled && executor.initialized()){
+34 -4
View File
@@ -1,5 +1,6 @@
package mindustry.tools; package mindustry.tools;
import arc.audio.*;
import arc.files.*; import arc.files.*;
import arc.func.*; import arc.func.*;
import arc.math.*; import arc.math.*;
@@ -10,12 +11,15 @@ import arc.util.serialization.Jval.*;
import com.github.javaparser.*; import com.github.javaparser.*;
import com.github.javaparser.ast.body.*; import com.github.javaparser.ast.body.*;
import mindustry.*; import mindustry.*;
import mindustry.content.*;
import mindustry.ctype.*; import mindustry.ctype.*;
import mindustry.entities.*; import mindustry.entities.*;
import mindustry.entities.units.*; import mindustry.entities.units.*;
import mindustry.game.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.world.*; import mindustry.world.*;
import mindustry.world.meta.*;
import java.lang.reflect.*; import java.lang.reflect.*;
@@ -41,9 +45,7 @@ public class SchemaGenerator{
if(type.contentClass != null && all.size > 0 && all.first() instanceof UnlockableContent){ if(type.contentClass != null && all.size > 0 && all.first() instanceof UnlockableContent){
mappings.put(type.name(), type.contentClass.getCanonicalName()); mappings.put(type.name(), type.contentClass.getCanonicalName());
var values = Jval.newObject(); var values = Jval.newObject();
all.<UnlockableContent>as().each(c -> { all.<UnlockableContent>as().each(c -> values.put(c.name, Jval.valueOf((c.getClass().isAnonymousClass() ? c.getClass().getSuperclass() : c.getClass()).getCanonicalName())));
values.put(c.name, Jval.valueOf((c.getClass().isAnonymousClass() ? c.getClass().getSuperclass() : c.getClass()).getCanonicalName()));
});
root.asObject().put(type.name(), values); root.asObject().put(type.name(), values);
} }
} }
@@ -150,12 +152,40 @@ public class SchemaGenerator{
writeSchema(Interp.class.getCanonicalName(), """ writeSchema(Interp.class.getCanonicalName(), """
{ {
"doc": "Various types of interpolation.", "doc": "All types of interpolation.",
"superclass": "Enum", "superclass": "Enum",
"values": [%VALUES%] "values": [%VALUES%]
} }
""".replace("%VALUES%", Seq.with(Interp.class.getFields()).toString(", ", t -> "\"" + t.getName() + "\""))); """.replace("%VALUES%", Seq.with(Interp.class.getFields()).toString(", ", t -> "\"" + t.getName() + "\"")));
writeSchema("allTeams", """
{
"doc": "All team names.",
"values": [%VALUES%]
}
""".replace("%VALUES%", Seq.with(Team.class.getFields()).select(f -> f.getType() == Team.class).toString(", ", t -> "\"" + t.getName() + "\"")));
writeSchema("allEffects", """
{
"doc": "All preset effect names.",
"values": [%VALUES%]
}
""".replace("%VALUES%", Seq.with(Fx.class.getFields()).select(f -> f.getType() == Effect.class).toString(", ", t -> "\"" + t.getName() + "\"")));
writeSchema("allAttributes", """
{
"doc": "All attribute names.",
"values": [%VALUES%]
}
""".replace("%VALUES%", Seq.with(Attribute.class.getFields()).select(f -> f.getType() == Attribute.class).toString(", ", t -> "\"" + t.getName() + "\"")));
writeSchema("allSounds", """
{
"doc": "All preset sound names.",
"values": [%VALUES%]
}
""".replace("%VALUES%", Seq.with(Sounds.class.getFields()).select(f -> f.getType() == Sound.class).toString(", ", t -> "\"" + t.getName() + "\"")));
new Fi("../../tools/extra-schemas").copyFilesTo(outputDir); new Fi("../../tools/extra-schemas").copyFilesTo(outputDir);
} }