List of usage examples for com.badlogic.gdx.files FileHandle nameWithoutExtension
public String nameWithoutExtension()
From source file:by.aleks.christmasboard.data.BitmapFontWriter.java
License:Apache License
/** Writes the given BitmapFontData to a file, using the specified <tt>pageRefs</tt> strings as the image paths for each texture * page. The glyphs in BitmapFontData have a "page" id, which references the index of the pageRef you specify here. * //from w w w . ja v a 2 s . com * The FontInfo parameter is useful for cleaner output; such as including a size and font face name hint. However, it can be * null to use default values. Ultimately, LibGDX ignores the "info" line when reading back fonts. * * Likewise, the scaleW and scaleH are only for cleaner output. They are currently ignored by LibGDX's reader. For maximum * compatibility with other BMFont tools, you should use the width and height of your texture pages (each page should be the * same size). * * @param fontData the bitmap font * @param pageRefs the references to each texture page image file, generally in the same folder as outFntFile * @param outFntFile the font file to save to (typically ends with '.fnt') * @param info the optional info for the file header; can be null * @param scaleW the width of your texture pages * @param scaleH the height of your texture pages */ public static void writeFont(BitmapFontData fontData, String[] pageRefs, FileHandle outFntFile, FontInfo info, int scaleW, int scaleH) { if (info == null) { info = new FontInfo(); info.face = outFntFile.nameWithoutExtension(); } int lineHeight = (int) fontData.lineHeight; int pages = pageRefs.length; int packed = 0; int base = (int) ((fontData.capHeight) + (fontData.flipped ? -fontData.ascent : fontData.ascent)); OutputFormat fmt = BitmapFontWriter.getOutputFormat(); boolean xml = fmt == OutputFormat.XML; StringBuilder buf = new StringBuilder(); if (xml) { buf.append("<font>\n"); } String xmlOpen = xml ? "\t<" : ""; String xmlCloseSelf = xml ? "/>" : ""; String xmlTab = xml ? "\t" : ""; String xmlClose = xml ? ">" : ""; String xmlQuote = xml ? "\"" : ""; String alphaChnlParams = xml ? " alphaChnl=\"0\" redChnl=\"0\" greenChnl=\"0\" blueChnl=\"0\"" : " alphaChnl=0 redChnl=0 greenChnl=0 blueChnl=0"; //INFO LINE buf.append(xmlOpen).append("info face=\"").append(info.face == null ? "" : info.face.replaceAll("\"", "'")) .append("\" size=").append(quote(info.size)).append(" bold=").append(quote(info.bold ? 1 : 0)) .append(" italic=").append(quote(info.italic ? 1 : 0)).append(" charset=\"") .append(info.charset == null ? "" : info.charset).append("\" unicode=") .append(quote(info.unicode ? 1 : 0)).append(" stretchH=").append(quote(info.stretchH)) .append(" smooth=").append(quote(info.smooth ? 1 : 0)).append(" aa=").append(quote(info.aa)) .append(" padding=").append(xmlQuote).append(info.padding.up).append(",").append(info.padding.down) .append(",").append(info.padding.left).append(",").append(info.padding.right).append(xmlQuote) .append(" spacing=").append(xmlQuote).append(info.spacing.horizontal).append(",") .append(info.spacing.vertical).append(xmlQuote).append(xmlCloseSelf).append("\n"); //COMMON line buf.append(xmlOpen).append("common lineHeight=").append(quote(lineHeight)).append(" base=") .append(quote(base)).append(" scaleW=").append(quote(scaleW)).append(" scaleH=") .append(quote(scaleH)).append(" pages=").append(quote(pages)).append(" packed=") .append(quote(packed)).append(alphaChnlParams).append(xmlCloseSelf).append("\n"); if (xml) buf.append("\t<pages>\n"); //PAGES for (int i = 0; i < pageRefs.length; i++) { buf.append(xmlTab).append(xmlOpen).append("page id=").append(quote(i)).append(" file=\"") .append(pageRefs[i]).append("\"").append(xmlCloseSelf).append("\n"); } if (xml) buf.append("\t</pages>\n"); //CHARS Array<Glyph> glyphs = new Array<Glyph>(256); for (int i = 0; i < fontData.glyphs.length; i++) { if (fontData.glyphs[i] == null) continue; for (int j = 0; j < fontData.glyphs[i].length; j++) { if (fontData.glyphs[i][j] != null) { glyphs.add(fontData.glyphs[i][j]); } } } buf.append(xmlOpen).append("chars count=").append(quote(glyphs.size)).append(xmlClose).append("\n"); //CHAR definitions for (int i = 0; i < glyphs.size; i++) { Glyph g = glyphs.get(i); buf.append(xmlTab).append(xmlOpen).append("char id=").append(quote(String.format("%-5s", g.id), true)) .append("x=").append(quote(String.format("%-5s", g.srcX), true)).append("y=") .append(quote(String.format("%-5s", g.srcY), true)).append("width=") .append(quote(String.format("%-5s", g.width), true)).append("height=") .append(quote(String.format("%-5s", g.height), true)).append("xoffset=") .append(quote(String.format("%-5s", g.xoffset), true)).append("yoffset=") .append(quote(String.format("%-5s", fontData.flipped ? g.yoffset : -(g.height + g.yoffset)), true)) .append("xadvance=").append(quote(String.format("%-5s", g.xadvance), true)).append("page=") .append(quote(String.format("%-5s", g.page), true)).append("chnl=").append(quote(0, true)) .append(xmlCloseSelf).append("\n"); } if (xml) buf.append("\t</chars>\n"); //KERNINGS int kernCount = 0; StringBuilder kernBuf = new StringBuilder(); for (int i = 0; i < glyphs.size; i++) { for (int j = 0; j < glyphs.size; j++) { Glyph first = glyphs.get(i); Glyph second = glyphs.get(j); int kern = first.getKerning((char) second.id); if (kern != 0) { kernCount++; kernBuf.append(xmlTab).append(xmlOpen).append("kerning first=").append(quote(first.id)) .append(" second=").append(quote(second.id)).append(" amount=") .append(quote(kern, true)).append(xmlCloseSelf).append("\n"); } } } //KERN info buf.append(xmlOpen).append("kernings count=").append(quote(kernCount)).append(xmlClose).append("\n"); buf.append(kernBuf); if (xml) { buf.append("\t</kernings>\n"); buf.append("</font>"); } String charset = info.charset; if (charset != null && charset.length() == 0) charset = null; outFntFile.writeString(buf.toString(), false, charset); }
From source file:by.aleks.christmasboard.data.BitmapFontWriter.java
License:Apache License
/** A utility method which writes the given font data to a file. * //from w w w . jav a2 s . c om * 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()); }
From source file:com.agateau.pixelwheels.sound.SoundAtlas.java
License:Open Source License
public void load(String filename, String name) { FileHandle file = mRootDir.child(filename); Assert.check(file.exists(), "No sound named " + filename + " in " + mRootDir.path()); if ("".equals(name)) { name = file.nameWithoutExtension(); }/*w ww . j a v a2 s . c om*/ NLog.i("Loading sound %s from %s", name, file.path()); mSounds.put(name, Gdx.audio.newSound(file)); }
From source file:com.agateau.pixelwheels.tools.MapScreenshotGenerator.java
License:Apache License
public static void main(String[] args) { new CommandLineApplication("MapScreenshotGenerator", args) { @Override/*from w ww . ja v a 2 s . c o m*/ int run(String[] arguments) { if (arguments.length == 2) { String shotFileName = arguments[0]; String tmxFileName = arguments[1]; processFile(shotFileName, tmxFileName); } else { FileHandle tmxDir = Gdx.files.absolute("android/assets/maps"); FileHandle shotDir = Gdx.files.absolute("core/assets/ui/map-screenshots"); for (FileHandle tmxFile : tmxDir.list(".tmx")) { String shotFileName = shotDir.path() + "/" + tmxFile.nameWithoutExtension() + ".png"; processFile(shotFileName, tmxFile.path()); } } return 0; } }; }
From source file:com.andgate.ikou.io.LevelDatabaseService.java
License:Open Source License
public static LevelData getLevelData(final FileHandle levelFile, ProgressDatabase progressDB) throws IOException { final String levelName = levelFile.nameWithoutExtension(); final int completedFloors = progressDB.getFloorsCompleted(levelName); final InputStream levelIn = new GZIPInputStream(levelFile.read()); final int totalFloors = levelIn.read(); levelIn.close();/*from w ww . j av a 2 s. c o m*/ return new LevelData(levelName, totalFloors, completedFloors); }
From source file:com.arnopaja.supermac.helpers.load.AssetLoader.java
License:Creative Commons License
public static void loadCharacter(FileHandle handle) { EnumMap<Direction, TextureRegion> person = new EnumMap<Direction, TextureRegion>(Direction.class); EnumMap<Direction, TextureRegion> stepRight = new EnumMap<Direction, TextureRegion>(Direction.class); EnumMap<Direction, TextureRegion> stepLeft = new EnumMap<Direction, TextureRegion>(Direction.class); EnumMap<Direction, Animation> personAnim = new EnumMap<Direction, Animation>(Direction.class); String name = handle.nameWithoutExtension(); characterTexture = new Texture(handle); TextureRegion[][] regions = SpriteUtils.split(characterTexture); for (int i = 0; i < 4; i++) { Direction dir = Direction.values()[i]; person.put(dir, regions[0][i]);/*www . j a v a 2 s. c o m*/ stepRight.put(dir, regions[1][i]); if (i % 2 == 0) { stepLeft.put(dir, regions[2][i]); } else { stepLeft.put(dir, regions[1][i]); } TextureRegion[] array = { person.get(dir), stepRight.get(dir), person.get(dir), stepLeft.get(dir) }; Animation animation = new Animation(0.1f, array); animation.setPlayMode(Animation.PlayMode.LOOP); personAnim.put(dir, animation); } characterAssetMap.put(name, new CharacterAsset(person, personAnim)); }
From source file:com.company.minery.utils.spine.SkeletonBinary.java
License:Open Source License
public SkeletonData readSkeletonData(FileHandle file) { if (file == null) throw new IllegalArgumentException("file cannot be null."); float scale = this.scale; SkeletonData skeletonData = new SkeletonData(); skeletonData.name = file.nameWithoutExtension(); DataInput input = new DataInput(file.read(512)); try {/*from ww w. j a v a2 s. com*/ skeletonData.hash = input.readString(); if (skeletonData.hash.isEmpty()) skeletonData.hash = null; skeletonData.version = input.readString(); if (skeletonData.version.isEmpty()) skeletonData.version = null; skeletonData.width = input.readFloat(); skeletonData.height = input.readFloat(); boolean nonessential = input.readBoolean(); if (nonessential) { skeletonData.imagesPath = input.readString(); if (skeletonData.imagesPath.isEmpty()) skeletonData.imagesPath = null; } // Bones. for (int i = 0, n = input.readInt(true); i < n; i++) { String name = input.readString(); BoneData parent = null; int parentIndex = input.readInt(true) - 1; if (parentIndex != -1) parent = skeletonData.bones.get(parentIndex); BoneData boneData = new BoneData(name, parent); boneData.x = input.readFloat() * scale; boneData.y = input.readFloat() * scale; boneData.scaleX = input.readFloat(); boneData.scaleY = input.readFloat(); boneData.rotation = input.readFloat(); boneData.length = input.readFloat() * scale; boneData.flipX = input.readBoolean(); boneData.flipY = input.readBoolean(); boneData.inheritScale = input.readBoolean(); boneData.inheritRotation = input.readBoolean(); if (nonessential) Color.rgba8888ToColor(boneData.color, input.readInt()); skeletonData.bones.add(boneData); } // IK constraints. for (int i = 0, n = input.readInt(true); i < n; i++) { IkConstraintData ikConstraintData = new IkConstraintData(input.readString()); for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) ikConstraintData.bones.add(skeletonData.bones.get(input.readInt(true))); ikConstraintData.target = skeletonData.bones.get(input.readInt(true)); ikConstraintData.mix = input.readFloat(); ikConstraintData.bendDirection = input.readByte(); skeletonData.ikConstraints.add(ikConstraintData); } // Slots. for (int i = 0, n = input.readInt(true); i < n; i++) { String slotName = input.readString(); BoneData boneData = skeletonData.bones.get(input.readInt(true)); SlotData slotData = new SlotData(slotName, boneData); Color.rgba8888ToColor(slotData.color, input.readInt()); slotData.attachmentName = input.readString(); slotData.additiveBlending = input.readBoolean(); skeletonData.slots.add(slotData); } // Default skin. Skin defaultSkin = readSkin(input, "default", nonessential); if (defaultSkin != null) { skeletonData.defaultSkin = defaultSkin; skeletonData.skins.add(defaultSkin); } // Skins. for (int i = 0, n = input.readInt(true); i < n; i++) skeletonData.skins.add(readSkin(input, input.readString(), nonessential)); // Events. for (int i = 0, n = input.readInt(true); i < n; i++) { EventData eventData = new EventData(input.readString()); eventData.intValue = input.readInt(false); eventData.floatValue = input.readFloat(); eventData.stringValue = input.readString(); skeletonData.events.add(eventData); } // Animations. for (int i = 0, n = input.readInt(true); i < n; i++) readAnimation(input.readString(), input, skeletonData); } catch (IOException ex) { throw new SerializationException("Error reading skeleton file.", ex); } finally { try { input.close(); } catch (IOException ignored) { } } skeletonData.bones.shrink(); skeletonData.slots.shrink(); skeletonData.skins.shrink(); return skeletonData; }
From source file:com.company.minery.utils.spine.SkeletonJson.java
License:Open Source License
public SkeletonData readSkeletonData(FileHandle file) { if (file == null) throw new IllegalArgumentException("file cannot be null."); float scale = this.scale; SkeletonData skeletonData = new SkeletonData(); skeletonData.name = file.nameWithoutExtension(); JsonValue root = new JsonReader().parse(file); // Skeleton./*w w w . j av a 2 s . c o m*/ JsonValue skeletonMap = root.get("skeleton"); if (skeletonMap != null) { skeletonData.hash = skeletonMap.getString("hash", null); skeletonData.version = skeletonMap.getString("spine", null); skeletonData.width = skeletonMap.getFloat("width", 0); skeletonData.height = skeletonMap.getFloat("height", 0); skeletonData.imagesPath = skeletonMap.getString("images", null); } // Bones. for (JsonValue boneMap = root.getChild("bones"); boneMap != null; boneMap = boneMap.next) { BoneData parent = null; String parentName = boneMap.getString("parent", null); if (parentName != null) { parent = skeletonData.findBone(parentName); if (parent == null) throw new SerializationException("Parent bone not found: " + parentName); } BoneData boneData = new BoneData(boneMap.getString("name"), parent); boneData.length = boneMap.getFloat("length", 0) * scale; boneData.x = boneMap.getFloat("x", 0) * scale; boneData.y = boneMap.getFloat("y", 0) * scale; boneData.rotation = boneMap.getFloat("rotation", 0); boneData.scaleX = boneMap.getFloat("scaleX", 1); boneData.scaleY = boneMap.getFloat("scaleY", 1); boneData.flipX = boneMap.getBoolean("flipX", false); boneData.flipY = boneMap.getBoolean("flipY", false); boneData.inheritScale = boneMap.getBoolean("inheritScale", true); boneData.inheritRotation = boneMap.getBoolean("inheritRotation", true); String color = boneMap.getString("color", null); if (color != null) boneData.getColor().set(Color.valueOf(color)); skeletonData.bones.add(boneData); } // IK constraints. for (JsonValue ikMap = root.getChild("ik"); ikMap != null; ikMap = ikMap.next) { IkConstraintData ikConstraintData = new IkConstraintData(ikMap.getString("name")); for (JsonValue boneMap = ikMap.getChild("bones"); boneMap != null; boneMap = boneMap.next) { String boneName = boneMap.asString(); BoneData bone = skeletonData.findBone(boneName); if (bone == null) throw new SerializationException("IK bone not found: " + boneName); ikConstraintData.bones.add(bone); } String targetName = ikMap.getString("target"); ikConstraintData.target = skeletonData.findBone(targetName); if (ikConstraintData.target == null) throw new SerializationException("Target bone not found: " + targetName); ikConstraintData.bendDirection = ikMap.getBoolean("bendPositive", true) ? 1 : -1; ikConstraintData.mix = ikMap.getFloat("mix", 1); skeletonData.ikConstraints.add(ikConstraintData); } // Slots. for (JsonValue slotMap = root.getChild("slots"); slotMap != null; slotMap = slotMap.next) { String slotName = slotMap.getString("name"); String boneName = slotMap.getString("bone"); BoneData boneData = skeletonData.findBone(boneName); if (boneData == null) throw new SerializationException("Slot bone not found: " + boneName); SlotData slotData = new SlotData(slotName, boneData); String color = slotMap.getString("color", null); if (color != null) slotData.getColor().set(Color.valueOf(color)); slotData.attachmentName = slotMap.getString("attachment", null); slotData.additiveBlending = slotMap.getBoolean("additive", false); skeletonData.slots.add(slotData); } // Skins. for (JsonValue skinMap = root.getChild("skins"); skinMap != null; skinMap = skinMap.next) { Skin skin = new Skin(skinMap.name); for (JsonValue slotEntry = skinMap.child; slotEntry != null; slotEntry = slotEntry.next) { int slotIndex = skeletonData.findSlotIndex(slotEntry.name); if (slotIndex == -1) throw new SerializationException("Slot not found: " + slotEntry.name); for (JsonValue entry = slotEntry.child; entry != null; entry = entry.next) { Attachment attachment = readAttachment(skin, entry.name, entry); if (attachment != null) skin.addAttachment(slotIndex, entry.name, attachment); } } skeletonData.skins.add(skin); if (skin.name.equals("default")) skeletonData.defaultSkin = skin; } // Events. for (JsonValue eventMap = root.getChild("events"); eventMap != null; eventMap = eventMap.next) { EventData eventData = new EventData(eventMap.name); eventData.intValue = eventMap.getInt("int", 0); eventData.floatValue = eventMap.getFloat("float", 0f); eventData.stringValue = eventMap.getString("string", null); skeletonData.events.add(eventData); } // Animations. for (JsonValue animationMap = root .getChild("animations"); animationMap != null; animationMap = animationMap.next) readAnimation(animationMap.name, animationMap, skeletonData); skeletonData.bones.shrink(); skeletonData.slots.shrink(); skeletonData.skins.shrink(); skeletonData.animations.shrink(); return skeletonData; }
From source file:com.dongbat.invasion.registry.AtlasRegistry.java
public static void load() { FileHandle internal = Gdx.files.internal("./atlas"); for (FileHandle file : internal.list(".atlas")) { String name = file.nameWithoutExtension(); registry.put(name, new TextureAtlas(file)); }//from w w w. j a v a 2 s . c o m SkeletonJson json; for (FileHandle file : internal.list(".json")) { String name = file.nameWithoutExtension(); TextureAtlas atlas = getAtlas(name); if (atlas != null) { json = new SkeletonJson(atlas); // TODO scale for each enemy type or base on size json.setScale(0.5f); SkeletonData ske = json.readSkeletonData(file); skeReg.put(name, ske); } } }
From source file:com.dongbat.invasion.registry.BulletRegistry.java
public static void load() { FileHandle internal = Gdx.files.internal("./bullet"); for (FileHandle file : internal.list()) { String content = file.readString(); BulletInfo bulletInfo = getBulletInfo(content); if (bulletInfo != null) { bulletMap.put(file.nameWithoutExtension(), bulletInfo); }/*from ww w .j a va2 s .c o m*/ } }