Java Code Examples for com.badlogic.gdx.utils.Json#readValue()

The following examples show how to use com.badlogic.gdx.utils.Json#readValue() . 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: 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 2
Source File: DialogOption.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) {
		text = json.readValue("text", String.class, jsonData);
		responseText = json.readValue("responseText", String.class, jsonData);
		verbId = json.readValue("verbId", String.class, jsonData);
		next = json.readValue("next", String.class, jsonData);
		once = json.readValue("once", Boolean.class, jsonData);
		voiceId = json.readValue("soundId", String.class, jsonData);
		responseVoiceId = json.readValue("responseSoundId", String.class, jsonData);
	} else {

	}

	visible = json.readValue("visible", boolean.class, false, jsonData);
}
 
Example 3
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 4
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 5
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 6
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 7
Source File: ParticleRenderer.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
	BladeJson bjson = (BladeJson) json;
	if (bjson.getMode() == Mode.MODEL) {
		setAtlasName(json.readValue("atlasName", String.class, jsonData));
		setParticleName(json.readValue("particleName", String.class, jsonData));
		orgAlign = json.readValue("orgAlign", int.class, Align.bottom, jsonData);
	} else {
		lastAnimationTime = json.readValue("lastAnimationTime", Float.class, jsonData);
	}
}
 
Example 8
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 9
Source File: WorldSerialization.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Load the world description in 'world.json'.
 * 
 * @throws IOException
 */
public void loadWorldDesc() throws IOException {

	String worldFilename = EngineAssetManager.WORLD_FILENAME;

	if (!EngineAssetManager.getInstance().getModelFile(worldFilename).exists()) {

		// Search the world file with ".json" ext if not found.
		worldFilename = EngineAssetManager.WORLD_FILENAME + ".json";

		if (!EngineAssetManager.getInstance().getModelFile(worldFilename).exists()) {
			EngineLogger.error("ERROR LOADING WORLD: world file not found.");
			w.dispose();
			throw new IOException("ERROR LOADING WORLD: world file not found.");
		}
	}

	JsonValue root = new JsonReader()
			.parse(EngineAssetManager.getInstance().getModelFile(worldFilename).reader("UTF-8"));

	Json json = new BladeJson(w, Mode.MODEL);
	json.setIgnoreUnknownFields(true);

	int width = json.readValue("width", Integer.class, root);
	int height = json.readValue("height", Integer.class, root);

	// We know the world width, so we can set the scale
	EngineAssetManager.getInstance().setScale(width, height);
	float scale = EngineAssetManager.getInstance().getScale();

	w.setWidth((int) (width * scale));
	w.setHeight((int) (height * scale));
	w.setInitChapter(json.readValue("initChapter", String.class, root));
	w.getVerbManager().read(json, root);
	w.getI18N().loadWorld(EngineAssetManager.MODEL_DIR + EngineAssetManager.WORLD_FILENAME);
}
 
Example 10
Source File: MusicVolumeTween.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);	
	
	startVolume = json.readValue("startVolume", Float.class, 1f, jsonData);
	targetVolume = json.readValue("targetVolume", Float.class, 1f, jsonData);
}
 
Example 11
Source File: WalkTween.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) {
	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 12
Source File: Level.java    From Entitas-Java with MIT License 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {

    map = json.readValue("map", String.class, jsonData);
    levelName = json.readValue("levelName", String.class, jsonData);
    description = json.readValue("description", String.class, jsonData);
    music = json.readValue("music", String.class, jsonData);
    active = json.readValue("active", Boolean.class, jsonData);
    achievements = json.readValue("achievements", Integer.class, jsonData);
    highScore = json.readValue("highScore", Integer.class, jsonData);
    num = json.readValue("num", Integer.class, jsonData);

}
 
Example 13
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 14
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 15
Source File: SpritePosTween.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);	
	
	startX = json.readValue("startX", Float.class, jsonData);
	startY = json.readValue("startY", Float.class, jsonData);
	targetX = json.readValue("targetX", Float.class, jsonData);
	targetY = json.readValue("targetY", Float.class, jsonData);
	interpolationX = json.readValue("interpolationX", InterpolationMode.class, jsonData);
	interpolationY = json.readValue("interpolationY", InterpolationMode.class, jsonData);

}
 
Example 16
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 17
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 18
Source File: CameraTween.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);

	startX = json.readValue("startX", Float.class, jsonData);
	startY = json.readValue("startY", Float.class, jsonData);
	startZoom = json.readValue("startZoom", Float.class, jsonData);
	targetX = json.readValue("targetX", Float.class, jsonData);
	targetY = json.readValue("targetY", Float.class, jsonData);
	targetZoom = json.readValue("targetZoom", Float.class, jsonData);
}
 
Example 19
Source File: InteractiveActor.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
	super.read(json, jsonData);

	BladeJson bjson = (BladeJson) json;
	if (bjson.getMode() == Mode.MODEL) {
		layer = json.readValue("layer", String.class, jsonData);
		Vector2 r = json.readValue("refPoint", Vector2.class, jsonData);

		if (r != null) {
			float worldScale = EngineAssetManager.getInstance().getScale();
			getRefPoint().set(r.x * worldScale, r.y * worldScale);
		}

		// Load actor sounds for backwards compatibility.
		@SuppressWarnings("unchecked")
		HashMap<String, SoundDesc> sounds = json.readValue("sounds", HashMap.class, SoundDesc.class, jsonData);

		if (sounds != null) {
			for (Entry<String, SoundDesc> e : sounds.entrySet()) {
				e.getValue().setId(id + "_" + e.getKey());
				bjson.getWorld().getSounds().put(id + "_" + e.getKey(), e.getValue());
			}
		}

	} else {

		playerInside = json.readValue("playerInside", boolean.class, false, jsonData);
		String newLayer = json.readValue("layer", String.class, jsonData);

		if (newLayer != null && !newLayer.equals(layer)) {
			if (scene != null) {
				if (scene.getLayer(layer).remove(this))
					scene.getLayer(newLayer).add(this);
			}

			layer = newLayer;
		}
	}

	verbs.read(json, jsonData);
	interaction = json.readValue("interaction", boolean.class, interaction, jsonData);
	state = json.readValue("state", String.class, state, jsonData);
	zIndex = json.readValue("zIndex", float.class, zIndex, jsonData);
	desc = json.readValue("desc", String.class, desc, jsonData);
}
 
Example 20
Source File: RepeatAction.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void read (Json json, JsonValue jsonData) {
	currentRepeat = json.readValue("currentRepeat", int.class, 0, jsonData);
}