Java Code Examples for com.badlogic.gdx.utils.JsonValue

The following examples show how to use com.badlogic.gdx.utils.JsonValue. These examples are extracted from open source projects. 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
@Override
public void create() {
	batch = new SpriteBatch();
	img = new Texture("core/assets/WatchDog.png");
	camera = new OrthographicCamera();
	camera.setToOrtho(false);

	spineKeeperArray = new Array<PerSpineKeeper>();
	if (jsonType) {
		JsonReader reader = new JsonReader();
		JsonValue jsonValue = reader.parse(Gdx.files.absolute(args.get(0)));
		System.out.println();
		array = jsonValue.asStringArray();
		size = array.length;
	}
	path = System.getProperty("user.dir");

	scale=Float.parseFloat(Gdx.files.internal("core/assets/scale.txt").readString());
}
 
Example 2
@Override
public void read(Json json, JsonValue jsonData) {

	BladeJson bjson = (BladeJson) json;
	if (bjson.getMode() == Mode.MODEL) {

		// In next versions, the fanims loading will be generic
		// fanims = json.readValue("fanims", HashMap.class, AnimationDesc.class,
		// jsonData);

		initAnimation = json.readValue("initAnimation", String.class, jsonData);
		orgAlign = json.readValue("orgAlign", int.class, Align.bottom, jsonData);
	} else {

		String currentAnimationId = json.readValue("currentAnimation", String.class, jsonData);

		if (currentAnimationId != null)
			currentAnimation = fanims.get(currentAnimationId);
		flipX = json.readValue("flipX", Boolean.class, jsonData);
	}
}
 
Example 3
@Override
public ScaleFactorModel read(Json json, JsonValue jsonData, Class type) {
    String suffix = "";
    float factor = 1f;
    TexturePacker.Resampling resampling = TexturePacker.Resampling.bicubic;

    JsonValue.JsonIterator iterator = jsonData.iterator();
    while (iterator.hasNext()) {
        JsonValue value = iterator.next();
        switch (value.name) {
            case "suffix":
                suffix = value.asString();
                break;
            case "factor":
                factor = value.asFloat();
                break;
            case "resampling":
                resampling = TexturePacker.Resampling.valueOf(value.asString());
                break;
        }
    }
    return new ScaleFactorModel(suffix, factor, resampling);
}
 
Example 4
Source Project: gdx-proto   Source File: HeadlessG3dModelLoader.java    License: Apache License 2.0 6 votes vote down vote up
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);
	//parseMaterials(model, json, handle.parent().path());
	parseNodes(model, json);
	parseAnimations(model, json);
	return model;
}
 
Example 5
Source Project: bladecoder-adventure-engine   Source File: AtlasRenderer.java    License: Apache License 2.0 6 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) {
		fanims = json.readValue("fanims", HashMap.class, AtlasAnimationDesc.class, jsonData);
	} else {

		currentFrameIndex = json.readValue("currentFrameIndex", Integer.class, jsonData);
		faTween = json.readValue("faTween", FATween.class, jsonData);

		if (faTween != null)
			faTween.setTarget(this);
	}
}
 
Example 6
Source Project: skin-composer   Source File: StyleProperty.java    License: MIT License 6 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonValue) {
    try {
        name = jsonValue.getString("name");
        optional = jsonValue.getBoolean("optional");
        if (jsonValue.get("value").isNumber()) {
            type = Float.TYPE;
            value = Double.parseDouble(jsonValue.getString("value"));
        } else {
            type = ClassReflection.forName(jsonValue.getString("type"));
            if (jsonValue.get("value").isNull()) {
                value = null;
            } else {
                value = jsonValue.getString("value");
            }
        }
    } catch (ReflectionException ex) {
        Gdx.app.error(getClass().toString(), "Error reading from serialized object" , ex);
        DialogFactory.showDialogErrorStatic("Read Error...","Error reading from serialized object.\n\nOpen log?");
    }
}
 
Example 7
Source Project: bladecoder-adventure-engine   Source File: Tween.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
	duration = json.readValue("duration", Float.class, jsonData);
	time = json.readValue("time", Float.class, jsonData);

	reverse = json.readValue("reverse", Boolean.class, jsonData);
	began = json.readValue("began", Boolean.class, jsonData);
	complete = json.readValue("complete", Boolean.class, jsonData);
	type = json.readValue("type", Type.class, jsonData);
	count = json.readValue("count", Integer.class, jsonData);

	interpolation = json.readValue("interpolation", InterpolationMode.class, jsonData);

	BladeJson bjson = (BladeJson) json;
	cb = ActionCallbackSerializer.find(bjson.getWorld(), bjson.getScene(),
			json.readValue("cb", String.class, jsonData));
}
 
Example 8
Source Project: gdx-gamesvcs   Source File: GjScoreboardEntry.java    License: Apache License 2.0 6 votes vote down vote up
protected static GjScoreboardEntry fromJson(JsonValue json, int rank, String currentPlayer) {
    GjScoreboardEntry gje = new GjScoreboardEntry();
    gje.rank = String.valueOf(rank);
    gje.score = json.getString("score");
    gje.sort = json.getLong("sort");
    gje.tag = json.getString("extra_data");
    String userId = json.getString("user_id");

    if (userId != null && !userId.isEmpty()) {
        gje.userId = userId;
        gje.displayName = json.getString("user");
        gje.currentPlayer = (currentPlayer != null && currentPlayer.equalsIgnoreCase(gje.displayName));
    } else
        gje.displayName = json.getString("guest");

    gje.stored = json.getString("stored");

    return gje;
}
 
Example 9
Source Project: bladecoder-adventure-engine   Source File: VerbManager.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void read(Json json, JsonValue jsonData) {

	BladeJson bjson = (BladeJson) json;
	if (bjson.getMode() == Mode.MODEL) {
		this.w = bjson.getWorld();
		
		verbs = json.readValue("verbs", HashMap.class, Verb.class, jsonData);
	} else {
		for (String v : verbs.keySet()) {
			Verb verb = verbs.get(v);

			JsonValue jsonValue = jsonData.get("verbs").get(v);

			if (jsonValue != null)
				verb.read(json, jsonValue);
			else
				EngineLogger.debug("LOAD WARNING: Verb not found in saved game: " + jsonData.name + "." + v);
		}
	}
}
 
Example 10
Source Project: bladecoder-adventure-engine   Source File: BaseActor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
	BladeJson bjson = (BladeJson) json;
	if (bjson.getMode() == Mode.MODEL) {
		id = json.readValue("id", String.class, jsonData);

		float[] verts = json.readValue("bbox", float[].class, jsonData);

		if (verts.length > 0)
			bbox.setVertices(verts);
	}

	Vector2 pos = json.readValue("pos", Vector2.class, jsonData);

	if (pos != null) {
		float worldScale = EngineAssetManager.getInstance().getScale();
		bbox.setPosition(pos.x * worldScale, pos.y * worldScale);
		bbox.setScale(worldScale, worldScale);
	}

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

	dirtyProps = json.readValue("dirtyProps", long.class, 0L, jsonData);
}
 
Example 11
Source Project: FruitCatcher   Source File: GameScreenState.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void read(Json json, JsonValue jsonData) {
	startGameTime = json.readValue("startGameTime", Long.class, jsonData);
	lastBadObjectTime = json.readValue("lastBadObjectTime", Long.class, jsonData);
	lastBonusItemTime = json.readValue("lastBonusItemTime", Long.class, jsonData);
	lastFruitTime = json.readValue("lastFruitTime", Long.class, jsonData);
	score = json.readValue("score", Integer.class, jsonData);
	basketX = json.readValue("basketX", Integer.class, jsonData);
	isPaused = json.readValue("isPaused", Boolean.class, jsonData);
	isStarted = json.readValue("isStarted", Boolean.class, jsonData);
	isFinished = json.readValue("isFinished", Boolean.class, jsonData);
	secondsRemaining = json.readValue("secondsRemaining", Integer.class, jsonData);
	
	fallingObjectStates = json.readValue( "fallingObjects", Array.class,
			FallingObjectState.class, jsonData ); 
}
 
Example 12
Source Project: bladecoder-adventure-engine   Source File: ImageRenderer.java    License: Apache License 2.0 5 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) {
		fanims = json.readValue("fanims", HashMap.class, AnimationDesc.class, jsonData);
	} else {

	}
}
 
Example 13
Source Project: talos   Source File: MathModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void read (Json json, JsonValue jsonData) {
    super.read(json, jsonData);
    defaultA = jsonData.getFloat("a", 0);
    defaultB = jsonData.getFloat("b", 0);
    currentExpression = MathExpressionMappings.getMathExpressionForName(jsonData.getString("mathExpression"));
}
 
Example 14
Source Project: bladecoder-adventure-engine   Source File: WalkTween.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void read(Json json, JsonValue jsonData) {
	super.read(json, jsonData);

	walkingPath = json.readValue("path", ArrayList.class, Vector2.class, jsonData);
	currentStep = json.readValue("currentStep", Integer.class, jsonData);
	speed = json.readValue("speed", Float.class, jsonData);

	World w = ((BladeJson) json).getWorld();
	Scene s = ((BladeJson) json).getScene();
	walkCb = ActionCallbackSerializer.find(w, s, json.readValue("walkCb", String.class, jsonData));
}
 
Example 15
Source Project: bladecoder-adventure-engine   Source File: ModelTools.java    License: Apache License 2.0 5 votes vote down vote up
public static void readableInkDialogs(String story, String lang) throws IOException {
	String file = Ctx.project.getModelPath() + "/" + story + EngineAssetManager.INK_EXT;

	BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
	StringBuilder sb = new StringBuilder();

	try {
		String line = br.readLine();

		// Replace the BOM mark
		if (line != null)
			line = line.replace('\uFEFF', ' ');

		while (line != null) {
			sb.append(line);
			sb.append("\n");
			line = br.readLine();
		}

	} finally {
		br.close();
	}

	JsonValue root = new JsonReader().parse(sb.toString());

	// TODO: Add lang and check if default
	File propFile = new File(Ctx.project.getModelPath() + "/" + story + "-ink.properties");
	OrderedProperties langProp = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering()
			.build();

	langProp.load(new InputStreamReader(new FileInputStream(propFile), I18N.ENCODING));

	// .md generation to have a better readable document of texts
	StringBuilder mdString = new StringBuilder();

	readableInkDialogsInternal(root, mdString, langProp);
	FileUtils.writeStringToFile(new File(Ctx.project.getModelPath() + "/" + story + "-DIALOGS.txt"),
			mdString.toString());
}
 
Example 16
Source Project: Mundus   Source File: MetaLoader.java    License: Apache License 2.0 5 votes vote down vote up
private void parseTerrain(Meta meta, JsonValue jsonTerrain) {
    if(jsonTerrain == null) return;

    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);
}
 
Example 17
Source Project: talos   Source File: FromToModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
    super.read(json, jsonData);

    defaultFrom.x = jsonData.getFloat("fromX", 0);
    defaultFrom.y = jsonData.getFloat("fromY", 0);
    defaultTo.x = jsonData.getFloat("toX", 0);
    defaultTo.y = jsonData.getFloat("toY", 0);
}
 
Example 18
Source Project: gdx-proto   Source File: HeadlessG3dModelLoader.java    License: 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 19
Source Project: talos   Source File: RandomRangeModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void read (Json json, JsonValue jsonData) {
    super.read(json, jsonData);
    min = jsonData.getFloat("min", 0);
    max = jsonData.getFloat("max", 0);
    distributed = jsonData.getBoolean("distributed", false);
}
 
Example 20
Source Project: artemis-odb-orion   Source File: OperationTreeSerializer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public OperationTree read(Json json, JsonValue jsonData, Class type) {
	try {
		Class<Operation> opType =
			(Class<Operation>) Class.forName(jsonData.child.child.asString());

		Operation op = json.readValue(opType, jsonData.child);
		return util.toNode(op);
	} catch (ClassNotFoundException e) {
		throw new RuntimeException(e);
	}
}
 
Example 21
@Override
public void read(Json json, JsonValue jsonData) {
	super.read(json, jsonData);	
	
	startVolume = json.readValue("startVolume", Float.class, 1f, jsonData);
	targetVolume = json.readValue("targetVolume", Float.class, 1f, jsonData);
}
 
Example 22
Source Project: Mundus   Source File: MetaLoader.java    License: 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 23
@Override
public void read(Json json, JsonValue jsonData) {
	super.read(json, jsonData);	
	
	startRot = json.readValue("startRot", Float.class, jsonData);
	targetRot = json.readValue("targetRot", Float.class, jsonData);
}
 
Example 24
Source Project: talos   Source File: RibbonModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void read (Json json, JsonValue jsonData) {
    super.read(json, jsonData);
    detail = jsonData.getInt("details", 10);
    memoryDuration = jsonData.getFloat("memory", 10);
    RibbonRenderer renderer = (RibbonRenderer) outputValue.getDrawable();
    renderer.setConfig(detail, memoryDuration);
}
 
Example 25
Source Project: talos   Source File: GradientColorModule.java    License: 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 26
Source Project: talos   Source File: NinePatchModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void read (Json json, JsonValue jsonData) {
    super.read(json, jsonData);
    splits[0] = jsonData.getInt("lsplit", 0);
    splits[1] = jsonData.getInt("rsplit", 0);
    splits[2] = jsonData.getInt("tsplit", 0);
    splits[3] = jsonData.getInt("bsplit", 0);
}
 
Example 27
Source Project: talos   Source File: PolylineModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void read (Json json, JsonValue jsonData) {
    super.read(json, jsonData);
    pointCount = jsonData.getInt("points", 0) + 2;
    polylineDrawable.setCount(pointCount - 2);
    regionName = jsonData.getString("regionName", "fire");
}
 
Example 28
Source Project: bladecoder-adventure-engine   Source File: SpineRenderer.java    License: Apache License 2.0 5 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) {
		fanims = json.readValue("fanims", HashMap.class, SpineAnimationDesc.class, jsonData);

		world = bjson.getWorld();
	} else {

		animationCb = ActionCallbackSerializer.find(((BladeJson) json).getWorld(), ((BladeJson) json).getScene(),
				json.readValue("cb", String.class, jsonData));

		currentCount = json.readValue("currentCount", Integer.class, jsonData);

		if (currentAnimation != null)
			currentAnimationType = json.readValue("currentAnimationType", Tween.Type.class, jsonData);

		lastAnimationTime = json.readValue("lastAnimationTime", Float.class, jsonData);
		complete = json.readValue("complete", Boolean.class, jsonData);
		loopCount = json.readValue("loopCount", int.class, loopCount, jsonData);

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

	skin = json.readValue("skin", String.class, skin, jsonData);
}
 
Example 29
Source Project: beatoraja   Source File: JsonSkinSerializer.java    License: 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 30
Source Project: talos   Source File: FlipbookModuleWrapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
    super.read(json, jsonData);
    rows.setValue(module.getRows());
    cols.setValue(module.getCols());
    duration.setValue(module.duration);
}