mirror of
https://github.com/yawaflua/Informatis.git
synced 2025-12-10 12:09:27 +02:00
update
This commit is contained in:
@@ -5,31 +5,25 @@ import arc.struct.Seq;
|
|||||||
import arc.util.Log;
|
import arc.util.Log;
|
||||||
import mindustry.*;
|
import mindustry.*;
|
||||||
import mindustry.ctype.Content;
|
import mindustry.ctype.Content;
|
||||||
import mindustry.ctype.UnlockableContent;
|
import mindustry.ctype.MappableContent;
|
||||||
import org.hjson.*;
|
import org.hjson.*;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
import static UnitInfo.SVars.modRoot;
|
import static UnitInfo.SVars.modRoot;
|
||||||
public class ContentJSON {
|
public class ContentJSON {
|
||||||
public static void createFile() {
|
|
||||||
save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void save() {
|
public static void save() {
|
||||||
for(Seq<Content> content : Vars.content.getContentMap()) {
|
for(Seq<Content> content : Vars.content.getContentMap()) {
|
||||||
if(!content.contains(cont -> cont instanceof UnlockableContent)) continue;
|
|
||||||
JsonObject data = new JsonObject();
|
JsonObject data = new JsonObject();
|
||||||
content.each(cont -> {
|
content.each(cont -> {
|
||||||
UnlockableContent type = (UnlockableContent) cont;
|
|
||||||
JsonObject obj = new JsonObject();
|
JsonObject obj = new JsonObject();
|
||||||
Seq<Field> seq = new Seq<Field>(type.getClass().getFields());
|
Seq<Field> seq = new Seq<Field>(cont.getClass().getFields());
|
||||||
seq.reverse();
|
seq.reverse();
|
||||||
obj.add("type", type.getClass().getName());
|
obj.add("type", cont.getClass().getName());
|
||||||
for(Field field : seq){
|
for(Field field : seq){
|
||||||
try {
|
try {
|
||||||
String str = field.getName();
|
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 Integer val) obj.add(str, val);
|
||||||
if(object instanceof Long 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 Float val) obj.add(str, val);
|
||||||
@@ -40,15 +34,17 @@ public class ContentJSON {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.add(type.localizedName, obj);
|
String name = cont.toString();
|
||||||
|
if(cont instanceof MappableContent mapCont) name = mapCont.name;
|
||||||
|
data.add(name, obj);
|
||||||
});
|
});
|
||||||
try {
|
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){
|
} catch (Throwable t){
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.info("JSON file is completely generated!");
|
Log.info("JSON file is completely updated!");
|
||||||
Core.app.exit();
|
Core.app.exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class Main extends Mod {
|
|||||||
hud.addWaveInfoTable();
|
hud.addWaveInfoTable();
|
||||||
hud.setEvents();
|
hud.setEvents();
|
||||||
OverDrawer.setEvent();
|
OverDrawer.setEvent();
|
||||||
if(debug) ContentJSON.createFile();
|
if(debug) ContentJSON.save();
|
||||||
});
|
});
|
||||||
|
|
||||||
Events.on(WorldLoadEvent.class, e -> {
|
Events.on(WorldLoadEvent.class, e -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user