List of usage examples for com.badlogic.gdx.utils JsonValue getString
public String getString(String name, String defaultValue)
From source file:com.ahsgaming.valleyofbones.map.TileSet.java
License:Apache License
public TileSet(JsonValue json) { firstgid = json.getInt("firstgid"); name = json.getString("name", ""); atlas = json.getString("atlas"); images = new Array<String>(); tiles = new Array<TextureRegion>(); depths = new Array<TextureRegion>(); for (JsonValue v : json.get("tiles")) { images.add(v.asString());//from www .j a v a 2 s. c om tiles.add(VOBGame.instance.getTextureManager().getSpriteFromAtlas(atlas, v.asString())); depths.add(VOBGame.instance.getTextureManager().getSpriteFromAtlas(atlas, v.asString() + "-depth")); } }
From source file:com.company.minery.utils.spine.SkeletonJson.java
License:Open Source License
public SkeletonData readSkeletonData(FileHandle file) { if (file == null) throw new IllegalArgumentException("file cannot be null."); float scale = this.scale; SkeletonData skeletonData = new SkeletonData(); skeletonData.name = file.nameWithoutExtension(); JsonValue root = new JsonReader().parse(file); // Skeleton.//from w w w.j a v a 2s .c o m JsonValue skeletonMap = root.get("skeleton"); if (skeletonMap != null) { skeletonData.hash = skeletonMap.getString("hash", null); skeletonData.version = skeletonMap.getString("spine", null); skeletonData.width = skeletonMap.getFloat("width", 0); skeletonData.height = skeletonMap.getFloat("height", 0); skeletonData.imagesPath = skeletonMap.getString("images", null); } // Bones. for (JsonValue boneMap = root.getChild("bones"); boneMap != null; boneMap = boneMap.next) { BoneData parent = null; String parentName = boneMap.getString("parent", null); if (parentName != null) { parent = skeletonData.findBone(parentName); if (parent == null) throw new SerializationException("Parent bone not found: " + parentName); } BoneData boneData = new BoneData(boneMap.getString("name"), parent); boneData.length = boneMap.getFloat("length", 0) * scale; boneData.x = boneMap.getFloat("x", 0) * scale; boneData.y = boneMap.getFloat("y", 0) * scale; boneData.rotation = boneMap.getFloat("rotation", 0); boneData.scaleX = boneMap.getFloat("scaleX", 1); boneData.scaleY = boneMap.getFloat("scaleY", 1); boneData.flipX = boneMap.getBoolean("flipX", false); boneData.flipY = boneMap.getBoolean("flipY", false); boneData.inheritScale = boneMap.getBoolean("inheritScale", true); boneData.inheritRotation = boneMap.getBoolean("inheritRotation", true); String color = boneMap.getString("color", null); if (color != null) boneData.getColor().set(Color.valueOf(color)); skeletonData.bones.add(boneData); } // IK constraints. for (JsonValue ikMap = root.getChild("ik"); ikMap != null; ikMap = ikMap.next) { IkConstraintData ikConstraintData = new IkConstraintData(ikMap.getString("name")); for (JsonValue boneMap = ikMap.getChild("bones"); boneMap != null; boneMap = boneMap.next) { String boneName = boneMap.asString(); BoneData bone = skeletonData.findBone(boneName); if (bone == null) throw new SerializationException("IK bone not found: " + boneName); ikConstraintData.bones.add(bone); } String targetName = ikMap.getString("target"); ikConstraintData.target = skeletonData.findBone(targetName); if (ikConstraintData.target == null) throw new SerializationException("Target bone not found: " + targetName); ikConstraintData.bendDirection = ikMap.getBoolean("bendPositive", true) ? 1 : -1; ikConstraintData.mix = ikMap.getFloat("mix", 1); skeletonData.ikConstraints.add(ikConstraintData); } // Slots. for (JsonValue slotMap = root.getChild("slots"); slotMap != null; slotMap = slotMap.next) { String slotName = slotMap.getString("name"); String boneName = slotMap.getString("bone"); BoneData boneData = skeletonData.findBone(boneName); if (boneData == null) throw new SerializationException("Slot bone not found: " + boneName); SlotData slotData = new SlotData(slotName, boneData); String color = slotMap.getString("color", null); if (color != null) slotData.getColor().set(Color.valueOf(color)); slotData.attachmentName = slotMap.getString("attachment", null); slotData.additiveBlending = slotMap.getBoolean("additive", false); skeletonData.slots.add(slotData); } // Skins. for (JsonValue skinMap = root.getChild("skins"); skinMap != null; skinMap = skinMap.next) { Skin skin = new Skin(skinMap.name); for (JsonValue slotEntry = skinMap.child; slotEntry != null; slotEntry = slotEntry.next) { int slotIndex = skeletonData.findSlotIndex(slotEntry.name); if (slotIndex == -1) throw new SerializationException("Slot not found: " + slotEntry.name); for (JsonValue entry = slotEntry.child; entry != null; entry = entry.next) { Attachment attachment = readAttachment(skin, entry.name, entry); if (attachment != null) skin.addAttachment(slotIndex, entry.name, attachment); } } skeletonData.skins.add(skin); if (skin.name.equals("default")) skeletonData.defaultSkin = skin; } // Events. for (JsonValue eventMap = root.getChild("events"); eventMap != null; eventMap = eventMap.next) { EventData eventData = new EventData(eventMap.name); eventData.intValue = eventMap.getInt("int", 0); eventData.floatValue = eventMap.getFloat("float", 0f); eventData.stringValue = eventMap.getString("string", null); skeletonData.events.add(eventData); } // Animations. for (JsonValue animationMap = root .getChild("animations"); animationMap != null; animationMap = animationMap.next) readAnimation(animationMap.name, animationMap, skeletonData); skeletonData.bones.shrink(); skeletonData.slots.shrink(); skeletonData.skins.shrink(); skeletonData.animations.shrink(); return skeletonData; }
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 w w w. ja 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.mbrlabs.mundus.commons.assets.meta.MetaLoader.java
License:Apache License
private void parseTerrain(Meta meta, JsonValue jsonTerrain) { if (jsonTerrain == null) return;/*ww w.j a va 2 s. c o m*/ final MetaTerrain terrain = new MetaTerrain(); terrain.setSize(jsonTerrain.getInt(MetaTerrain.JSON_SIZE)); terrain.setSplatmap(jsonTerrain.getString(MetaTerrain.JSON_SPLATMAP, null)); terrain.setSplatBase(jsonTerrain.getString(MetaTerrain.JSON_SPLAT_BASE, null)); terrain.setSplatR(jsonTerrain.getString(MetaTerrain.JSON_SPLAT_R, null)); terrain.setSplatG(jsonTerrain.getString(MetaTerrain.JSON_SPLAT_G, null)); terrain.setSplatB(jsonTerrain.getString(MetaTerrain.JSON_SPLAT_B, null)); terrain.setSplatA(jsonTerrain.getString(MetaTerrain.JSON_SPLAT_A, null)); meta.setTerrain(terrain); }
From source file:com.mbrlabs.mundus.commons.g3d.MG3dModelLoader.java
License:Apache License
public ModelData parseModel(FileHandle handle) { JsonValue json = reader.parse(handle); ModelData model = new ModelData(); JsonValue version = json.require("version"); model.version[0] = version.getShort(0); model.version[1] = version.getShort(1); if (model.version[0] != VERSION_HI || model.version[1] != VERSION_LO) throw new GdxRuntimeException("Model version not supported"); model.id = json.getString("id", ""); parseMeshes(model, json);//from w ww.jav a2s . c om parseMaterials(model, json, handle.parent().path()); parseNodes(model, json); parseAnimations(model, json); return model; }
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;//from ww w. j ava2 s. c o 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.runtime.SceneLoader.java
License:Apache License
private GameObject convertGameObject(SceneGraph sceneGraph, JsonValue jsonGo) { final GameObject go = new GameObject(sceneGraph, jsonGo.getString(JsonScene.GO_NAME, ""), jsonGo.getInt(JsonScene.GO_ID)); go.active = jsonGo.getBoolean(JsonScene.GO_ACTIVE, true); // TODO tags//from w ww . j a v a 2s . c om // model component JsonValue modelComp = jsonGo.get(JsonScene.GO_MODEL_COMPONENT); if (modelComp != null) { ModelComponent mc = new ModelComponent(go, mundus.getShaders().getModelShader()); mc.setModel((ModelAsset) assetManager .findAssetByID(modelComp.getString(JsonScene.MODEL_COMPONENT_MODEL_ID)), false); JsonValue mats = modelComp.get(JsonScene.MODEL_COMPONENT_MATERIALS); for (JsonValue mat : mats.iterator()) { mc.getMaterials().put(mat.name, (MaterialAsset) assetManager.findAssetByID(mats.getString(mat.name))); } mc.applyMaterials(); try { go.addComponent(mc); } catch (InvalidComponentException e) { e.printStackTrace(); } } // TODO terrain component JsonValue terrainComp = jsonGo.get(JsonScene.GO_TERRAIN_COMPONENT); if (terrainComp != null) { TerrainComponent tc = new TerrainComponent(go, mundus.getShaders().getTerrainShader()); tc.setTerrain((TerrainAsset) assetManager .findAssetByID(terrainComp.getString(JsonScene.TERRAIN_COMPONENT_TERRAIN_ID))); try { go.addComponent(tc); } catch (InvalidComponentException e) { e.printStackTrace(); } } // transformation final float[] transform = jsonGo.get(JsonScene.GO_TRANSFORM).asFloatArray(); go.setLocalPosition(transform[0], transform[1], transform[2]); go.setLocalRotation(transform[3], transform[4], transform[5], transform[6]); go.setLocalScale(transform[7], transform[8], transform[9]); // children JsonValue children = jsonGo.get(JsonScene.GO_CHILDREN); if (children != null) { for (JsonValue c : children) { go.addChild(convertGameObject(sceneGraph, c)); } } return go; }
From source file:com.siondream.core.physics.PhysicsLoader.java
License:Apache License
private void loadBodyDef(JsonValue root) { logger.info("loading BodyDef"); physicsData.bodyDef.bullet = root.getBoolean("bullet", false); physicsData.bodyDef.active = root.getBoolean("active", true); physicsData.bodyDef.fixedRotation = root.getBoolean("fixedRotation", false); physicsData.bodyDef.gravityScale = root.getFloat("gravityScale", 1.0f); physicsData.bodyDef.linearDamping = root.getFloat("linearDamping", 0.0f); physicsData.bodyDef.angularDamping = root.getFloat("angularDamping", 0.0f); String type = root.getString("type", "dynamic"); if (type.equals("dynamic")) { physicsData.bodyDef.type = BodyDef.BodyType.DynamicBody; } else if (type.equals("kynematic")) { physicsData.bodyDef.type = BodyDef.BodyType.KinematicBody; } else if (type.equals("static")) { physicsData.bodyDef.type = BodyDef.BodyType.KinematicBody; } else {/*from w ww . j a va 2 s . c om*/ logger.error("unknown body type " + type); } }
From source file:com.siondream.core.physics.PhysicsLoader.java
License:Apache License
private void loadFixtureDefs(JsonValue root) { JsonValue fixtures = root.get("fixtures"); JsonIterator fixturesIt = fixtures.iterator(); int index = 0; while (fixturesIt.hasNext()) { JsonValue fixture = fixturesIt.next(); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.density = fixture.getFloat("density", 1.0f); fixtureDef.restitution = fixture.getFloat("restitution", 0.0f); fixtureDef.friction = fixture.getFloat("friction", 1.0f); fixtureDef.isSensor = fixture.getBoolean("isSensor", false); fixtureDef.shape = loadShape(fixture); loadFilter(fixture, fixtureDef.filter); String id = fixture.getString("id", ""); logger.info("loading fixture with id " + id); physicsData.fixtureNames.add(id); physicsData.fixtureIdx.put(id, index); physicsData.fixtureDefs.add(fixtureDef); ++index;/*from w w w.j a va 2 s . c om*/ } }
From source file:com.siondream.core.physics.PhysicsLoader.java
License:Apache License
private Filter loadFilter(JsonValue root, Filter filter) { JsonValue filterValue = root.get("filter"); if (filterValue == null) { logger.info("no filter for shape, returning default one"); return filter; }/* w ww . j a v a2 s . c o m*/ logger.info("loading filter"); CategoryBitsManager categoryManager = Env.game.getCategoryBitsManager(); filter.categoryBits = categoryManager.getCategoryBits(filterValue.getString("categoryBits", "")); filter.groupIndex = (short) filterValue.getInt("groupIndex", 0); filter.maskBits = 0; JsonValue maskBits = filterValue.get("maskBits"); JsonIterator maskBitsIt = maskBits.iterator(); while (maskBitsIt.hasNext()) { filter.maskBits |= categoryManager.getCategoryBits(maskBitsIt.next().asString()); } return filter; }