List of usage examples for com.badlogic.gdx.utils JsonValue name
String name
To view the source code for com.badlogic.gdx.utils JsonValue name.
Click Source Link
From source file:br.com.questingsoftware.libgdx.g3db.G3DBConverter.java
License:Apache License
private void writeObject(JsonValue root, UBJsonWriter writer) throws IOException { if (root.type() == ValueType.array) { if (root.name() != null) { writer.array(root.name());/*from w ww .ja va 2 s . c o m*/ } else { writer.array(); } } else { if (root.name() != null) { writer.object(root.name()); } else { writer.object(); } } JsonValue child = root.child(); while (child != null) { switch (child.type()) { case booleanValue: if (child.name() != null) { writer.set(child.name(), child.asBoolean()); } else { writer.value(child.asBoolean()); } break; case doubleValue: if (child.name() != null) { writer.set(child.name(), child.asDouble()); } else { writer.value(child.asDouble()); } break; case longValue: if (child.name() != null) { writer.set(child.name(), child.asLong()); } else { writer.value(child.asLong()); } break; case stringValue: if (child.name() != null) { writer.set(child.name(), child.asString()); } else { writer.value(child.asString()); } break; case nullValue: if (child.name() != null) { writer.set(child.name()); } break; case array: case object: writeObject(child, writer); break; } child = child.next(); } writer.pop(); }
From source file:com.jupiter.europa.entity.stats.AttributeSet.java
License:Open Source License
@Override public void read(Json json, JsonValue jsonData) { jsonData.iterator().forEach((JsonValue value) -> { Attributes attr = Attributes.valueOf(value.name()); if (attr != null) { this.attributes.put(attr, value.asInt()); }/*from w w w .j av a2 s . c o m*/ }); }
From source file:com.jupiter.europa.entity.stats.SkillSet.java
License:Open Source License
@Override public void read(Json json, JsonValue jsonData) { jsonData.iterator().forEach((JsonValue value) -> { SkillSet.Skills skill = SkillSet.Skills.valueOf(value.name()); if (skill != null) { this.skills.put(skill, value.asInt()); }/*from w ww .j ava 2 s . com*/ }); }
From source file:com.ray3k.skincomposer.data.JsonData.java
License:Open Source License
public void readFile(FileHandle fileHandle) throws Exception { main.getProjectData().setChangesSaved(false); //read drawables from texture atlas file FileHandle atlasHandle = fileHandle.sibling(fileHandle.nameWithoutExtension() + ".atlas"); if (atlasHandle.exists()) { main.getProjectData().getAtlasData().readAtlas(atlasHandle); }//w w w. java2 s . c o m //folder for critical files to be copied to FileHandle saveFile = main.getProjectData().getSaveFile(); FileHandle targetDirectory; if (saveFile != null) { targetDirectory = saveFile.sibling(saveFile.nameWithoutExtension() + "_data"); } else { targetDirectory = Gdx.files.local("temp/" + main.getProjectData().getId() + "_data"); } //read json file and create styles JsonReader reader = new JsonReader(); JsonValue val = reader.parse(fileHandle); for (JsonValue child : val.iterator()) { //fonts if (child.name().equals(BitmapFont.class.getName())) { for (JsonValue font : child.iterator()) { FileHandle fontFile = fileHandle.sibling(font.getString("file")); FileHandle fontCopy = targetDirectory.child(font.getString("file")); if (!fontCopy.parent().equals(fontFile.parent())) { fontFile.copyTo(fontCopy); } FontData fontData = new FontData(font.name(), fontCopy); //delete fonts with the same name for (FontData originalData : new Array<>(fonts)) { if (originalData.getName().equals(fontData.getName())) { fonts.removeValue(originalData, true); } } fonts.add(fontData); BitmapFont.BitmapFontData bitmapFontData = new BitmapFont.BitmapFontData(fontCopy, false); for (String path : bitmapFontData.imagePaths) { FileHandle file = new FileHandle(path); main.getProjectData().getAtlasData() .getDrawable(file.nameWithoutExtension()).visible = false; } } } //colors else if (child.name().equals(Color.class.getName())) { for (JsonValue color : child.iterator()) { ColorData colorData = new ColorData(color.name, new Color(color.getFloat("r", 0.0f), color.getFloat("g", 0.0f), color.getFloat("b", 0.0f), color.getFloat("a", 0.0f))); //delete colors with the same name for (ColorData originalData : new Array<>(colors)) { if (originalData.getName().equals(colorData.getName())) { colors.removeValue(originalData, true); } } colors.add(colorData); } } //tinted drawables else if (child.name().equals(TintedDrawable.class.getName())) { for (JsonValue tintedDrawable : child.iterator()) { DrawableData drawableData = new DrawableData(main.getProjectData().getAtlasData() .getDrawable(tintedDrawable.getString("name")).file); drawableData.name = tintedDrawable.name; if (!tintedDrawable.get("color").isString()) { drawableData.tint = new Color(tintedDrawable.get("color").getFloat("r", 0.0f), tintedDrawable.get("color").getFloat("g", 0.0f), tintedDrawable.get("color").getFloat("b", 0.0f), tintedDrawable.get("color").getFloat("a", 0.0f)); } else { drawableData.tintName = tintedDrawable.getString("color"); } //todo:test overwriting a base drawable that is depended on by another tint //delete drawables with the same name for (DrawableData originalData : new Array<>( main.getProjectData().getAtlasData().getDrawables())) { if (originalData.name.equals(drawableData.name)) { main.getProjectData().getAtlasData().getDrawables().removeValue(originalData, true); } } main.getProjectData().getAtlasData().getDrawables().add(drawableData); } } //styles else { int classIndex = 0; Class matchClass = ClassReflection.forName(child.name); for (Class clazz : Main.STYLE_CLASSES) { if (clazz.equals(matchClass)) { break; } else { classIndex++; } } Class clazz = Main.BASIC_CLASSES[classIndex]; for (JsonValue style : child.iterator()) { StyleData data = newStyle(clazz, style.name); for (JsonValue property : style.iterator()) { StyleProperty styleProperty = data.properties.get(property.name); if (styleProperty.type.equals(Float.TYPE)) { styleProperty.value = (double) property.asFloat(); } else if (styleProperty.type.equals(Color.class)) { if (property.isString()) { styleProperty.value = property.asString(); } else { Gdx.app.error(getClass().getName(), "Can't import JSON files that do not use predefined colors."); } } else { if (property.isString()) { styleProperty.value = property.asString(); } else { Gdx.app.error(getClass().getName(), "Can't import JSON files that do not use String names for field values."); } } } } } } }
From source file:com.strategames.engine.gameobject.types.Balloon.java
License:Open Source License
@Override protected void readValue(JsonValue jsonData) { String name = jsonData.name(); if (name.contentEquals("liftfactor")) { setLiftFactor(Float.valueOf(jsonData.asFloat())); }/*from w ww . ja v a2 s . c om*/ }
From source file:com.strategames.engine.gameobject.types.Door.java
License:Open Source License
@Override protected void readValue(JsonValue jsonData) { String name = jsonData.name(); if (name.contentEquals("nextLevelPosition")) { this.entryLevel = jsonData.asIntArray(); }//www . jav a 2 s.c o m }
From source file:com.strategames.engine.gameobject.types.Star.java
License:Open Source License
@Override protected void readValue(JsonValue jsonData) { String name = jsonData.name(); if (name.contentEquals("rotationSpeed")) { this.rotationSpeed = jsonData.asFloat(); }//from www. j a va2s . c o m }
From source file:com.strategames.engine.gameobject.types.Wall.java
License:Open Source License
@Override protected void readValue(JsonValue jsonData) { String name = jsonData.name(); if (name.contentEquals("length")) { setLength(jsonData.asFloat());/* w ww. ja v a 2s. c om*/ } else if (name.contentEquals("border")) { setBorder(jsonData.asBoolean()); } }
From source file:com.tnf.ptm.common.PtmNames.java
License:Apache License
private ArrayList<String> readList(ResourceUrn fileName) { Json json = Assets.getJson(fileName); JsonValue rootNode = json.getJsonValue(); ArrayList<String> list = new ArrayList<>(); for (JsonValue node : rootNode) { list.add(node.name()); }// w ww . j a v a 2s. com json.dispose(); return list; }
From source file:com.tussle.stream.JsonDistributingWriter.java
License:Open Source License
public void write(JsonValue jsonVal) { try {/*from w ww .j a va 2s . co m*/ for (JsonValue i : jsonVal) { //Not a typo, we're iterating over the jsonValue we were handed if (writers.containsKey(i.name())) { try { writers.get(i.name()) .write(i.prettyPrint(JsonWriter.OutputType.json, Integer.MAX_VALUE) + "\n"); } catch (IOException ex) { JsonValue value = Utility.exceptionToJson(ex); value.addChild("Invalid String", i); errorWriter.write(value.toString()); } } else { JsonValue value = new JsonValue(JsonValue.ValueType.object); value.addChild("Invalid String", i); errorWriter.write(value.toString()); } } } catch (IOException ex) { throw new SerializationException(ex); } }