Exemplo n.º 1
0
  public void pack(File outputDir, String packFileName) {
    outputDir.mkdirs();

    // if (packFileName.indexOf('.') == -1 || packFileName.endsWith(".png") ||
    // packFileName.endsWith(".jpg"))
    //	packFileName += ".atlas";

    int dotIndex = packFileName.indexOf('.');
    if (dotIndex != -1) packFileName = packFileName.substring(0, dotIndex);

    for (float scale : settings.scale) {
      String scaledPackFileName = packFileName;
      if (scale != 1 || settings.scale.length != 1) {
        FileHandle file = new FileHandle(scaledPackFileName);
        String suffix =
            scale == (int) scale ? Integer.toString((int) scale) : Float.toString(scale);
        scaledPackFileName = file.nameWithoutExtension(); // + suffix ; //+ "." + file.extension();
      }

      imageProcessor.setScale(scale);
      for (InputImage inputImage : inputImages) {
        if (inputImage.file != null) imageProcessor.addImage(inputImage.file);
        else imageProcessor.addImage(inputImage.image, inputImage.name);
      }

      Array<Page> pages = packer.pack(imageProcessor.getImages());

      writeImages(outputDir, pages, scaledPackFileName);
      try {
        System.out.println("--Start writing pack file.");
        writePackFile(outputDir, pages, scaledPackFileName);
        writePlistFile(outputDir, pages, scaledPackFileName);
      } catch (IOException ex) {
        throw new RuntimeException("Error writing pack file.", ex);
      }
      imageProcessor.clear();
    }
  }