List of usage examples for com.badlogic.gdx.utils JsonValue getFloat
public float getFloat(int index)
From source file:be.ac.ucl.lfsab1509.bouboule.game.physicEditor.BodyEditorLoader.java
License:Open Source License
private RigidBodyModel readRigidBody(JsonValue bodyElem) { RigidBodyModel rbModel = new RigidBodyModel(); rbModel.name = bodyElem.getString("name"); rbModel.imagePath = bodyElem.getString("imagePath"); JsonValue originElem = bodyElem.get("origin"); rbModel.origin.x = originElem.getFloat("x"); rbModel.origin.y = originElem.getFloat("y"); // polygons// w w w.jav a 2 s. c o m JsonValue polygonsElem = bodyElem.getChild("polygons"); for (; polygonsElem != null; polygonsElem = polygonsElem.next()) { PolygonModel polygon = new PolygonModel(); rbModel.polygons.add(polygon); JsonValue vertexElem = polygonsElem.child(); for (; vertexElem != null; vertexElem = vertexElem.next()) { float x = vertexElem.getFloat("x"); float y = vertexElem.getFloat("y"); polygon.vertices.add(new Vector2(x, y)); } polygon.buffer = new Vector2[polygon.vertices.size()]; } // circles JsonValue circleElem = bodyElem.getChild("circles"); for (; circleElem != null; circleElem = circleElem.next()) { CircleModel circle = new CircleModel(); rbModel.circles.add(circle); circle.center.x = circleElem.getFloat("cx"); circle.center.y = circleElem.getFloat("cy"); circle.radius = circleElem.getFloat("r"); } return rbModel; }
From source file:com.company.minery.utils.spine.SkeletonJson.java
License:Open Source License
void readCurve(CurveTimeline timeline, int frameIndex, JsonValue valueMap) { JsonValue curve = valueMap.get("curve"); if (curve == null) return;//w w w. j a va 2s . c o m if (curve.isString() && curve.asString().equals("stepped")) timeline.setStepped(frameIndex); else if (curve.isArray()) { timeline.setCurve(frameIndex, curve.getFloat(0), curve.getFloat(1), curve.getFloat(2), curve.getFloat(3)); } }
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 ww .jav a 2s .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.WalkComponent.java
@Override public void read(Json json, JsonValue jsonData) { this.setSpeed(jsonData.getFloat(SPEED_KEY)); }
From source file:com.jupiter.europa.settings.Settings.java
License:Open Source License
@Override public void read(Json json, JsonValue jsonData) { if (jsonData.has(MUSIC_VOLUME_KEY)) { this.musicVolume.set(jsonData.getFloat(MUSIC_VOLUME_KEY)); }/* ww w . j av a 2 s . c om*/ }
From source file:com.mbrlabs.mundus.commons.g3d.MG3dModelLoader.java
License:Apache License
private Color parseColor(JsonValue colorArray) { if (colorArray.size >= 3) return new Color(colorArray.getFloat(0), colorArray.getFloat(1), colorArray.getFloat(2), 1.0f); else/*from ww w . j a v a 2 s . com*/ throw new GdxRuntimeException("Expected Color values <> than three."); }
From source file:com.mbrlabs.mundus.commons.g3d.MG3dModelLoader.java
License:Apache License
private Vector2 readVector2(JsonValue vectorArray, float x, float y) { if (vectorArray == null) return new Vector2(x, y); else if (vectorArray.size == 2) return new Vector2(vectorArray.getFloat(0), vectorArray.getFloat(1)); else/* www. j av a 2 s .co m*/ throw new GdxRuntimeException("Expected Vector2 values <> than two."); }
From source file:com.mbrlabs.mundus.commons.g3d.MG3dModelLoader.java
License:Apache License
private ModelNode parseNodesRecursively(JsonValue json) { ModelNode jsonNode = new ModelNode(); String id = json.getString("id", null); if (id == null) throw new GdxRuntimeException("Node id missing."); jsonNode.id = id;/* ww w. ja v a 2 s. co m*/ JsonValue translation = json.get("translation"); if (translation != null && translation.size != 3) throw new GdxRuntimeException("Node translation incomplete"); jsonNode.translation = translation == null ? null : new Vector3(translation.getFloat(0), translation.getFloat(1), translation.getFloat(2)); JsonValue rotation = json.get("rotation"); if (rotation != null && rotation.size != 4) throw new GdxRuntimeException("Node rotation incomplete"); jsonNode.rotation = rotation == null ? null : new Quaternion(rotation.getFloat(0), rotation.getFloat(1), rotation.getFloat(2), rotation.getFloat(3)); JsonValue scale = json.get("scale"); if (scale != null && scale.size != 3) throw new GdxRuntimeException("Node scale incomplete"); jsonNode.scale = scale == null ? null : new Vector3(scale.getFloat(0), scale.getFloat(1), scale.getFloat(2)); String meshId = json.getString("mesh", null); if (meshId != null) jsonNode.meshId = meshId; JsonValue materials = json.get("parts"); if (materials != null) { jsonNode.parts = new ModelNodePart[materials.size]; int i = 0; for (JsonValue material = materials.child; material != null; material = material.next, i++) { ModelNodePart nodePart = new ModelNodePart(); String meshPartId = material.getString("meshpartid", null); String materialId = material.getString("materialid", null); if (meshPartId == null || materialId == null) { throw new GdxRuntimeException("Node " + id + " part is missing meshPartId or materialId"); } nodePart.materialId = materialId; nodePart.meshPartId = meshPartId; JsonValue bones = material.get("bones"); if (bones != null) { nodePart.bones = new ArrayMap<String, Matrix4>(true, bones.size, String.class, Matrix4.class); int j = 0; for (JsonValue bone = bones.child; bone != null; bone = bone.next, j++) { String nodeId = bone.getString("node", null); if (nodeId == null) throw new GdxRuntimeException("Bone node ID missing"); Matrix4 transform = new Matrix4(); JsonValue val = bone.get("translation"); if (val != null && val.size >= 3) transform.translate(val.getFloat(0), val.getFloat(1), val.getFloat(2)); val = bone.get("rotation"); if (val != null && val.size >= 4) transform.rotate( tempQ.set(val.getFloat(0), val.getFloat(1), val.getFloat(2), val.getFloat(3))); val = bone.get("scale"); if (val != null && val.size >= 3) transform.scale(val.getFloat(0), val.getFloat(1), val.getFloat(2)); nodePart.bones.put(nodeId, transform); } } jsonNode.parts[i] = nodePart; } } JsonValue children = json.get("children"); if (children != null) { jsonNode.children = new ModelNode[children.size]; int i = 0; for (JsonValue child = children.child; child != null; child = child.next, i++) { jsonNode.children[i] = parseNodesRecursively(child); } } return jsonNode; }
From source file:com.mbrlabs.mundus.commons.g3d.MG3dModelLoader.java
License:Apache License
private void parseAnimations(ModelData model, JsonValue json) { JsonValue animations = json.get("animations"); if (animations == null) return;//from w w w . j av a 2 s. com model.animations.ensureCapacity(animations.size); for (JsonValue anim = animations.child; anim != null; anim = anim.next) { JsonValue nodes = anim.get("bones"); if (nodes == null) continue; ModelAnimation animation = new ModelAnimation(); model.animations.add(animation); animation.nodeAnimations.ensureCapacity(nodes.size); animation.id = anim.getString("id"); for (JsonValue node = nodes.child; node != null; node = node.next) { ModelNodeAnimation nodeAnim = new ModelNodeAnimation(); animation.nodeAnimations.add(nodeAnim); nodeAnim.nodeId = node.getString("boneId"); // For backwards compatibility (version 0.1): JsonValue keyframes = node.get("keyframes"); if (keyframes != null && keyframes.isArray()) { for (JsonValue keyframe = keyframes.child; keyframe != null; keyframe = keyframe.next) { final float keytime = keyframe.getFloat("keytime", 0f) / 1000.f; JsonValue translation = keyframe.get("translation"); if (translation != null && translation.size == 3) { if (nodeAnim.translation == null) nodeAnim.translation = new Array<ModelNodeKeyframe<Vector3>>(); ModelNodeKeyframe<Vector3> tkf = new ModelNodeKeyframe<Vector3>(); tkf.keytime = keytime; tkf.value = new Vector3(translation.getFloat(0), translation.getFloat(1), translation.getFloat(2)); nodeAnim.translation.add(tkf); } JsonValue rotation = keyframe.get("rotation"); if (rotation != null && rotation.size == 4) { if (nodeAnim.rotation == null) nodeAnim.rotation = new Array<ModelNodeKeyframe<Quaternion>>(); ModelNodeKeyframe<Quaternion> rkf = new ModelNodeKeyframe<Quaternion>(); rkf.keytime = keytime; rkf.value = new Quaternion(rotation.getFloat(0), rotation.getFloat(1), rotation.getFloat(2), rotation.getFloat(3)); nodeAnim.rotation.add(rkf); } JsonValue scale = keyframe.get("scale"); if (scale != null && scale.size == 3) { if (nodeAnim.scaling == null) nodeAnim.scaling = new Array<ModelNodeKeyframe<Vector3>>(); ModelNodeKeyframe<Vector3> skf = new ModelNodeKeyframe(); skf.keytime = keytime; skf.value = new Vector3(scale.getFloat(0), scale.getFloat(1), scale.getFloat(2)); nodeAnim.scaling.add(skf); } } } else { // Version 0.2: JsonValue translationKF = node.get("translation"); if (translationKF != null && translationKF.isArray()) { nodeAnim.translation = new Array<ModelNodeKeyframe<Vector3>>(); nodeAnim.translation.ensureCapacity(translationKF.size); for (JsonValue keyframe = translationKF.child; keyframe != null; keyframe = keyframe.next) { ModelNodeKeyframe<Vector3> kf = new ModelNodeKeyframe<Vector3>(); nodeAnim.translation.add(kf); kf.keytime = keyframe.getFloat("keytime", 0f) / 1000.f; JsonValue translation = keyframe.get("value"); if (translation != null && translation.size >= 3) kf.value = new Vector3(translation.getFloat(0), translation.getFloat(1), translation.getFloat(2)); } } JsonValue rotationKF = node.get("rotation"); if (rotationKF != null && rotationKF.isArray()) { nodeAnim.rotation = new Array<ModelNodeKeyframe<Quaternion>>(); nodeAnim.rotation.ensureCapacity(rotationKF.size); for (JsonValue keyframe = rotationKF.child; keyframe != null; keyframe = keyframe.next) { ModelNodeKeyframe<Quaternion> kf = new ModelNodeKeyframe<Quaternion>(); nodeAnim.rotation.add(kf); kf.keytime = keyframe.getFloat("keytime", 0f) / 1000.f; JsonValue rotation = keyframe.get("value"); if (rotation != null && rotation.size >= 4) kf.value = new Quaternion(rotation.getFloat(0), rotation.getFloat(1), rotation.getFloat(2), rotation.getFloat(3)); } } JsonValue scalingKF = node.get("scaling"); if (scalingKF != null && scalingKF.isArray()) { nodeAnim.scaling = new Array<ModelNodeKeyframe<Vector3>>(); nodeAnim.scaling.ensureCapacity(scalingKF.size); for (JsonValue keyframe = scalingKF.child; keyframe != null; keyframe = keyframe.next) { ModelNodeKeyframe<Vector3> kf = new ModelNodeKeyframe<Vector3>(); nodeAnim.scaling.add(kf); kf.keytime = keyframe.getFloat("keytime", 0f) / 1000.f; JsonValue scaling = keyframe.get("value"); if (scaling != null && scaling.size >= 3) kf.value = new Vector3(scaling.getFloat(0), scaling.getFloat(1), scaling.getFloat(2)); } } } } } }