Example usage for com.badlogic.gdx.utils Json prettyPrint

List of usage examples for com.badlogic.gdx.utils Json prettyPrint

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils Json prettyPrint.

Prototype

public String prettyPrint(String json) 

Source Link

Usage

From source file:com.bladecoder.engine.model.World.java

License:Apache License

public void saveWorldDesc(FileHandle file) throws IOException {

    float scale = EngineAssetManager.getInstance().getScale();

    Json json = new Json();
    json.setOutputType(OutputType.javascript);

    SerializationHelper.getInstance().setMode(Mode.MODEL);

    json.setWriter(new StringWriter());

    json.writeObjectStart();// w w w.j av a 2s. c om
    json.writeValue("width", width / scale);
    json.writeValue("height", height / scale);
    json.writeValue("initChapter", initChapter);
    verbs.write(json);
    json.writeObjectEnd();

    String s = null;

    if (EngineLogger.debugMode())
        s = json.prettyPrint(json.getWriter().getWriter().toString());
    else
        s = json.getWriter().getWriter().toString();

    Writer w = file.writer(false, "UTF-8");
    w.write(s);
    w.close();
}

From source file:com.bladecoder.engine.model.World.java

License:Apache License

public void saveGameState(String filename) throws IOException {
    EngineLogger.debug("SAVING GAME STATE");

    if (disposed)
        return;/*ww w.j  a v  a 2s .c  o m*/

    Json json = new Json();
    json.setOutputType(OutputType.javascript);

    String s = null;

    SerializationHelper.getInstance().setMode(Mode.STATE);

    if (EngineLogger.debugMode())
        s = json.prettyPrint(this);
    else
        s = json.toJson(this);

    Writer w = EngineAssetManager.getInstance().getUserFile(filename).writer(false, "UTF-8");

    try {
        w.write(s);
        w.close();
    } catch (IOException e) {
        throw new IOException("ERROR SAVING GAME", e);
    }

    // Save Screenshot
    takeScreenshot(filename + ".png", SCREENSHOT_DEFAULT_WIDTH);
}

From source file:com.bladecoder.engine.model.World.java

License:Apache License

public void saveModel(String chapterId) throws IOException {
    EngineLogger.debug("SAVING GAME MODEL");

    if (disposed)
        return;/*w w w.  j  a va  2  s  . co m*/

    Json json = new Json();
    json.setOutputType(OutputType.javascript);

    String s = null;

    SerializationHelper.getInstance().setMode(Mode.MODEL);

    if (EngineLogger.debugMode())
        s = json.prettyPrint(this);
    else
        s = json.toJson(this);

    Writer w = EngineAssetManager.getInstance().getModelFile(chapterId + EngineAssetManager.CHAPTER_EXT)
            .writer(false, "UTF-8");

    try {
        w.write(s);
        w.close();
    } catch (IOException e) {
        throw new IOException("ERROR SAVING MODEL", e);
    }
}

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

private void generateNewAnimationInfo(Json json) {
    rootContent.foreachFilesInContentDirectoriesExec(new FileExec() {
        @Override/*w w w  .j  ava 2 s .co m*/
        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();
            }
        }
    });
}

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

private void createAnimationOutput(Json json) {
    for (String groupTagName : mapGroupTagResource.keySet()) {
        GroupTag groupTag = mapGroupTagResource.get(groupTagName);

        String outputApInfo = API_INFO_OUTPUT + groupTag.getName() + "." + API_EXTENSION;
        String outputTexture = TEXTURE_OUTPUT + groupTag.getName() + "." + TEXTURE_EXTENSION;
        groupTag.setTextureOutput(outputTexture);

        // Write Animation Pack Info
        AnimationPackInfo api = groupTag.createAnimationPackInfo();
        String toWrite = (PRETTY_PRINT ? json.prettyPrint(api) : json.toJson(api, AnimationPackInfo.class));
        if (ENCODED)
            toWrite = new String(Base64.getEncoder().encode(toWrite.getBytes()));
        getFileHandle(outputApInfo).writeString(toWrite, false);

        // Write Texture file
        PixmapIO.writePNG(files.local(outputTexture), groupTag.getPixmap());

        System.out.println("GROUP TAG: " + groupTagName);
        System.out.println("  " + outputApInfo);
        System.out.println("  " + outputTexture);
    }//from  w w w .j a  v  a2s.c  o  m
}

From source file:com.maplescot.loggerbill.misc.Profile.java

License:Creative Commons License

public byte[] serialize() {
    ckSum = makeCkSum();//  ww  w . j  av  a 2 s. co m
    ckSumV = ckVersion;
    Json json = new Json();

    String out = json.prettyPrint(this);

    Gdx.app.debug(TAG, out);
    return out.getBytes();
}

From source file:com.mbrlabs.mundus.core.RuntimeExporter.java

License:Apache License

public static void export(KryoManager kryoManager, ProjectContext projectContext, FileHandle destFolder,
        boolean prettyPrint) throws IOException {
    ProjectDTO dto = new ProjectDTO();
    dto.setName(projectContext.name);//from   w ww.  j  a  v a 2  s.c  om

    // models
    ModelDTO[] models = new ModelDTO[projectContext.models.size];
    for (int i = 0; i < models.length; i++) {
        models[i] = convert(projectContext.models.get(i));
    }
    dto.setModels(models);

    // terrains
    TerrainDTO[] terrains = new TerrainDTO[projectContext.terrains.size];
    for (int i = 0; i < terrains.length; i++) {
        terrains[i] = convert(projectContext.terrains.get(i));
    }
    dto.setTerrains(terrains);

    // textures
    TextureDTO[] textures = new TextureDTO[projectContext.textures.size];
    for (int i = 0; i < textures.length; i++) {
        textures[i] = convert(projectContext.textures.get(i));
    }
    dto.setTextures(textures);

    // scenes
    SceneDTO[] scenes = new SceneDTO[projectContext.scenes.size];
    for (int i = 0; i < scenes.length; i++) {
        String name = projectContext.scenes.get(i);
        Scene scene = DescriptorConverter.convert(kryoManager.loadScene(projectContext, name),
                projectContext.terrains, projectContext.models);
        scenes[i] = convert(scene);
    }
    dto.setScenes(scenes);

    // write JSON
    if (!destFolder.exists()) {
        destFolder.mkdirs();
    }
    FileHandle jsonOutput = Gdx.files.absolute(FilenameUtils.concat(destFolder.path(), "mundus"));
    OutputStream outputStream = new FileOutputStream(jsonOutput.path());
    Json json = new Json();
    json.setOutputType(JsonWriter.OutputType.json);
    String output = prettyPrint ? json.prettyPrint(dto) : json.toJson(dto);
    IOUtils.write(output, outputStream);

    // copy assets
    FileHandle assetOutput = Gdx.files.absolute(FilenameUtils.concat(destFolder.path(), "assets"));
    Gdx.files.absolute(FilenameUtils.concat(projectContext.path, "assets")).copyTo(assetOutput);
}

From source file:com.nsoft.boxuniverse.misc.BaseSound.java

License:Open Source License

/**
 * Load all the sounds definitions from Sounds.list
 *///from ww w .j  a  v a  2s .  c  o m
public static void loadSounds() {

    try {

        Json a = new Json();
        soundslist = a.fromJson(ArrayList.class,
                Gdx.files.internal("com/nsoft/boxuniverse/resources/Sounds.list"));

        for (SoundDefinition soundDefinition : soundslist)

            sounds.put(soundDefinition.SoundName, soundDefinition);
        System.out.println(a.prettyPrint(soundslist));
    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:com.o2d.pkayjava.editor.data.vo.EditorConfigVO.java

License:Apache License

public String constructJsonString() {
    String str = "";
    Json json = new Json();
    json.setOutputType(JsonWriter.OutputType.json);
    str = json.prettyPrint(this);
    return str;/*w ww .j a v  a 2s  . c  o  m*/
}

From source file:com.o2d.pkayjava.editor.data.vo.ProjectVO.java

License:Apache License

public String constructJsonString() {
    String str = "";
    Json json = new Json();
    json.setOutputType(OutputType.json);
    str = json.prettyPrint(this);
    return str;//from  www .  ja  va 2 s .co m
}