com.badlogic.gdx.utils.JsonValue Java Examples

The following examples show how to use com.badlogic.gdx.utils.JsonValue. 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: StyleProperty.java    From skin-composer with 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 #2
Source File: BaseActor.java    From bladecoder-adventure-engine with 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 #3
Source File: AzurLaneSpineCharacterDecoder.java    From AzurLaneSpineCharacterDecoder with MIT License 6 votes vote down vote up
@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 #4
Source File: AtlasRenderer.java    From bladecoder-adventure-engine with 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 #5
Source File: AnimationRenderer.java    From bladecoder-adventure-engine with 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) {

		// 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 #6
Source File: HeadlessG3dModelLoader.java    From gdx-proto with 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 #7
Source File: ScaleFactorJsonSerializer.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
@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 #8
Source File: VerbManager.java    From bladecoder-adventure-engine with 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 #9
Source File: Tween.java    From bladecoder-adventure-engine with 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 #10
Source File: GjScoreboardEntry.java    From gdx-gamesvcs with 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 #11
Source File: GameScreenState.java    From FruitCatcher with 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 File: EmitterModuleWrapper.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);
    delayField.setText(module.defaultDelay + "");
    durationField.setText(module.defaultDuration + "");
    emissionField.setText(module.defaultRate + "");
}
 
Example #13
Source File: MathModule.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);
    defaultA = jsonData.getFloat("a", 0);
    defaultB = jsonData.getFloat("b", 0);
    currentExpression = MathExpressionMappings.getMathExpressionForName(jsonData.getString("mathExpression"));
}
 
Example #14
Source File: FromToModuleWrapper.java    From talos with Apache License 2.0 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
    lock = true;
    super.read(json, jsonData);
    lock = false;
    dragFrom.position.set(module.defaultFrom);
    dragTo.position.set(module.defaultTo);
}
 
Example #15
Source File: FontData.java    From skin-composer with MIT License 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
    name = jsonData.getString("name");
    if (!jsonData.get("file").isNull()) {
        file = new FileHandle(jsonData.getString("file"));
    }
}
 
Example #16
Source File: FlipbookModuleWrapper.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);
    rows.setValue(module.getRows());
    cols.setValue(module.getCols());
    duration.setValue(module.duration);
}
 
Example #17
Source File: JsonResultUnitTests.java    From gdx-facebook with Apache License 2.0 5 votes vote down vote up
@Test
public void constructorWithJsonValue() {
    JsonReader writer = new JsonReader();
    JsonValue value = writer.parse("{testValue:5}");
    fixture = new JsonResult(value);
    assertEquals(value, fixture.getJsonValue());

    assertTrue(fixture.getJsonValue().has("testValue"));
    assertEquals(5, fixture.getJsonValue().getInt("testValue"));
}
 
Example #18
Source File: OffsetModuleWrapper.java    From talos with Apache License 2.0 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
    lockUpdate = true;
    super.read(json, jsonData);

    equalsButton.setChecked(jsonData.getBoolean("equals"));
    lowShape.setScaleVal(jsonData.getFloat("lowScale"));
    highShape.setScaleVal(jsonData.getFloat("highScale"));

    updateWidgetsFromModuleData();
    lockUpdate = false;
}
 
Example #19
Source File: DisableActionAction.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public Action getAction() {
	if(action == null) {
		Json json = new Json();
		JsonValue root = new JsonReader().parse(serializedAction);
		action =  ActionUtils.readJson(w, json, root);
	}
	
	return action;
}
 
Example #20
Source File: SpriteScaleTween.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
	super.read(json, jsonData);

	startSclX = json.readValue("startSclX", Float.class, jsonData);
	startSclY = json.readValue("startSclY", Float.class, jsonData);
	
	targetSclX = json.readValue("targetSclX", Float.class, jsonData);
	targetSclY = json.readValue("targetSclY", Float.class, jsonData);
}
 
Example #21
Source File: MG3dModelLoader.java    From Mundus with Apache License 2.0 5 votes vote down vote up
private VertexAttribute[] parseAttributes(JsonValue attributes) {
    Array<VertexAttribute> vertexAttributes = new Array<VertexAttribute>();
    int unit = 0;
    int blendWeightCount = 0;
    for (JsonValue value = attributes.child; value != null; value = value.next) {
        String attribute = value.asString();
        String attr = (String) attribute;
        if (attr.equals("POSITION")) {
            vertexAttributes.add(VertexAttribute.Position());
        } else if (attr.equals("NORMAL")) {
            vertexAttributes.add(VertexAttribute.Normal());
        } else if (attr.equals("COLOR")) {
            vertexAttributes.add(VertexAttribute.ColorUnpacked());
        } else if (attr.equals("COLORPACKED")) {
            vertexAttributes.add(VertexAttribute.ColorPacked());
        } else if (attr.equals("TANGENT")) {
            vertexAttributes.add(VertexAttribute.Tangent());
        } else if (attr.equals("BINORMAL")) {
            vertexAttributes.add(VertexAttribute.Binormal());
        } else if (attr.startsWith("TEXCOORD")) {
            vertexAttributes.add(VertexAttribute.TexCoords(unit++));
        } else if (attr.startsWith("BLENDWEIGHT")) {
            vertexAttributes.add(VertexAttribute.BoneWeight(blendWeightCount++));
        } else {
            throw new GdxRuntimeException("Unknown vertex attribute '" + attr
                    + "', should be one of position, normal, uv, tangent or binormal");
        }
    }
    return vertexAttributes.toArray(VertexAttribute.class);
}
 
Example #22
Source File: SpriteAlphaTween.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
	super.read(json, jsonData);

	startAlpha = json.readValue("startAlpha", float.class, 1.0f, jsonData);
	targetAlpha = json.readValue("targetAlpha", float.class, 1.0f, jsonData);
}
 
Example #23
Source File: CustomStyle.java    From skin-composer with MIT License 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
    name = jsonData.getString("name");
    properties = json.readValue("properties", Array.class, CustomProperty.class, jsonData);
    for (CustomProperty property : properties) {
        property.setParentStyle(this);
    }
    deletable = jsonData.getBoolean("deletable");
}
 
Example #24
Source File: ColorModuleWrapper.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);

    final Color color = module.getColor();
    tmpClr.set(color);

    colorBtn.setColor(tmpClr);
    rField.setText(""+(int)(color.r * 255f));
    gField.setText(""+(int)(color.g * 255f));
    bField.setText(""+(int)(color.b * 255f));
}
 
Example #25
Source File: GameJoltClient.java    From gdx-gamesvcs with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method when just interested if GameJolt request was successful
 */
protected boolean parseSuccessFromResponse(String json) {
    JsonValue response = null;
    boolean success;
    try {
        response = new JsonReader().parse(json).get("response");
        success = response != null && response.getBoolean("success");
    } catch (Throwable t) {
        Gdx.app.error(GAMESERVICE_ID, "Cannot parse GameJolt response: " + json, t);
        success = false;
    }
    return success;
}
 
Example #26
Source File: FreeTypeFontData.java    From skin-composer with MIT License 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
    name = jsonData.getString("name");
    file = jsonData.has("file") ? Gdx.files.absolute(jsonData.getString("file")) : null;
    previewTTF = jsonData.getString("previewTTF");
    useCustomSerializer = jsonData.getBoolean("useCustomSerializer", false);
    size = jsonData.getInt("size", 16);
    mono = jsonData.getBoolean("mono");
    hinting = jsonData.getString("hinting", "AutoMedium");
    color = jsonData.getString("color");
    gamma = jsonData.getFloat("gamma", 1.8f);
    renderCount = jsonData.getInt("renderCount", 2);
    borderWidth = jsonData.getFloat("borderWidth", 0);
    borderColor = jsonData.getString("borderColor");
    borderStraight = jsonData.getBoolean("borderStraight", false);
    borderGamma = jsonData.getFloat("borderGamma", 1.8f);
    shadowOffsetX = jsonData.getInt("shadowOffsetX", 0);
    shadowOffsetY = jsonData.getInt("shadowOffsetY", 0);
    shadowColor = jsonData.getString("shadowColor");
    spaceX = jsonData.getInt("spaceX");
    spaceY = jsonData.getInt("spaceY");
    characters = jsonData.getString("characters", "");
    kerning = jsonData.getBoolean("kerning", true);
    flip = jsonData.getBoolean("flip", false);
    genMipMaps = jsonData.getBoolean("genMipMaps", false);
    minFilter = jsonData.getString("minFilter", "Nearest");
    magFilter = jsonData.getString("magFilter", "Nearest");
    incremental = jsonData.getBoolean("incremental");
}
 
Example #27
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 #28
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 #29
Source File: GLTFMorphTarget.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
	for(JsonIterator i = jsonData.iterator(); i.hasNext() ; ){
		JsonValue e = i.next();
		put(e.name, e.asInt());
	}
}
 
Example #30
Source File: FallingObjectState.java    From FruitCatcher with Apache License 2.0 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
	posX = json.readValue("posX", Integer.class, jsonData);
	posY = json.readValue("posY", Integer.class, jsonData);
	index = json.readValue("index", Integer.class, jsonData);
	points = json.readValue("points", Integer.class, jsonData);
	int val = json.readValue("type", Integer.class, jsonData);
	type = FallingObjectType.fromValue(val);
}