Java Code Examples for com.badlogic.gdx.utils.JsonValue#get()

The following examples show how to use com.badlogic.gdx.utils.JsonValue#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceManager.java    From Unlucky with MIT License 6 votes vote down vote up
private void loadWorlds() {
    // parse worlds.json
    JsonValue base = jsonReader.parse(Gdx.files.internal("maps/worlds.json"));

    int worldIndex = 0;
    for (JsonValue world : base.get("worlds")) {
        String worldName = world.getString("name");
        String shortDesc = world.getString("shortDesc");
        String longDesc = world.getString("longDesc");
        int numLevels = world.getInt("numLevels");

        int levelIndex = 0;
        Level[] temp = new Level[numLevels];
        // load levels
        for (JsonValue level : world.get("levels")) {
            temp[levelIndex] = new Level(worldIndex, levelIndex, level.getString("name"), level.getInt("avgLevel"));
            levelIndex++;
        }
        worlds.add(new World(worldName, shortDesc, longDesc, numLevels, temp));

        worldIndex++;
    }
}
 
Example 2
Source File: ResourceManager.java    From Unlucky with MIT License 6 votes vote down vote up
private void loadItems(JsonValue itemPool, int rarity, String r) {
    Array<Item> rare = new Array<Item>();
    for (JsonValue i : itemPool.get(r)) {
        int type = i.getInt("type");
        if (type == 0) {
            rare.add(new Item(this, i.getString("name"), i.getString("desc"),
                rarity, i.getInt("imgIndex"), i.getInt("minLevel"), i.getInt("maxLevel"),
                i.getInt("hp"), i.getInt("exp"), i.getInt("sell")));
        }
        else if (type == 1) {
            rare.add(new Item(this, i.getString("name"), i.getString("desc"),
                rarity, i.getInt("imgIndex"), i.getInt("minLevel"), i.getInt("maxLevel"), i.getInt("sell")));
        }
        else if (type >= 2 && type <= 9) {
            rare.add(new Item(this, i.getString("name"), i.getString("desc"),
                i.getInt("type"), rarity, i.getInt("imgIndex"), i.getInt("minLevel"), i.getInt("maxLevel"),
                i.getInt("mhp"), i.getInt("dmg"), i.getInt("acc"), i.getInt("sell")));
        }
        else if (type == 10) {
            rare.add(new Item(this, i.getString("name"), i.getString("desc"), rarity, i.getInt("imgIndex"),
                i.getInt("minLevel"), i.getInt("maxLevel"), i.getInt("eChance"), i.getInt("sell")));
        }
    }
    items.add(rare);
}
 
Example 3
Source File: ResourceManager.java    From Unlucky with MIT License 6 votes vote down vote up
private void loadShopItems(JsonValue itemPool, int rarity, String r) {
    Array<ShopItem> rare = new Array<ShopItem>();
    for (JsonValue i : itemPool.get(r)) {
        int type = i.getInt("type");
        if (type == 0) {
            rare.add(new ShopItem(this, i.getString("name"), i.getString("desc"),
                rarity, i.getInt("imgIndex"), i.getInt("level"), i.getInt("hp"),
                i.getInt("exp"), i.getInt("sell"), i.getInt("price")));
        }
        else if (type >= 2 && type <= 9) {
            rare.add(new ShopItem(this, i.getString("name"), i.getString("desc"), type, rarity, i.getInt("imgIndex"),
                i.getInt("level"), i.getInt("mhp"), i.getInt("dmg"), i.getInt("acc"), i.getInt("sell"), i.getInt("price")));
        }
        else if (type == 10) {
            rare.add(new ShopItem(this, i.getString("name"), i.getString("desc"), rarity, i.getInt("imgIndex"),
                i.getInt("level"), i.getInt("eChance"), i.getInt("sell"), i.getInt("price")));
        }
    }
    shopItems.add(rare);
}
 
Example 4
Source File: BoundEffect.java    From talos with Apache License 2.0 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
    String effectName = jsonData.getString("effectName");
    String effectPath = parent.getWorkspace().getPath(effectName + ".p");
    FileHandle effectHandle = TalosMain.Instance().ProjectController().findFile(effectPath);
    this.name = effectName;

    if(effectHandle == null || !effectHandle.exists()) {
       throw new GdxRuntimeException("Particle effect not found");
    }

    parent.getWorkspace().registerTalosAssets(effectHandle);

    //TODO: refactor this
    ParticleEffectDescriptor descriptor = new ParticleEffectDescriptor();
    descriptor.setAssetProvider(TalosMain.Instance().TalosProject().getProjectAssetProvider());
    descriptor.load(effectHandle);
    parent.getWorkspace().getVfxLibrary().put(name, descriptor);

    // track this file
    TalosMain.Instance().FileTracker().trackFile(effectHandle, parent.getWorkspace().bvb.particleTracker);

    this.particleEffectDescriptor = descriptor;

    positionAttachment = json.readValue(AttachmentPoint.class, jsonData.get("positionAttachment"));
    JsonValue valueAttachmentsJson = jsonData.get("valueAttachments");
    for(JsonValue valueAttachmentJson: valueAttachmentsJson) {
        AttachmentPoint point = json.readValue(AttachmentPoint.class, valueAttachmentJson);
        valueAttachments.add(point);
    }

    setStartEvent(jsonData.getString("startEvent", ""));
    setCompleteEvent(jsonData.getString("completeEvent", ""));

    isBehind = jsonData.getBoolean("isBehind");

    setForever(startEvent.equals("") && completeEvent.equals(""));
}
 
Example 5
Source File: AttachmentPoint.java    From talos with Apache License 2.0 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
    attachedToSlot = jsonData.getInt("slotId", -1);
    type = Type.valueOf(jsonData.getString("type", Type.STATIC.name()));

    if(type == Type.ATTACHED) {
        attachmentType = AttachmentType.valueOf(jsonData.getString("attachmentType", AttachmentType.POSITION.name()));
        boneName = jsonData.getString("boneName");
        offset = json.readValue(Vector2.class, jsonData.get("offset"));
    } else {
        JsonValue arr = jsonData.get("value");
        numericalValue.set(arr.get(0).asFloat(), arr.get(1).asFloat(), arr.get(2).asFloat());
    }
}
 
Example 6
Source File: BodyEditorLoader.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
private Model readJson (String str) {
	Model m = new Model();
	JsonValue root = new JsonReader().parse(str);
	JsonValue bodies = root.get("rigidBodies");

	for (JsonValue body = bodies.child(); body != null; body = body.next()) {
		RigidBodyModel rbModel = readRigidBody(body);
		m.rigidBodies.put(rbModel.name, rbModel);
	}

	return m;
}
 
Example 7
Source File: HeadlessG3dModelLoader.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
private void parseAnimations (ModelData model, JsonValue json) {
	JsonValue animations = json.get("animations");
	if (animations == null) return;

	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) {
			JsonValue keyframes = node.get("keyframes");

			ModelNodeAnimation nodeAnim = new ModelNodeAnimation();
			animation.nodeAnimations.add(nodeAnim);
			nodeAnim.nodeId = node.getString("boneId");
			nodeAnim.keyframes.ensureCapacity(keyframes.size);

			for (JsonValue keyframe = keyframes.child; keyframe != null; keyframe = keyframe.next) {
				ModelNodeKeyframe kf = new ModelNodeKeyframe();
				nodeAnim.keyframes.add(kf);
				kf.keytime = keyframe.getFloat("keytime") / 1000.f;
				JsonValue translation = keyframe.get("translation");
				if (translation != null && translation.size == 3)
					kf.translation = new Vector3(translation.getFloat(0), translation.getFloat(1), translation.getFloat(2));
				JsonValue rotation = keyframe.get("rotation");
				if (rotation != null && rotation.size == 4)
					kf.rotation = new Quaternion(rotation.getFloat(0), rotation.getFloat(1), rotation.getFloat(2),
							rotation.getFloat(3));
				JsonValue scale = keyframe.get("scale");
				if (scale != null && scale.size == 3)
					kf.scale = new Vector3(scale.getFloat(0), scale.getFloat(1), scale.getFloat(2));
			}
		}
	}
}
 
Example 8
Source File: GradientColorModule.java    From talos with Apache License 2.0 5 votes vote down vote up
@Override
public void read (Json json, JsonValue jsonData) {
	super.read(json, jsonData);
       points.clear();
       final JsonValue jsonPpoints = jsonData.get("points");
       for (JsonValue point : jsonPpoints) {
           createPoint(new Color(point.getFloat("r"), point.getFloat("g"), point.getFloat("b"), 1f), point.getFloat("pos"));
       }
   }
 
Example 9
Source File: JsonSkinSerializer.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
protected boolean testOption(JsonValue ops) {
	if (ops == null) {
		return true;
	} else if (ops.isNumber()) {
		return testNumber(ops.asInt());
	} else if (ops.isArray()) {
		boolean enabled = true;
		for (int j = 0; j < ops.size; j++) {
			JsonValue ops2 = ops.get(j);
			if (ops2.isNumber()) {
				enabled = testNumber(ops2.asInt());
			} else if (ops2.isArray()) {
				boolean enabled_sub = false;
				for (int k = 0; k < ops2.size; k++) {
					JsonValue ops3 = ops2.get(k);
					if (ops3.isNumber() && testNumber(ops3.asInt())) {
						enabled_sub = true;
						break;
					}
				}
				enabled = enabled_sub;
			} else {
				enabled = false;
			}
			if (!enabled)
				break;
		}
		return enabled;
	} else {
		return false;
	}
}
 
Example 10
Source File: TextManager.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void read(Json json, JsonValue jsonData) {
	inScreenTime = json.readValue("inScreenTime", Float.class, jsonData);
	currentText = json.readValue("currentText", Text.class, jsonData);
	fifo = new LinkedList<>(json.readValue("fifo", ArrayList.class, Text.class, jsonData));
	previousCharacterAnim = json.readValue("previousAnim", String.class, jsonData);

	JsonValue jsonValue = jsonData.get("voiceManager");

	if (jsonValue != null)
		voiceManager.read(json, jsonValue);
}
 
Example 11
Source File: BodyEditorLoader.java    From ninja-rabbit with GNU General Public License v2.0 5 votes vote down vote up
private Model readJson(final String str) {
	Model m = new Model();
	JsonValue rootElem = new JsonReader().parse(str);

	JsonValue bodiesElems = rootElem.get("rigidBodies");

	for (int i = 0; i < bodiesElems.size; i++) {
		JsonValue bodyElem = bodiesElems.get(i);
		RigidBodyModel rbModel = readRigidBody(bodyElem);
		m.rigidBodies.put(rbModel.name, rbModel);
	}

	return m;
}
 
Example 12
Source File: Dialog.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void read(Json json, JsonValue jsonData) {

	BladeJson bjson = (BladeJson) json;
	if (bjson.getMode() == Mode.MODEL) {
		id = json.readValue("id", String.class, jsonData);
		// actor = json.readValue("actor", String.class, jsonData);
		options = json.readValue("options", ArrayList.class, DialogOption.class, jsonData);
	} else {
		JsonValue optionsValue = jsonData.get("options");

		int i = 0;

		for (DialogOption o : options) {
			JsonValue jsonValue = optionsValue.get(i);

			if (jsonValue == null)
				break;

			o.read(json, jsonValue);
			i++;
		}

		currentOption = json.readValue("currentOption", int.class, jsonData);
	}
}
 
Example 13
Source File: HeadlessG3dModelLoader.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
private Array<ModelNode> parseNodes (ModelData model, JsonValue json) {
	JsonValue nodes = json.get("nodes");
	if (nodes == null) {
		throw new GdxRuntimeException("At least one node is required.");
	}

	model.nodes.ensureCapacity(nodes.size);
	for (JsonValue node = nodes.child; node != null; node = node.next) {
		model.nodes.add(parseNodesRecursively(node));
	}
	return model.nodes;
}
 
Example 14
Source File: MetaLoader.java    From Mundus with Apache License 2.0 5 votes vote down vote up
private void parseModel(Meta meta, JsonValue jsonModel) {
    if(jsonModel == null) return;

    final MetaModel model = new MetaModel();
    final JsonValue materials = jsonModel.get(MetaModel.JSON_DEFAULT_MATERIALS);

    for(final JsonValue mat : materials) {
        System.out.println(mat.name);
        final String g3dbID = mat.name;
        final String assetUUID = materials.getString(g3dbID);
        model.getDefaultMaterials().put(g3dbID, assetUUID);
    }

    meta.setModel(model);
}
 
Example 15
Source File: SceneLoader.java    From Mundus with Apache License 2.0 5 votes vote down vote up
public Scene load(String name) {
    final JsonReader reader = new JsonReader();
    final JsonValue json = reader.parse(root.child(name));

    Scene scene = new Scene();
    scene.setId(json.getInt(JsonScene.ID));
    scene.setName(json.getString(JsonScene.NAME));

    // game objects
    for(JsonValue go : json.get(JsonScene.GAME_OBJECTS)) {
        scene.sceneGraph.addGameObject(convertGameObject(scene.sceneGraph, go));
    }

    return scene;
}
 
Example 16
Source File: ModelTools.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
private static void readableInkDialogsInternal(JsonValue v, StringBuilder sbMD, OrderedProperties prop) {
	if (v.isArray() || v.isObject()) {
		if (v.name != null && v.isArray() && v.parent != null && v.parent.parent != null
				&& v.parent.parent.parent != null) {
			if (v.name.contains("-"))
				sbMD.append('\n');
			else if (v.parent.parent.parent.parent == null)
				sbMD.append("\n==== " + v.name + " ====\n");
			else if (v.name.equals("s"))
				sbMD.append("  * ");
			// else
			// sbMD.append("\n-- " + v.name + " --\n");
		}

		for (int i = 0; i < v.size; i++) {
			JsonValue aValue = v.get(i);

			readableInkDialogsInternal(aValue, sbMD, prop);
		}

	} else if (v.isString() && v.asString().charAt(0) == '^') {
		String key = v.asString().substring(1).trim();

		if (key.length() == 0 || key.charAt(0) == '>')
			return;

		int idx = key.indexOf('>');
		String charName = "";

		if (idx != -1) {
			charName = key.substring(0, idx).trim();
			key = key.substring(idx + 1).trim();

			if (key.length() <= 1)
				return;
		}

		key = key.substring(1);

		String value = prop.getProperty(key);

		sbMD.append(charName + (charName.isEmpty() ? "" : ": ") + value + " (" + key + ")\n");
	}
}
 
Example 17
Source File: SpriteActor.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void read(Json json, JsonValue jsonData) {
	super.read(json, jsonData);

	BladeJson bjson = (BladeJson) json;
	if (bjson.getMode() == Mode.MODEL) {
		renderer = json.readValue("renderer", ActorRenderer.class, jsonData);
	} else {
		tweens = json.readValue("tweens", ArrayList.class, Tween.class, jsonData);

		if (tweens == null) {
			EngineLogger.debug("Couldn't load state of actor: " + id);
			return;
		}

		for (Tween<SpriteActor> t : tweens)
			t.setTarget(this);

		renderer.read(json, jsonData.get("renderer"));

		playingSound = json.readValue("playingSound", String.class, jsonData);
	}

	renderer.setWorld(bjson.getWorld());

	if (jsonData.get("scale") != null) {
		scaleX = json.readValue("scale", float.class, jsonData);
		scaleY = scaleX;
	} else {
		scaleX = json.readValue("scaleX", float.class, scaleX, jsonData);
		scaleY = json.readValue("scaleY", float.class, scaleY, jsonData);
	}

	rot = json.readValue("rot", float.class, rot, jsonData);
	tint = json.readValue("tint", Color.class, tint, jsonData);

	// backwards compatibility fakeDepth
	if (jsonData.get("depthType") != null) {
		String depthType = json.readValue("depthType", String.class, (String) null, jsonData);

		fakeDepth = "VECTOR".equals(depthType);
	} else {
		fakeDepth = json.readValue("fakeDepth", boolean.class, fakeDepth, jsonData);
	}

	bboxFromRenderer = json.readValue("bboxFromRenderer", boolean.class, bboxFromRenderer, jsonData);

	if (bboxFromRenderer)
		renderer.updateBboxFromRenderer(getBBox());

	setScale(scaleX, scaleY);
	setRot(rot);

	// restore dirtyProps after rotation and scale
	dirtyProps = json.readValue("dirtyProps", long.class, 0L, jsonData);
}
 
Example 18
Source File: MG3dModelLoader.java    From Mundus with Apache License 2.0 4 votes vote down vote up
private void parseMaterials(ModelData model, JsonValue json, String materialDir) {
    JsonValue materials = json.get("materials");
    if (materials == null) {
        // we should probably create some default material in this case
    } else {
        model.materials.ensureCapacity(materials.size);
        for (JsonValue material = materials.child; material != null; material = material.next) {
            ModelMaterial jsonMaterial = new ModelMaterial();

            String id = material.getString("id", null);
            if (id == null) throw new GdxRuntimeException("Material needs an id.");

            jsonMaterial.id = id;

            // Read material colors
            final JsonValue diffuse = material.get("diffuse");
            if (diffuse != null) jsonMaterial.diffuse = parseColor(diffuse);
            final JsonValue ambient = material.get("ambient");
            if (ambient != null) jsonMaterial.ambient = parseColor(ambient);
            final JsonValue emissive = material.get("emissive");
            if (emissive != null) jsonMaterial.emissive = parseColor(emissive);
            final JsonValue specular = material.get("specular");
            if (specular != null) jsonMaterial.specular = parseColor(specular);
            final JsonValue reflection = material.get("reflection");
            if (reflection != null) jsonMaterial.reflection = parseColor(reflection);
            // Read shininess
            jsonMaterial.shininess = material.getFloat("shininess", 0.0f);
            // Read opacity
            jsonMaterial.opacity = material.getFloat("opacity", 1.0f);

            // Read textures
            // JsonValue textures = material.get("textures");
            // if (textures != null) {
            // for (JsonValue texture = textures.child; texture != null;
            // texture = texture.next) {
            // ModelTexture jsonTexture = new ModelTexture();
            //
            // String textureId = texture.getString("id", null);
            // if (textureId == null) throw new GdxRuntimeException("Texture
            // has no id.");
            // jsonTexture.id = textureId;
            //
            // String fileName = texture.getString("filename", null);
            // if (fileName == null) throw new GdxRuntimeException("Texture
            // needs filename.");
            // jsonTexture.fileName = materialDir + (materialDir.length() ==
            // 0 || materialDir.endsWith("/") ? "" : "/")
            // + fileName;
            //
            // jsonTexture.uvTranslation =
            // readVector2(texture.get("uvTranslation"), 0f, 0f);
            // jsonTexture.uvScaling = readVector2(texture.get("uvScaling"),
            // 1f, 1f);
            //
            // String textureType = texture.getString("type", null);
            // if (textureType == null) throw new
            // GdxRuntimeException("Texture needs type.");
            //
            // jsonTexture.usage = parseTextureUsage(textureType);
            //
            // if (jsonMaterial.textures == null) jsonMaterial.textures =
            // new Array<ModelTexture>();
            // jsonMaterial.textures.add(jsonTexture);
            // }
            // }

            model.materials.add(jsonMaterial);
        }
    }
}
 
Example 19
Source File: InputFileSerializer.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
@Override
public InputFile read(Json json, JsonValue jsonData, Class clazz) {
    String path = jsonData.getString("path");
    InputFile.Type type = InputFile.Type.valueOf(jsonData.getString("type"));
    String dirFilePrefix = jsonData.getString("dirFilePrefix", null);
    String regionName = jsonData.getString("regionName", null);
    boolean recursive = jsonData.getBoolean("recursive", false);
    boolean flattenPaths = jsonData.getBoolean("flattenPaths", false);

    FileHandle fileHandle;
    if (new File(path).isAbsolute()) {
        fileHandle = Gdx.files.absolute(path);
    } else {
        fileHandle = Gdx.files.absolute(new File(root, path).getAbsolutePath());
    }

    InputFile inputFile = new InputFile(fileHandle, type);
    inputFile.setDirFilePrefix(dirFilePrefix);
    inputFile.setRegionName(regionName);
    inputFile.setRecursive(recursive);
    inputFile.setFlattenPaths(flattenPaths);

    // Ninepatch
    JsonValue ninepatch = jsonData.get("ninepatch");
    if (ninepatch != null) {
        InputFile.NinePatchProps npp = inputFile.getNinePatchProps();
        int[] splits = ninepatch.get("splits").asIntArray();
        int[] pads = ninepatch.get("pads").asIntArray();
        npp.left = splits[0];
        npp.right = splits[1];
        npp.top = splits[2];
        npp.bottom = splits[3];
        npp.padLeft = pads[0];
        npp.padRight = pads[1];
        npp.padTop = pads[2];
        npp.padBottom = pads[3];
        inputFile.setProgrammaticNinePatch(true);
    }

    return inputFile;
}
 
Example 20
Source File: Theme.java    From Klooni1010 with GNU General Public License v3.0 4 votes vote down vote up
private Theme update(final FileHandle handle) {
    if (skin == null) {
        throw new NullPointerException("A Theme.skin must be set before updating any Theme instance");
    }

    final JsonValue json = new JsonReader().parse(handle.readString());

    name = handle.nameWithoutExtension();
    displayName = json.getString("name");
    price = json.getInt("price");

    JsonValue colors = json.get("colors");
    // Java won't allow unsigned integers, we need to use Long
    background = new Color((int) Long.parseLong(colors.getString("background"), 16));
    foreground = new Color((int) Long.parseLong(colors.getString("foreground"), 16));

    JsonValue buttonColors = colors.get("buttons");
    Color[] buttons = new Color[buttonColors.size];
    for (int i = 0; i < buttons.length; ++i) {
        buttons[i] = new Color((int) Long.parseLong(buttonColors.getString(i), 16));
        if (buttonStyles[i] == null) {
            buttonStyles[i] = new ImageButton.ImageButtonStyle();
        }
        // Update the style. Since every button uses an instance from this
        // array, the changes will appear on screen automatically.
        buttonStyles[i].up = skin.newDrawable("button_up", buttons[i]);
        buttonStyles[i].down = skin.newDrawable("button_down", buttons[i]);
    }

    currentScore = new Color((int) Long.parseLong(colors.getString("current_score"), 16));
    highScore = new Color((int) Long.parseLong(colors.getString("high_score"), 16));
    bonus = new Color((int) Long.parseLong(colors.getString("bonus"), 16));
    bandColor = new Color((int) Long.parseLong(colors.getString("band"), 16));
    textColor = new Color((int) Long.parseLong(colors.getString("text"), 16));

    emptyCell = new Color((int) Long.parseLong(colors.getString("empty_cell"), 16));

    JsonValue cellColors = colors.get("cells");
    cells = new Color[cellColors.size];
    for (int i = 0; i < cells.length; ++i) {
        cells[i] = new Color((int) Long.parseLong(cellColors.getString(i), 16));
    }

    String cellTextureFile = json.getString("cell_texture");
    cellTexture = SkinLoader.loadPng("cells/" + cellTextureFile);

    return this;
}