Search in sources :

Example 1 with Component

use of com.artemis.Component in project commons-gdx by gemserk.

the class EntityDebugger method debug.

public static void debug(String message, Entity e) {
    System.out.println(message);
    System.out.println("e.id=" + e.getId());
    System.out.println("e.uniqueId=" + e.getUniqueId());
    ImmutableBag<Component> components = e.getComponents();
    for (int i = 0; i < components.size(); i++) {
        Component component = components.get(i);
        System.out.println("e.component=" + component.getClass().getSimpleName());
    }
}
Also used : Component(com.artemis.Component)

Example 2 with Component

use of com.artemis.Component in project commons-gdx by gemserk.

the class ComponentMapperInitHelper method config.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void config(Object target, EntityManager entityManager) {
    try {
        for (Field field : target.getClass().getDeclaredFields()) {
            String fieldName = field.getName();
            Class<?> fieldType = field.getType();
            if (ComponentMapper.class.isAssignableFrom(fieldType)) {
                System.out.println("ComponentMapper detected: " + fieldName);
                ParameterizedType genericType = (ParameterizedType) field.getGenericType();
                Class componentType = (Class) genericType.getActualTypeArguments()[0];
                ComponentMapper<Component> componentMapper = new ComponentMapper<Component>(componentType, entityManager);
                field.setAccessible(true);
                field.set(target, componentMapper);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException("Error while setting component mappers", e);
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Field(java.lang.reflect.Field) ComponentMapper(com.artemis.ComponentMapper) Component(com.artemis.Component)

Aggregations

Component (com.artemis.Component)2 ComponentMapper (com.artemis.ComponentMapper)1 Field (java.lang.reflect.Field)1 ParameterizedType (java.lang.reflect.ParameterizedType)1