Пример #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
 public static final void save() {
   try {
     Json json = new Json(new DataManage());
     String text = json.toString();
     if (text.hashCode() != hashCode) {
       hashCode = text.hashCode();
       System.out.println("save data");
       FileUtil.save(getFile(), text);
       Messager.send(L.get("Message.data_save") + "    " + new Date().toString());
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Пример #3
0
 // 保存类文件到 指定文件夹
 public static final void save(ClassElement classElement, File folder) {
   try {
     if (folder.exists() == false) {
       folder.mkdirs();
     }
     File jsonFile = new File(folder, classElement.getObjId());
     jsonFile.createNewFile();
     FileUtil.save(jsonFile, new Json(classElement.getObject()).toString());
     //
     ClassPath classPath = classElement.getParent();
     Messager.send(
         L.get("message.class_element_save")
             + "  "
             + classPath.getClassName()
             + "  "
             + classElement.getObjId()
             + "  "
             + new Date().toString());
   } catch (Exception e) {
     e.printStackTrace();
   }
 }