Search in sources :

Example 1 with AnimationConfig

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

the class StateAnimationUtil method loadStates.

/**
 * Load all existing animations defined in the xml file.
 *
 * @param states The states values.
 * @param factory The factory reference.
 * @param provider The featurable reference.
 * @param setup The setup reference.
 */
public static void loadStates(StateAnimationBased[] states, StateFactory factory, FeatureProvider provider, Setup setup) {
    final AnimationConfig configAnimations = AnimationConfig.imports(setup);
    for (final StateAnimationBased type : states) {
        try {
            final Animation animation = configAnimations.getAnimation(type.getAnimationName());
            final State state = UtilReflection.create(type.getStateClass(), UtilReflection.getParamTypes(provider, animation), provider, animation);
            factory.addState(state);
        } catch (final NoSuchMethodException exception) {
            throw new LionEngineException(exception);
        }
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) State(com.b3dgs.lionengine.game.State) Animation(com.b3dgs.lionengine.Animation) AnimationConfig(com.b3dgs.lionengine.game.AnimationConfig)

Example 2 with AnimationConfig

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

the class StateHandler method create.

/**
 * Create state from its type.
 *
 * @param state The state to create (must not be <code>null</code>).
 * @return The created state.
 * @throws LionEngineException If unable to create state.
 */
@SuppressWarnings("unchecked")
private State create(Class<? extends State> state) {
    Check.notNull(state);
    try {
        if (setup.hasNode(AnimationConfig.NODE_ANIMATIONS)) {
            final AnimationConfig configAnimations = AnimationConfig.imports(setup);
            final String name = converter.apply(state);
            final Animation animation = configAnimations.getAnimation(name);
            final Class<? extends Feature> feature;
            feature = (Class<? extends Feature>) UtilReflection.getCompatibleConstructor(state, FeatureProvider.class, Animation.class).getParameters()[PARAM_FEATURE_INDEX].getType();
            return UtilReflection.create(state, UtilReflection.getParamTypes(feature, animation), getFeature(feature), animation);
        }
        return UtilReflection.createReduce(state);
    } catch (final LionEngineException exception) {
        throw new LionEngineException(exception, setup.getMedia());
    } catch (final NoSuchMethodException exception) {
        throw new LionEngineException(exception);
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) Animation(com.b3dgs.lionengine.Animation) FeatureProvider(com.b3dgs.lionengine.game.FeatureProvider) AnimationConfig(com.b3dgs.lionengine.game.AnimationConfig)

Aggregations

Animation (com.b3dgs.lionengine.Animation)2 LionEngineException (com.b3dgs.lionengine.LionEngineException)2 AnimationConfig (com.b3dgs.lionengine.game.AnimationConfig)2 FeatureProvider (com.b3dgs.lionengine.game.FeatureProvider)1 State (com.b3dgs.lionengine.game.State)1