/**
   * Loads the specified file with one of the loaders registered with this ModelLoaderRegistry. Uses
   * the extension to determine which loader to use. The comparison of extensions is done case
   * insensitive.
   *
   * @param file the file to be loaded
   * @param hints the {@link ModelLoaderHints} to use
   * @return the {@link Model}
   * @throws GdxRuntimeException in case the model could not be loaded.
   */
  public static Model load(FileHandle file, ModelLoaderHints hints) {
    String name = file.name();
    int dotIndex = name.lastIndexOf('.');
    if (dotIndex == -1)
      throw new GdxRuntimeException(
          "file '"
              + file.name()
              + "' does not have an extension that can be matched to a ModelLoader");
    String extension = name.substring(dotIndex + 1).toLowerCase();

    Array<ModelLoader> loaders = ModelLoaderRegistry.loaders.get(extension);
    if (loaders == null)
      throw new GdxRuntimeException("no loaders for extension '" + extension + "'");

    Model model = null;
    StringBuilder errors = new StringBuilder();
    for (int i = 0; i < loaders.size; i++) {
      ModelLoader loader = loaders.get(i);
      try {
        model = loader.load(file, hints);
      } catch (GdxRuntimeException e) {
        errors.append(
            "Couldn't load '"
                + file.name()
                + "' with loader of type "
                + loader.getClass().getSimpleName()
                + ": "
                + e.getMessage()
                + "\n");
      }
    }

    if (model == null) throw new GdxRuntimeException(errors.toString());
    else return model;
  }
  /**
   * Will load font from file. If that fails, font will be generated and saved to file.
   *
   * @param fontFile the actual font (.otf, .ttf)
   * @param fontName the name of the font, i.e. "arial-small", "arial-large", "monospace-10" This
   *     will be used for creating the font file names
   * @param fontSize fontSize of font when screen width equals referenceScreenWidth
   */
  public AnimvsBitmapFont createFont(
      FileHandle fontFile,
      String fontName,
      int fontSize,
      String characters,
      String language,
      int pageSize) {
    if (pageSize < 50)
      throw new RuntimeException("Page fontSize too small during font generation: " + pageSize);

    AnimvsBitmapFont font = null;
    // if fonts are already generated, just load from file
    Preferences fontPrefs = Gdx.app.getPreferences(propertyName);
    String lastVersionTag = fontPrefs.getString("tag");
    int displayWidth = fontPrefs.getInteger("display-width", 0);
    int displayHeight = fontPrefs.getInteger("display-height", 0);
    String lastUsedLanguage = fontPrefs.getString("lang");
    boolean loaded = false;
    if (displayWidth != Gdx.graphics.getWidth() || displayHeight != Gdx.graphics.getHeight())
      Gdx.app.debug(TAG, "Screen fontSize change detected, regenerating fonts");
    else if (!lastUsedLanguage.equals(language))
      Gdx.app.debug(TAG, "Language change detected, regenerating fonts");
    else if (!lastVersionTag.equals(versionTag))
      Gdx.app.debug(TAG, "Version change detected, regenerating fonts");
    else if (!forceGeneration) {
      try {
        // try to load from file
        Gdx.app.debug(TAG, "Loading generated font from file cache");
        font = new AnimvsBitmapFont(getFontFile(fontName + ".fnt"));
        setDefaultFilter(font);

        loaded = true;

        // arquivosFonte.add(fontFile.path());
      } catch (GdxRuntimeException e) {
        Gdx.app.error(TAG, e.getMessage());
        Gdx.app.debug(TAG, "Couldn't load pre-generated fonts. Will generate fonts.");
      }
    }
    if (!loaded || forceGeneration) {
      forceGeneration = false;
      // float width = Gdx.graphics.getWidth();
      // float ratio = width / referenceScreenWidth; // use 1920x1280 as
      // float baseSize = 28f; // for 28 sized fonts at baseline width
      // above

      Gdx.app.log(
          TAG,
          "Generating Font - Name: "
              + fontName
              + " Size: "
              + fontSize
              + " characters: "
              + characters);
      font = generateFontWriteFiles(fontName, fontFile, fontSize, pageSize, pageSize, characters);
      // arquivosFonte.add(fontFile.path());
    }
    return font;
  }
 private void loadImage(ParticleEmitter emitter) {
   final String imagePath = emitter.getImagePath();
   String imageName = new File(imagePath.replace('\\', '/')).getName();
   try {
     FileHandle file;
     if (imagePath.equals("particle.png")) file = Gdx.files.classpath(imagePath);
     else file = Gdx.files.absolute(imagePath);
     emitter.setSprite(new Sprite(new Texture(file)));
   } catch (GdxRuntimeException ex) {
     ex.printStackTrace();
     EventQueue.invokeLater(
         new Runnable() {
           public void run() {
             JOptionPane.showMessageDialog(
                 ParticleEditor.this, "Error loading image:\n" + imagePath);
           }
         });
     emitter.setImagePath(null);
   }
 }