Java Code Examples for com.badlogic.gdx.utils.Json
The following examples show how to use
com.badlogic.gdx.utils.Json. These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: gdx-fireapp Source File: JsonProcessor.java License: Apache License 2.0 | 6 votes |
static <R> R process(Class<?> wantedType, String jsonString) { Json json = new Json(); json.setIgnoreUnknownFields(true); json.setTypeName(null); R result = null; if (ClassReflection.isAssignableFrom(List.class, wantedType) || ClassReflection.isAssignableFrom(Map.class, wantedType)) { if (wantedType == List.class) { wantedType = ArrayList.class; } else if (wantedType == Map.class) { wantedType = HashMap.class; } json.setDefaultSerializer(new JsonListMapDeserializer(HashMap.class)); result = (R) json.fromJson(wantedType, jsonString); } else { result = (R) json.fromJson(wantedType, jsonString); } return result; }
Example 2
Source Project: gdx-gltf Source File: GLTFDemo.java License: Apache License 2.0 | 6 votes |
private void loadModelIndex() { rootFolder = Gdx.files.internal(samplesPath); String indexFilename = Gdx.app.getType() == ApplicationType.WebGL || Gdx.app.getType() == ApplicationType.Android ? "model-index-web.json" : "model-index.json"; FileHandle file = rootFolder.child(indexFilename); entries = new Json().fromJson(Array.class, ModelEntry.class, file); ui.entrySelector.setItems(entries); if(AUTOLOAD_ENTRY != null && AUTOLOAD_VARIANT != null){ for(int i=0 ; i<entries.size ; i++){ ModelEntry entry = entries.get(i); if(entry.name.equals(AUTOLOAD_ENTRY)){ ui.entrySelector.setSelected(entry); // will be auto select if there is only one variant. if(entry.variants.size != 1){ ui.variantSelector.setSelected(AUTOLOAD_VARIANT); } break; } } } }
Example 3
Source Project: artemis-odb-orion Source File: InterpolationSerializer.java License: Apache License 2.0 | 6 votes |
public static void registerAll(Json backend) { backend.setSerializer(Interpolation.Pow.class, new PowSerializer()); backend.setSerializer(Interpolation.PowIn.class, new PowInSerializer()); backend.setSerializer(Interpolation.PowOut.class, new PowOutSerializer()); backend.setSerializer(Interpolation.Exp.class, new ExpSerializer()); backend.setSerializer(Interpolation.ExpIn.class, new ExpInSerializer()); backend.setSerializer(Interpolation.ExpOut.class, new ExpOutSerializer()); backend.setSerializer(Interpolation.Elastic.class, new ElasticSerializer()); backend.setSerializer(Interpolation.ElasticIn.class, new ElasticInSerializer()); backend.setSerializer(Interpolation.ElasticOut.class, new ElasticOutSerializer()); backend.setSerializer(Interpolation.Bounce.class, new BounceSerializer()); backend.setSerializer(Interpolation.BounceIn.class, new BounceInSerializer()); backend.setSerializer(Interpolation.BounceOut.class, new BounceOutSerializer()); backend.setSerializer(Interpolation.Swing.class, new SwingSerializer()); backend.setSerializer(Interpolation.SwingIn.class, new SwingInSerializer()); backend.setSerializer(Interpolation.SwingOut.class, new SwingOutSerializer()); }
Example 4
Source Project: bladecoder-adventure-engine Source File: AnimationRenderer.java License: Apache License 2.0 | 6 votes |
@Override public void read(Json json, JsonValue jsonData) { BladeJson bjson = (BladeJson) json; if (bjson.getMode() == Mode.MODEL) { // In next versions, the fanims loading will be generic // fanims = json.readValue("fanims", HashMap.class, AnimationDesc.class, // jsonData); initAnimation = json.readValue("initAnimation", String.class, jsonData); orgAlign = json.readValue("orgAlign", int.class, Align.bottom, jsonData); } else { String currentAnimationId = json.readValue("currentAnimation", String.class, jsonData); if (currentAnimationId != null) currentAnimation = fanims.get(currentAnimationId); flipX = json.readValue("flipX", Boolean.class, jsonData); } }
Example 5
Source Project: beatoraja Source File: Config.java License: GNU General Public License v3.0 | 6 votes |
public static Config read() { Config config = null; if (Files.exists(MainController.configpath)) { Json json = new Json(); json.setIgnoreUnknownFields(true); try (FileReader reader = new FileReader(MainController.configpath.toFile())) { config = json.fromJson(Config.class, reader); } catch (Exception e) { e.printStackTrace(); } } if(config == null) { config = new Config(); } config.validate(); PlayerConfig.init(config); return config; }
Example 6
Source Project: FruitCatcher Source File: HighScoreManager.java License: Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private void retrieveHighScores() { FileHandle highScoresFile = Gdx.files.local(SCORES_DATA_FILE); if( highScoresFile.exists() ) { Json json = new Json(); try { String encScoresStr = highScoresFile.readString(); String scoresStr = Base64Coder.decodeString( encScoresStr ); highScores = json.fromJson(ArrayList.class, HighScore.class, scoresStr); return; } catch( Exception e ) { Gdx.app.error( HighScoreManager.class.getName(), "Unable to parse high scores data file", e ); } } highScores = new ArrayList<HighScore>(); String playerName = textResources.getDefaultPlayerName(); for(int i=0;i<HIGH_SCORES_COUNT;i++){ highScores.add(new HighScore(playerName, 50 - 10*i, false)); } }
Example 7
Source Project: bladecoder-adventure-engine Source File: Text.java License: Apache License 2.0 | 6 votes |
@Override public void write(Json json) { json.writeValue("str", str); json.writeValue("x", x); json.writeValue("y", y); json.writeValue("time", time); json.writeValue("type", type); json.writeValue("color", color); json.writeValue("style", style); json.writeValue("actorId", actorId); json.writeValue("voiceId", voiceId); json.writeValue("animation", animation); if (cb != null) { World w = ((BladeJson) json).getWorld(); Scene s = ((BladeJson) json).getScene(); json.writeValue("cb", ActionCallbackSerializer.find(w, s, cb)); } }
Example 8
Source Project: bladecoder-adventure-engine Source File: DialogOption.java License: Apache License 2.0 | 6 votes |
@Override public void write(Json json) { BladeJson bjson = (BladeJson) json; if (bjson.getMode() == Mode.MODEL) { json.writeValue("text", text); json.writeValue("responseText", responseText); json.writeValue("verbId", verbId); json.writeValue("next", next); json.writeValue("once", once); json.writeValue("soundId", voiceId); json.writeValue("responseSoundId", responseVoiceId); } else { } json.writeValue("visible", visible); }
Example 9
Source Project: bladecoder-adventure-engine Source File: Text.java License: Apache License 2.0 | 6 votes |
@Override public void read(Json json, JsonValue jsonData) { str = json.readValue("str", String.class, jsonData); x = json.readValue("x", Float.class, jsonData); y = json.readValue("y", Float.class, jsonData); time = json.readValue("time", Float.class, jsonData); type = json.readValue("type", Type.class, jsonData); color = json.readValue("color", Color.class, jsonData); style = json.readValue("style", String.class, jsonData); actorId = json.readValue("actorId", String.class, jsonData); voiceId = json.readValue("voiceId", String.class, jsonData); animation = json.readValue("animation", String.class, jsonData); BladeJson bjson = (BladeJson) json; cb = ActionCallbackSerializer.find(bjson.getWorld(), bjson.getScene(), json.readValue("cb", String.class, jsonData)); }
Example 10
Source Project: bladecoder-adventure-engine Source File: DisableActionAction.java License: Apache License 2.0 | 5 votes |
public Action getAction() { if(action == null) { Json json = new Json(); JsonValue root = new JsonReader().parse(serializedAction); action = ActionUtils.readJson(w, json, root); } return action; }
Example 11
Source Project: bladecoder-adventure-engine Source File: AtlasRenderer.java License: Apache License 2.0 | 5 votes |
@Override public void write(Json json) { super.write(json); BladeJson bjson = (BladeJson) json; if (bjson.getMode() == Mode.MODEL) { } else { json.writeValue("currentFrameIndex", currentFrameIndex); if (faTween != null) json.writeValue("faTween", faTween); } }
Example 12
Source Project: bladecoder-adventure-engine Source File: InteractiveActor.java License: Apache License 2.0 | 5 votes |
@Override public void write(Json json) { super.write(json); BladeJson bjson = (BladeJson) json; if (bjson.getMode() == Mode.MODEL) { if (desc != null) json.writeValue("desc", desc); if (state != null) json.writeValue("state", state); float worldScale = EngineAssetManager.getInstance().getScale(); json.writeValue("refPoint", new Vector2(getRefPoint().x / worldScale, getRefPoint().y / worldScale)); } else { json.writeValue("playerInside", playerInside); if (isDirty(DirtyProps.DESC)) json.writeValue("desc", desc); if (isDirty(DirtyProps.STATE)) json.writeValue("state", state); } verbs.write(json); if (bjson.getMode() == Mode.MODEL || isDirty(DirtyProps.INTERACTION)) json.writeValue("interaction", interaction); if (bjson.getMode() == Mode.MODEL || isDirty(DirtyProps.ZINDEX)) json.writeValue("zIndex", zIndex); if (bjson.getMode() == Mode.MODEL || isDirty(DirtyProps.LAYER)) json.writeValue("layer", layer); }
Example 13
Source Project: bladecoder-adventure-engine Source File: SpriteScaleTween.java License: Apache License 2.0 | 5 votes |
@Override public void read(Json json, JsonValue jsonData) { super.read(json, jsonData); startSclX = json.readValue("startSclX", Float.class, jsonData); startSclY = json.readValue("startSclY", Float.class, jsonData); targetSclX = json.readValue("targetSclX", Float.class, jsonData); targetSclY = json.readValue("targetSclY", Float.class, jsonData); }
Example 14
Source Project: bladecoder-adventure-engine Source File: Recorder.java License: Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public void load() { String gameStateFileName = fileName + GAMESTATE_REC_EXT; String recordFileName = fileName + RECORD_EXT; FileHandle verbsFile = EngineAssetManager.getInstance().getUserFile(recordFileName); if (!verbsFile.exists()) verbsFile = EngineAssetManager.getInstance().getAsset("tests/" + recordFileName); if (verbsFile.exists()) { // LOAD GAME STATE IF EXISTS FileHandle gameStateFile = EngineAssetManager.getInstance().getUserFile(gameStateFileName); if (!gameStateFile.exists()) gameStateFile = EngineAssetManager.getInstance().getAsset("tests/" + gameStateFileName); if (gameStateFile.exists()) try { w.getSerializer().loadGameState(gameStateFile); } catch (IOException e) { EngineLogger.error(e.getMessage()); } else EngineLogger.debug("LOADING RECORD: no saved file exists"); // LOAD VERBS list = new Json().fromJson(ArrayList.class, TimeVerb.class, verbsFile.reader("UTF-8")); } else { EngineLogger.error("LOADING RECORD: no record file exists"); } }
Example 15
Source Project: talos Source File: FlipbookModule.java License: Apache License 2.0 | 5 votes |
@Override public void write (Json json) { super.write(json); json.writeValue("regionName", regionName); json.writeValue("rows", rows); json.writeValue("cols", cols); json.writeValue("duration", duration); }
Example 16
Source Project: talos Source File: EmitterModule.java License: Apache License 2.0 | 5 votes |
@Override public void write (Json json) { super.write(json); json.writeValue("delay", defaultDelay); json.writeValue("duration", defaultDuration); json.writeValue("rate", defaultRate); }
Example 17
Source Project: bladecoder-adventure-engine Source File: MusicVolumeTween.java License: Apache License 2.0 | 5 votes |
@Override public void write(Json json) { super.write(json); json.writeValue("startVolume", startVolume); json.writeValue("targetVolume", targetVolume); }
Example 18
Source Project: talos Source File: DynamicRangeModule.java License: Apache License 2.0 | 5 votes |
@Override public void write (Json json) { super.write(json); json.writeValue("lowMin", lowMin, float.class); json.writeValue("lowMax", lowMax, float.class); json.writeValue("highMin", highMin, float.class); json.writeValue("highMax", highMax, float.class); }
Example 19
Source Project: talos Source File: DynamicRangeModule.java License: Apache License 2.0 | 5 votes |
@Override public void read (Json json, JsonValue jsonData) { super.read(json, jsonData); lowMin = jsonData.getFloat("lowMin"); lowMax = jsonData.getFloat("lowMax"); highMin = jsonData.getFloat("highMin"); highMax = jsonData.getFloat("highMax"); }
Example 20
Source Project: Norii Source File: AITeamFileReader.java License: Apache License 2.0 | 5 votes |
public static void loadLevelsInMemory() { if (!statsLoaded) { final Json json = new Json(); final AITeamData[] aiTeamStats = json.fromJson(AITeamData[].class, Gdx.files.internal(LEVELS_FILE_LOCATION)); for (int i = 0; i < aiTeamStats.length; i++) { final AITeamData data = aiTeamStats[i]; aiTeamData.put(data.getId(), data); } statsLoaded = true; } }
Example 21
Source Project: RuinsOfRevenge Source File: JsonDOM.java License: MIT License | 5 votes |
public void writeJsonArray(JsonArray array, Json json) { for (JsonObject obj : array.elements) { json.writeObjectStart(); writeJsonObject(obj, json); json.writeObjectEnd(); } }
Example 22
Source Project: gdx-fireapp Source File: JsonDataModifier.java License: Apache License 2.0 | 5 votes |
/** * Returns modified json data. * * @param oldJsonData Old data as json string. * @return New data as json string */ @SuppressWarnings("unchecked") public String modify(String oldJsonData) { T oldData = JsonProcessor.process(wantedType, oldJsonData); T newData = (T) transactionFunction.apply(oldData); Json json = new Json(); json.setTypeName(null); json.setQuoteLongValues(true); json.setIgnoreUnknownFields(true); json.setOutputType(JsonWriter.OutputType.json); return json.toJson(newData, wantedType); }
Example 23
Source Project: Entitas-Java Source File: Level.java License: MIT License | 5 votes |
@Override public void read(Json json, JsonValue jsonData) { map = json.readValue("map", String.class, jsonData); levelName = json.readValue("levelName", String.class, jsonData); description = json.readValue("description", String.class, jsonData); music = json.readValue("music", String.class, jsonData); active = json.readValue("active", Boolean.class, jsonData); achievements = json.readValue("achievements", Integer.class, jsonData); highScore = json.readValue("highScore", Integer.class, jsonData); num = json.readValue("num", Integer.class, jsonData); }
Example 24
Source Project: gdx-fireapp Source File: NSDictionaryHelper.java License: Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") static NSDictionary toNSDictionary(Object object) { if (object instanceof Map) { return toNSDictionary((Map) object); } else { String objectJsonData = new Json().toJson(object); Json json = new Json(); json.setIgnoreUnknownFields(true); Map objectMap = json.fromJson(HashMap.class, objectJsonData); return toNSDictionary(objectMap); } }
Example 25
Source Project: gdx-proto Source File: Recorder.java License: Apache License 2.0 | 5 votes |
private void writeJson() { Json json = new Json(); String data = json.toJson(history); FileHandle fh = Gdx.files.external(demoDir + "history.json.gz"); byte[] bytes = Compression.writeCompressedString(data); if (bytes == null) { Log.error("Could not write compressed playback (JSON)"); } else { int byteCount = bytes.length; fh.writeBytes(bytes, false); Log.debug("Wrote compressed playback: " + byteCount + " bytes"); } }
Example 26
Source Project: skin-composer Source File: FontData.java License: MIT License | 5 votes |
@Override public void write(Json json) { json.writeValue("name", name); if (file != null) { json.writeValue("file", file.path()); } else { json.writeValue("file", (String) null); } }
Example 27
Source Project: skin-composer Source File: CustomStyle.java License: MIT License | 5 votes |
@Override public void read(Json json, JsonValue jsonData) { name = jsonData.getString("name"); properties = json.readValue("properties", Array.class, CustomProperty.class, jsonData); for (CustomProperty property : properties) { property.setParentStyle(this); } deletable = jsonData.getBoolean("deletable"); }
Example 28
Source Project: gdx-gltf Source File: GLTFMorphTarget.java License: Apache License 2.0 | 5 votes |
@Override public void read(Json json, JsonValue jsonData) { for(JsonIterator i = jsonData.iterator(); i.hasNext() ; ){ JsonValue e = i.next(); put(e.name, e.asInt()); } }
Example 29
Source Project: FruitCatcher Source File: StateManager.java License: Apache License 2.0 | 5 votes |
public StateBundle retrieveState() { FileHandle stateDataFile = Gdx.files.local(STATE_DATA_FILE); if( stateDataFile.exists() ) { Json json = new Json(); try { String stateStr = stateDataFile.readString(); return json.fromJson(StateBundle.class, stateStr ); } catch( Exception e ) { Gdx.app.error( "StateManager", "Unable to parse existing game screen state data file", e ); } } return null; }
Example 30
Source Project: talos Source File: GradientColorModule.java License: Apache License 2.0 | 5 votes |
@Override public void write (Json json) { super.write(json); Array<ColorPoint> points = getPoints(); json.writeArrayStart("points"); for (ColorPoint point : points) { json.writeObjectStart(); json.writeValue("r", point.color.r); json.writeValue("g", point.color.g); json.writeValue("b", point.color.b); json.writeValue("pos", point.pos); json.writeObjectEnd(); } json.writeArrayEnd(); }