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

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

Introduction

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

Prototype

public void writeObjectEnd() 

Source Link

Usage

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

License:Apache License

@Override
public void write(Json json) {
    SceneActorRef actorRef;//from w  w  w .  ja  v  a2s .c  o  m

    json.writeValue("visible", visible);
    ;

    json.writeObjectStart("items");
    for (SpriteActor a : items) {
        actorRef = new SceneActorRef(a.getInitScene(), a.getId());
        json.writeValue(actorRef.toString(), a);
    }
    json.writeObjectEnd();
}

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

License:Apache License

@Override
public void write(Json json) {
    if (SerializationHelper.getInstance().getMode() == Mode.MODEL) {

        json.writeValue("id", id);
        json.writeValue("layers", layers, layers.getClass(), SceneLayer.class);

        json.writeValue("actors", actors);

        if (backgroundAtlas != null) {
            json.writeValue("backgroundAtlas", backgroundAtlas);
            json.writeValue("backgroundRegionId", backgroundRegionId);
        }/*from   ww w. j ava 2 s.c om*/

        if (musicFilename != null) {
            json.writeValue("musicFilename", musicFilename);
            json.writeValue("loopMusic", loopMusic);
            json.writeValue("initialMusicDelay", initialMusicDelay);
            json.writeValue("repeatMusicDelay", repeatMusicDelay);
        }

        if (depthVector != null)
            json.writeValue("depthVector", depthVector);

        if (polygonalNavGraph != null)
            json.writeValue("polygonalNavGraph", polygonalNavGraph);

        if (sceneSize != null)
            json.writeValue("sceneSize", sceneSize);

    } else {
        SceneActorRef actorRef;

        json.writeObjectStart("actors");
        for (BaseActor a : actors.values()) {
            actorRef = new SceneActorRef(a.getInitScene(), a.getId());
            json.writeValue(actorRef.toString(), a);
        }
        json.writeObjectEnd();

        if (musicFilename != null) {
            json.writeValue("isPlaying", music != null && music.isPlaying());
            json.writeValue("musicPos", music != null && music.isPlaying() ? music.getPosition() : 0f);
        }

        json.writeValue("camera", camera);

        if (followActor != null)
            json.writeValue("followActor", followActor.getId());
    }

    verbs.write(json);

    if (state != null)
        json.writeValue("state", state);

    if (player != null)
        json.writeValue("player", player);
}

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 w ww  .  j a  v  a  2  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();/*from  ww w.  ja  v  a 2  s . c o m*/
    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.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 ww  w . j  a va2s .  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 {/*from  ww w.  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);/*from w  w  w .  j av  a 2  s  .  com*/
    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);/*from w w w  . j  a va2 s  .  c om*/
    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();//from ww  w . j a v a2s .c  om
            json.writeValue(COMPONENT_CLASS_KEY, component.getClass().getName());
            json.writeValue(COMPONENT_DATA_KEY, component, component.getClass());
            json.writeObjectEnd();
        }
    }
    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 w  w w.j  a v a  2 s.co 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();
}