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

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

Introduction

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

Prototype

public String extension() 

Source Link

Usage

From source file:CB_UI_Base.GL_UI.Fonts.java

License:Open Source License

/**
 * Ldt die verwendeten Bitmap Fonts und berechnet die entsprechenden Gren
 *//*from   w  ww.ja  va  2  s .c om*/
public static void loadFonts(SkinBase skin) {

    cfg = skin.getSettings();
    COLOR.loadColors(skin);
    FreeTypeFontGenerator generator = null;

    // get the first found ttf-font

    FileHandle font = null;

    if (cfg.SkinFolder.isDirectory()) {
        FileHandle[] ttfFonts = cfg.SkinFolder.list();
        for (FileHandle file : ttfFonts) {
            if (file.extension().equalsIgnoreCase("ttf")) {
                font = file;
                break;
            }
        }
    }

    if (font == null || !font.exists()) {
        // no skin font found, use default font
        font = Global.getInternalFileHandle("skins/default/DroidSans-Bold.ttf");
    }

    Log.debug(log, "Generate scaled Fonts from " + font);
    generator = new FreeTypeFontGenerator(font);

    double density = UiSizes.that.getScale();

    compass = loadFontFromFile(generator, (int) (cfg.SizeBiggest * density));
    big = loadFontFromFile(generator, (int) (cfg.SizeBig * density));
    normal = loadFontFromFile(generator, (int) (cfg.SizeNormal * density));
    small = loadFontFromFile(generator, (int) (cfg.SizeSmall * density));
    normalBubble = loadFontFromFile(generator, (int) (cfg.SizeNormalbubble * density));
    smallBubble = loadFontFromFile(generator, (int) (cfg.SizeSmallBubble * density));
    generator.dispose();
}

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

License:Open Source License

public static Level[] getLevels() {
    FileHandle[] levelFiles = Gdx.files.external(Constants.LEVELS_EXTERNAL_PATH).list();

    Array<Level> levels = new Array<>();

    for (FileHandle levelFile : levelFiles) {
        String extension = levelFile.extension();

        if (!levelFile.isDirectory() && extension.equals(Constants.LEVEL_EXTENSION_NO_DOT)) {
            try {
                levels.add(LevelService.read(levelFile));
            } catch (final IOException e) {
                final String errorMessage = "Failed to read level file.";
                Gdx.app.error(TAG, errorMessage, e);
            }/* ww  w  . j  av a  2 s.c  o m*/
        }
    }

    return levels.toArray(new Level[levels.size].getClass().getComponentType());
}

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

License:Open Source License

public static LevelData[] readLevelDatas(FileHandle[] levelFolder, ProgressDatabase progressDB) {
    Array<LevelData> levelDatas = new Array<>();

    for (int i = 0; i < levelFolder.length; i++) {
        FileHandle levelFile = levelFolder[i];

        if (levelFile.exists() && levelFile.extension().equals(Constants.LEVEL_EXTENSION_NO_DOT)) {
            try {
                levelDatas.add(getLevelData(levelFile, progressDB));
            } catch (final IOException e) {
                final String errorMessage = "Error reading level data.";
                Gdx.app.error(TAG, errorMessage, e);
            }//from   w ww .  jav  a 2 s  . c o  m
        }
    }

    return levelDatas.toArray(new LevelData[levelDatas.size].getClass().getComponentType());
}

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;/* www.j  a v a2  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.badlogic.gdx.spriter.demo.SpriterDemoUtils.java

static void findFiles(Array<FileHandle> files, FileHandle fileHandle, String[] acceptedExtensions) {
    if (fileHandle.isDirectory()) {
        for (FileHandle child : fileHandle.list())
            findFiles(files, child, acceptedExtensions);
    } else {/*from   ww  w  .  j  a  v a 2 s  .c  o  m*/
        String extension = fileHandle.extension();
        for (String acceptedExtension : acceptedExtensions) {
            if (acceptedExtension.equalsIgnoreCase(extension)) {
                files.add(fileHandle);
                break;
            }
        }
    }
}

From source file:com.badlogic.gdx.tests.utils.AssetsFileGenerator.java

License:Apache License

private static final void traverse(FileHandle directory, String base, StringBuffer list) {
    if (directory.name().equals(".svn"))
        return;//from ww w  .ja  va 2  s .  c  om
    String dirName = directory.toString().replace("\\", "/").replace(base, "") + "/";
    System.out.println(dirName);
    for (FileHandle file : directory.list()) {
        if (file.isDirectory()) {
            traverse(file, base, list);
        } else {
            String fileName = file.toString().replace("\\", "/").replace(base, "");
            if (fileName.endsWith(".png") || fileName.endsWith(".jpg") || fileName.endsWith(".jpeg")) {
                list.append("i:" + fileName + "\n");
                System.out.println(fileName);
            } else if (fileName.endsWith(".glsl") || fileName.endsWith(".fnt") || fileName.endsWith(".pack")
                    || fileName.endsWith(".obj") || file.extension().equals("") || fileName.endsWith("txt")) {
                list.append("t:" + fileName + "\n");
                System.out.println(fileName);
            } else {
                if (fileName.endsWith(".mp3") || fileName.endsWith(".ogg") || fileName.endsWith(".wav"))
                    continue;
                list.append("b:" + fileName + "\n");
                System.out.println(fileName);
            }
        }
    }
}

From source file:com.esotericsoftware.spine.SkeletonViewer.java

License:Open Source License

void loadSkeleton(FileHandle skeletonFile, boolean reload) {
    if (skeletonFile == null)
        return;/*from ww w . j ava 2  s  .  c  o  m*/

    // A regular texture atlas would normally usually be used. This returns a white image for images not found in the atlas.
    Pixmap pixmap = new Pixmap(32, 32, Format.RGBA8888);
    pixmap.setColor(new Color(1, 1, 1, 0.33f));
    pixmap.fill();
    final AtlasRegion fake = new AtlasRegion(new Texture(pixmap), 0, 0, 32, 32);
    pixmap.dispose();

    String atlasFileName = skeletonFile.nameWithoutExtension();
    if (atlasFileName.endsWith(".json"))
        atlasFileName = new FileHandle(atlasFileName).nameWithoutExtension();
    FileHandle atlasFile = skeletonFile.sibling(atlasFileName + ".atlas");
    if (!atlasFile.exists())
        atlasFile = skeletonFile.sibling(atlasFileName + ".atlas.txt");
    TextureAtlasData data = !atlasFile.exists() ? null
            : new TextureAtlasData(atlasFile, atlasFile.parent(), false);
    TextureAtlas atlas = new TextureAtlas(data) {
        public AtlasRegion findRegion(String name) {
            AtlasRegion region = super.findRegion(name);
            return region != null ? region : fake;
        }
    };

    try {
        String extension = skeletonFile.extension();
        if (extension.equalsIgnoreCase("json") || extension.equalsIgnoreCase("txt")) {
            SkeletonJson json = new SkeletonJson(atlas);
            json.setScale(ui.scaleSlider.getValue());
            skeletonData = json.readSkeletonData(skeletonFile);
        } else {
            SkeletonBinary binary = new SkeletonBinary(atlas);
            binary.setScale(ui.scaleSlider.getValue());
            skeletonData = binary.readSkeletonData(skeletonFile);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        ui.toast("Error loading skeleton: " + skeletonFile.name());
        lastModifiedCheck = 5;
        return;
    }

    skeleton = new Skeleton(skeletonData);
    skeleton.setToSetupPose();
    skeleton = new Skeleton(skeleton);
    skeleton.updateWorldTransform();

    state = new AnimationState(new AnimationStateData(skeletonData));

    this.skeletonFile = skeletonFile;
    Preferences prefs = Gdx.app.getPreferences("spine-skeletontest");
    prefs.putString("lastFile", skeletonFile.path());
    prefs.flush();
    lastModified = skeletonFile.lastModified();
    lastModifiedCheck = checkModifiedInterval;

    // Populate UI.

    ui.skeletonLabel.setText(skeletonFile.name());
    {
        Array<String> items = new Array();
        for (Skin skin : skeletonData.getSkins())
            items.add(skin.getName());
        ui.skinList.setItems(items);
    }
    {
        Array<String> items = new Array();
        for (Animation animation : skeletonData.getAnimations())
            items.add(animation.getName());
        ui.animationList.setItems(items);
    }

    // Configure skeleton from UI.

    skeleton.setSkin(ui.skinList.getSelected());
    state.setAnimation(0, ui.animationList.getSelected(), ui.loopCheckbox.isChecked());

    if (reload)
        ui.toast("Reloaded.");
}

From source file:com.github.fauu.helix.editor.ui.Sidebar.java

License:Open Source License

public void updateModel(MapRegion mapRegion) {
    setEditorMode(EditorMode.Type.TILE_GENERAL);

    for (Geometry geometry : mapRegion.getGeometrySet().getGeometries()) {
        geometryListModel.addElement(// w  w  w .  jav a 2 s  .  com
                new GeometryWrapper(geometry.getId(), geometry.getId() + ": " + geometry.getName()));
        geometryPicker.setSelectedIndex(0);
    }

    final FileHandle objectDirHandle = Gdx.files.internal("assets/objects/");
    int objectModelFileCount = 0;
    for (FileHandle entry : objectDirHandle.list()) {
        if (entry.extension().compareToIgnoreCase("g3db") == 0) {
            objectListModel.addElement(new ObjectWrapper(objectModelFileCount,
                    objectModelFileCount + ": " + entry.nameWithoutExtension(), entry.nameWithoutExtension()));

            objectModelFileCount += 1;
        }
    }

    for (TextureAtlas.AtlasRegion texture : mapRegion.getTextureAtlas().getRegions()) {
        textureListModel.addElement(new TextureWrapper(texture.index, texture.index + ": " + texture.name));
        texturePicker.setSelectedIndex(0);
    }
}

From source file:com.github.fauu.helix.manager.AreaManager.java

License:Open Source License

public Array<String> getAllNames() {
    Array<String> names = new Array<String>();

    FileHandle directory = Gdx.files.internal("area");

    for (FileHandle entry : directory.list()) {
        if (entry.extension().equalsIgnoreCase("json")) {
            names.add(entry.nameWithoutExtension());
        }//from   w w w .j av  a2s  . co m
    }

    return names;
}

From source file:com.intrepid.studio.animation.GenerateAnimationPackInfo.java

private void generateNewAnimationInfo(Json json) {
    rootContent.foreachFilesInContentDirectoriesExec(new FileExec() {
        @Override/*from   ww w  .  j a  v a 2s.c om*/
        public void runOver(FileHandle fHandle) {
            if (fHandle.extension().equals(NEW_EXTENSION)) {
                String line = null;
                try (BufferedReader br = new BufferedReader(new FileReader(fHandle.file()))) {
                    line = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }

                String path = fHandle.path();
                String[] split = path.split("/");
                String dir = split[split.length - 2];
                String name = split[split.length - 1];
                String tagName = dir + "." + name;
                AnimationInfo animationInfo = AnimationInfoFactory.create(tagName, line);

                System.out.println("  new found: [ " + fHandle.path() + " ]");

                String toWrite = json.prettyPrint(animationInfo);
                String output = fHandle.pathWithoutExtension() + "." + SAI_EXTENSION;
                files.local(output).writeString(toWrite, false);

                fHandle.delete();
            }
        }
    });
}