Exemplo n.º 1
0
 public static final void export() {
   // 打包规则 , 打包输出默认 本地 assets 文件夹
   // 复制所有类的文件
   // 复制资源的文件夹 , 有 文件夹的 资源复制到 最后一级文件夹目录 , 没有目录的复制到根目录
   Messager.send("Export", MessageKey.H1);
   File asssets = new File("assests");
   FileUtil.delete(asssets); // 清空数据
   asssets.mkdirs();
   Messager.send("clean cache", MessageKey.H2);
   // 打包类对象
   for (ClassPath classPath : classPaths) {
     Messager.send("Saving " + classPath.getClassName(), MessageKey.H1);
     File classFolder = getFolder(classPath);
     classFolder = new File(asssets, classFolder.getName());
     classFolder.mkdirs();
     for (ClassElement element : classPath.getElements()) {
       Messager.send("saving : " + element.getObjId(), MessageKey.H2);
       save(element, classFolder);
     }
   }
   // 打包资源对象
   Messager.send("Saving Images ", MessageKey.H1);
   for (ResoucePath resourcePath : resourcePaths) {
     File file = resourcePath.getFile();
     if (resourcePath.isPSD()) { // 打包 PSD
       Psd psd = PsdCache.get(file);
       List<Layer> layers = new ArrayList<Layer>();
       filterImage(psd, layers);
       final Settings settings = new Settings();
       settings.pot = false;
       settings.maxWidth = 2048;
       settings.maxHeight = 2048;
       TexturePacker packer = new TexturePacker(settings);
       for (Layer layer : layers) {
         packer.addImage(layer.getImage(), layer.getName());
       }
       String imagePath = resourcePath.getAssetsPath().replace(".psd", ".atlas");
       Messager.send("saving image : " + imagePath);
       packer.pack(asssets, imagePath);
     } else { // 拷贝文件
       try {
         File copyTo = new File(asssets, resourcePath.getAssetsPath());
         FileUtil.copy(file, copyTo);
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
   }
 }
Exemplo n.º 2
0
  @Override
  public void init() {
    settings = new Settings();
    settings.maxWidth = 4096;
    settings.maxHeight = 4096;
    settings.combineSubdirectories = true;
    settings.silent = true;
    settings.useIndexes = false;
    settings.fast = true;

    loadingRegion = Assets.icons.findRegion("refresh-big");
    missingRegion = Assets.icons.findRegion("file-question-big");

    FileHandle out = fileAccess.getModuleFolder(".textureCache");
    cachePath = out.path();
    cacheFile = out.child("cache.atlas");

    gfxPath = fileAccess.getAssetsFolder().child("gfx").path();
    atlasesFolder = fileAccess.getAssetsFolder().child("atlas");

    watcher.addListener(this);

    try {
      if (cacheFile.exists()) cache = new TextureAtlas(cacheFile);
    } catch (Exception e) {
      Log.error("Error while loading texture cache, texture cache will be regenerated");
    }

    try {
      if (atlasesFolder.exists()) {
        FileHandle[] files = atlasesFolder.list();

        for (FileHandle file : files) if (file.extension().equals("atlas")) updateAtlas(file);
      }
    } catch (Exception e) {
      Log.error("Error encountered while loading one of atlases");
      Log.exception(e);
    }

    updateCache();
  }
Exemplo n.º 3
0
  private void CreateTextureAndCopy() {

    Settings textureSettings = new Settings();

    textureSettings.pot = true;
    textureSettings.paddingX = 2;
    textureSettings.paddingY = 2;
    textureSettings.duplicatePadding = true;
    textureSettings.edgePadding = true;
    textureSettings.rotation = false;
    textureSettings.minWidth = 16;
    textureSettings.minHeight = 16;
    textureSettings.maxWidth = 512;
    textureSettings.maxHeight = 1024;
    textureSettings.stripWhitespaceX = false;
    textureSettings.stripWhitespaceY = false;
    textureSettings.alphaThreshold = 0;
    textureSettings.filterMin = TextureFilter.Linear;
    textureSettings.filterMag = TextureFilter.Linear;
    textureSettings.wrapX = TextureWrap.ClampToEdge;
    textureSettings.wrapY = TextureWrap.ClampToEdge;
    textureSettings.format = Format.RGBA8888;
    textureSettings.alias = true;
    textureSettings.outputFormat = "png";
    textureSettings.jpegQuality = 0.9f;
    textureSettings.ignoreBlankImages = true;
    textureSettings.fast = false;
    textureSettings.debug = false;

    // Pack Default day
    String inputFolder = imageWorkPath + "\\LibgdxPacker\\default\\input\\day\\UI_IconPack";
    String outputFolder = imageWorkPath + "\\LibgdxPacker\\default\\Output\\day";
    String Name = "UI_IconPack.spp";
    ArrayList<String> outPutFolders = new ArrayList<String>();

    try {
      TexturePacker.process(textureSettings, inputFolder, outputFolder, Name);
    } catch (Exception e1) {
      writeMsg(e1.getCause().getMessage());
      writeMsg(e1.getCause().getCause().getMessage());
    }

    // Pack Default night
    inputFolder = imageWorkPath + "\\LibgdxPacker\\default\\input\\night\\UI_IconPack";
    outputFolder = imageWorkPath + "\\LibgdxPacker\\default\\Output\\night";
    outPutFolders.add(outputFolder);
    Name = "UI_IconPack.spp";
    TexturePacker.process(textureSettings, inputFolder, outputFolder, Name);

    // Pack small day
    inputFolder = imageWorkPath + "\\LibgdxPacker\\small\\input\\day\\UI_IconPack";
    outputFolder = imageWorkPath + "\\LibgdxPacker\\small\\Output\\day";
    outPutFolders.add(outputFolder);
    Name = "UI_IconPack.spp";
    TexturePacker.process(textureSettings, inputFolder, outputFolder, Name);

    // Pack small night
    inputFolder = imageWorkPath + "\\LibgdxPacker\\small\\input\\night\\UI_IconPack";
    outputFolder = imageWorkPath + "\\LibgdxPacker\\small\\Output\\night";
    outPutFolders.add(outputFolder);
    Name = "UI_IconPack.spp";
    TexturePacker.process(textureSettings, inputFolder, outputFolder, Name);

    // Pack Default day
    inputFolder = imageWorkPath + "\\LibgdxPacker\\default\\input\\splash";
    outputFolder = imageWorkPath + "\\LibgdxPacker\\default\\Output\\day";
    outPutFolders.add(outputFolder);
    Name = "SplashPack.spp";
    TexturePacker.process(textureSettings, inputFolder, outputFolder, Name);

    writeMsg("Copy Textures");
    writeMsg("Copy: ");

    // Change TexturFilter at *.spp files with in all output folder
    String br = Global.br;
    for (String folder : outPutFolders) {
      File dir = new File(folder);
      File[] files =
          dir.listFiles(
              new FileFilter() {

                @Override
                public boolean accept(File pathname) {
                  if (pathname.getName().endsWith(".spp")) {
                    if (pathname.getName().endsWith("_MipMap.spp")) return false;
                    return true;
                  }
                  return false;
                }
              });

      for (File tmp : files) {
        // now open and change Line
        // "filter: Linear,Linear"
        // to
        // "filter: MipMapLinearNearest,Nearest"

        BufferedReader in;
        try {
          in = new BufferedReader(new FileReader(tmp));

          String line; // a line in the file

          StringBuilder builder = new StringBuilder();

          while ((line = in.readLine()) != null) {
            if (line.contains("filter:")) {
              builder.append("filter: MipMapLinearNearest,Nearest" + br);
            } else {
              builder.append(line + br);
            }
          }

          in.close();

          FileWriter writer;

          String newName = tmp.getAbsolutePath().replace(".spp", "_MipMap.spp");
          File newPerformanceFile = new File(newName);

          writer = new FileWriter(newPerformanceFile, false);
          writer.write(builder.toString());
          writer.close();

        } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }

    Copy copy = new Copy(getCopyRulesTexture());
    try {
      copy.Run(
          new CopyMsg() {
            @Override
            public void Msg(String msg) {
              writeMsg(msg, true);
            }
          });
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    writeMsg("Ready", true);
    writeMsg("");
    writeMsg("Don�t forgot refresh and clean on Eclipse");
  }