Example usage for com.badlogic.gdx.files FileHandle child

List of usage examples for com.badlogic.gdx.files FileHandle child

Introduction

In this page you can find the example usage for com.badlogic.gdx.files FileHandle child.

Prototype

public FileHandle child(String name) 

Source Link

Document

Returns a handle to the child with the specified name.

Usage

From source file:by.aleks.christmasboard.data.BitmapFontWriter.java

License:Apache License

/** A utility method to write the given array of pixmaps to the given output directory, with the specified file name. If the
 * pages array is of length 1, then the resulting file ref will look like: "fileName.png".
 * /* w  w  w . ja va2s .c  o  m*/
 * If the pages array is greater than length 1, the resulting file refs will be appended with "_N", such as "fileName_0.png",
 * "fileName_1.png", "fileName_2.png" etc.
 * 
 * The returned string array can then be passed to the <tt>writeFont</tt> method.
 * 
 * Note: None of the pixmaps will be disposed.
 * 
 * @param pages the pages of pixmap data to write
 * @param outputDir the output directory
 * @param fileName the file names for the output images
 * @return the array of string references to be used with <tt>writeFont</tt> */
public static String[] writePixmaps(Pixmap[] pages, FileHandle outputDir, String fileName) {
    if (pages == null || pages.length == 0)
        throw new IllegalArgumentException("no pixmaps supplied to BitmapFontWriter.write");

    String[] pageRefs = new String[pages.length];

    for (int i = 0; i < pages.length; i++) {
        String ref = pages.length == 1 ? (fileName + ".png") : (fileName + "_" + i + ".png");

        //the ref for this image
        pageRefs[i] = ref;

        //write the PNG in that directory
        PixmapIO.writePNG(outputDir.child(ref), pages[i]);
    }
    return pageRefs;
}

From source file:com.blastedstudios.gdxworld.util.ui.TreeFileChooser.java

License:Apache License

/** creates an anonymous subclass of {@link Node} that recursively adds the children of the given file to it when being {@link Node#setExpanded(boolean) expanded} for the first time
 *  @param file the file to put in {@link Node#setObject(Object)}
 *  @param filter Filters children from being added. May be null to accept all files.
 *  @param labelSupplier supplies labels to use
 *  @param nodeConsumer Does something with nodes after they were created. May be null.
 *  @return the created Node *///from   ww w .  java 2  s .c om
public static Node fileNode(final FileHandle file, final FileFilter filter,
        final Accessor<Label, FileHandle> labelSupplier, final Accessor<Void, Node> nodeConsumer) {
    Label label = labelSupplier.access(file);

    Node node;
    if (file.isDirectory()) {
        final Node dummy = new Node(new Actor());

        node = new Node(label) {
            private boolean childrenAdded;

            @Override
            public void setExpanded(boolean expanded) {
                if (expanded == isExpanded())
                    return;

                if (expanded && !childrenAdded) {
                    if (filter != null)
                        for (File child : file.file().listFiles(filter))
                            add(fileNode(file.child(child.getName()), filter, labelSupplier, nodeConsumer));
                    else
                        for (FileHandle child : file.list())
                            add(fileNode(child, filter, labelSupplier, nodeConsumer));
                    childrenAdded = true;
                    remove(dummy);
                }

                super.setExpanded(expanded);
            }
        };
        node.add(dummy);

        if (nodeConsumer != null)
            nodeConsumer.access(dummy);
    } else
        node = new Node(label);
    node.setObject(file);

    if (nodeConsumer != null)
        nodeConsumer.access(node);

    return node;
}

From source file:com.blindtigergames.werescrewed.graphics.particle.ParticleEffect.java

License:Apache License

public void loadEmitterImages(FileHandle imagesDir) {
    for (int i = 0, n = emitters.size; i < n; i++) {
        ParticleEmitter emitter = emitters.get(i);
        String imagePath = emitter.getImagePath();
        if (imagePath == null)
            continue;
        String imageName = new File(imagePath.replace('\\', '/')).getName();
        emitter.setSprite(new Sprite(loadTexture(imagesDir.child(imageName))));
    }/*  w  w  w .  jav  a2s. co  m*/
}

From source file:com.cmein.tilemap.utils.TileSetLayout.java

License:Apache License

/**
 * Constructs a Tile Set layout. The tile set image contained in the baseDir should be the original tile set images before
 * being processed by {@link TiledMapPacker} (the ones actually read by Tiled).
 * @param tileSet the tile set to process
 * @param baseDir the directory in which the tile set image is stored
 * *///from  www.  j a v a 2s  . c o  m
TileSetLayout(TileSet tileSet, FileHandle baseDir) throws IOException {
    this.tileSet = tileSet;
    image = ImageIO.read(baseDir.child(tileSet.imageName).read());

    imageTilePositions = new IntMap<Vector2>();

    // fill the tile regions
    int x, y, tile = 0;
    numRows = 0;
    numCols = 0;
    for (y = tileSet.margin; y < image.getHeight() - tileSet.margin; y += tileSet.tileHeight
            + tileSet.spacing) {
        for (x = tileSet.margin; x < image.getWidth() - tileSet.margin; x += tileSet.tileWidth
                + tileSet.spacing) {
            if (y == tileSet.margin)
                numCols++;
            imageTilePositions.put(tile, new Vector2(x, y));
            tile++;
        }
        numRows++;
    }

    numTiles = numRows * numCols;
}

From source file:com.github.fauu.helix.graphics.ParticleEffect.java

License:Apache License

public void loadEmitterImages(FileHandle imagesDir) {
    ownsTexture = true;//  w  w w.  j a v a2 s .  co m
    HashMap<String, Sprite> loadedSprites = new HashMap<String, Sprite>(emitters.size);
    for (int i = 0, n = emitters.size; i < n; i++) {
        ParticleEmitter emitter = emitters.get(i);
        String imagePath = emitter.getImagePath();
        if (imagePath == null)
            continue;
        String imageName = new File(imagePath.replace('\\', '/')).getName();
        Sprite sprite = loadedSprites.get(imageName);
        if (sprite == null) {
            sprite = new Sprite(loadTexture(imagesDir.child(imageName)));
            loadedSprites.put(imageName, sprite);
        }
        emitter.setSprite(sprite);
    }
}

From source file:com.kotcrab.vis.editor.assets.transaction.action.DeleteFileAction.java

License:Apache License

public DeleteFileAction(FileHandle source, FileHandle transactionStorage) {
    this.source = source;
    this.transactionStorage = transactionStorage;
    this.backup = transactionStorage.child(source.name());
}

From source file:com.kotcrab.vis.editor.extension.SpriterUIContextGenerator.java

License:Apache License

@Override
public VisTable provideContext(FileHandle fileHandle, String relativePath) {
    if (ProjectPathUtils.isNotImportedSpriterAnimationDir(assetsMetadata, fileHandle)) {
        this.animFolder = fileHandle;
        this.relativePath = relativePath;

        FileHandle visFolder = fileHandle.child(".vis");
        if (visFolder.exists() == false) {
            return importTable;
        }/*from w ww  . j a v a2s .c o m*/

        if (visFolder.child("update").list().length > 0) {
            return updateTable;
        }
    }

    return null;
}

From source file:com.kotcrab.vis.editor.module.editor.DonateReminderModule.java

License:Apache License

@Override
public void init() {
    FileHandle storage = fileAccess.getMetadataFolder();
    FileHandle storageFile = storage.child("donateReminder.json");

    Json json = new Json();
    json.setIgnoreUnknownFields(true);/* w  ww  .j av  a2s .  co m*/
    json.addClassTag("EditorRunCounter", EditorRunCounter.class);

    EditorRunCounter runCounter;
    try {
        if (storageFile.exists()) {
            runCounter = json.fromJson(EditorRunCounter.class, storageFile);
        } else
            runCounter = new EditorRunCounter();
    } catch (SerializationException ignored) {
        runCounter = new EditorRunCounter();
    }

    runCounter.counter++;

    if (runCounter.counter % 50 == 0) {
        VisTable table = new VisTable(true);

        table.add("If you like VisEditor please consider").spaceRight(3);
        table.add(new LinkLabel("donating.", DONATE_URL));
        LinkLabel hide = new LinkLabel("Hide");
        table.add(hide);
        menuBar.setUpdateInfoTableContent(table);

        hide.setListener(labelUrl -> menuBar.setUpdateInfoTableContent(null));
    }

    json.toJson(runCounter, storageFile);
}

From source file:com.kotcrab.vis.editor.module.editor.ProjectIOModule.java

License:Apache License

public void load(FileHandle projectRoot) throws EditorException {
    if (projectRoot.exists() == false)
        throw new EditorException("Selected folder does not exist!");
    if (projectRoot.name().equals(PROJECT_FILE)) {
        loadProject(projectRoot);// www  .j  a va 2s . c o  m
        return;
    }

    if (projectRoot.name().equals("vis") && projectRoot.isDirectory()) {
        loadProject(projectRoot.child(PROJECT_FILE));
        return;
    }

    if (projectRoot.child(PROJECT_FILE).exists()) {
        loadProject(projectRoot.child(PROJECT_FILE));
        return;
    }

    FileHandle visFolder = projectRoot.child("vis");
    if (visFolder.child(PROJECT_FILE).exists()) {
        loadProject(visFolder.child(PROJECT_FILE));
        return;
    }

    throw new EditorException("Selected folder is not a Vis project!");
}

From source file:com.kotcrab.vis.editor.module.editor.ProjectIOModule.java

License:Apache License

private void backupProject(FileHandle dataFile, int oldVersionCode, AsyncTaskAdapter listener) {
    Project project = readProjectDataFile(dataFile);
    FileHandle backupRoot = project.getVisDirectory();
    FileHandle backupOut = backupRoot.child("modules").child(".conversionBackup");
    backupOut.mkdirs();/*  ww w. ja v a  2 s .  com*/

    FileHandle backupArchive = backupOut
            .child("before-conversion-from-" + oldVersionCode + "-to-" + App.VERSION_CODE + ".zip");

    AsyncTaskProgressDialog taskDialog = Async.startTask(stage, "Creating backup",
            new CreateProjectBackupAsyncTask(backupRoot, backupArchive));
    taskDialog.addListener(listener);
}