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

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

Introduction

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

Prototype

public String path() 

Source Link

Usage

From source file:ca.viaware.game.assets.TilesetManager.java

License:Open Source License

public static void loadTileset(String name, FileHandle imageFile) {
    if (tilesets == null)
        tilesets = new HashMap<String, Tileset>();

    System.out.println("Loading tileset " + name + " at " + imageFile.path());

    try {//from   w  w  w  . j  a v a2 s  .co m
        Texture texture = new Texture(imageFile);
        Tileset tileset = new Tileset(texture);
        DataInputStream input = new DataInputStream(
                Gdx.files.internal(imageFile.pathWithoutExtension() + ".regions").read());

        while (true) {
            int[] read = new int[4];
            for (int i = 0; i < read.length; i++) {
                int r = input.readShort();
                if (r == -100) { //TODO This is stupid
                    input.close();
                    tilesets.put(name, tileset);
                    System.out.println("Done loading tileset.");
                    return;
                }
                read[i] = r;
            }
            String tileName = input.readUTF();
            System.out.println("Adding region " + tileName + "(" + read[0] + "," + read[1] + ")(" + read[2]
                    + "," + read[3] + ")");
            tileset.addRegion(tileName, read[0], read[1], read[2], read[3]);
        }

    } catch (IOException e) {
        e.printStackTrace();
    }
}

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 .  ja va2  s .  co  m*/
    NLog.i("Loading sound %s from %s", name, file.path());
    mSounds.put(name, Gdx.audio.newSound(file));
}

From source file:com.agateau.pixelwheels.tools.LapPositionTableGenerator.java

License:Apache License

public static void generateTable(FileHandle tmxFile, FileHandle tableFile) {
    TiledMap map = new TmxMapLoader().load(tmxFile.path());
    LapPositionTable table = LapPositionTableIO.load(map);

    TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(0);
    int width = layer.getWidth() * ((int) layer.getTileWidth());
    int height = layer.getHeight() * ((int) layer.getTileHeight());

    Pixmap pixmap = LapPositionTableIO.createPixmap(table, width, height);
    PixmapIO.writePNG(tableFile, pixmap);
}

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 . j  av  a2 s . c om*/
        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.agateau.pixelwheels.tools.MapScreenshotGenerator.java

License:Apache License

private static void processFile(String shotFileName, String tmxFileName) {
    FileHandle tmxFile = Gdx.files.absolute(tmxFileName);
    FileHandle shotFile = Gdx.files.absolute(shotFileName);
    if (isOutdated(shotFile, tmxFile)) {
        NLog.i("%s: updating", shotFile.path());
        Pixmap pix1 = generateScreenshot(tmxFile);
        Pixmap pix2 = scaleScreenshot(pix1);
        pix1.dispose();/*from   ww w . ja v  a 2 s. c o m*/
        PixmapIO.writePNG(shotFile, pix2);
        pix2.dispose();
    } else {
        NLog.i("%s: up to date", shotFile.path());
    }
}

From source file:com.agateau.pixelwheels.tools.MapScreenshotGenerator.java

License:Apache License

private static Pixmap generateScreenshot(FileHandle tmxFile) {
    TiledMap map = new TmxMapLoader().load(tmxFile.path());
    TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(0);
    int mapWidth = (int) (layer.getWidth() * layer.getTileWidth());
    int mapHeight = (int) (layer.getHeight() * layer.getTileHeight());

    FrameBuffer fbo = new FrameBuffer(Pixmap.Format.RGB888, mapWidth, mapHeight, false /* hasDepth */);
    OrthogonalTiledMapRenderer renderer = new OrthogonalTiledMapRenderer(map);

    OrthographicCamera camera = new OrthographicCamera();
    camera.setToOrtho(true /* yDown */, mapWidth, mapHeight);
    renderer.setView(camera);//from w ww .  j a  va2s.  c  o m

    fbo.begin();
    renderer.render();

    return ScreenUtils.getFrameBufferPixmap(0, 0, mapWidth, mapHeight);
}

From source file:com.agateau.utils.FileUtils.java

License:Apache License

public static XmlReader.Element parseXml(FileHandle handle) {
    XmlReader reader = new XmlReader();
    XmlReader.Element root = reader.parse(handle);
    if (root == null) {
        NLog.e("Failed to parse xml file from %s. No root element.", handle.path());
        return null;
    }//from  w ww  .  j  a  v a  2s . c om
    return root;
}

From source file:com.agateau.utils.ScreenshotCreator.java

License:Apache License

public static String saveScreenshot() {
    Pixmap pixmap = takeScreenshot();/*w w w  . ja v  a2s  .com*/
    FileHandle handle = generateFileHandle();
    PixmapIO.writePNG(handle, pixmap);
    try {
        sPNG.write(handle, pixmap);
    } catch (IOException ex) {
        throw new GdxRuntimeException("Error writing PNG: " + handle, ex);
    }
    return handle.path();
}

From source file:com.andgate.ikou.io.LevelService.java

License:Open Source License

public static Level read(final FileHandle levelFile) throws IOException {
    Level level = null;/* w  ww  .  java  2  s  . co  m*/

    if (levelFile.exists() && levelFile.extension().equals(Constants.LEVEL_EXTENSION_NO_DOT)) {
        InputStream levelIn = new GZIPInputStream(levelFile.read());
        Reader reader = new BufferedReader(new InputStreamReader(levelIn));
        JsonReader jsonReader = new JsonReader(reader);

        try {
            // Skip the first int, it's just the floor numbers.
            levelIn.read();
            Gson gson = new Gson();
            level = gson.fromJson(jsonReader, Level.class);
        } finally {
            jsonReader.close();
        }
    }

    if (level == null) {
        final String errorMessage = "Failed to load level \"" + levelFile.path() + levelFile.name() + "\"";
        throw new IOException(errorMessage);
    }

    return level;
}

From source file:com.betmansmall.game.gameLogic.mapLoader.MapLoader.java

License:Apache License

/** Loads the {@link TiledMap} from the given file. The file is resolved via the {@link FileHandleResolver} set in the
 * constructor of this class. By default it will resolve to an internal file.
 * @param fileName the filename/*w ww .jav  a2 s.  com*/
 * @param parameters specifies whether to use y-up, generate mip maps etc.
 * @return the TiledMap */
public TiledMap load(String fileName, MapLoader.Parameters parameters) {
    try {
        this.convertObjectToTileSpace = parameters.convertObjectToTileSpace;
        this.flipY = parameters.flipY;
        FileHandle tmxFile = resolve(fileName);
        root = xml.parse(tmxFile);
        ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>();
        Array<FileHandle> textureFiles = loadTilesets(root, tmxFile);
        textureFiles.addAll(loadImages(root, tmxFile));

        for (FileHandle textureFile : textureFiles) {
            Texture texture = new Texture(textureFile, parameters.generateMipMaps);
            texture.setFilter(parameters.textureMinFilter, parameters.textureMagFilter);
            textures.put(textureFile.path(), texture);
        }

        DirectImageResolver imageResolver = new DirectImageResolver(textures);
        TiledMap map = loadTilemap(root, tmxFile, imageResolver);
        map.setOwnedResources(textures.values().toArray());
        return map;
    } catch (IOException e) {
        throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
    }
}