diff --git a/src/UnitInfo/SVars.java b/src/UnitInfo/SVars.java index 7a780cb..0a7f590 100644 --- a/src/UnitInfo/SVars.java +++ b/src/UnitInfo/SVars.java @@ -16,10 +16,13 @@ import static arc.Core.settings; import static mindustry.Vars.*; public class SVars { + public static Fi modRoot = modDirectory.child("UnitInfo"); public static SettingS settingAdder = new SettingS(); public static HudUi hud = new HudUi(); public static float modUiScale = settings.getInt("infoUiScale") / 100f == 0 ? 1 : settings.getInt("infoUiScale") / 100f; public static boolean pathLine = false, unitLine = false, logicLine = false; public static TextureRegion clear = atlas.find("clear"); public static TextureRegion error = atlas.find("error"); + + public static boolean debug = false; } diff --git a/src/UnitInfo/core/ContentJSON.java b/src/UnitInfo/core/ContentJSON.java new file mode 100644 index 0000000..99e544f --- /dev/null +++ b/src/UnitInfo/core/ContentJSON.java @@ -0,0 +1,54 @@ +package UnitInfo.core; + +import arc.Core; +import arc.struct.Seq; +import arc.util.Log; +import mindustry.*; +import mindustry.ctype.Content; +import mindustry.ctype.UnlockableContent; +import org.hjson.*; + +import java.lang.reflect.Field; + +import static UnitInfo.SVars.modRoot; +public class ContentJSON { + public static void createFile() { + save(); + } + + public static void save() { + for(Seq content : Vars.content.getContentMap()) { + if(!content.contains(cont -> cont instanceof UnlockableContent)) continue; + JsonObject data = new JsonObject(); + content.each(cont -> { + UnlockableContent type = (UnlockableContent) cont; + JsonObject obj = new JsonObject(); + Seq seq = new Seq(type.getClass().getFields()); + seq.reverse(); + obj.add("type", type.getClass().getName()); + for(Field field : seq){ + try { + String str = field.getName(); + Object object = field.get(type); + if(object instanceof Integer val) obj.add(str, val); + if(object instanceof Long val) obj.add(str, val); + if(object instanceof Float val) obj.add(str, val); + if(object instanceof String val) obj.add(str, val); + if(object instanceof Double val) obj.add(str, val); + if(object instanceof Boolean val) obj.add(str, val); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + data.add(type.localizedName, obj); + }); + try { + modRoot.child(content.peek().getContentType().toString() + ".hjson").writeString(data.toString(Stringify.HJSON)); + } catch (Throwable t){ + + } + } + Log.info("JSON file is completely generated!"); + Core.app.exit(); + } +} diff --git a/src/UnitInfo/core/Main.java b/src/UnitInfo/core/Main.java index 8875202..0abfa8a 100644 --- a/src/UnitInfo/core/Main.java +++ b/src/UnitInfo/core/Main.java @@ -50,6 +50,7 @@ public class Main extends Mod { hud.addWaveInfoTable(); hud.setEvents(); OverDrawer.setEvent(); + if(debug) ContentJSON.createFile(); }); Events.on(WorldLoadEvent.class, e -> {