Search in sources :

Example 11 with Feature

use of com.b3dgs.lionengine.game.Feature in project lionengine by b3dgs.

the class Features method add.

/**
 * Add a feature. Stores its interface, and all sub interfaces which describe also a {@link Feature} annotated by
 * {@link FeatureInterface}.
 *
 * @param feature The feature to add.
 * @param overwrite <code>true</code> to overwrite existing feature, <code>false</code> else.
 * @throws LionEngineException If feature is not annotated by {@link FeatureInterface} or already referenced.
 */
public void add(Feature feature, boolean overwrite) {
    if (!isAnnotated(feature)) {
        throw new LionEngineException(ERROR_FEATURE_NOT_ANNOTATED + feature.getClass());
    }
    final Feature old;
    // CHECKSTYLE IGNORE LINE: InnerAssignment
    if ((old = typeToFeature.put(feature.getClass(), feature)) != null) {
        throw new LionEngineException(ERROR_FEATURE_EXISTS + feature.getClass() + WITH + old.getClass());
    }
    checkTypeDepth(feature, feature.getClass(), overwrite);
    features.add(feature);
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) Feature(com.b3dgs.lionengine.game.Feature)

Example 12 with Feature

use of com.b3dgs.lionengine.game.Feature in project lionengine by b3dgs.

the class HandlablesImpl method add.

/**
 * Add a featurable.
 *
 * @param featurable The featurable to add.
 */
public void add(Featurable featurable) {
    featurables.put(featurable.getFeature(Identifiable.class).getId(), featurable);
    for (final Class<?> type : featurable.getClass().getInterfaces()) {
        addType(type, featurable);
    }
    for (final Class<? extends Feature> feature : featurable.getFeaturesType()) {
        final Feature object = featurable.getFeature(feature);
        addType(feature, object);
        for (final Class<?> other : UtilReflection.getInterfaces(feature, Feature.class)) {
            addType(other, object);
        }
    }
    addType(featurable.getClass(), featurable);
    addSuperClass(featurable, featurable.getClass());
}
Also used : Feature(com.b3dgs.lionengine.game.Feature)

Example 13 with Feature

use of com.b3dgs.lionengine.game.Feature in project lionengine by b3dgs.

the class Factory method addFeatures.

/**
 * Add all features declared in configuration.
 *
 * @param featurable The featurable to handle.
 * @param services The services reference.
 * @param setup The setup reference.
 */
private void addFeatures(Featurable featurable, Services services, Setup setup) {
    final List<Feature> rawFeatures = FeaturableConfig.getFeatures(classLoader, services, setup);
    final int length = rawFeatures.size();
    for (int i = 0; i < length; i++) {
        final Feature feature = rawFeatures.get(i);
        featurable.addFeature(feature);
    }
    featurable.addAfter(services, setup);
}
Also used : Feature(com.b3dgs.lionengine.game.Feature)

Example 14 with Feature

use of com.b3dgs.lionengine.game.Feature in project lionengine by b3dgs.

the class Routines method prepare.

/*
     * Feature
     */
@Override
public void prepare(FeatureProvider provider) {
    super.prepare(provider);
    for (final Feature feature : provider.getFeatures()) {
        if (feature instanceof Routine) {
            routines.add((Routine) feature);
        }
    }
    routinesCount = routines.size();
}
Also used : Feature(com.b3dgs.lionengine.game.Feature)

Aggregations

Feature (com.b3dgs.lionengine.game.Feature)14 Test (org.junit.jupiter.api.Test)8 Media (com.b3dgs.lionengine.Media)3 Xml (com.b3dgs.lionengine.Xml)3 LionEngineException (com.b3dgs.lionengine.LionEngineException)2 XmlReader (com.b3dgs.lionengine.XmlReader)1 FeatureProvider (com.b3dgs.lionengine.game.FeatureProvider)1 ArrayList (java.util.ArrayList)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1