From 0823868b4b5beeffee8721ac7ca17c65eee6d5a1 Mon Sep 17 00:00:00 2001 From: sharlotte Date: Tue, 31 Aug 2021 17:47:21 +0900 Subject: [PATCH] update --- src/UnitInfo/core/ContentJSON.java | 22 +++++++++------------- src/UnitInfo/core/Main.java | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/UnitInfo/core/ContentJSON.java b/src/UnitInfo/core/ContentJSON.java index 99e544f..0f0de97 100644 --- a/src/UnitInfo/core/ContentJSON.java +++ b/src/UnitInfo/core/ContentJSON.java @@ -5,31 +5,25 @@ import arc.struct.Seq; import arc.util.Log; import mindustry.*; import mindustry.ctype.Content; -import mindustry.ctype.UnlockableContent; +import mindustry.ctype.MappableContent; 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 seq = new Seq(cont.getClass().getFields()); seq.reverse(); - obj.add("type", type.getClass().getName()); + obj.add("type", cont.getClass().getName()); for(Field field : seq){ try { String str = field.getName(); - Object object = field.get(type); + Object object = field.get(cont); 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); @@ -40,15 +34,17 @@ public class ContentJSON { e.printStackTrace(); } } - data.add(type.localizedName, obj); + String name = cont.toString(); + if(cont instanceof MappableContent mapCont) name = mapCont.name; + data.add(name, obj); }); try { - modRoot.child(content.peek().getContentType().toString() + ".hjson").writeString(data.toString(Stringify.HJSON)); + modRoot.child(content.peek().getContentType().toString() + ".json").writeString(data.toString(Stringify.FORMATTED)); } catch (Throwable t){ } } - Log.info("JSON file is completely generated!"); + Log.info("JSON file is completely updated!"); Core.app.exit(); } } diff --git a/src/UnitInfo/core/Main.java b/src/UnitInfo/core/Main.java index f4bca6a..9ccc165 100644 --- a/src/UnitInfo/core/Main.java +++ b/src/UnitInfo/core/Main.java @@ -28,7 +28,7 @@ public class Main extends Mod { hud.addWaveInfoTable(); hud.setEvents(); OverDrawer.setEvent(); - if(debug) ContentJSON.createFile(); + if(debug) ContentJSON.save(); }); Events.on(WorldLoadEvent.class, e -> {