List of usage examples for com.badlogic.gdx.utils Json toJson
public String toJson(Object object)
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.bladecoder.engine.model.World.java
License:Apache License
public void saveGameState(String filename) throws IOException { EngineLogger.debug("SAVING GAME STATE"); if (disposed) return;//from w ww. ja v a 2 s . c om 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;/*from w ww . j a v a 2 s . c o 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.flaiker.reaktio.servcies.PreferencesManager.java
License:Open Source License
public void addScoreEntry(ScoreEntry score) { Json json = new Json(); String string = getPreferences().getString(PREF_SCORE, null); ScoreArray scores;//from w w w . ja v a 2s . c om if (string == null) { scores = new ScoreArray(); scores.scores = new ScoreEntry[0]; } else scores = json.fromJson(ScoreArray.class, string); ArrayList<ScoreEntry> scoreList = new ArrayList<ScoreEntry>(Arrays.asList(scores.scores)); scoreList.add(score); scores.scores = scoreList.toArray(new ScoreEntry[scoreList.size()]); getPreferences().putString(PREF_SCORE, json.toJson(scores)); getPreferences().flush(); Gdx.app.log(LOG, "Added scoreentry"); }
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 a2 s .c o m // 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.o2d.pkayjava.editor.controller.commands.CopyItemsCommand.java
License:Apache License
public static String getJsonStringFromEntities(Set<Entity> entities) { CompositeVO holderComposite = new CompositeVO(); for (Entity entity : entities) { int entityType = ComponentRetriever.get(entity, MainItemComponent.class).entityType; if (entityType == EntityFactory.COMPOSITE_TYPE) { CompositeItemVO vo = new CompositeItemVO(); vo.loadFromEntity(entity);/*from w w w .j a v a 2 s . c o m*/ holderComposite.sComposites.add(vo); } if (entityType == EntityFactory.IMAGE_TYPE) { SimpleImageVO vo = new SimpleImageVO(); vo.loadFromEntity(entity); holderComposite.sImages.add(vo); } if (entityType == EntityFactory.NINE_PATCH) { Image9patchVO vo = new Image9patchVO(); vo.loadFromEntity(entity); holderComposite.sImage9patchs.add(vo); } if (entityType == EntityFactory.LABEL_TYPE) { LabelVO vo = new LabelVO(); vo.loadFromEntity(entity); holderComposite.sLabels.add(vo); } if (entityType == EntityFactory.PARTICLE_TYPE) { ParticleEffectVO vo = new ParticleEffectVO(); vo.loadFromEntity(entity); holderComposite.sParticleEffects.add(vo); } if (entityType == EntityFactory.SPRITE_TYPE) { SpriteAnimationVO vo = new SpriteAnimationVO(); vo.loadFromEntity(entity); holderComposite.sSpriteAnimations.add(vo); } if (entityType == EntityFactory.SPRITER_TYPE) { SpriterVO vo = new SpriterVO(); vo.loadFromEntity(entity); holderComposite.sSpriterAnimations.add(vo); } if (entityType == EntityFactory.SPINE_TYPE) { SpineVO vo = new SpineVO(); vo.loadFromEntity(entity); holderComposite.sSpineAnimations.add(vo); } if (entityType == EntityFactory.LIGHT_TYPE) { LightVO vo = new LightVO(); vo.loadFromEntity(entity); holderComposite.sLights.add(vo); } } Json json = new Json(); String result = json.toJson(holderComposite); return result; }
From source file:com.siondream.superjumper.systems.BobSystem.java
License:Apache License
private void sendLocation(float x, float y) { try {//from w w w . jav a2 s . c o m Json data = new Json(); String message = data.toJson(new Vector2(x, y)); WarpController.getInstance().sendGameUpdate(message); } catch (Exception e) { // exception in sendLocation } }
From source file:com.strategames.engine.storage.GameMetaData.java
License:Open Source License
public String getJson() { Json json = new Json(); json.setOutputType(OutputType.minimal); return json.toJson(this); }
From source file:com.strategames.engine.utils.Level.java
License:Open Source License
@Override public String getJson() { Json json = new Json(); json.setOutputType(OutputType.minimal); return json.toJson(this); }