mirror of
https://github.com/yawaflua/Informatis.git
synced 2025-12-10 03:59:26 +02:00
add JSON content generator
This commit is contained in:
@@ -16,10 +16,13 @@ import static arc.Core.settings;
|
|||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class SVars {
|
public class SVars {
|
||||||
|
public static Fi modRoot = modDirectory.child("UnitInfo");
|
||||||
public static SettingS settingAdder = new SettingS();
|
public static SettingS settingAdder = new SettingS();
|
||||||
public static HudUi hud = new HudUi();
|
public static HudUi hud = new HudUi();
|
||||||
public static float modUiScale = settings.getInt("infoUiScale") / 100f == 0 ? 1 : settings.getInt("infoUiScale") / 100f;
|
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 boolean pathLine = false, unitLine = false, logicLine = false;
|
||||||
public static TextureRegion clear = atlas.find("clear");
|
public static TextureRegion clear = atlas.find("clear");
|
||||||
public static TextureRegion error = atlas.find("error");
|
public static TextureRegion error = atlas.find("error");
|
||||||
|
|
||||||
|
public static boolean debug = false;
|
||||||
}
|
}
|
||||||
|
|||||||
54
src/UnitInfo/core/ContentJSON.java
Normal file
54
src/UnitInfo/core/ContentJSON.java
Normal file
@@ -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> 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<Field> seq = new Seq<Field>(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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,6 +50,7 @@ public class Main extends Mod {
|
|||||||
hud.addWaveInfoTable();
|
hud.addWaveInfoTable();
|
||||||
hud.setEvents();
|
hud.setEvents();
|
||||||
OverDrawer.setEvent();
|
OverDrawer.setEvent();
|
||||||
|
if(debug) ContentJSON.createFile();
|
||||||
});
|
});
|
||||||
|
|
||||||
Events.on(WorldLoadEvent.class, e -> {
|
Events.on(WorldLoadEvent.class, e -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user