com.badlogic.gdx.files.FileHandle Java Examples
The following examples show how to use
com.badlogic.gdx.files.FileHandle.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DialogImageFont.java From skin-composer with MIT License | 6 votes |
private void loadSettings(FileHandle file) { var imagePath = ((TextField) findActor("imagepath")).getText(); var targetPath = ((TextField) findActor("targetpath")).getText(); json.setOutputType(JsonWriter.OutputType.json); settings = json.fromJson(ImageFontSettings.class, file.readString("utf-8")); refreshTable(); previewStyle.fontColor = settings.previewColor; previewStyle.background = ((NinePatchDrawable) previewStyle.background).tint(settings.previewBackgroundColor); previewStyle.focusedBackground = ((NinePatchDrawable) previewStyle.focusedBackground).tint(settings.previewBackgroundColor); if (targetPath != null && !targetPath.equals("")) { processSaveFile(targetPath); } if (imagePath != null && !imagePath.equals("")) { processSourceFile(Gdx.files.absolute(imagePath), false); } }
Example #2
Source File: UI.java From bladecoder-adventure-engine with Apache License 2.0 | 6 votes |
private void loadAssets() { FileHandle skinFile = EngineAssetManager.getInstance().getAsset(SKIN_FILENAME); TextureAtlas atlas = new TextureAtlas(EngineAssetManager.getInstance() .getResAsset(SKIN_FILENAME.substring(0, SKIN_FILENAME.lastIndexOf('.')) + ".atlas")); skin = new BladeSkin(atlas); ((BladeSkin) skin).addStyleTag(VerbUI.VerbUIStyle.class); ((BladeSkin) skin).addStyleTag(TextManagerUI.TextManagerUIStyle.class); ((BladeSkin) skin).addStyleTag(DialogUI.DialogUIStyle.class); ((BladeSkin) skin).addStyleTag(InventoryUI.InventoryUIStyle.class); ((BladeSkin) skin).addStyleTag(CreditsScreen.CreditScreenStyle.class); ((BladeSkin) skin).addStyleTag(LoadSaveScreen.LoadSaveScreenStyle.class); ((BladeSkin) skin).addStyleTag(MenuScreen.MenuScreenStyle.class); skin.load(skinFile); if (!Config.getInstance().getProperty(Config.CHARACTER_ICON_ATLAS, "").equals("")) { EngineAssetManager.getInstance().loadAtlas(Config.getInstance().getProperty(Config.CHARACTER_ICON_ATLAS, null)); EngineAssetManager.getInstance().finishLoading(); } }
Example #3
Source File: Terrain.java From gdx-proto with Apache License 2.0 | 6 votes |
/** * Return a heightmap chunk * TODO NOT IMPLEMENTED! * @param heightmap * @param tex * @param width * @param height * @return */ public static TerrainChunk CreateHeightMapChunk (FileHandle heightmap, Texture tex, int width, int height) { HeightMap hp = new HeightMap(heightmap, 10, 10, false, 3); HeightMapModel md = new HeightMapModel(hp); //Model model = md.ground; md.ground.materials.get(0).set(TextureAttribute.createDiffuse(tex)); //btCollisionObject obj = new btCollisionObject(); //btCollisionShape shape = new btBvhTriangleMeshShape(model.meshParts); //obj.setCollisionShape(shape); ////Physics.applyStaticGeometryCollisionFlags(obj); //Physics.inst.addStaticGeometryToWorld(obj); TerrainChunk ch = new TerrainChunk(); ch.setModelInstance(md.ground); return ch; }
Example #4
Source File: Dialog9Patch.java From skin-composer with MIT License | 6 votes |
private void showLoadPatchesDialog() { Runnable runnable = () -> { String defaultPath = main.getProjectData().getLastDrawablePath(); String[] filterPatterns = null; if (!Utils.isMac()) { filterPatterns = new String[]{"*.9.png;"}; } File file = main.getDesktopWorker().openDialog("Load Patches from File...", defaultPath, filterPatterns, "Nine Patch files"); if (file != null) { Gdx.app.postRunnable(() -> { var fileHandle = new FileHandle(file); loadPatches(fileHandle); }); } }; main.getDialogFactory().showDialogLoading(runnable); }
Example #5
Source File: Screenshot.java From Cubes with MIT License | 6 votes |
private static void writeScreenshot(final Pixmap pixmap) { FileHandle dir = Compatibility.get().getBaseFolder().child("screenshots"); dir.mkdirs(); final FileHandle f = dir.child(System.currentTimeMillis() + ".png"); Log.info("Writing screenshot '" + f.file().getAbsolutePath() + "'"); Executor.executeNotSided(new Runnable() { @Override public void run() { long start = System.currentTimeMillis(); try { PixmapIO.PNG writer = new PixmapIO.PNG((int) (pixmap.getWidth() * pixmap.getHeight() * 1.5f)); try { writer.setFlipY(true); writer.write(f, pixmap); } finally { writer.dispose(); } } catch (IOException ex) { throw new CubesException("Error writing PNG: " + f, ex); } finally { pixmap.dispose(); } Log.debug("Finished writing screenshot '" + f.file().getAbsolutePath() + "' (took " + (System.currentTimeMillis() - start) + "ms)"); } }); }
Example #6
Source File: GlobalActions.java From gdx-texture-packer-gui with Apache License 2.0 | 6 votes |
@LmlAction("openProject") public void openProject() { final ProjectModel project = getProject(); FileHandle dir = fileChooserHistory.getLastDir(FileChooserHistory.Type.PROJECT); if (FileUtils.fileExists(project.getProjectFile())) { dir = project.getProjectFile().parent(); } final FileChooser fileChooser = new FileChooser(dir, FileChooser.Mode.OPEN); fileChooser.setIconProvider(new AppIconProvider(fileChooser)); fileChooser.setSelectionMode(FileChooser.SelectionMode.FILES); fileChooser.setFileTypeFilter(new FileUtils.FileTypeFilterBuilder(true) .rule(getString("projectFileDescription", AppConstants.PROJECT_FILE_EXT), AppConstants.PROJECT_FILE_EXT).get()); fileChooser.setListener(new FileChooserAdapter() { @Override public void selected (Array<FileHandle> file) { final FileHandle chosenFile = file.first(); commonDialogs.checkUnsavedChanges(new Runnable() { @Override public void run() { loadProject(chosenFile); } }); } }); getStage().addActor(fileChooser.fadeIn()); }
Example #7
Source File: ReplayUtils.java From uracer-kotd with Apache License 2.0 | 6 votes |
public static boolean pruneReplay (ReplayInfo info) { if (info != null && ReplayUtils.areValidIds(info)) { String rid = info.getId(); if (rid.length() > 0) { String path = getFullPath(info); if (path.length() > 0) { FileHandle hf = Gdx.files.external(path); if (hf.exists()) { hf.delete(); Gdx.app.log("ReplayUtils", "Pruned #" + rid); return true; } else { Gdx.app.error("ReplayUtils", "Couldn't prune #" + rid); } } } } return false; }
Example #8
Source File: ProjectController.java From talos with Apache License 2.0 | 6 votes |
public void reportProjectFileInterraction(FileHandle handle) { Preferences prefs = TalosMain.Instance().Prefs(); String data = prefs.getString("recents"); Array<RecentsEntry> list = new Array<>(); //read Json json = new Json(); try { if (data != null && !data.isEmpty()) { list = json.fromJson(list.getClass(), data); } } catch( Exception e) { } RecentsEntry newEntry = new RecentsEntry(handle.path(), TimeUtils.millis()); list.removeValue(newEntry, false); list.add(newEntry); //sort list.sort(recentsEntryComparator); //write String result = json.toJson(list); prefs.putString("recents", result); prefs.flush(); updateRecentsList(); }
Example #9
Source File: FileLoading.java From ud406 with MIT License | 6 votes |
@Override public void create() { batch = new SpriteBatch(); img = new Texture("badlogic.jpg"); String encryptedPunchline = encrypt("Very Carefully"); Gdx.app.log(TAG, encryptedPunchline); Gdx.app.log(TAG, "How does GigaGal tie her shoelaces when her arms are cannons?"); // TODO: Go find the text file in the android/assets directory // TODO: Get a FileHandle using Gdx.files.internal() FileHandle file = Gdx.files.internal("punchline"); // TODO: Read the file using FileHandle.readString() String encrypted = file.readString(); // TODO: Decrypt the punchline String punchline = decrypt(encrypted); // TODO: Log the rest of the joke Gdx.app.log(TAG, punchline); }
Example #10
Source File: MG3dModelLoader.java From Mundus with Apache License 2.0 | 6 votes |
public ModelData parseModel(FileHandle handle) { JsonValue json = reader.parse(handle); ModelData model = new ModelData(); JsonValue version = json.require("version"); model.version[0] = version.getShort(0); model.version[1] = version.getShort(1); if (model.version[0] != VERSION_HI || model.version[1] != VERSION_LO) throw new GdxRuntimeException("Model version not supported"); model.id = json.getString("id", ""); parseMeshes(model, json); parseMaterials(model, json, handle.parent().path()); parseNodes(model, json); parseAnimations(model, json); return model; }
Example #11
Source File: TextureUnpackerDialogController.java From gdx-texture-packer-gui with Apache License 2.0 | 6 votes |
@LmlAction("pickOutputDir") void pickOutputDir() { FileHandle dir = FileUtils.obtainIfExists(edtOutputDir.getText()); if (dir == null && FileUtils.fileExists(edtAtlasPath.getText())) { dir = FileUtils.obtainIfExists(edtAtlasPath.getText()).parent(); } FileChooser fileChooser = new FileChooser(dir, FileChooser.Mode.OPEN); fileChooser.setIconProvider(new AppIconProvider(fileChooser)); fileChooser.setSelectionMode(FileChooser.SelectionMode.DIRECTORIES); fileChooser.setListener(new FileChooserAdapter() { @Override public void selected (Array<FileHandle> file) { FileHandle chosenFile = file.first(); edtOutputDir.setText(chosenFile.path()); } }); stage.addActor(fileChooser.fadeIn()); }
Example #12
Source File: BatchConvertDialog.java From talos with Apache License 2.0 | 6 votes |
private void startConversion() { String inputPath = inputPathField.getText(); outputPath = outputPathField.getText(); String extension = inputFilterField.getText(); fileList.clear(); FileHandle input = Gdx.files.absolute(inputPath); if(input.isDirectory() && input.exists()) { traverseFolder(input, fileList, extension, 0); } isConverting = true; logArea.clearItems(); }
Example #13
Source File: FileChooser.java From gdx-soundboard with MIT License | 6 votes |
/** * Create file picking dialog. * * @param title * @param skin * @param path * @return */ public static FileChooser createPickDialog(String title, final Skin skin, final FileHandle path) { final FileChooser pick = new FileChooser(title, skin, path) { @Override protected void result(Object object) { if (resultListener == null) { return; } final boolean success = (Boolean) object; resultListener.result(success, getResult()); } }.setOkButtonText("Select"); return pick; }
Example #14
Source File: BitmapFontLoader.java From riiablo with Apache License 2.0 | 5 votes |
@Override public FontTBL.BitmapFont loadSync(AssetManager assets, String fileName, FileHandle file, Params params) { FontTBL.BitmapFont font = new FontTBL.BitmapFont(data); name = null; dc6 = null; data = null; return font; }
Example #15
Source File: ProjectData.java From skin-composer with MIT License | 5 votes |
public void save(FileHandle file) { moveImportedFiles(saveFile, file); if (main.getProjectData().areResourcesRelative()) { makeResourcesRelative(file); } saveFile = file; putRecentFile(file.path()); file.writeString(json.prettyPrint(this), false, "UTF8"); setChangesSaved(true); }
Example #16
Source File: Compatibility.java From Cubes with MIT License | 5 votes |
public void makeBaseFolder() { FileHandle baseFolder = getBaseFolder(); baseFolder.mkdirs(); if (!baseFolder.isDirectory()) { FileHandle parent = baseFolder.parent(); if (!parent.isDirectory()) Log.error("Parent directory '" + parent.path() + "' doesn't exist!"); throw new CubesException("Failed to make Cubes folder! '" + baseFolder.path() + "'"); } }
Example #17
Source File: Skybox.java From Mundus with Apache License 2.0 | 5 votes |
public Skybox(FileHandle positiveX, FileHandle negativeX, FileHandle positiveY, FileHandle negativeY, FileHandle positiveZ, FileHandle negativeZ) { set(positiveX, negativeX, positiveY, negativeY, positiveZ, negativeZ); boxModel = createModel(); boxInstance = new ModelInstance(boxModel); }
Example #18
Source File: BatchConvertDialog.java From talos with Apache License 2.0 | 5 votes |
private void convertOne(FileHandle fileHandle) { String subPath; if (inputPathField.getText().length() == fileHandle.parent().path().length()) { subPath = File.separator; } else { subPath = fileHandle.parent().path().substring(inputPathField.getText().length() + 1) + File.separator; } String projectPath = outputPath + File.separator + "projects" + File.separator + subPath + fileHandle.nameWithoutExtension() + ".tls"; String runtimePath = outputPath + File.separator + "runtime" + File.separator + subPath + fileHandle.nameWithoutExtension() + ".p"; FileHandle projectDestination = Gdx.files.absolute(projectPath); FileHandle exportDestination = Gdx.files.absolute(runtimePath); String result = "ok"; try { TalosMain.Instance().TalosProject().importFromLegacyFormat(fileHandle); // now that it's done save TLS file TalosMain.Instance().ProjectController().saveProject(projectDestination); TalosMain.Instance().TalosProject().exportProject(exportDestination); } catch (Exception e) { result = "nok"; } String text = "converting: " + fileHandle.name() + " " + result + "\n"; logItems.add(new Label(text, getSkin())); logArea.setItems(logItems); Label lbl = logArea.getItems().get(logArea.getItems().size-1); logArea.setSelected(lbl); scrollPane.layout(); scrollPane.scrollTo(0, 0, 0, 0); }
Example #19
Source File: FileHistoryManager.java From vis-ui with Apache License 2.0 | 5 votes |
public void historyForward () { FileHandle dir = historyForward.pop(); history.add(callback.getCurrentDirectory()); if (setDirectoryFromHistory(dir) == false) history.pop(); if (!hasHistoryForward()) forwardButton.setDisabled(true); backButton.setDisabled(false); }
Example #20
Source File: WorldIO.java From TerraLegion with MIT License | 5 votes |
public static void savePlayer(Player player) { // create the JSONObject for the player information JSONObject playerInfo = new JSONObject(); // create a JSONObject for the x and y position of the player JSONObject playerPosition = new JSONObject(); playerPosition.put("x", player.getX()); playerPosition.put("y", player.getY()); // add the position to the JSONObject playerInfo playerInfo.put("playerPosition", playerPosition); // create a JSONArray for the inventory items of the player JSONObject playerInventory = JSONConverter.getJSONFromInventory(player.getInventory()); // add the playerInventory "list" to the JSONObject playerInfo playerInfo.put("playerInventory", playerInventory); // write to file try { FileHandle handle = Gdx.files.external("player.save"); if (!handle.exists()) { handle.file().createNewFile(); } handle.writeString(playerInfo.toJSONString(), false); } catch(IOException ex) { ex.printStackTrace(); } }
Example #21
Source File: GLTFExporter.java From gdx-gltf with Apache License 2.0 | 5 votes |
/** convenient method to export a single scene */ public void export(SceneModel scene, FileHandle file) { GLTFScene glScene = beginSingleScene(file); exportScene(glScene, scene); end(file); }
Example #22
Source File: Save.java From Cubes with MIT License | 5 votes |
public Player readPlayer(UUID uuid, ClientIdentifier clientIdentifier) { if (fileHandle == null) return null; FileHandle folder = folderPlayer(); FileHandle file = folder.child(uuid.toString()); if (!file.exists()) return null; try { DataGroup data = (DataGroup) Data.input(file.file()); Player player = new Player(data.getString("username"), uuid, clientIdentifier); player.read(data); return player; } catch (Exception e) { Log.warning("Failed to read player", e); return null; } }
Example #23
Source File: PlistReader.java From cocos-ui-libgdx with Apache License 2.0 | 5 votes |
public ObjectMap<String, Object> dictionaryWithContentsOfFile(FileHandle handle) { try { this.parse(handle); } catch (IOException e) { e.printStackTrace(); } return m_pCurDict; }
Example #24
Source File: BinGenerationTool.java From riiablo with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public void generate(FileHandle txt, FileHandle bin, Class<Excel> excelClass) throws Exception { Gdx.app.log(TAG, bin.toString()); Excel<Excel.Entry> excel = Excel.load(excelClass, txt, Excel.EXPANSION); OutputStream out = null; try { out = bin.write(false, 8192); LittleEndianDataOutputStream dos = new LittleEndianDataOutputStream(out); excel.writeBin(dos); } catch (Throwable t) { Gdx.app.error(TAG, t.getMessage(), t); } finally { IOUtils.closeQuietly(out); } if (VALIDATE_BIN) { Class<Excel.Entry> entryClass = getEntryClass(excelClass); String binClassName = excelClass.getName() + "Bin"; Class binClass = Class.forName(binClassName); Method equals = binClass.getMethod("equals", entryClass, entryClass); Excel binExcel = Excel.load(excelClass, txt, bin, null); if (binExcel.size() != excel.size()) Gdx.app.error(TAG, "excel sizes do not match!"); for (Excel.Entry e1 : excel) { Excel.Entry eq = getEqual(equals, e1, binExcel); if (eq == null) { Gdx.app.log(TAG, "ERROR at index " + e1); //break; } else { //Gdx.app.log(TAG, e1 + "=" + eq); } } } }
Example #25
Source File: VfxGLUtils.java From gdx-vfx with Apache License 2.0 | 5 votes |
public static ShaderProgram compileShader(FileHandle vertexFile, FileHandle fragmentFile, String defines) { if (fragmentFile == null) { throw new IllegalArgumentException("Vertex shader file cannot be null."); } if (vertexFile == null) { throw new IllegalArgumentException("Fragment shader file cannot be null."); } if (defines == null) { throw new IllegalArgumentException("Defines cannot be null."); } StringBuilder sb = new StringBuilder(); sb.append("Compiling \"").append(vertexFile.name()).append('/').append(fragmentFile.name()).append('\"'); if (defines.length() > 0) { sb.append(" w/ (").append(defines.replace("\n", ", ")).append(")"); } sb.append("..."); Gdx.app.log(TAG, sb.toString()); String prependVert = prependVertexCode + defines; String prependFrag = prependFragmentCode + defines; String srcVert = vertexFile.readString(); String srcFrag = fragmentFile.readString(); ShaderProgram shader = new ShaderProgram(prependVert + "\n" + srcVert, prependFrag + "\n" + srcFrag); if (!shader.isCompiled()) { throw new GdxRuntimeException("Shader compile error: " + vertexFile.name() + "/" + fragmentFile.name() + "\n" + shader.getLog()); } return shader; }
Example #26
Source File: UAtlasTmxMapLoader.java From uracer-kotd with Apache License 2.0 | 5 votes |
/** May return null. */ protected FileHandle loadAtlas (Element root, FileHandle tmxFile) throws IOException { Element e = root.getChildByName("properties"); if (e != null) { for (Element property : e.getChildrenByName("property")) { String name = property.getAttribute("name", null); String value = property.getAttribute("value", null); if (name.equals("atlas")) { if (value == null) { value = property.getText(); } if (value == null || value.length() == 0) { // keep trying until there are no more atlas properties continue; } return getRelativeFileHandle(tmxFile, value); } } } else { FileHandle atlasFile = tmxFile.sibling(tmxFile.nameWithoutExtension() + ".atlas"); return atlasFile.exists() ? atlasFile : null; } return null; }
Example #27
Source File: PdAudioBakery.java From gdx-pd with Apache License 2.0 | 5 votes |
/** * Add a new baking task. * @param patchFile patch file to bake. * @param array destination array to write to. * @param sampleRate sample rate to use. * @param time destination duration. */ public void addTask(FileHandle patchFile, String array, int sampleRate, float time){ if(bakingThread != null){ throw new GdxRuntimeException("addTask should only be called before baking process."); } Baking baking = new Baking(); baking.patchFile = patchFile; baking.array = array; baking.sampleRate = sampleRate; baking.time = time; pendingBakings.add(baking); }
Example #28
Source File: DS1Loader.java From riiablo with Apache License 2.0 | 5 votes |
@Override public DS1 loadSync(AssetManager assets, String fileName, FileHandle file, DS1LoaderParameters params) { DS1 ds1 = this.ds1; if (ds1 == null) { ds1 = DS1.loadFromFile(file); } else { this.ds1 = null; } return ds1; }
Example #29
Source File: GameLevels.java From uracer-kotd with Apache License 2.0 | 5 votes |
public static final boolean init () { // setup map loader mapLoaderParams.forceTextureFilters = true; mapLoaderParams.textureMinFilter = TextureFilter.Linear; mapLoaderParams.textureMagFilter = TextureFilter.Linear; mapLoaderParams.yUp = false; // check invalid FileHandle dirLevels = Gdx.files.internal(Storage.Levels); if (dirLevels == null || !dirLevels.isDirectory()) { throw new URacerRuntimeException("Path not found (" + Storage.Levels + "), cannot check for available game levels."); } // check for any level FileHandle[] tracks = dirLevels.list("tmx"); if (tracks.length == 0) { throw new URacerRuntimeException("Cannot find game levels."); } // build internal maps for (int i = 0; i < tracks.length; i++) { GameLevelDescriptor desc = computeDescriptor(tracks[i].name()); levels.add(desc); // build lookup table levelIdToDescriptor.put(desc.getId(), desc); Gdx.app.log("GameLevels", "Found level \"" + desc.getName() + "\" (" + desc.getId() + ")"); } // sort tracks Collections.sort(levels); return true; }
Example #30
Source File: Mini2DxOpenALAudio.java From mini2Dx with Apache License 2.0 | 5 votes |
public Mini2DxOpenALSound newSound(FileHandle file) { if (file == null) throw new IllegalArgumentException("file cannot be null."); Class<? extends Mini2DxOpenALSound> soundClass = extensionToSoundClass.get(file.extension().toLowerCase()); if (soundClass == null) throw new GdxRuntimeException("Unknown file extension for sound: " + file); try { return soundClass.getConstructor(new Class[] { Mini2DxOpenALAudio.class, FileHandle.class }).newInstance(this, file); } catch (Exception ex) { throw new GdxRuntimeException("Error creating sound " + soundClass.getName() + " for file: " + file, ex); } }