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);
}
}
}
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);
}
}
Aggregations