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

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

Introduction

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

Prototype

public void writeString(String string, boolean append) 

Source Link

Document

Writes the specified string to the file using the default charset.

Usage

From source file:br.unb.unbomber.Settings.java

License:Apache License

public static void save() {
    try {/*  w  w  w . jav a 2s.  c  o  m*/
        FileHandle filehandle = Gdx.files.external(file);

        filehandle.writeString(Boolean.toString(soundEnabled) + "\n", false);
        for (int i = 0; i < 5; i++) {
            filehandle.writeString(Integer.toString(highscores[i]) + "\n", true);
        }
    } catch (Throwable e) {
    }
}

From source file:com.ads.puzzle.fifa.Settings.java

License:Apache License

public static void save() {
    try {//  w  ww  .  j  a v a2  s . c  o  m
        FileHandle filehandle = Gdx.files.external(file);
        filehandle.writeString(Boolean.toString(soundEnabled) + "\n", false);
        for (int i = 0; i < 5; i++) {
            filehandle.writeString(Integer.toString(highscores[i]) + "\n", true);
        }
    } catch (Throwable e) {
    }
}

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

License:Open Source License

public static void write(ProgressDatabase progressDatabase) {
    Json json = new Json();
    String jsonString = json.toJson(progressDatabase);
    String encodedString = Base64Coder.encodeString(jsonString);
    FileHandle saveFile = Gdx.files.external(Constants.PROGRESS_DATABASE_EXTERNAL_PATH);
    saveFile.writeString(encodedString, false);
}

From source file:com.andgate.pokeadot.HighScoreService.java

License:Open Source License

public static void set(HighScore newHighScore) {
    Json json = new Json();
    String jsonString = json.toJson(newHighScore);
    String encodedString = Base64Coder.encodeString(jsonString);
    FileHandle saveFile = Gdx.files.external(HIGHSCORE_EXTERNAL_PATH);
    saveFile.writeString(encodedString, false);

}

From source file:com.idp.engine.base.IdpFiles.java

/**
 * Writes given string to a file.//from   ww  w.  j a  v a 2  s .co m
 * @param fileHandle file to write to
 * @param s string to write
 */
public void writeFileString(FileHandle fileHandle, String s) {
    try {
        fileHandle.writeString(s, false);
    } catch (Exception ex) {
        if (LOG_EXCEPTIONS)
            Idp.logger.log(ex);
        throw new RuntimeException("cannot save to file: " + fileHandle.path(), ex);
    }
}

From source file:com.libgdx.skin.editor.utils.scene2d.CustomSkin.java

License:Apache License

/** Store all resources in the specified skin JSON file. */
public boolean save(FileHandle skinFile) {
    StringWriter jsonText = new StringWriter();

    Json json = new Json();
    json.setWriter(new JsonWriter(jsonText));

    // ????? type
    json.writeObjectStart();//from  ww  w .j a  v  a 2 s  .c o  m
    for (Class<? extends Object> resType : saveResoureTypes) {
        ObjectMap<String, ? extends Object> typeResources = super.getAll(resType);
        if (emptyMap(typeResources)) {
            continue;
        }
        //  type 
        json.writeObjectStart(resType.getName());
        write1ResType(typeResources, resType, json);
        json.writeObjectEnd();

    }
    json.writeObjectEnd();

    PrettyPrintSettings settings = new PrettyPrintSettings();
    settings.outputType = OutputType.minimal;
    settings.singleLineColumns = 50;

    // ?
    skinFile.writeString(json.prettyPrint(jsonText.toString(), settings), false);
    return true;
}

From source file:com.nebula2d.editor.framework.Project.java

License:Open Source License

public void build(String startScene, FileHandle sceneFileOut, FileHandle assetsFileOut,
        BuildProgressUpdateListener listener) throws IOException {
    StringWriter sceneStrWriter = new StringWriter();
    StringWriter assetsStrWriter = new StringWriter();
    XmlWriter sceneXmlWriter = new XmlWriter(sceneStrWriter);
    XmlWriter assetsXmlWriter = new XmlWriter(assetsStrWriter);

    sceneXmlWriter.element("project").attribute("name", projectName).attribute("startScene", startScene);
    assetsXmlWriter.element("assets");

    for (int i = 0; i < scenes.size(); ++i) {
        Scene scene = scenes.get(i);//  w  ww.  j  a  v  a2s.c  o  m
        scene.build(sceneXmlWriter, assetsXmlWriter, scene.getName());
        sceneXmlWriter.pop();
        listener.onBuildProgressUpdate(scene, i, scenes.size());
    }
    sceneXmlWriter.pop();
    assetsXmlWriter.pop();

    sceneFileOut.writeString(sceneStrWriter.toString(), false);
    assetsFileOut.writeString(assetsStrWriter.toString(), false);

    listener.onProjectCompiled();
}

From source file:com.ray3k.skincomposer.data.JsonData.java

License:Open Source License

public void writeFile(FileHandle fileHandle) {
    StringWriter stringWriter = new StringWriter();
    JsonWriter jsonWriter = new JsonWriter(stringWriter);
    jsonWriter.setOutputType(OutputType.minimal);
    Json json = new Json();
    json.setWriter(jsonWriter);//w w  w .  j  a v a 2  s. co  m
    json.writeObjectStart();

    //fonts
    if (fonts.size > 0) {
        json.writeObjectStart(BitmapFont.class.getName());
        for (FontData font : fonts) {
            json.writeObjectStart(font.getName());
            json.writeValue("file", font.file.name());
            json.writeObjectEnd();
        }
        json.writeObjectEnd();
    }

    //colors
    if (colors.size > 0) {
        json.writeObjectStart(Color.class.getName());
        for (ColorData color : colors) {
            json.writeObjectStart(color.getName());
            json.writeValue("r", color.color.r);
            json.writeValue("g", color.color.g);
            json.writeValue("b", color.color.b);
            json.writeValue("a", color.color.a);
            json.writeObjectEnd();
        }
        json.writeObjectEnd();
    }

    //tinted drawables
    Array<DrawableData> tintedDrawables = new Array<>();
    for (DrawableData drawable : main.getProjectData().getAtlasData().getDrawables()) {
        if (drawable.tint != null || drawable.tintName != null) {
            tintedDrawables.add(drawable);
        }
    }
    if (tintedDrawables.size > 0) {
        json.writeObjectStart(TintedDrawable.class.getName());
        for (DrawableData drawable : tintedDrawables) {
            json.writeObjectStart(drawable.name);
            json.writeValue("name", DrawableData.proper(drawable.file.name()));
            if (drawable.tint != null) {
                json.writeObjectStart("color");
                json.writeValue("r", drawable.tint.r);
                json.writeValue("g", drawable.tint.g);
                json.writeValue("b", drawable.tint.b);
                json.writeValue("a", drawable.tint.a);
                json.writeObjectEnd();
            } else if (drawable.tintName != null) {
                json.writeValue("color", drawable.tintName);
            }
            json.writeObjectEnd();
        }
        json.writeObjectEnd();
    }

    //styles
    Array<Array<StyleData>> valuesArray = classStyleMap.values().toArray();
    for (int i = 0; i < Main.STYLE_CLASSES.length; i++) {
        Class clazz = Main.STYLE_CLASSES[i];
        Array<StyleData> styles = valuesArray.get(i);

        //check if any style has the mandatory fields necessary to write
        boolean hasMandatoryStyles = true;
        for (StyleData style : styles) {
            if (!style.hasMandatoryFields() || style.hasAllNullFields()) {
                hasMandatoryStyles = false;
                break;
            }
        }

        if (hasMandatoryStyles) {
            json.writeObjectStart(clazz.getName());
            for (StyleData style : styles) {
                if (style.hasMandatoryFields() && !style.hasAllNullFields()) {
                    json.writeObjectStart(style.name);
                    for (StyleProperty property : style.properties.values()) {

                        //if not optional, null, or zero
                        if (!property.optional || property.value != null && !(property.value instanceof Number
                                && MathUtils.isZero((float) (double) property.value))) {
                            json.writeValue(property.name, property.value);
                        }
                    }
                    json.writeObjectEnd();
                }
            }
            json.writeObjectEnd();
        }
    }

    json.writeObjectEnd();
    fileHandle.writeString(json.prettyPrint(stringWriter.toString()), false);
}

From source file:com.ray3k.skincomposer.data.ProjectData.java

License:Open Source License

public void save(FileHandle file) {
    moveImportedFiles(saveFile, file);//from   w  w w  . ja va  2s .  c  o m

    saveFile = file;
    putRecentFile(file.path());
    Json json = new Json(JsonWriter.OutputType.minimal);
    json.setUsePrototypes(false);
    file.writeString(json.prettyPrint(this), false);
    setChangesSaved(true);
}

From source file:com.retrom.volcano.game.Settings.java

License:Apache License

public static void save() {
    try {/*from ww w  .j a  va2s  .c  o m*/
        FileHandle filehandle = Gdx.files.external(file);

        filehandle.writeString(Boolean.toString(soundEnabled.on()) + "\n", false);
        for (int i = 0; i < 5; i++) {
            filehandle.writeString(Integer.toString(highscores[i]) + "\n", true);
        }
    } catch (Throwable e) {
    }
}