mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-30 22:49:06 +07:00
Fixed chat not working while paused
This commit is contained in:
102
tools/src/mindustry/tools/BindingsGenerator.java
Normal file
102
tools/src/mindustry/tools/BindingsGenerator.java
Normal file
@ -0,0 +1,102 @@
|
||||
package mindustry.tools;
|
||||
|
||||
import arc.files.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
|
||||
import static mindustry.tools.ScriptMainGenerator.*;
|
||||
|
||||
//experimental
|
||||
public class BindingsGenerator{
|
||||
|
||||
public static void main(String[] args) throws Exception{
|
||||
|
||||
Seq<String> blacklist = Seq.with("mindustry.tools", "arc.backend");
|
||||
Seq<Class<?>> classes = Seq.withArrays(
|
||||
getClasses("mindustry"),
|
||||
getClasses("arc")
|
||||
);
|
||||
classes.sort(Structs.comparing(Class::getName));
|
||||
|
||||
classes.removeAll(type -> type.isSynthetic() || type.isAnonymousClass() || type.getCanonicalName() == null || Modifier.isPrivate(type.getModifiers())
|
||||
|| blacklist.contains(s -> type.getName().startsWith(s)));
|
||||
|
||||
classes.distinct();
|
||||
classes.sortComparing(Class::getName);
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("import jnim, jnim/java/lang\n\n{.experimental: \"codeReordering\".}\n\n");
|
||||
|
||||
for(Class<?> type : classes){
|
||||
String name = type.getCanonicalName();
|
||||
result.append("jclass ").append(name).append("* of ")
|
||||
.append(type.getSuperclass() == null ? "JVMObject" : type.getSuperclass().getSimpleName()).append(":\n");
|
||||
|
||||
for(Field field : type.getFields()){
|
||||
if(Modifier.isPublic(field.getModifiers())){
|
||||
result.append(" proc `").append(field.getName()).append("`*");
|
||||
result.append(": ").append(str(field.getType()));
|
||||
result.append(" {.prop");
|
||||
if(Modifier.isStatic(field.getModifiers())) result.append(", `static`");
|
||||
if(Modifier.isStatic(field.getModifiers())) result.append(", `final`");
|
||||
result.append(".}\n");
|
||||
}
|
||||
}
|
||||
|
||||
Seq<Executable> exec = new Seq<>();
|
||||
|
||||
exec.addAll(type.getDeclaredMethods());
|
||||
exec.addAll(type.getDeclaredConstructors());
|
||||
|
||||
for(Executable method : exec){
|
||||
if(Modifier.isPublic(method.getModifiers())){
|
||||
String mname = method.getName().equals("<init>") || method.getName().equals(type.getCanonicalName()) ? "new" : method.getName();
|
||||
result.append(" proc `").append(mname).append("`*");
|
||||
|
||||
if(method.getParameterCount() > 0){
|
||||
result.append("(");
|
||||
|
||||
for(int i = 0; i < method.getParameterCount(); i++){
|
||||
Class p = method.getParameterTypes()[i];
|
||||
|
||||
result.append(method.getParameters()[i].getName()).append(": ").append(str(p));
|
||||
|
||||
if(i != method.getParameterCount() - 1){
|
||||
result.append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
result.append(")");
|
||||
}
|
||||
|
||||
if(method instanceof Method){
|
||||
Method m = (Method)method;
|
||||
if(!m.getReturnType().equals(void.class)){
|
||||
result.append(": ").append(str(m.getReturnType()));
|
||||
}
|
||||
}
|
||||
|
||||
//result.append(" {.");
|
||||
//if(Modifier.isStatic(field.getModifiers())) result.append(", `static`");
|
||||
//if(Modifier.isStatic(field.getModifiers())) result.append(", `final`");
|
||||
//result.append(".}\n");
|
||||
result.append("\n");
|
||||
}
|
||||
}
|
||||
result.append("\n");
|
||||
}
|
||||
|
||||
Fi.get(OS.userhome).child("mindustry.nim").writeString(result.toString());
|
||||
Log.info(result);
|
||||
}
|
||||
|
||||
static String str(Class type){
|
||||
if(type.isArray()){
|
||||
return "seq[" + str(type.getComponentType()) + "]";
|
||||
}
|
||||
if(type.isPrimitive()) return "j" + type.getSimpleName();
|
||||
return type.getSimpleName();
|
||||
}
|
||||
}
|
@ -71,8 +71,7 @@ public class ScriptMainGenerator{
|
||||
new Fi("core/assets/scripts/global.js").writeString(result.toString());
|
||||
}
|
||||
|
||||
|
||||
private static Seq<Class> getClasses(String packageName) throws Exception{
|
||||
public static Seq<Class> getClasses(String packageName) throws Exception{
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
Seq<File> dirs = new Seq<>();
|
||||
|
||||
@ -87,7 +86,7 @@ public class ScriptMainGenerator{
|
||||
return classes;
|
||||
}
|
||||
|
||||
private static Seq<Class> findClasses(File directory, String packageName) throws Exception{
|
||||
public static Seq<Class> findClasses(File directory, String packageName) throws Exception{
|
||||
Seq<Class> classes = new Seq<>();
|
||||
if(!directory.exists()) return classes;
|
||||
|
||||
|
Reference in New Issue
Block a user