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

The following examples show how to use com.badlogic.gdx.files.FileHandle#parent() . 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: TextureUnpackerDialogController.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
@LmlAction("launchUnpackProcess") void launchUnpackProcess() {
    try {
        Gdx.app.log(TAG, "Start texture unpacking");

        FileHandle outputDir = Gdx.files.absolute(edtOutputDir.getText());
        FileHandle atlasFile = FileUtils.obtainIfExists(edtAtlasPath.getText());
        if (atlasFile == null) throw new IllegalStateException("Atlas file does not exist: " + edtAtlasPath.getText());

        TextureAtlas.TextureAtlasData atlasData = new TextureAtlas.TextureAtlasData(atlasFile, atlasFile.parent(), false);

        TextureUnpacker textureUnpacker = new TextureUnpacker();
        textureUnpacker.splitAtlas(atlasData, outputDir.path());

        Gdx.app.log(TAG, "Texture unpacking successfully finished");
        showSuccessfulDialog(outputDir);
    } catch (Exception e) {
        Gdx.app.log(TAG, "Texture unpacking failed with error", e);
        showErrorDialog(e);
    }
}
 
Example 2
Source File: GdxFileValidator.java    From riiablo with Apache License 2.0 6 votes vote down vote up
@Override
public void validate(@Nullable Object obj) {
  if (obj == null) {
    throw new ValidationException("obj cannot be null");
  } else if (!(obj instanceof String)) {
    throw new ValidationException("obj must be a String");
  }

  String fileName = (String) obj;
  FileHandle handle = RESOLVER.resolve(fileName);
  if (!handle.exists()) {
    throw new ValidationException("File not found!");
  }

  File file = handle.parent() != null ? handle.parent().file() : null;
  if (FILTER != null && !FILTER.accept(file, handle.name())) {
    throw new ValidationException("File not accepted!");
  }
}
 
Example 3
Source File: GLTFExporter.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
private void beginMultiScene(FileHandle file){
	binManager = new GLTFBinaryExporter(file.parent(), config);
	
	root = new GLTF();
	root.asset = new GLTFAsset();
	root.asset.version = "2.0";
	root.asset.generator = GENERATOR_INFO;
	
	root.scenes = new Array<GLTFScene>();
	
}
 
Example 4
Source File: UAtlasTmxMapLoader.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
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 5
Source File: CCTextureAtlasLoader.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: AtlasModel.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
public AtlasModel(FileHandle atlasFile) {
    this.atlasFile = atlasFile;
    this.atlasData = new TextureAtlasData(atlasFile, atlasFile.parent(), false);
    atlasPath = atlasFile.file().getAbsolutePath();

    generatePages(atlasData);
}
 
Example 7
Source File: GlobalActions.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@LmlAction("saveProjectAs") public void saveProjectAs() {
      resetViewFocus();

      final ProjectModel project = getProject();
      FileHandle projectFile = project.getProjectFile();
      FileHandle dir = fileChooserHistory.getLastDir(FileChooserHistory.Type.PROJECT);
      if (FileUtils.fileExists(projectFile)) {
          dir = projectFile.parent();
      }

      FileChooser fileChooser = new FileChooser(dir, FileChooser.Mode.SAVE);
      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) {
              FileHandle chosenFile = file.first();
              fileChooserHistory.putLastDir(FileChooserHistory.Type.PROJECT, chosenFile.parent());

              if (chosenFile.extension().length() == 0) {
                  chosenFile = Gdx.files.getFileHandle(chosenFile.path()+"."+AppConstants.PROJECT_FILE_EXT, chosenFile.type());
              }

              getProject().setProjectFile(chosenFile);
              projectSerializer.saveProject(project, chosenFile);
          }
      });
      getStage().addActor(fileChooser.fadeIn());

      if (FileUtils.fileExists(projectFile)) { fileChooser.setSelectedFiles(projectFile); }
  }
 
Example 8
Source File: Compatibility.java    From Cubes with MIT License 5 votes vote down vote up
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 9
Source File: SeparatedDataFileResolver.java    From gdx-gltf with Apache License 2.0 4 votes vote down vote up
@Override
public void load(FileHandle file) {
	glModel = new Json().fromJson(GLTF.class, file);
	path = file.parent();
	loadBuffers(path);
}
 
Example 10
Source File: PixmapAtlas.java    From libgdx-snippets with MIT License 4 votes vote down vote up
public PixmapAtlas(FileHandle packFile) {
	this(packFile, packFile.parent(), false);
}
 
Example 11
Source File: LibgdxTextureAtlasWrapper.java    From mini2Dx with Apache License 2.0 4 votes vote down vote up
/** Loads the specified pack file, using the parent directory of the pack file to find the page images. */
public LibgdxTextureAtlasWrapper (FileHandle packFile) {
	this(packFile, packFile.parent());
}
 
Example 12
Source File: LibgdxTextureAtlasWrapper.java    From mini2Dx with Apache License 2.0 4 votes vote down vote up
/** @param flip If true, all regions loaded will be flipped for use with a perspective where 0,0 is the upper left corner.
 * @see #LibgdxTextureAtlasWrapper(FileHandle) */
public LibgdxTextureAtlasWrapper (FileHandle packFile, boolean flip) {
	this(packFile, packFile.parent(), flip);
}