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

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

Introduction

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

Prototype

public void writeObjectStart() 

Source Link

Usage

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

License:Apache License

@Override
public void write(Json json) {

    if (SerializationHelper.getInstance().getMode() == Mode.MODEL) {
        json.writeValue("id", id);
        json.writeValue("target", target);
        json.writeValue("state", state);
        json.writeValue("icon", icon);
        json.writeArrayStart("actions");
        for (Action a : actions) {
            ActionUtils.writeJson(a, json);
        }//from   ww w.j a v a2 s  .  c  om
        json.writeArrayEnd();
    } else {
        json.writeValue("ip", ip);

        json.writeArrayStart("actions");
        for (Action a : actions) {
            if (a instanceof Serializable) {
                json.writeObjectStart();
                ((Serializable) a).write(json);
                json.writeObjectEnd();
            }
        }
        json.writeArrayEnd();
    }
}

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();
    json.writeValue("width", width / scale);
    json.writeValue("height", height / scale);
    json.writeValue("initChapter", initChapter);
    verbs.write(json);/*from w w  w  .ja  v a 2  s. c  o  m*/
    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.github.fauu.helix.manager.AreaManager.java

License:Open Source License

public void create(String name, int width, int length) {
    Json json = new Json();

    IntVector2 dimensions = new IntVector2(width, length);

    FileHandle file = Gdx.files.internal("area/" + name + ".json");

    try {/*from  w ww.  j a v  a 2  s  . co m*/
        json.setWriter(new JsonWriter(new FileWriter(file.file())));
    } catch (IOException e) {
        e.printStackTrace();
    }

    json.writeObjectStart();
    json.writeValue("width", dimensions.x);
    json.writeValue("length", dimensions.y);
    json.writeArrayStart("tiles");
    for (int y = 0; y < dimensions.y; y++) {
        for (int x = 0; x < dimensions.x; x++) {
            json.writeObjectStart();
            json.writeValue("permissions", TilePermission.LEVEL0.toString());
            json.writeObjectEnd();
        }
    }
    json.writeArrayEnd();
    json.writeObjectEnd();

    try {
        json.getWriter().close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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

License:Open Source License

public void save() {
    Json json = new Json();

    String name = nameMapper.get(area).get();

    FileHandle file = Gdx.files.internal("area/" + name + ".json");

    IntVector2 dimensions = dimensionsMapper.get(area).get();

    AreaType type = areaTypeMapper.get(area).get();

    try {/* www.ja v a  2  s.c  o  m*/
        json.setWriter(new JsonWriter(new FileWriter(file.file())));
    } catch (IOException e) {
        e.printStackTrace();
    }

    json.writeObjectStart();
    json.writeValue("width", dimensions.x);
    json.writeValue("length", dimensions.y);
    json.writeValue("type", type);
    json.writeArrayStart("tiles");
    Tile[][] tiles = tilesMapper.get(area).get();
    for (int y = 0; y < dimensions.y; y++) {
        for (int x = 0; x < dimensions.x; x++) {
            Tile tile = tiles[y][x];

            json.writeObjectStart();

            json.writeValue("permissions", tile.getPermissions().toString());

            if (tile.getAreaPassage() != null) {
                TileAreaPassage passage = tile.getAreaPassage();

                json.writeObjectStart("passage");

                json.writeValue("area", passage.getTargetAreaName());

                json.writeObjectStart("position");
                json.writeValue("x", passage.getTargetCoords().x);
                json.writeValue("y", passage.getTargetCoords().y);
                json.writeObjectEnd();

                json.writeObjectEnd();
            }

            json.writeObjectEnd();
        }
    }
    json.writeArrayEnd();
    json.writeObjectEnd();

    try {
        json.getWriter().close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.jupiter.europa.entity.component.EffectsComponent.java

License:Open Source License

@Override
public void write(Json json) {
    json.writeArrayStart(EFFECTS_KEY);// w  w w .java  2s  .co m
    this.effects.stream().forEach((Effect effect) -> {
        json.writeObjectStart();
        json.writeValue(EFFECT_CLASS_KEY, effect.getClass().getName());
        json.writeValue(EFFECT_DATA_KEY, effect, effect.getClass());
        json.writeObjectEnd();
    });
    json.writeArrayEnd();
}

From source file:com.jupiter.europa.entity.effects.MultiEffect.java

License:Open Source License

@Override
public void write(Json json) {
    json.writeArrayStart(EFFECTS_KEY);//  w  ww.  jav  a  2s . c o m
    for (Effect effect : this.effects) {
        json.writeObjectStart();
        json.writeValue(EFFECT_CLASS_KEY, effect.getClass().getName());
        json.writeValue(EFFECT_DATA_KEY, effect, effect.getClass());
        json.writeObjectEnd();
    }
    json.writeArrayEnd();
}

From source file:com.jupiter.europa.entity.EuropaEntity.java

License:Open Source License

@Override
public void write(Json json) {
    json.writeValue(OLD_ID_KEY, this.getId());

    json.writeArrayStart(COMPONENTS_KEY);
    for (Component component : this.getComponents()) {
        if (component instanceof Serializable) {
            json.writeObjectStart();
            json.writeValue(COMPONENT_CLASS_KEY, component.getClass().getName());
            json.writeValue(COMPONENT_DATA_KEY, component, component.getClass());
            json.writeObjectEnd();/*w w w  . jav a 2s .  co  m*/
        }
    }
    json.writeArrayEnd();
}

From source file:com.jupiter.europa.entity.trait.TraitPool.java

License:Open Source License

@Override
public void write(Json json) {
    json.writeValue(CAPACITY_KEY, this.capacity);

    json.writeArrayStart(SELECTED_KEY);/*from  ww w.j  a va 2  s.c o  m*/
    this.selected.stream().forEach((T item) -> {
        json.writeObjectStart();
        json.writeValue(ITEM_CLASS_KEY, item.getClass().getName());
        json.writeValue(ITEM_DATA_KEY, item, item.getClass());
        json.writeObjectEnd();
    });
    json.writeArrayEnd();
}

From source file:com.kotcrab.vis.runtime.scene.IntMapJsonSerializer.java

License:Apache License

@Override
public void write(Json json, IntMap object, Class knownType) {
    json.writeObjectStart();

    for (IntMap.Entry entry : (IntMap.Entries<?>) object.entries()) {
        json.writeValue(String.valueOf(entry.key), entry.value, null);
    }/*from  w ww .j a  v  a2 s  .c o m*/

    json.writeObjectEnd();
}

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();
    for (Class<? extends Object> resType : saveResoureTypes) {
        ObjectMap<String, ? extends Object> typeResources = super.getAll(resType);
        if (emptyMap(typeResources)) {
            continue;
        }/*w w w . j ava2s. c o  m*/
        //  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;
}