Beispiel #1
0
  /**
   * Create entity factory for entities with a predefined component composition.
   *
   * @param factory type to create.
   * @param <T> type to create. Should implement {@link EntityFactory}.
   * @return Implementation of EntityFactory.
   * @see EntityFactory for instructions about configuration.
   */
  @SuppressWarnings("unchecked")
  public <T extends EntityFactory> T createFactory(Class<?> factory) {
    if (!factory.isInterface())
      throw new MundaneWireException("Expected interface for type: " + factory);

    String impl = factory.getName() + "Impl";
    try {
      Class<?> implClass = ClassReflection.forName(impl);
      Constructor constructor = ClassReflection.getConstructor(implClass, World.class);
      return (T) constructor.newInstance(this);
    } catch (ReflectionException e) {
      throw new RuntimeException(e);
    }
  }