use of ilargia.entitas.codeGenerator.data.ComponentInfo in project Entitas-Java by Rubentxu.
the class MatcherGenerator method generateMatchers.
private JavaClassSource generateMatchers(String contextName, List<ComponentInfo> componentInfos, String pkgDestiny) {
JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, String.format("public class %1$s {}", CodeGeneratorOld.capitalize(contextName) + "Matcher"));
if (componentInfos.size() > 0 && !pkgDestiny.endsWith(componentInfos.get(0).subDir)) {
pkgDestiny += "." + componentInfos.get(0).subDir;
}
javaClass.setPackage(pkgDestiny);
// javaClass.addImport("ilargia.entitas.interfaces.IMatcher");
javaClass.addImport("Matcher");
for (ComponentInfo info : componentInfos) {
addMatcher(contextName, info, javaClass);
addMatcherMethods(contextName, info, javaClass);
}
System.out.println(javaClass);
return javaClass;
}
use of ilargia.entitas.codeGenerator.data.ComponentInfo in project Entitas-Java by Rubentxu.
the class ComponentIndicesGenerator method addComponentTypes.
public void addComponentTypes(List<ComponentInfo> componentInfos, JavaClassSource javaClass) {
String format = " %1$s%2$s,\n";
String code = "return new Class[] {";
ArrayList<ComponentInfo> totalInfos = new ArrayList<>(Collections.nCopies(componentInfos.get(0).totalComponents, null));
for (ComponentInfo info : componentInfos) {
totalInfos.add(info.index, info);
}
totalInfos.subList(componentInfos.get(0).totalComponents, totalInfos.size()).clear();
for (int i = 0; i < totalInfos.size(); i++) {
ComponentInfo info = totalInfos.get(i);
if (info != null && info.index == i) {
code += String.format(format, info.typeName, ".class");
javaClass.addImport(info.fullTypeName);
} else {
code += String.format(format, null, "");
}
}
StringBuilder codeFinal = new StringBuilder(code);
if (code.endsWith(",\n")) {
codeFinal.replace(code.lastIndexOf(",\n"), code.lastIndexOf(",") + 1, " }; ");
}
javaClass.addMethod().setName("componentTypes").setReturnType("Class[]").setPublic().setStatic(true).setBody(codeFinal.toString());
}
use of ilargia.entitas.codeGenerator.data.ComponentInfo in project Entitas-Java by Rubentxu.
the class EntityGenerator method generateEntity.
private JavaClassSource generateEntity(String contextName, List<ComponentInfo> infos, String pkgDestiny) {
JavaClassSource entityClass = Roaster.parse(JavaClassSource.class, String.format("public class %1$sEntity extends Entity {}", contextName));
if (infos.size() > 0 && !pkgDestiny.endsWith(infos.get(0).subDir)) {
pkgDestiny += "." + infos.get(0).subDir;
}
entityClass.setPackage(pkgDestiny);
entityClass.addMethod().setName(contextName + "Entity").setPublic().setConstructor(true).setBody("");
entityClass.addImport("ilargia.entitas.api.*");
entityClass.addImport("Entity");
entityClass.addImport("java.util.Stack");
for (ComponentInfo info : infos) {
if (info.generateMethods) {
addImporEnums(info, entityClass);
addEntityMethods(contextName, info, entityClass);
}
}
System.out.println(Roaster.format(entityClass.toString()));
return entityClass;
}
use of ilargia.entitas.codeGenerator.data.ComponentInfo in project Entitas-Java by Rubentxu.
the class EntityGenerator method generateMatchers.
private JavaClassSource generateMatchers(String contextName, List<ComponentInfo> componentInfos, String pkgDestiny) {
JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, String.format("public class %1$s {}", CodeGeneratorOld.capitalize(contextName) + "Matcher"));
javaClass.setPackage(pkgDestiny);
// javaClass.addImport("ilargia.entitas.interfaces.IMatcher");
javaClass.addImport("Matcher");
for (ComponentInfo info : componentInfos) {
addMatcher(contextName, info, javaClass);
addMatcherMethods(contextName, info, javaClass);
}
System.out.println(javaClass);
return javaClass;
}
use of ilargia.entitas.codeGenerator.data.ComponentInfo in project Entitas-Java by Rubentxu.
the class CodeGeneratorOld method generateMap.
public static Map<String, List<ComponentInfo>> generateMap(List<ComponentInfo> componentInfos) {
Map<String, List<ComponentInfo>> poolsComponents = new HashMap<>();
componentInfos.sort((c1, c2) -> c1.typeName.compareTo(c2.typeName));
for (ComponentInfo info : componentInfos) {
for (String poolName : info.contexts) {
if (!poolsComponents.containsKey(poolName)) {
poolsComponents.put(poolName, new ArrayList<>());
}
List<ComponentInfo> list = poolsComponents.get(poolName);
list.add(info);
}
}
for (List<ComponentInfo> infos : poolsComponents.values()) {
int index = 0;
for (ComponentInfo info : infos) {
info.index = index++;
info.totalComponents = infos.size();
}
}
return poolsComponents;
}
Aggregations