Java Code Examples for com.badlogic.gdx.files.FileHandle#child()
The following examples show how to use
com.badlogic.gdx.files.FileHandle#child() .
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: SeparatedDataFileResolver.java From gdx-gltf with Apache License 2.0 | 6 votes |
private ObjectMap<Integer, ByteBuffer> loadBuffers(FileHandle path) { if(glModel.buffers != null){ for(int i=0 ; i<glModel.buffers.size ; i++){ GLTFBuffer glBuffer = glModel.buffers.get(i); ByteBuffer buffer = ByteBuffer.allocate(glBuffer.byteLength); buffer.order(ByteOrder.LITTLE_ENDIAN); if(glBuffer.uri.startsWith("data:")){ // data:application/octet-stream;base64, String [] headerBody = glBuffer.uri.split(",", 2); String header = headerBody[0]; // System.out.println(header); String body = headerBody[1]; byte [] data = Base64Coder.decode(body); buffer.put(data); }else{ FileHandle file = path.child(glBuffer.uri); buffer.put(file.readBytes()); } bufferMap.put(i, buffer); } } return bufferMap; }
Example 2
Source File: LocalCloudSave.java From dice-heroes with GNU General Public License v3.0 | 6 votes |
@Override public void sync(UserData userData, IConflictResolver resolver) { FileHandle dir = Gdx.files.external(DIR); dir.mkdirs(); final FileHandle saveFile = dir.child(SAVE_FILE_NAME); final FileHandle conflicted = dir.child(CONFLICT_FILE_NAME); if (saveFile.exists()) { DiceHeroes app = (DiceHeroes) Gdx.app.getApplicationListener(); if (app.firstSession) { if (!conflicted.exists()) conflicted.write(saveFile.read(), false); } } toFile(userData, saveFile); if (conflicted.exists()) { final Map local = fromFile(saveFile); final Map server = fromFile(conflicted); resolver.resolveConflict(server, new IConflictResolverCallback() { @Override public void onResolved(boolean useLocal) { conflicted.delete(); toFile(useLocal ? local : server, saveFile); } }); } }
Example 3
Source File: AndroidModLoader.java From Cubes with MIT License | 6 votes |
private FileHandle convertToDex(FileHandle fileHandle) throws Exception { String inputHash = hashFile(fileHandle); FileHandle cacheDir = new FileHandle(androidCompatibility.androidLauncher.getCacheDir()); FileHandle dexDir = cacheDir.child("converted_mod_dex"); dexDir.mkdirs(); FileHandle dexFile = dexDir.child(inputHash + ".dex"); if (!dexFile.exists()) { Log.warning("Trying to convert jar to dex: " + fileHandle.file().getAbsolutePath()); com.android.dx.command.dexer.Main.Arguments arguments = new com.android.dx.command.dexer.Main.Arguments(); arguments.parse(new String[]{"--output=" + dexFile.file().getAbsolutePath(), fileHandle.file().getAbsolutePath()}); int result = com.android.dx.command.dexer.Main.run(arguments); if (result != 0) throw new CubesException("Failed to convert jar to dex [" + result + "]: " + fileHandle.file().getAbsolutePath()); Log.warning("Converted jar to dex: " + fileHandle.file().getAbsolutePath()); } return dexFile; }
Example 4
Source File: Save.java From Cubes with MIT License | 6 votes |
public Cave readCave(AreaReference areaReference) { if (fileHandle == null) return null; FileHandle folder = folderCave(); FileHandle file = folder.child(areaReference.areaX + "_" + areaReference.areaZ); if (!file.exists()) return null; try { InputStream read = file.read(); DataInputStream dataInputStream = new DataInputStream(read); Cave cave = Cave.read(dataInputStream); read.close(); return cave; } catch (IOException e) { Log.warning("Failed to read cave", e); return null; } }
Example 5
Source File: ClientSaveManager.java From Cubes with MIT License | 6 votes |
public static Save createSave(String name, String generatorID, Gamemode gamemode, String seedString) { if (name != null) name = name.trim(); if (name == null || name.isEmpty()) name = "world-" + Integer.toHexString(MathUtils.random.nextInt()); FileHandle folder = getSavesFolder(); FileHandle handle = folder.child(name); handle.mkdirs(); Compatibility.get().nomedia(handle); Save s = new Save(name, handle); SaveOptions options = new SaveOptions(); options.setWorldSeed(seedString); options.worldType = generatorID; options.worldGamemode = gamemode; s.setSaveOptions(options); return s; }
Example 6
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 7
Source File: UAtlasTmxMapLoader.java From uracer-kotd with Apache License 2.0 | 5 votes |
public static FileHandle getRelativeFileHandle (FileHandle file, String path) { StringTokenizer tokenizer = new StringTokenizer(path, "\\/"); FileHandle result = file.parent(); while (tokenizer.hasMoreElements()) { String token = tokenizer.nextToken(); if (token.equals("..")) result = result.parent(); else { result = result.child(token); } } return result; }
Example 8
Source File: CCTextureAtlasLoader.java From cocos-ui-libgdx with Apache License 2.0 | 5 votes |
@Override public Array<AssetDescriptor> getDependencies(String fileName, FileHandle file, TextureAtlasLoader.TextureAtlasParameter parameter) { FileHandle imgDir = file.parent(); map = LyU.createDictionaryWithContentsOfFile(file); ObjectMap<String, Object> metadata = (ObjectMap<String, Object>) map.get("metadata"); String dependFile = (String) metadata.get("textureFileName"); Array<AssetDescriptor> res = new Array<AssetDescriptor>(); TextureLoader.TextureParameter params = new TextureLoader.TextureParameter(); params.magFilter = Texture.TextureFilter.Linear; params.minFilter = Texture.TextureFilter.Linear; params.format = Pixmap.Format.RGBA8888; texture = new Texture(imgDir.child(dependFile)); res.add(new AssetDescriptor(imgDir.child(dependFile), Texture.class, params)); return res; }
Example 9
Source File: DesktopCompatibility.java From Cubes with MIT License | 5 votes |
public FileHandle getBaseFolder() { if (baseFolder != null) return baseFolder; if (Adapter.isDedicatedServer()) return workingFolder; FileHandle homeDir = Gdx.files.absolute(System.getProperty("user.home")); switch (os) { case Windows: return Gdx.files.absolute(System.getenv("APPDATA")).child(Branding.NAME); case Mac: return homeDir.child("Library").child("Application Support").child(Branding.NAME); default: return homeDir.child("." + Branding.NAME); } }
Example 10
Source File: SaveAreaIO.java From Cubes with MIT License | 5 votes |
public static FileHandle file(Save save, int x, int z) { FileHandle folderArea = save.folderArea(); FileHandle xMostSignificant = folderArea.child(Integer.toString(x & 0xFFFF0000)); FileHandle xLeastSignificant = xMostSignificant.child(Integer.toString(x & 0xFFFF)); FileHandle zMostSignificant = xLeastSignificant.child(Integer.toString(z & 0xFFFF0000)); zMostSignificant.mkdirs(); Compatibility.get().nomedia(zMostSignificant); return zMostSignificant.child(Integer.toString(z & 0xFFFF)); }
Example 11
Source File: Save.java From Cubes with MIT License | 5 votes |
public void writePlayer(Player player) { if (readOnly) return; FileHandle folder = folderPlayer(); FileHandle file = folder.child(player.uuid.toString()); DataGroup data = player.write(); try { Data.output(data, file.file()); } catch (Exception e) { Log.warning("Failed to write player", e); } }
Example 12
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 13
Source File: Save.java From Cubes with MIT License | 5 votes |
public void writeCave(AreaReference areaReference, Cave cave) { if (readOnly) return; FileHandle folder = folderCave(); FileHandle file = folder.child(areaReference.areaX + "_" + areaReference.areaZ); try { OutputStream write = file.write(false); DataOutputStream dataOutputStream = new DataOutputStream(write); cave.write(dataOutputStream); write.close(); } catch (IOException e) { Log.warning("Failed to write cave", e); } }
Example 14
Source File: GLTFDemo.java From gdx-gltf with Apache License 2.0 | 4 votes |
private void load(ModelEntry entry, String variant) { clearScene(); if(rootModel != null){ rootModel.dispose(); rootModel = null; if(lastFileName != null){ if(USE_ASSET_MANAGER){ assetManager.unload(lastFileName); } lastFileName = null; } } if(variant.isEmpty()) return; final String fileName = entry.variants.get(variant); if(fileName == null) return; if(entry.url != null){ final Table waitUI = new Table(skin); waitUI.add("LOADING...").expand().center(); waitUI.setFillParent(true); stage.addActor(waitUI); HttpRequest httpRequest = new HttpRequest(HttpMethods.GET); httpRequest.setUrl(entry.url + variant + "/" + fileName); Gdx.net.sendHttpRequest(httpRequest, new SafeHttpResponseListener(){ @Override protected void handleData(byte[] bytes) { Gdx.app.log(TAG, "loading " + fileName); if(fileName.endsWith(".gltf")){ throw new GdxRuntimeException("remote gltf format not supported."); }else if(fileName.endsWith(".glb")){ rootModel = new GLBLoader().load(bytes); }else{ throw new GdxRuntimeException("unknown file extension for " + fileName); } load(); Gdx.app.log(TAG, "loaded " + fileName); } @Override protected void handleError(Throwable t) { Gdx.app.error(TAG, "request error", t); } @Override protected void handleEnd() { waitUI.remove(); } }); }else{ FileHandle baseFolder = rootFolder.child(entry.name).child(variant); FileHandle glFile = baseFolder.child(fileName); load(glFile); } }
Example 15
Source File: MenuBar.java From gdx-skineditor with Apache License 2.0 | 4 votes |
protected void showExportDialog() { final Preferences prefs = Gdx.app.getPreferences("skin_editor_project_" + game.screenMain.getcurrentProject()); final TextField textDirectory = new TextField(prefs.getString("export_to_directory"),game.skin); Dialog dlg = new Dialog("Export to Directory", game.skin) { @Override protected void result(Object object) { if ((Boolean) object == true) { if (textDirectory.getText().isEmpty() == true) { game.showNotice("Warning", "Directory field is empty!", game.screenMain.stage); return; } FileHandle targetDirectory = new FileHandle(textDirectory.getText()); if (targetDirectory.exists() == false) { game.showNotice("Warning", "Directory not found!", game.screenMain.stage); return; } // Copy uiskin.* and *.fnt FileHandle projectFolder = Gdx.files.local("projects").child(game.screenMain.getcurrentProject()); for(FileHandle file : projectFolder.list()) { if (file.name().startsWith("uiskin.") || (file.extension().equalsIgnoreCase("fnt"))) { Gdx.app.log("MenuBar","Copying file: " + file.name() + " ..."); FileHandle target = targetDirectory.child(file.name()); file.copyTo(target); } } game.showNotice("Operation Completed", "Project successfully exported!", game.screenMain.stage); } } }; dlg.pad(20); Table table = dlg.getContentTable(); table.padTop(20); table.add("Directory:"); table.add(textDirectory).width(320); TextButton buttonChoose = new TextButton("...", game.skin); buttonChoose.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { // Need to steal focus first with this hack (Thanks to Z-Man) Frame frame = new Frame(); frame.setUndecorated(true); frame.setOpacity(0); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.toFront(); frame.setVisible(false); frame.dispose(); JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int ret = chooser.showOpenDialog(null); if (ret == JFileChooser.APPROVE_OPTION) { File f = chooser.getSelectedFile(); textDirectory.setText(f.getAbsolutePath()); // Store to file prefs.putString("export_to_directory", f.getAbsolutePath()); prefs.flush(); } } }); table.add(buttonChoose); table.row(); table.padBottom(20); dlg.button("Export", true); dlg.button("Cancel", false); dlg.key(com.badlogic.gdx.Input.Keys.ENTER, true); dlg.key(com.badlogic.gdx.Input.Keys.ESCAPE, false); dlg.show(getStage()); }
Example 16
Source File: NinePatchEditorDialog.java From gdx-skineditor with Apache License 2.0 | 2 votes |
public void refreshPreview() { Gdx.app.log("NinePatchEditorDialog","refresh preview."); Pixmap pixmapImage = new Pixmap(Gdx.files.internal(textSourceImage.getText())); Pixmap pixmap = new Pixmap((int) (pixmapImage.getWidth()+2), (int) (pixmapImage.getHeight()+2), Pixmap.Format.RGBA8888); pixmap.drawPixmap(pixmapImage,1,1); pixmap.setColor(Color.BLACK); // Range left int h = pixmapImage.getHeight()+1; pixmap.drawLine(0, (int) (h * rangeLeft.rangeStart),0, (int) (h * rangeLeft.rangeStop)); // Range top int w = pixmapImage.getWidth()+1; pixmap.drawLine((int) (w * rangeTop.rangeStart), 0,(int) (w * rangeTop.rangeStop), 0); // Range right h = pixmapImage.getHeight()+1; pixmap.drawLine(pixmapImage.getWidth()+1, (int) (h * rangeRight.rangeStart),pixmapImage.getWidth()+1, (int) (h * rangeRight.rangeStop)); // Range bottom w = pixmapImage.getWidth()+1; pixmap.drawLine((int) (w * rangeBottom.rangeStart), pixmap.getHeight()-1,(int) (w * rangeBottom.rangeStop), pixmap.getHeight()-1); PixmapIO.writePNG(tmpFile, pixmap); pixmapImage.dispose(); pixmap.dispose(); FileHandle fh = new FileHandle(System.getProperty("java.io.tmpdir")).child("skin_ninepatch"); TexturePacker.Settings settings = new TexturePacker.Settings(); TexturePacker.process(settings, fh.path(), fh.path(), "pack"); TextureAtlas ta = new TextureAtlas(fh.child("pack.atlas")); NinePatch np = ta.createPatch("button"); NinePatchDrawable drawable = new NinePatchDrawable(np); reviewTablePreview(); buttonPreview1.getStyle().up = drawable; }