示例#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();
       }
     }
   }
 }
示例#2
0
 private static final void _addResource(File rootFolder, File file) {
   if (file != null && file.exists()) {
     for (ResoucePath resoucePath : resourcePaths) {
       if (resoucePath.getFilePath().equals(file.getPath())) {
         return;
       }
     }
     if (file.isDirectory()) {
       File[] files = file.listFiles();
       if (files != null) {
         for (File cFile : files) {
           _addResource(rootFolder, cFile);
         }
       }
     } else { // 文件
       resourcePaths.add(new ResoucePath(rootFolder, file));
     }
   }
 }