@Override public FreeTypeFontGenerator load (AssetManager assetManager, String fileName, FileHandle file, FreeTypeFontGeneratorParameters parameter) { FreeTypeFontGenerator generator = null; if (file.extension().equals("gen")) { generator = new FreeTypeFontGenerator(file.sibling(file.nameWithoutExtension())); } else { generator = new FreeTypeFontGenerator(file); } return generator; }
@Override public FreeTypeFontGenerator load (AssetManager assetManager, String fileName, FileHandle file, FreeTypeFontGeneratorParameters parameter) { FreeTypeFontGenerator generator = null; if (file.extension().equals("gen")) { generator = new FreeTypeFontGenerator(file.sibling(file.nameWithoutExtension())); } else { generator = new FreeTypeFontGenerator(file); } return generator; }
/** Creates a new generator from the given font file. Uses {@link FileHandle#length()} to determine the file size. If the file * length could not be determined (it was 0), an extra copy of the font bytes is performed. Throws a * {@link GdxRuntimeException} if loading did not succeed. */ public FreeTypeFontGenerator (FileHandle fontFile, int faceIndex) { name = fontFile.nameWithoutExtension(); library = FreeType.initFreeType(); face = library.newFace(fontFile, faceIndex); if (checkForBitmapFont()) return; setPixelSizes(0, 15); }
/** Creates a new generator from the given font file. Uses {@link FileHandle#length()} to determine the file size. If the file * length could not be determined (it was 0), an extra copy of the font bytes is performed. Throws a * {@link GdxRuntimeException} if loading did not succeed. */ public FreeTypeFontGenerator (FileHandle fontFile, int faceIndex) { name = fontFile.nameWithoutExtension(); library = FreeType.initFreeType(); face = library.newFace(fontFile, faceIndex); if (checkForBitmapFont()) return; setPixelSizes(0, 15); }
/** If the PSH file contains a line starting with {@link PolygonRegionParameters#texturePrefix params.texturePrefix}, an * {@link AssetDescriptor} for the file referenced on that line will be added to the returned Array. Otherwise a sibling of the * given file with the same name and the first found extension in {@link PolygonRegionParameters#textureExtensions * params.textureExtensions} will be used. If no suitable file is found, the returned Array will be empty. */ @Override public Array<AssetDescriptor> getDependencies (String fileName, FileHandle file, PolygonRegionParameters params) { if (params == null) params = defaultParameters; String image = null; try { BufferedReader reader = file.reader(params.readerBuffer); for (String line = reader.readLine(); line != null; line = reader.readLine()) if (line.startsWith(params.texturePrefix)) { image = line.substring(params.texturePrefix.length()); break; } reader.close(); } catch (IOException e) { throw new GdxRuntimeException("Error reading " + fileName, e); } if (image == null && params.textureExtensions != null) for (String extension : params.textureExtensions) { FileHandle sibling = file.sibling(file.nameWithoutExtension().concat("." + extension)); if (sibling.exists()) image = sibling.name(); } if (image != null) { Array<AssetDescriptor> deps = new Array<AssetDescriptor>(1); deps.add(new AssetDescriptor<Texture>(file.sibling(image), Texture.class)); return deps; } return null; }
/** If the PSH file contains a line starting with {@link PolygonRegionParameters#texturePrefix params.texturePrefix}, an * {@link AssetDescriptor} for the file referenced on that line will be added to the returned Array. Otherwise a sibling of the * given file with the same name and the first found extension in {@link PolygonRegionParameters#textureExtensions * params.textureExtensions} will be used. If no suitable file is found, the returned Array will be empty. */ @Override public Array<AssetDescriptor> getDependencies (String fileName, FileHandle file, PolygonRegionParameters params) { if (params == null) params = defaultParameters; String image = null; try { BufferedReader reader = file.reader(params.readerBuffer); for (String line = reader.readLine(); line != null; line = reader.readLine()) if (line.startsWith(params.texturePrefix)) { image = line.substring(params.texturePrefix.length()); break; } reader.close(); } catch (IOException e) { throw new GdxRuntimeException("Error reading " + fileName, e); } if (image == null && params.textureExtensions != null) for (String extension : params.textureExtensions) { FileHandle sibling = file.sibling(file.nameWithoutExtension().concat("." + extension)); if (sibling.exists()) image = sibling.name(); } if (image != null) { Array<AssetDescriptor> deps = new Array<AssetDescriptor>(1); deps.add(new AssetDescriptor<Texture>(file.sibling(image), Texture.class)); return deps; } return null; }
/** Creates a skin containing the resources in the specified skin JSON file. If a file in the same directory with a ".atlas" * extension exists, it is loaded as a {@link TextureAtlas} and the texture regions added to the skin. The atlas is * automatically disposed when the skin is disposed. */ public Skin (FileHandle skinFile) { FileHandle atlasFile = skinFile.sibling(skinFile.nameWithoutExtension() + ".atlas"); if (atlasFile.exists()) { atlas = new TextureAtlas(atlasFile); addRegions(atlas); } load(skinFile); }
/** Creates a skin containing the resources in the specified skin JSON file. If a file in the same directory with a ".atlas" * extension exists, it is loaded as a {@link TextureAtlas} and the texture regions added to the skin. The atlas is * automatically disposed when the skin is disposed. */ public Skin (FileHandle skinFile) { FileHandle atlasFile = skinFile.sibling(skinFile.nameWithoutExtension() + ".atlas"); if (atlasFile.exists()) { atlas = new TextureAtlas(atlasFile); addRegions(atlas); } load(skinFile); }
/** 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); } } } FileHandle atlasFile = tmxFile.sibling(tmxFile.nameWithoutExtension() + ".atlas"); return atlasFile.exists() ? atlasFile : null; }
/** 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); } } } FileHandle atlasFile = tmxFile.sibling(tmxFile.nameWithoutExtension() + ".atlas"); return atlasFile.exists() ? atlasFile : null; }
private void processSingleMap (File mapFile, FileHandle dirHandle, Settings texturePackerSettings) throws IOException { boolean combineTilesets = this.settings.combineTilesets; if (combineTilesets == false) { tilesetUsedIds = new HashMap<String, IntArray>(); tilesetsToPack = new ObjectMap<String, TiledMapTileSet>(); } map = mapLoader.load(mapFile.getCanonicalPath()); // if enabled, build a list of used tileids for the tileset used by this map boolean stripUnusedTiles = this.settings.stripUnusedTiles; if (stripUnusedTiles) { stripUnusedTiles(); } else { for (TiledMapTileSet tileset : map.getTileSets()) { String tilesetName = tileset.getName(); if (!tilesetsToPack.containsKey(tilesetName)) { tilesetsToPack.put(tilesetName, tileset); } } } if (combineTilesets == false) { FileHandle tmpHandle = new FileHandle(mapFile.getName()); this.settings.atlasOutputName = tmpHandle.nameWithoutExtension(); packTilesets(dirHandle, texturePackerSettings); } FileHandle tmxFile = new FileHandle(mapFile.getCanonicalPath()); writeUpdatedTMX(map, tmxFile); }
/** A utility method which writes the given font data to a file. * * The specified pixmaps are written to the parent directory of <tt>outFntFile</tt>, using that file's name without an * extension for the PNG file name(s). * * The specified FontInfo is optional, and can be null. * * Typical usage looks like this: * * <pre> * BitmapFontWriter.writeFont(myFontData, myFontPixmaps, Gdx.files.external("fonts/output.fnt"), new FontInfo("Arial", 16)); * </pre> * * @param fontData the font data * @param pages the pixmaps to write as PNGs * @param outFntFile the output file for the font definition * @param info the optional font info for the header file, can be null */ public static void writeFont (BitmapFontData fontData, Pixmap[] pages, FileHandle outFntFile, FontInfo info) { String[] pageRefs = writePixmaps(pages, outFntFile.parent(), outFntFile.nameWithoutExtension()); // write the font data writeFont(fontData, pageRefs, outFntFile, info, pages[0].getWidth(), pages[0].getHeight()); }
private void processSingleMap (File mapFile, FileHandle dirHandle, Settings texturePackerSettings) throws IOException { boolean combineTilesets = this.settings.combineTilesets; if (combineTilesets == false) { tilesetUsedIds = new HashMap<String, IntArray>(); tilesetsToPack = new ObjectMap<String, TiledMapTileSet>(); } map = mapLoader.load(mapFile.getCanonicalPath()); // if enabled, build a list of used tileids for the tileset used by this map boolean stripUnusedTiles = this.settings.stripUnusedTiles; if (stripUnusedTiles) { stripUnusedTiles(); } else { for (TiledMapTileSet tileset : map.getTileSets()) { String tilesetName = tileset.getName(); if (!tilesetsToPack.containsKey(tilesetName)) { tilesetsToPack.put(tilesetName, tileset); } } } if (combineTilesets == false) { FileHandle tmpHandle = new FileHandle(mapFile.getName()); this.settings.atlasOutputName = tmpHandle.nameWithoutExtension(); packTilesets(dirHandle, texturePackerSettings); } FileHandle tmxFile = new FileHandle(mapFile.getCanonicalPath()); writeUpdatedTMX(map, tmxFile); }
/** A utility method which writes the given font data to a file. * * The specified pixmaps are written to the parent directory of <tt>outFntFile</tt>, using that file's name without an * extension for the PNG file name(s). * * The specified FontInfo is optional, and can be null. * * Typical usage looks like this: * * <pre> * BitmapFontWriter.writeFont(myFontData, myFontPixmaps, Gdx.files.external("fonts/output.fnt"), new FontInfo("Arial", 16)); * </pre> * * @param fontData the font data * @param pages the pixmaps to write as PNGs * @param outFntFile the output file for the font definition * @param info the optional font info for the header file, can be null */ public static void writeFont (BitmapFontData fontData, Pixmap[] pages, FileHandle outFntFile, FontInfo info) { String[] pageRefs = writePixmaps(pages, outFntFile.parent(), outFntFile.nameWithoutExtension()); // write the font data writeFont(fontData, pageRefs, outFntFile, info, pages[0].getWidth(), pages[0].getHeight()); }
@Override public BitmapFont loadSync (AssetManager manager, String fileName, FileHandle file, BitmapFontParameter parameter) { if (parameter != null && parameter.atlasName != null) { TextureAtlas atlas = manager.get(parameter.atlasName, TextureAtlas.class); String name = file.sibling(data.imagePaths[0]).nameWithoutExtension().toString(); AtlasRegion region = atlas.findRegion(name); if (region == null) throw new GdxRuntimeException("Could not find font region " + name + " in atlas " + parameter.atlasName); return new BitmapFont(file, region); } else { int n = data.getImagePaths().length; Array<TextureRegion> regs = new Array(n); for (int i = 0; i < n; i++) { regs.add(new TextureRegion(manager.get(data.getImagePath(i), Texture.class))); } return new BitmapFont(data, regs, true); } }
@Override public BitmapFont loadSync (AssetManager manager, String fileName, FileHandle file, BitmapFontParameter parameter) { if (parameter != null && parameter.atlasName != null) { TextureAtlas atlas = manager.get(parameter.atlasName, TextureAtlas.class); String name = file.sibling(data.imagePaths[0]).nameWithoutExtension().toString(); AtlasRegion region = atlas.findRegion(name); if (region == null) throw new GdxRuntimeException("Could not find font region " + name + " in atlas " + parameter.atlasName); return new BitmapFont(file, region); } else { int n = data.getImagePaths().length; Array<TextureRegion> regs = new Array(n); for (int i = 0; i < n; i++) { regs.add(new TextureRegion(manager.get(data.getImagePath(i), Texture.class))); } return new BitmapFont(data, regs, true); } }
private void testClasspath () throws IOException { // no classpath support on ios if (Gdx.app.getType() == ApplicationType.iOS) return; FileHandle handle = Gdx.files.classpath("com/badlogic/gdx/utils/arial-15.png"); if (!handle.exists()) fail(); if (handle.isDirectory()) fail(); try { handle.delete(); fail(); } catch (Exception expected) { } try { handle.list(); fail(); } catch (Exception expected) { } try { handle.read().close(); fail(); } catch (Exception ignored) { } FileHandle dir = Gdx.files.classpath("com/badlogic/gdx/utils"); if (dir.isDirectory()) fail(); FileHandle child = dir.child("arial-15.fnt"); if (!child.name().equals("arial-15.fnt")) fail(); if (!child.nameWithoutExtension().equals("arial-15")) fail(); if (!child.extension().equals("fnt")) fail(); handle.read().close(); if (handle.readBytes().length != handle.length()) fail(); }
FileHandle child = dir.child("badlogic.jpg"); if (!child.name().equals("badlogic.jpg")) fail(); if (!child.nameWithoutExtension().equals("badlogic")) fail(); if (!child.extension().equals("jpg")) fail(); if (Gdx.app.getType() != ApplicationType.Android) {
String regionName = fontFile.nameWithoutExtension(); try { BitmapFont font;
String regionName = fontFile.nameWithoutExtension(); try { BitmapFont font;