List of usage examples for com.badlogic.gdx.utils JsonValue has
public boolean has(String name)
From source file:com.company.minery.utils.spine.SkeletonJson.java
License:Open Source License
private Attachment readAttachment(Skin skin, String name, JsonValue map) { float scale = this.scale; name = map.getString("name", name); String path = map.getString("path", name); switch (AttachmentType.valueOf(map.getString("type", AttachmentType.region.name()))) { case region: { RegionAttachment region = attachmentLoader.newRegionAttachment(skin, name, path); if (region == null) return null; region.setPath(path);/*from ww w .j a va 2 s.co m*/ region.setX(map.getFloat("x", 0) * scale); region.setY(map.getFloat("y", 0) * scale); region.setScaleX(map.getFloat("scaleX", 1)); region.setScaleY(map.getFloat("scaleY", 1)); region.setRotation(map.getFloat("rotation", 0)); region.setWidth(map.getFloat("width") * scale); region.setHeight(map.getFloat("height") * scale); String color = map.getString("color", null); if (color != null) region.getColor().set(Color.valueOf(color)); region.updateOffset(); return region; } case boundingbox: { BoundingBoxAttachment box = attachmentLoader.newBoundingBoxAttachment(skin, name); if (box == null) return null; float[] vertices = map.require("vertices").asFloatArray(); if (scale != 1) { for (int i = 0, n = vertices.length; i < n; i++) vertices[i] *= scale; } box.setVertices(vertices); return box; } case mesh: { MeshAttachment mesh = attachmentLoader.newMeshAttachment(skin, name, path); if (mesh == null) return null; mesh.setPath(path); float[] vertices = map.require("vertices").asFloatArray(); if (scale != 1) { for (int i = 0, n = vertices.length; i < n; i++) vertices[i] *= scale; } mesh.setVertices(vertices); mesh.setTriangles(map.require("triangles").asShortArray()); mesh.setRegionUVs(map.require("uvs").asFloatArray()); mesh.updateUVs(); String color = map.getString("color", null); if (color != null) mesh.getColor().set(Color.valueOf(color)); if (map.has("hull")) mesh.setHullLength(map.require("hull").asInt() * 2); if (map.has("edges")) mesh.setEdges(map.require("edges").asIntArray()); mesh.setWidth(map.getFloat("width", 0) * scale); mesh.setHeight(map.getFloat("height", 0) * scale); return mesh; } case skinnedmesh: { SkinnedMeshAttachment mesh = attachmentLoader.newSkinnedMeshAttachment(skin, name, path); if (mesh == null) return null; mesh.setPath(path); float[] uvs = map.require("uvs").asFloatArray(); float[] vertices = map.require("vertices").asFloatArray(); FloatArray weights = new FloatArray(uvs.length * 3 * 3); IntArray bones = new IntArray(uvs.length * 3); for (int i = 0, n = vertices.length; i < n;) { int boneCount = (int) vertices[i++]; bones.add(boneCount); for (int nn = i + boneCount * 4; i < nn;) { bones.add((int) vertices[i]); weights.add(vertices[i + 1] * scale); weights.add(vertices[i + 2] * scale); weights.add(vertices[i + 3]); i += 4; } } mesh.setBones(bones.toArray()); mesh.setWeights(weights.toArray()); mesh.setTriangles(map.require("triangles").asShortArray()); mesh.setRegionUVs(uvs); mesh.updateUVs(); String color = map.getString("color", null); if (color != null) mesh.getColor().set(Color.valueOf(color)); if (map.has("hull")) mesh.setHullLength(map.require("hull").asInt() * 2); if (map.has("edges")) mesh.setEdges(map.require("edges").asIntArray()); mesh.setWidth(map.getFloat("width", 0) * scale); mesh.setHeight(map.getFloat("height", 0) * scale); return mesh; } } // RegionSequenceAttachment regionSequenceAttachment = (RegionSequenceAttachment)attachment; // // float fps = map.getFloat("fps"); // regionSequenceAttachment.setFrameTime(fps); // // String modeString = map.getString("mode"); // regionSequenceAttachment.setMode(modeString == null ? Mode.forward : Mode.valueOf(modeString)); return null; }
From source file:com.esotericsoftware.spine.JsonRollback.java
License:Open Source License
static Array<JsonValue> find(JsonValue current, Array<JsonValue> values, int index, String... path) { String name = path[index];//from w ww .j a v a2 s . c o m if (current.name == null) { if (name.equals("*") && index == path.length - 1) values.add(current); else if (current.has(name)) return find(current.get(name), values, index, path); } else if (name.equals("*") || current.name.equals(name)) { if (++index == path.length || (index == path.length - 1 && current.isString() && current.asString().equals(path[index]))) values.add(current); else { for (JsonValue child = current.child; child != null; child = child.next) find(child, values, index, path); } } return values; }
From source file:com.izacc.equipment.Item.java
public Item(JsonValue json) { this.file = json.getString("file"); this.name = json.getString("name"); this.description = json.getString("description"); this.disable = json.has("disable") ? json.getBoolean("disable") : false; this.packable = json.has("packable") ? json.getBoolean("packable") : true; this.isPermanent = json.has("isPermanent") ? json.getBoolean("isPermanent") : true; this.bonus = json.has("bonus") ? json.getFloat("bonus") : 0.0f; this.time = json.has("time") ? json.getInt("time") : 0; this.buy = json.has("buy") ? json.getInt("buy") : 0; this.sell = json.has("sell") ? json.getInt("sell") : 0; this.itemType = ItemType.valueOf(json.getString("itemType")); this.effectType = EffectType.valueOf(json.getString("type")); }
From source file:com.izacc.equipment.SpellCard.java
public SpellCard(JsonValue json) { super(json);/*from w w w.j a v a 2 s . com*/ this.id = json.has("id") ? json.getInt("id") : 0; this.speed = json.has("speed") ? json.getFloat("speed") : 0.0f; this.damage = json.has("damage") ? json.getFloat("damage") : 0.0f; this.spellType = SpellType.valueOf(json.getString("spellType")); }
From source file:com.jupiter.europa.entity.component.AttributesComponent.java
License:Open Source License
@Override public void read(Json json, JsonValue jsonData) { if (jsonData.has(BASE_ATTRIBUTES_KEY)) { this.baseAttributes = json.fromJson(AttributeSet.class, jsonData.get(BASE_ATTRIBUTES_KEY).prettyPrint(EuropaGame.PRINT_SETTINGS)); }/* w w w . j a v a 2 s . co m*/ if (jsonData.has(CURRENT_ATTRIBUTES_KEY)) { this.currentAttributes = json.fromJson(AttributeSet.class, jsonData.get(CURRENT_ATTRIBUTES_KEY).prettyPrint(EuropaGame.PRINT_SETTINGS)); } }
From source file:com.jupiter.europa.entity.component.CharacterClassComponent.java
License:Open Source License
@Override public void read(Json json, JsonValue jsonData) { if (jsonData.has(CHARACTER_CLASS_TYPE_KEY)) { String className = jsonData.getString(CHARACTER_CLASS_TYPE_KEY); if (jsonData.has(CHARACTER_CLASS_INSTANCE_KEY)) { try { Class<?> classType = Class.forName(className); if (CharacterClass.class.isAssignableFrom(classType)) { this.characterClass = (CharacterClass) json.fromJson(classType, jsonData.get(CHARACTER_CLASS_INSTANCE_KEY).prettyPrint(EuropaGame.PRINT_SETTINGS)); }/* w w w .ja v a 2 s. c om*/ } catch (ClassNotFoundException ex) { } } } // If a value was not assigned for whatver reason if (this.characterClass == null) { this.characterClass = new Champion(); } }
From source file:com.jupiter.europa.entity.component.EffectsComponent.java
License:Open Source License
@Override public void read(Json json, JsonValue jsonData) { if (jsonData.has(EFFECTS_KEY)) { JsonValue selectedData = jsonData.get(EFFECTS_KEY); if (selectedData.isArray()) { selectedData.iterator().forEach((JsonValue value) -> { if (value.has(EFFECT_CLASS_KEY) && value.has(EFFECT_DATA_KEY)) { String typeName = value.getString(EFFECT_CLASS_KEY); try { Class<?> type = Class.forName(typeName); if (Effect.class.isAssignableFrom(type)) { this.effects .add((Effect) json.fromJson(type, value.get(EFFECT_DATA_KEY).toString())); }/*from w ww. ja v a2s . c o m*/ } catch (ClassNotFoundException ex) { } } }); } } }
From source file:com.jupiter.europa.entity.component.NameComponent.java
License:Open Source License
@Override public void read(Json json, JsonValue jsonData) { if (jsonData.has(NAME_KEY)) { this.name = jsonData.getString(NAME_KEY); }// w w w . j a v a 2s . c om }
From source file:com.jupiter.europa.entity.component.RaceComponent.java
License:Open Source License
@Override public void read(Json json, JsonValue jsonData) { if (jsonData.has(RACE_KEY)) { this.race = PlayerRaces.valueOf(jsonData.getString(RACE_KEY)); }//from w w w . ja va 2 s .c om }
From source file:com.jupiter.europa.entity.component.SkillsComponent.java
@Override public void read(Json json, JsonValue jsonData) { if (jsonData.has(SKILL_SET_KEY)) { try {//ww w . j ava 2s.c o m this.skills = json.readValue(SkillSet.class, jsonData.get(SKILL_SET_KEY)); } catch (Exception ex) { this.skills = new SkillSet(); } } else { this.skills = new SkillSet(); } if (jsonData.has(CLASS_SKILLS_KEY)) { this.classSkills.clear(); jsonData.get(CLASS_SKILLS_KEY).iterator().forEach((JsonValue value) -> { try { this.classSkills.add(json.readValue(Skills.class, value)); } catch (Exception ex) { } }); } }