Java Code Examples for com.badlogic.gdx.files.FileHandle#sibling()

The following examples show how to use com.badlogic.gdx.files.FileHandle#sibling() . 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: DesktopLauncher.java    From skin-composer with MIT License 6 votes vote down vote up
@Override
public void texturePack(Array<FileHandle> handles, FileHandle localFile, FileHandle targetFile, FileHandle settingsFile) {
    var json = new Json();
    var settings = json.fromJson(TexturePacker.Settings.class, settingsFile);
    
    var p = new TexturePacker(settings);
    for (var handle : handles) {
        if (handle.exists()) {
            p.addImage(handle.file());
        } else {
            if (localFile != null) {
                var localHandle = localFile.sibling(localFile.nameWithoutExtension() + "_data/" + handle.name());
                if (localHandle.exists()) {
                    p.addImage(localHandle.file());
                } else {
                    Gdx.app.error(getClass().getName(), "File does not exist error while creating texture atlas: " + handle.path());
                }
            } else {
                Gdx.app.error(getClass().getName(), "File does not exist error while creating texture atlas: " + handle.path());
            }
        }
    }
    p.pack(targetFile.parent().file(), targetFile.nameWithoutExtension());
}
 
Example 2
Source File: UAtlasTmxMapLoader.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
/** 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 3
Source File: Skin.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 4
Source File: DialogSceneComposerModel.java    From skin-composer with MIT License 4 votes vote down vote up
public static void saveToJson(FileHandle saveFile) {
    if (!saveFile.extension().toLowerCase(Locale.ROOT).equals("json")) {
        saveFile = saveFile.sibling(saveFile.nameWithoutExtension() + ".json");
    }
    saveFile.writeString(json.prettyPrint(rootActor), false);
}