List of usage examples for com.badlogic.gdx.files FileHandle copyTo
public void copyTo(FileHandle dest)
From source file:com.forerunnergames.peril.client.assets.LocalAssetUpdater.java
License:Open Source License
@Override public void updateAssets() { if (!AssetSettings.UPDATE_ASSETS) { log.warn("Assets are not being updated.\nTo change this behavior, change {} in {} from false to true.\n" + "Make sure to back up any customizations you made to any assets first, as your changes " + "will be overwritten.", ClientApplicationProperties.UPDATE_ASSETS_KEY, ClientApplicationProperties.PROPERTIES_FILE_PATH_AND_NAME); return;/*w ww.ja va2s . c o m*/ } assetUpdatingFuture = executorService.submit(new Runnable() { @Override public void run() { final FileHandle destAssetsDir = Gdx.files .external(AssetSettings.RELATIVE_EXTERNAL_ASSETS_DIRECTORY); try { final FileHandle sourceAssetsDir = Gdx.files .absolute(AssetSettings.ABSOLUTE_UPDATED_ASSETS_LOCATION); log.info("Attempting to update assets in [{}] from [{}]...", destAssetsDir.file(), sourceAssetsDir); if (Thread.currentThread().isInterrupted()) { log.warn("Asset updating was cancelled before beginning."); return; } log.info("Removing old assets..."); destAssetsDir.deleteDirectory(); if (Thread.currentThread().isInterrupted()) { log.warn( "Asset updating was cancelled after removing old assets, but before copying new assets."); return; } log.info("Copying new assets..."); sourceAssetsDir.copyTo(destAssetsDir); log.info("Successfully updated assets."); } catch (final Exception e) { final String errorMessage = "Failed to update assets from: [" + AssetSettings.ABSOLUTE_UPDATED_ASSETS_LOCATION + "].\n" + "Make sure that " + ClientApplicationProperties.UPDATED_ASSETS_LOCATION_KEY + " is properly set in [" + ClientApplicationProperties.PROPERTIES_FILE_PATH_AND_NAME + "].\n" + "Also, " + ClientApplicationProperties.UPDATE_ASSETS_KEY + " must be set to true (in the same file) the first time you run the game.\n" + "If you already tried all of that, you can set " + ClientApplicationProperties.UPDATE_ASSETS_KEY + " to false.\nIn that case, you still need to make sure that you have a copy of all assets in " + destAssetsDir.file() + ".\n\n" + "Nerdy developer details:\n"; log.error(errorMessage, e); throw new RuntimeException(errorMessage, e); } } }); }
From source file:com.kotcrab.vis.editor.ui.dialog.SpriterImportDialog.java
License:Apache License
private void importAnimation() { SteppedAsyncTask importTask = new SteppedAsyncTask("SpriterImporter") { @Override/*from w ww .j a v a 2 s. c o m*/ public void execute() throws IOException { FileHandle[] files = animFolder.list(); setTotalSteps(files.length * 2); float scaleFactor = Float.valueOf(scaleField.getText()); visAnimFolder.mkdirs(); visAnimFolder.child("update").mkdirs(); FileHandle target = visAnimFolder.child("original"); target.mkdirs(); for (FileHandle file : files) { setMessage("Copying " + file.name()); file.copyTo(target); nextStep(); } for (FileHandle file : files) { if (file.extension().equals("png") == false) continue; setMessage("Converting " + file.name()); BufferedImage image = ImageIO.read(file.file()); BufferedImage scaledImage = Scalr.resize(image, MathUtils.round(image.getWidth() * scaleFactor), MathUtils.round(image.getHeight() * scaleFactor)); ImageIO.write(scaledImage, "png", file.file()); nextStep(); } setMessage("Saving data"); Json json = SpriterDataIOModule.getNewJson(); SpriterAssetData assetData = new SpriterAssetData(scaleFactor); json.toJson(assetData, visAnimFolder.child("data.json")); } }; getStage().addActor(new AsyncTaskProgressDialog("Importing animation", importTask)); }
From source file:com.kotcrab.vis.editor.ui.scene.SceneTab.java
License:Apache License
@Override public boolean save() { super.save(); //TODO: this deserves async task when scene has many entities scene.setSchemes(sceneMC.getEntityEngine().getSystem(EntityProxyCache.class).getEntitySchemes()); try {//from w ww . jav a 2 s .c o m FileHandle sceneFile = sceneIOModule.getFileHandleForScene(scene); FileHandle backupTarget = sceneIOModule.getSceneBackupFolder().child(scene.path); if (lastSaveFailed == false) { sceneFile.copyTo(backupTarget.sibling(sceneFile.name() + ".bak")); } if (savedAtLeastOnce == false) { sceneFile.copyTo(backupTarget.sibling(sceneFile.name() + ".firstSaveBak")); } if (sceneIOModule.save(scene)) { setDirty(false); sceneMC.save(); savedAtLeastOnce = true; lastSaveFailed = false; return true; } else { lastSaveFailed = true; Dialogs.showErrorDialog(stage, "Unknown error encountered while saving resource"); } } catch (Exception e) { lastSaveFailed = true; Log.exception(e); Dialogs.showErrorDialog(stage, "Unknown error encountered while saving resource", e); } return false; }
From source file:com.kotcrab.vis.plugin.spriter.ui.SpriterImportDialog.java
License:Apache License
private void importAnimation() { SteppedAsyncTask importTask = new SteppedAsyncTask("SpriterImporter") { @Override/*from ww w.j a v a 2 s .co m*/ public void doInBackground() throws IOException { FileHandle[] files = animFolder.list(); setTotalSteps(files.length * 2); float scaleFactor = Float.valueOf(scaleField.getText()); visAnimFolder.mkdirs(); visAnimFolder.child("update").mkdirs(); FileHandle target = visAnimFolder.child("original"); target.mkdirs(); for (FileHandle file : files) { setMessage("Copying " + file.name()); file.copyTo(target); nextStep(); } for (FileHandle file : files) { if (file.extension().equals("png") == false) continue; setMessage("Converting " + file.name()); BufferedImage image = ImageIO.read(file.file()); BufferedImage scaledImage = Scalr.resize(image, MathUtils.round(image.getWidth() * scaleFactor), MathUtils.round(image.getHeight() * scaleFactor)); ImageIO.write(scaledImage, "png", file.file()); nextStep(); } setMessage("Saving data"); Json json = SpriterDataIOModule.getNewJson(); SpriterAssetData assetData = new SpriterAssetData(scaleFactor); json.toJson(assetData, visAnimFolder.child("data.json")); } }; Async.startTask(getStage(), "Importing animation", importTask); }
From source file:com.mbrlabs.mundus.assets.EditorAssetManager.java
License:Apache License
private FileHandle copyToAssetFolder(FileHandle file) { FileHandle copy = new FileHandle(FilenameUtils.concat(rootFolder.path(), file.name())); file.copyTo(copy); return copy;//from www .j av a2 s. c o m }
From source file:com.mbrlabs.mundus.assets.ModelImporter.java
License:Apache License
public ImportedModel importToTempFolder(FileHandle modelFile) { if (modelFile == null || !modelFile.exists()) { return null; }/*from w w w . ja va 2 s .c o m*/ ImportedModel imported = new ImportedModel(); FileHandle tempModelCache = registry.createTempFolder(); // copy model file modelFile.copyTo(tempModelCache); FileHandle rawModelFile = Gdx.files.absolute(FilenameUtils.concat(tempModelCache.path(), modelFile.name())); if (!rawModelFile.exists()) { return null; } // convert copied importer boolean convert = FileFormatUtils.isFBX(rawModelFile) || FileFormatUtils.isCollada(rawModelFile) || FileFormatUtils.isWavefont(rawModelFile); if (convert) { fbxConv.clear(); imported.convResult = fbxConv.input(rawModelFile.path()).output(tempModelCache.file().getAbsolutePath()) .flipTexture(true).execute(); if (imported.convResult.isSuccess()) { imported.g3dbFile = Gdx.files.absolute(imported.convResult.getOutputFile()); } } else if (FileFormatUtils.isG3DB(rawModelFile)) { imported.g3dbFile = rawModelFile; } // check if converted file exists if (imported.g3dbFile == null || !imported.g3dbFile.exists()) { return null; } return imported; }
From source file:com.mbrlabs.mundus.core.AssetManager.java
License:Apache License
/** * * @param textureFile/* w ww.j av a 2s.co m*/ * @param mipMap * @return */ public MTexture importTexture(FileHandle textureFile, boolean mipMap) { long id = projectManager.current().obtainID(); String relativeImportPath = ProjectManager.PROJECT_TEXTURE_DIR + textureFile.name(); String absoluteImportPath = FilenameUtils.concat(projectManager.current().path, relativeImportPath); FileHandle absoluteImportFile = Gdx.files.absolute(absoluteImportPath); textureFile.copyTo(absoluteImportFile); MTexture tex = new MTexture(); tex.setId(id); tex.setPath(relativeImportPath); if (mipMap) { tex.texture = TextureUtils.loadMipmapTexture(absoluteImportFile, true); } else { tex.texture = new Texture(absoluteImportFile); } projectManager.current().textures.add(tex); // save whole project projectManager.saveCurrentProject(); return tex; }
From source file:com.mbrlabs.mundus.core.ImportManager.java
License:Apache License
public ImportedModel importToTempFolder(FileHandle modelFile, FileHandle textureFile) { if (modelFile == null || !modelFile.exists()) { return null; }//from w ww . ja v a 2 s. c o m if (textureFile == null || !textureFile.exists()) { return null; } ImportedModel imported = new ImportedModel(); FileHandle tempModelCache = registry.createTempFolder(); // copy texture file to temp folder textureFile.copyTo(tempModelCache); imported.textureFile = Gdx.files.absolute(FilenameUtils.concat(tempModelCache.path(), textureFile.name())); // check if copied texture file exists if (!imported.textureFile.exists()) { return null; } // copy model file modelFile.copyTo(tempModelCache); FileHandle rawModelFile = Gdx.files.absolute(FilenameUtils.concat(tempModelCache.path(), modelFile.name())); if (!rawModelFile.exists()) { return null; } // convert copied importer boolean convert = FileFormatUtils.isFBX(rawModelFile) || FileFormatUtils.isCollada(rawModelFile) || FileFormatUtils.isWavefont(rawModelFile); if (convert) { fbxConv.clear(); imported.convResult = fbxConv.input(rawModelFile.path()).output(tempModelCache.file().getAbsolutePath()) .flipTexture(true).execute(); if (imported.convResult.isSuccess()) { imported.g3dbFile = Gdx.files.absolute(imported.convResult.getOutputFile()); } } else if (FileFormatUtils.isG3DB(rawModelFile)) { imported.g3dbFile = rawModelFile; } // check if converted file exists if (imported.g3dbFile == null || !imported.g3dbFile.exists()) { return null; } return imported; }
From source file:com.ray3k.skincomposer.data.JsonData.java
License:Open Source License
public void readFile(FileHandle fileHandle) throws Exception { main.getProjectData().setChangesSaved(false); //read drawables from texture atlas file FileHandle atlasHandle = fileHandle.sibling(fileHandle.nameWithoutExtension() + ".atlas"); if (atlasHandle.exists()) { main.getProjectData().getAtlasData().readAtlas(atlasHandle); }/* w ww . j a va2 s. c o m*/ //folder for critical files to be copied to FileHandle saveFile = main.getProjectData().getSaveFile(); FileHandle targetDirectory; if (saveFile != null) { targetDirectory = saveFile.sibling(saveFile.nameWithoutExtension() + "_data"); } else { targetDirectory = Gdx.files.local("temp/" + main.getProjectData().getId() + "_data"); } //read json file and create styles JsonReader reader = new JsonReader(); JsonValue val = reader.parse(fileHandle); for (JsonValue child : val.iterator()) { //fonts if (child.name().equals(BitmapFont.class.getName())) { for (JsonValue font : child.iterator()) { FileHandle fontFile = fileHandle.sibling(font.getString("file")); FileHandle fontCopy = targetDirectory.child(font.getString("file")); if (!fontCopy.parent().equals(fontFile.parent())) { fontFile.copyTo(fontCopy); } FontData fontData = new FontData(font.name(), fontCopy); //delete fonts with the same name for (FontData originalData : new Array<>(fonts)) { if (originalData.getName().equals(fontData.getName())) { fonts.removeValue(originalData, true); } } fonts.add(fontData); BitmapFont.BitmapFontData bitmapFontData = new BitmapFont.BitmapFontData(fontCopy, false); for (String path : bitmapFontData.imagePaths) { FileHandle file = new FileHandle(path); main.getProjectData().getAtlasData() .getDrawable(file.nameWithoutExtension()).visible = false; } } } //colors else if (child.name().equals(Color.class.getName())) { for (JsonValue color : child.iterator()) { ColorData colorData = new ColorData(color.name, new Color(color.getFloat("r", 0.0f), color.getFloat("g", 0.0f), color.getFloat("b", 0.0f), color.getFloat("a", 0.0f))); //delete colors with the same name for (ColorData originalData : new Array<>(colors)) { if (originalData.getName().equals(colorData.getName())) { colors.removeValue(originalData, true); } } colors.add(colorData); } } //tinted drawables else if (child.name().equals(TintedDrawable.class.getName())) { for (JsonValue tintedDrawable : child.iterator()) { DrawableData drawableData = new DrawableData(main.getProjectData().getAtlasData() .getDrawable(tintedDrawable.getString("name")).file); drawableData.name = tintedDrawable.name; if (!tintedDrawable.get("color").isString()) { drawableData.tint = new Color(tintedDrawable.get("color").getFloat("r", 0.0f), tintedDrawable.get("color").getFloat("g", 0.0f), tintedDrawable.get("color").getFloat("b", 0.0f), tintedDrawable.get("color").getFloat("a", 0.0f)); } else { drawableData.tintName = tintedDrawable.getString("color"); } //todo:test overwriting a base drawable that is depended on by another tint //delete drawables with the same name for (DrawableData originalData : new Array<>( main.getProjectData().getAtlasData().getDrawables())) { if (originalData.name.equals(drawableData.name)) { main.getProjectData().getAtlasData().getDrawables().removeValue(originalData, true); } } main.getProjectData().getAtlasData().getDrawables().add(drawableData); } } //styles else { int classIndex = 0; Class matchClass = ClassReflection.forName(child.name); for (Class clazz : Main.STYLE_CLASSES) { if (clazz.equals(matchClass)) { break; } else { classIndex++; } } Class clazz = Main.BASIC_CLASSES[classIndex]; for (JsonValue style : child.iterator()) { StyleData data = newStyle(clazz, style.name); for (JsonValue property : style.iterator()) { StyleProperty styleProperty = data.properties.get(property.name); if (styleProperty.type.equals(Float.TYPE)) { styleProperty.value = (double) property.asFloat(); } else if (styleProperty.type.equals(Color.class)) { if (property.isString()) { styleProperty.value = property.asString(); } else { Gdx.app.error(getClass().getName(), "Can't import JSON files that do not use predefined colors."); } } else { if (property.isString()) { styleProperty.value = property.asString(); } else { Gdx.app.error(getClass().getName(), "Can't import JSON files that do not use String names for field values."); } } } } } } }
From source file:com.strattonbrazil.minimaze.PythonUtil.java
static PythonInterpreter getPythonInterpreter() { if (_interp == null) { _interp = new PythonInterpreter(); // TODO: copy all files in python instead of hard-coding String[] files = { "maze.py", "minigame.py" }; FileHandle tmpDir = FileHandle.tempDirectory("py_stuff"); for (String fileName : files) { FileHandle assetPyHandle = Gdx.files.internal("python/" + fileName); assetPyHandle.copyTo(tmpDir); }// ww w .j a va 2 s.c om _interp.exec("import sys"); _interp.exec("sys.path.append('" + tmpDir.path() + "')"); } return _interp; }