Search in sources :

Example 6 with ComponentInfo

use of com.ilargia.games.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("com.ilargia.games.entitas.interfaces.IMatcher");
    javaClass.addImport("Matcher");
    for (ComponentInfo info : componentInfos) {
        addMatcher(contextName, info, javaClass);
        addMatcherMethods(contextName, info, javaClass);
    }
    System.out.println(javaClass);
    return javaClass;
}
Also used : JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) ComponentInfo(com.ilargia.games.entitas.codeGenerator.data.ComponentInfo)

Example 7 with ComponentInfo

use of com.ilargia.games.entitas.codeGenerator.data.ComponentInfo in project Entitas-Java by Rubentxu.

the class ComponentIndicesGenerator method addComponentFactories.

public void addComponentFactories(ComponentInfo[] componentInfos, JavaClassSource javaClass) {
    String format = " %1$s.class,\n";
    String code = "return new FactoryComponent[] {";
    for (int i = 0; i < componentInfos.length; i++) {
        ComponentInfo info = componentInfos[i];
        JavaInterfaceSource interfaceSource = Roaster.parse(JavaInterfaceSource.class, String.format("public interface Factory%1$s extends FactoryComponent {}", info.typeName));
        interfaceSource.addMethod().setName(String.format("create%1$s", info.typeName)).setReturnType(info.typeName).setPublic();
        javaClass.addNestedType(interfaceSource.toString());
    }
}
Also used : JavaInterfaceSource(org.jboss.forge.roaster.model.source.JavaInterfaceSource) ComponentInfo(com.ilargia.games.entitas.codeGenerator.data.ComponentInfo)

Example 8 with ComponentInfo

use of com.ilargia.games.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());
}
Also used : ArrayList(java.util.ArrayList) ComponentInfo(com.ilargia.games.entitas.codeGenerator.data.ComponentInfo)

Aggregations

ComponentInfo (com.ilargia.games.entitas.codeGenerator.data.ComponentInfo)8 ArrayList (java.util.ArrayList)2 JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)2 JavaInterfaceSource (org.jboss.forge.roaster.model.source.JavaInterfaceSource)1