List of usage examples for com.badlogic.gdx.utils Json getWriter
public JsonWriter getWriter()
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 a v a 2 s. co 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 . jav a 2s .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.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 www . ja v a2 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.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(); } }