Single-texture font+UI packing
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
package mindustry.annotations;
|
||||
|
||||
import arc.files.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.serialization.*;
|
||||
import com.squareup.javapoet.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
|
||||
@@ -8,7 +12,6 @@ import javax.lang.model.*;
|
||||
import javax.lang.model.element.*;
|
||||
import javax.tools.Diagnostic.*;
|
||||
import javax.tools.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_8)
|
||||
@@ -34,9 +37,9 @@ public class AssetsAnnotationProcessor extends AbstractProcessor{
|
||||
if(round++ != 0) return false; //only process 1 round
|
||||
|
||||
try{
|
||||
path = Paths.get(Utils.filer.createResource(StandardLocation.CLASS_OUTPUT, "no", "no")
|
||||
path = Fi.get(Utils.filer.createResource(StandardLocation.CLASS_OUTPUT, "no", "no")
|
||||
.toUri().toURL().toString().substring(System.getProperty("os.name").contains("Windows") ? 6 : "file:".length()))
|
||||
.getParent().getParent().getParent().getParent().getParent().getParent().toString();
|
||||
.parent().parent().parent().parent().parent().parent().toString();
|
||||
path = path.replace("%20", " ");
|
||||
|
||||
processSounds("Sounds", path + "/assets/sounds", "arc.audio.Sound");
|
||||
@@ -54,15 +57,28 @@ public class AssetsAnnotationProcessor extends AbstractProcessor{
|
||||
String[] iconSizes = {"small", "smaller", "tiny"};
|
||||
|
||||
TypeSpec.Builder type = TypeSpec.classBuilder("Tex").addModifiers(Modifier.PUBLIC);
|
||||
TypeSpec.Builder ictype = TypeSpec.classBuilder("Icon").addModifiers(Modifier.PUBLIC);
|
||||
TypeSpec.Builder ictype = TypeSpec.classBuilder("Icon").addModifiers(Modifier.PUBLIC); //TODO remove and replace
|
||||
TypeSpec.Builder ictype_ = TypeSpec.classBuilder("Icon_").addModifiers(Modifier.PUBLIC);
|
||||
TypeSpec.Builder ichtype = TypeSpec.classBuilder("Iconc").addModifiers(Modifier.PUBLIC);
|
||||
MethodSpec.Builder load = MethodSpec.methodBuilder("load").addModifiers(Modifier.PUBLIC, Modifier.STATIC);
|
||||
MethodSpec.Builder loadStyles = MethodSpec.methodBuilder("loadStyles").addModifiers(Modifier.PUBLIC, Modifier.STATIC);
|
||||
MethodSpec.Builder icload = MethodSpec.methodBuilder("load").addModifiers(Modifier.PUBLIC, Modifier.STATIC);
|
||||
MethodSpec.Builder icload_ = MethodSpec.methodBuilder("load").addModifiers(Modifier.PUBLIC, Modifier.STATIC);
|
||||
String resources = path + "/assets-raw/sprites/ui";
|
||||
Files.walk(Paths.get(resources)).forEach(p -> {
|
||||
if(Files.isDirectory(p) || p.getFileName().toString().equals(".DS_Store")) return;
|
||||
Jval icons = Jval.read(Fi.get(path + "/assets-raw/fontgen/config.json").readString());
|
||||
|
||||
String filename = p.getFileName().toString();
|
||||
for(Jval val : icons.get("glyphs").asArray()){
|
||||
String name = capitalize(val.getString("css", ""));
|
||||
int code = val.getInt("code", 0);
|
||||
ichtype.addField(FieldSpec.builder(char.class, name, Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL).initializer("(char)" + code).build());
|
||||
ictype_.addField(TextureRegionDrawable.class, name, Modifier.PUBLIC, Modifier.STATIC);
|
||||
icload_.addStatement(name + " = mindustry.Vars.ui.getGlyph(mindustry.ui.Fonts.def, (char)" + code + ")");
|
||||
}
|
||||
|
||||
Fi.get(resources).walk(p -> {
|
||||
if(p.nameWithoutExtension().equals(".DS_Store")) return;
|
||||
|
||||
String filename = p.name();
|
||||
filename = filename.substring(0, filename.indexOf("."));
|
||||
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
@@ -75,7 +91,7 @@ public class AssetsAnnotationProcessor extends AbstractProcessor{
|
||||
suffix = suffix.isEmpty() ? "" : "-" + suffix;
|
||||
|
||||
String sfilen = filename + suffix;
|
||||
String dtype = p.getFileName().toString().endsWith(".9.png") ? "arc.scene.style.NinePatchDrawable" : "arc.scene.style.TextureRegionDrawable";
|
||||
String dtype = p.name().endsWith(".9.png") ? "arc.scene.style.NinePatchDrawable" : "arc.scene.style.TextureRegionDrawable";
|
||||
|
||||
String varname = capitalize(sfilen);
|
||||
TypeSpec.Builder ttype = type;
|
||||
@@ -96,8 +112,7 @@ public class AssetsAnnotationProcessor extends AbstractProcessor{
|
||||
});
|
||||
|
||||
for(Element elem : elements){
|
||||
TypeElement t = (TypeElement)elem;
|
||||
t.getEnclosedElements().stream().filter(e -> e.getKind() == ElementKind.FIELD).forEach(field -> {
|
||||
Array.with(((TypeElement)elem).getEnclosedElements()).each(e -> e.getKind() == ElementKind.FIELD, field -> {
|
||||
String fname = field.getSimpleName().toString();
|
||||
if(fname.startsWith("default")){
|
||||
loadStyles.addStatement("arc.Core.scene.addStyle(" + field.asType().toString() + ".class, mindustry.ui.Styles." + fname + ")");
|
||||
@@ -106,7 +121,10 @@ public class AssetsAnnotationProcessor extends AbstractProcessor{
|
||||
}
|
||||
|
||||
ictype.addMethod(icload.build());
|
||||
ictype_.addMethod(icload_.build());
|
||||
JavaFile.builder(packageName, ictype.build()).build().writeTo(Utils.filer);
|
||||
JavaFile.builder(packageName, ichtype.build()).build().writeTo(Utils.filer);
|
||||
JavaFile.builder(packageName, ictype_.build()).build().writeTo(Utils.filer);
|
||||
|
||||
type.addMethod(load.build());
|
||||
type.addMethod(loadStyles.build());
|
||||
@@ -119,10 +137,9 @@ public class AssetsAnnotationProcessor extends AbstractProcessor{
|
||||
MethodSpec.Builder loadBegin = MethodSpec.methodBuilder("load").addModifiers(Modifier.PUBLIC, Modifier.STATIC);
|
||||
|
||||
HashSet<String> names = new HashSet<>();
|
||||
Files.list(Paths.get(path)).forEach(p -> {
|
||||
String fname = p.getFileName().toString();
|
||||
String name = p.getFileName().toString();
|
||||
name = name.substring(0, name.indexOf("."));
|
||||
Fi.get(path).walk(p -> {
|
||||
String fname = p.name();
|
||||
String name = p.nameWithoutExtension();
|
||||
|
||||
if(names.contains(name)){
|
||||
Utils.messager.printMessage(Kind.ERROR, "Duplicate file name: " + p.toString() + "!");
|
||||
|
||||
Reference in New Issue
Block a user