public RubeSceneLoader(World world, Json gameJson) { json = gameJson; json.setTypeName(null); json.setUsePrototypes(false); json.setSerializer(RubeScene.class, mRubeWorldSerializer = new RubeWorldSerializer(json)); mWorld = world; }
@Override public void write(Json json) { json.writeValue("currentLevelId", currentLevelId); json.writeValue("credits", credits); json.writeValue("highScores", highScores); json.writeValue("coon", coon); }
public static Weapon load(String id) { Weapon w; Json j = new Json(OutputType.json); w = j.fromJson(Weapon.class, Gdx.files.internal("core/assets/json/weapons/" + id + ".json")); w.weaponID = id; return w; }
@SuppressWarnings("unchecked") public Map<?, ?> read(Json json, JsonValue jsonData) { Map<K, V> values; try { values = (Map<K, V>) map.map().newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new GdxRuntimeException(e); } JsonValue entry = jsonData.getChild(name); while (entry != null) { JsonValue keyValue = entry.get("key"); K key = json.readValue((Class<K>) map.key(), keyValue); JsonValue valueValue = entry.get("value"); V value = json.readValue((Class<V>) map.value(), valueValue); values.put(key, value); entry = entry.next; } return values; }
@Override public void write(Json json, PolygonCentroid object, Class knownType) { json.writeObjectStart(); json.writeValue("x", object.x); json.writeValue("y", object.y); json.writeObjectEnd(); }
@Override public void write(Json json) { json.writeValue("previousFA", previousAnim); json.writeValue("responseText", responseText); json.writeValue("characterTurn", characterTurn); json.writeValue("characterName", characterName); super.write(json); }
@Override public void read(Json json, JsonValue jsonData) { userEmail = json.readValue("user_email", String.class, jsonData); if (userEmail == null) userEmail = ""; userPassword = json.readValue("user_password", String.class, jsonData); if (userPassword == null) userPassword = ""; }
public String constructJsonString() { String str = ""; Json json = new Json(); json.setOutputType(OutputType.json); str = json.toJson(this); json.prettyPrint(str); return str; }
@Override public void read(Json json, JsonValue jsonData) { previousAnim = json.readValue("previousFA", String.class, jsonData); responseText = json.readValue("responseText", String.class, jsonData); characterTurn = json.readValue("characterTurn", Boolean.class, jsonData); characterName = json.readValue("characterName", String.class, jsonData); super.read(json, jsonData); }
@Override public void read(Json json, JsonValue jsonData) { actorId = json.readValue("actorId", String.class, jsonData); ip = json.readValue("ip", Integer.class, jsonData); verb = json.readValue("verb", String.class, jsonData); target = json.readValue("target", String.class, jsonData); state = json.readValue("state", String.class, jsonData); super.read(json, jsonData); }
@Override public void write(Json json) { json.writeValue(JsonKey.X, position.x); json.writeValue(JsonKey.Y, position.y); json.writeValue(JsonKey.Z, position.z); json.writeValue(JsonKey.YAW, eulerAngles.x); json.writeValue(JsonKey.PITCH, eulerAngles.y); json.writeValue(JsonKey.ROLL, eulerAngles.z); }
@Override public SceneVO getSceneVO(String name) { SceneDataManager sceneDataManager = facade.retrieveProxy(SceneDataManager.NAME); // TODO: this should be cached FileHandle file = Gdx.files.internal(sceneDataManager.getCurrProjectScenePathByName(name)); Json json = new Json(); json.setIgnoreUnknownFields(true); return json.fromJson(SceneVO.class, file.readString()); }
@Override public void write(Json json) { json.writeValue("actorId", actorId); json.writeValue("ip", ip); json.writeValue("verb", verb); json.writeValue("target", target); json.writeValue("state", state); super.write(json); }
@Override public IntMap read(Json json, JsonValue jsonData, Class type) { IntMap intMap = new IntMap(json.readValue(VALUE_SIZE, int.class, jsonData)); for (JsonValue entry = jsonData.getChild(VALUE_ENTRIES); entry != null; entry = entry.next) { intMap.put(Integer.parseInt(entry.name), json.readValue(entry.name, null, jsonData)); } return intMap; }
public RMESettings(FileHandle file) { keys = new ObjectMap<String, int[]>(); keys.put("left", new int[] {Keys.A, Keys.LEFT}); keys.put("up", new int[] {Keys.W, Keys.UP}); keys.put("right", new int[] {Keys.D, Keys.RIGHT}); keys.put("down", new int[] {Keys.S, Keys.DOWN}); Json json = new Json(); json.toJson(this, file); }
@Override public void write(Json json) { super.write(json); json.writeValue("path", walkingPath); json.writeValue("currentStep", currentStep); json.writeValue("speed", speed); json.writeValue( "walkCb", ActionCallbackSerialization.find(walkCb), walkCb == null ? null : String.class); }
@Override public void undoAction() { Json json = new Json(); CompositeVO compositeVO = json.fromJson(CompositeVO.class, backup); Set<Entity> newEntitiesList = PasteItemsCommand.createEntitiesFromVO(compositeVO); for (Entity entity : newEntitiesList) { Overlap2DFacade.getInstance().sendNotification(ItemFactory.NEW_ITEM_ADDED, entity); } sandbox.getSelector().setSelections(newEntitiesList, true); }
@SuppressWarnings("unchecked") @Override public void read(Json json, JsonValue jsonData) { super.read(json, jsonData); walkingPath = json.readValue("path", ArrayList.class, Vector2.class, jsonData); currentStep = json.readValue("currentStep", Integer.class, jsonData); speed = json.readValue("speed", Float.class, jsonData); String walkCbSer = json.readValue("walkCb", String.class, jsonData); walkCb = ActionCallbackSerialization.find(walkCbSer); }
@Override public void saveStatistics(es.danirod.rectball.model.Statistics statistics) { Json json = new Json(); json.setOutputType(JsonWriter.OutputType.json); String jsonData = json.toJson(statistics); // Encode statistics in Base64 and save it to a file. String encodedJson = Base64Coder.encodeString(jsonData); FileHandle handle; handle = getStatistics(); handle.writeString(encodedJson, false); }
@Override public Vector2 read(Json json, JsonValue jsonData, Class type) { Vector2 vector = new Vector2(0.0f, 0.0f); try { json.readValue(float.class, jsonData); } catch (SerializationException e) { vector.x = json.readValue("x", float.class, 0.0f, jsonData); vector.y = json.readValue("y", float.class, 0.0f, jsonData); } return vector; }
private void loadWeapons() { logger.debug("Loading Weapons"); Json json = new Json(); for (String s : manifest.weapons) { try { WeaponConfig config = json.fromJson(WeaponConfig.class, Gdx.files.internal(s)); weaponConfigs.put(config.name, config); } catch (SerializationException ex) { logger.error("Failed to load weapons file: " + s); logger.error(ex.getMessage()); } } }
private void loadEntities() { logger.debug("Loading Entities"); Json json = new Json(); for (String s : manifest.entities) { try { EntityConfig config = json.fromJson(EntityConfig.class, Gdx.files.internal(s)); entityConfigs.put(config.name, config); } catch (SerializationException ex) { logger.error("Failed to load entity file: " + s); logger.error(ex.getMessage()); } } }
@Override public es.danirod.rectball.model.Statistics loadStatistics() { try { // Read stats from file and decode them. FileHandle handle = getStatistics(); String encodedJson = handle.readString(); String decodedJson = Base64Coder.decodeString(encodedJson); // Convert JSON to statistics Json json = new Json(); return json.fromJson(es.danirod.rectball.model.Statistics.class, decodedJson); } catch (Exception ex) { return new es.danirod.rectball.model.Statistics(); } }
public static <T> void write( FileHandle path, T object, Class<T> clazz, Consumer<Json> setupJson) { Json json = new Json(JsonWriter.OutputType.json); json.setSerializer(clazz, new AnnotatedJsonSerializer<>(json, clazz)); if (setupJson != null) { setupJson.accept(json); } String output = json.toJson(object); String prettyOutput = json.prettyPrint(output); path.writeString(prettyOutput, false, "UTF-8"); }
protected void processDir(Entry inputDir, ArrayList<Entry> files) throws Exception { // Start with a copy of a parent dir's settings or the default settings. Settings settings = null; File parent = inputDir.inputFile; while (true) { if (parent.equals(root)) break; parent = parent.getParentFile(); settings = dirToSettings.get(parent); if (settings != null) { settings = new Settings(settings); break; } } if (settings == null) settings = new Settings(defaultSettings); dirToSettings.put(inputDir.inputFile, settings); // Merge settings from pack.json file. File settingsFile = new File(inputDir.inputFile, "pack.json"); if (settingsFile.exists()) json.readFields(settings, new JsonReader().parse(new FileReader(settingsFile))); // Pack. TexturePacker2 packer = new TexturePacker2(root, settings); for (Entry file : files) packer.addImage(file.inputFile); packer.pack(inputDir.outputDir, packFileName); }
// Json read @Override public void read(Json json, JsonValue jsonData) { logger.debug("Deserializing"); PhysicsConfig config = json.fromJson(PhysicsConfig.class, jsonData.toString()); collisionEffect = config.collisionEffect; this.buildFromModel(config.sceneModel); }
@SuppressWarnings("unchecked") @Override public void read(Json json, JsonValue jsonData) { width = jsonData.getInt("Width"); height = jsonData.getInt("Height"); keys = json.readValue("Keys", ObjectMap.class, jsonData); }
// Json Write @Override public void write(Json json) { logger.debug("Serializing.."); PhysicsConfig config = new PhysicsConfig(); config.collisionEffect = collisionEffect; config.sceneModel = scene.toSceneModel(); json.writeFields(config); }
public static <T> T read(FileHandle path, Class<T> clazz, Consumer<Json> setupJson) throws IOException { Json json = new Json(); json.setSerializer(clazz, new AnnotatedJsonSerializer<>(json, clazz)); if (setupJson != null) { setupJson.accept(json); } try { return json.fromJson(clazz, path); } catch (RuntimeException e) { throw new IOException(e); } }
public static void Initialize() { FileHandle file = Gdx.files.local("saves/savedata.json"); if (!file.exists()) { String savestring = json.prettyPrint( new SaveData( new PlayerData( PlayerData.AbilityType.NONE, 0, 0, 0, 0, PlayerData.SkinType.HUMAN), new LevelSaveData[] { new LevelSaveData(0, 0, true), new LevelSaveData(0, 0, false) }, 0)); file.writeString(savestring, true); } saveData = json.fromJson(SaveData.class, file); }