Search in sources :

Example 1 with ComponentInfo

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

Example 2 with ComponentInfo

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

the class ComponentIndicesGenerator method addComponentNames.

public void addComponentNames(List<ComponentInfo> componentInfos, JavaClassSource javaClass) {
    String format = " \"%1$s\",\n";
    String code = " return new String[] {";
    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);
        } else {
            code += " null,\n";
        }
    }
    StringBuilder codeFinal = new StringBuilder(code);
    if (code.endsWith(",\n")) {
        codeFinal.replace(code.lastIndexOf(",\n"), code.lastIndexOf(",") + 1, " }; ");
    }
    javaClass.addMethod().setName("componentNames").setReturnType("String[]").setPublic().setStatic(true).setBody(codeFinal.toString());
}
Also used : ArrayList(java.util.ArrayList) ComponentInfo(com.ilargia.games.entitas.codeGenerator.data.ComponentInfo)

Example 3 with ComponentInfo

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

the class ContextGenerator method generateContext.

private JavaClassSource generateContext(String contextName, List<ComponentInfo> infos, String pkgDestiny) {
    JavaClassSource contextClass = Roaster.parse(JavaClassSource.class, String.format("public class %1$sContext extends Context<%1$sEntity> {}", contextName));
    //        }
    if (infos.size() > 0 && !pkgDestiny.endsWith(infos.get(0).subDir)) {
        pkgDestiny += "." + infos.get(0).subDir;
    }
    contextClass.setPackage(pkgDestiny);
    contextClass.addMethod().setName(contextName + "Context").setPublic().setConstructor(true).setParameters(String.format("int totalComponents, int startCreationIndex, ContextInfo contextInfo, EntityBaseFactory<%1$sEntity> factoryMethod", contextName)).setBody("super(totalComponents, startCreationIndex, contextInfo, factoryMethod);");
    contextClass.addImport("com.ilargia.games.entitas.api.*");
    for (ComponentInfo info : infos) {
        if (info.isSingleEntity) {
            addContextMethods(contextName, info, contextClass);
        }
    }
    return contextClass;
}
Also used : JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) ComponentInfo(com.ilargia.games.entitas.codeGenerator.data.ComponentInfo)

Example 4 with ComponentInfo

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

Example 5 with ComponentInfo

use of com.ilargia.games.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("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 : 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