com.badlogic.gdx.utils.Json Java Examples

The following examples show how to use com.badlogic.gdx.utils.Json. 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: Text.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void write(Json json) {

	json.writeValue("str", str);
	json.writeValue("x", x);
	json.writeValue("y", y);
	json.writeValue("time", time);
	json.writeValue("type", type);
	json.writeValue("color", color);
	json.writeValue("style", style);
	json.writeValue("actorId", actorId);
	json.writeValue("voiceId", voiceId);
	json.writeValue("animation", animation);

	if (cb != null) {
		World w = ((BladeJson) json).getWorld();
		Scene s = ((BladeJson) json).getScene();
		json.writeValue("cb", ActionCallbackSerializer.find(w, s, cb));
	}
}
 
Example #2
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 #3
Source File: JsonProcessor.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
static <R> R process(Class<?> wantedType, String jsonString) {
    Json json = new Json();
    json.setIgnoreUnknownFields(true);
    json.setTypeName(null);
    R result = null;
    if (ClassReflection.isAssignableFrom(List.class, wantedType)
            || ClassReflection.isAssignableFrom(Map.class, wantedType)) {
        if (wantedType == List.class) {
            wantedType = ArrayList.class;
        } else if (wantedType == Map.class) {
            wantedType = HashMap.class;
        }
        json.setDefaultSerializer(new JsonListMapDeserializer(HashMap.class));
        result = (R) json.fromJson(wantedType, jsonString);
    } else {
        result = (R) json.fromJson(wantedType, jsonString);
    }
    return result;
}
 
Example #4
Source File: Text.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
	str = json.readValue("str", String.class, jsonData);
	x = json.readValue("x", Float.class, jsonData);
	y = json.readValue("y", Float.class, jsonData);
	time = json.readValue("time", Float.class, jsonData);
	type = json.readValue("type", Type.class, jsonData);
	color = json.readValue("color", Color.class, jsonData);
	style = json.readValue("style", String.class, jsonData);
	actorId = json.readValue("actorId", String.class, jsonData);
	voiceId = json.readValue("voiceId", String.class, jsonData);
	animation = json.readValue("animation", String.class, jsonData);
	BladeJson bjson = (BladeJson) json;
	cb = ActionCallbackSerializer.find(bjson.getWorld(), bjson.getScene(),
			json.readValue("cb", String.class, jsonData));
}
 
Example #5
Source File: DialogOption.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void write(Json json) {

	BladeJson bjson = (BladeJson) json;
	if (bjson.getMode() == Mode.MODEL) {
		json.writeValue("text", text);
		json.writeValue("responseText", responseText);
		json.writeValue("verbId", verbId);
		json.writeValue("next", next);
		json.writeValue("once", once);
		json.writeValue("soundId", voiceId);
		json.writeValue("responseSoundId", responseVoiceId);
	} else {

	}

	json.writeValue("visible", visible);
}
 
Example #6
Source File: Config.java    From beatoraja with GNU General Public License v3.0 6 votes vote down vote up
public static Config read() {
	Config config = null;
	if (Files.exists(MainController.configpath)) {
		Json json = new Json();
		json.setIgnoreUnknownFields(true);
		try (FileReader reader = new FileReader(MainController.configpath.toFile())) {
			config = json.fromJson(Config.class, reader);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	if(config == null) {
		config = new Config();
	}
	config.validate();

	PlayerConfig.init(config);

	return config;
}
 
Example #7
Source File: HighScoreManager.java    From FruitCatcher with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void retrieveHighScores() {
	FileHandle highScoresFile = Gdx.files.local(SCORES_DATA_FILE);
	if( highScoresFile.exists() ) {
		Json json = new Json();
		try {
			String encScoresStr = highScoresFile.readString();
			String scoresStr = Base64Coder.decodeString( encScoresStr );
			highScores = json.fromJson(ArrayList.class, HighScore.class, scoresStr);
			return;
           } catch( Exception e ) {
               Gdx.app.error( HighScoreManager.class.getName(), 
               		"Unable to parse high scores data file", e );
           }
	}
	highScores = new ArrayList<HighScore>();
	String playerName = textResources.getDefaultPlayerName();
	for(int i=0;i<HIGH_SCORES_COUNT;i++){
		highScores.add(new HighScore(playerName, 50 - 10*i, false));
	}
}
 
Example #8
Source File: InterpolationSerializer.java    From artemis-odb-orion with Apache License 2.0 6 votes vote down vote up
public static void registerAll(Json backend) {
	backend.setSerializer(Interpolation.Pow.class, new PowSerializer());
	backend.setSerializer(Interpolation.PowIn.class, new PowInSerializer());
	backend.setSerializer(Interpolation.PowOut.class, new PowOutSerializer());
	backend.setSerializer(Interpolation.Exp.class, new ExpSerializer());
	backend.setSerializer(Interpolation.ExpIn.class, new ExpInSerializer());
	backend.setSerializer(Interpolation.ExpOut.class, new ExpOutSerializer());
	backend.setSerializer(Interpolation.Elastic.class, new ElasticSerializer());
	backend.setSerializer(Interpolation.ElasticIn.class, new ElasticInSerializer());
	backend.setSerializer(Interpolation.ElasticOut.class, new ElasticOutSerializer());
	backend.setSerializer(Interpolation.Bounce.class, new BounceSerializer());
	backend.setSerializer(Interpolation.BounceIn.class, new BounceInSerializer());
	backend.setSerializer(Interpolation.BounceOut.class, new BounceOutSerializer());
	backend.setSerializer(Interpolation.Swing.class, new SwingSerializer());
	backend.setSerializer(Interpolation.SwingIn.class, new SwingInSerializer());
	backend.setSerializer(Interpolation.SwingOut.class, new SwingOutSerializer());
}
 
Example #9
Source File: GLTFDemo.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
private void loadModelIndex() 
{
	rootFolder = Gdx.files.internal(samplesPath);	
	
	String indexFilename = Gdx.app.getType() == ApplicationType.WebGL || Gdx.app.getType() == ApplicationType.Android ? "model-index-web.json" : "model-index.json";
	
	FileHandle file = rootFolder.child(indexFilename);
	
	entries = new Json().fromJson(Array.class, ModelEntry.class, file);
	
	ui.entrySelector.setItems(entries);
	
	if(AUTOLOAD_ENTRY != null && AUTOLOAD_VARIANT != null){
		for(int i=0 ; i<entries.size ; i++){
			ModelEntry entry = entries.get(i);
			if(entry.name.equals(AUTOLOAD_ENTRY)){
				ui.entrySelector.setSelected(entry);
				// will be auto select if there is only one variant.
				if(entry.variants.size != 1){
					ui.variantSelector.setSelected(AUTOLOAD_VARIANT);
				}
				break;
			}
		}
	}
}
 
Example #10
Source File: Recorder.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
private void writeJson() {
	Json json = new Json();
	String data = json.toJson(history);
	FileHandle fh = Gdx.files.external(demoDir + "history.json.gz");
	byte[] bytes = Compression.writeCompressedString(data);
	if (bytes == null) {
		Log.error("Could not write compressed playback (JSON)");
	} else {
		int byteCount = bytes.length;
		fh.writeBytes(bytes, false);
		Log.debug("Wrote compressed playback: " + byteCount + " bytes");
	}
}
 
Example #11
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 #12
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 #13
Source File: FontData.java    From skin-composer with MIT License 5 votes vote down vote up
@Override
public void write(Json json) {
    json.writeValue("name", name);
    if (file != null) {
        json.writeValue("file", file.path());
    } else {
        json.writeValue("file", (String) null);
    }
}
 
Example #14
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 #15
Source File: EmConfigModule.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);
    getUserValue().additive = jsonData.getBoolean("additive");
    getUserValue().attached = jsonData.getBoolean("attached");
    getUserValue().continuous = jsonData.getBoolean("continuous");
    getUserValue().aligned = jsonData.getBoolean("aligned");
}
 
Example #16
Source File: StateManager.java    From FruitCatcher with Apache License 2.0 5 votes vote down vote up
public StateBundle retrieveState() {
	FileHandle stateDataFile = Gdx.files.local(STATE_DATA_FILE);
	if( stateDataFile.exists() ) {
		Json json = new Json();
		try {
			String stateStr = stateDataFile.readString();
               return json.fromJson(StateBundle.class, stateStr );
           } catch( Exception e ) {
               Gdx.app.error( "StateManager", 
               		"Unable to parse existing game screen state data file", e );
           }
	}
	return null;
}
 
Example #17
Source File: ClientServerMessage.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void write(Json json, ClientServerMessage object, Class knownType) {
    json.writeObjectStart();
    json.writeValue("type", object.type.toString());
    if (object.participantId != null) json.writeValue("participant", object.participantId);
    if (object.data != null) json.writeValue("data", object.data);
    json.writeObjectEnd();
}
 
Example #18
Source File: FlipbookModule.java    From talos with Apache License 2.0 5 votes vote down vote up
@Override
public void write (Json json) {
    super.write(json);
    json.writeValue("regionName", regionName);

    json.writeValue("rows", rows);
    json.writeValue("cols", cols);

    json.writeValue("duration", duration);
}
 
Example #19
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 #20
Source File: ImageRenderer.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);

	BladeJson bjson = (BladeJson) json;
	if (bjson.getMode() == Mode.MODEL) {
		fanims = json.readValue("fanims", HashMap.class, AnimationDesc.class, jsonData);
	} else {

	}
}
 
Example #21
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 #22
Source File: PolylineModule.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);
    pointCount = jsonData.getInt("points", 0) + 2;
    polylineDrawable.setCount(pointCount - 2);
    regionName = jsonData.getString("regionName", "fire");
}
 
Example #23
Source File: CocoStudioUIEditor.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
public static List<String> getResources(FileHandle jsonFile) {
    dirName = jsonFile.parent().toString();

    if (!dirName.equals("")) {
        dirName += File.separator;
    }
    String json = jsonFile.readString("utf-8");
    Json jj = new Json();
    jj.setIgnoreUnknownFields(true);
    CCExport export = jj.fromJson(CCExport.class, json);
    return export.getContent().getContent().getUsedResources();
}
 
Example #24
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 #25
Source File: SpriteRotateTween.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Json json) {
	super.write(json);

	json.writeValue("startRot", startRot);
	json.writeValue("targetRot", targetRot);
}
 
Example #26
Source File: GradientColorModule.java    From talos with Apache License 2.0 5 votes vote down vote up
@Override
public void write (Json json) {
	super.write(json);
	Array<ColorPoint> points = getPoints();
	json.writeArrayStart("points");
	for (ColorPoint point : points) {
           json.writeObjectStart();
           json.writeValue("r", point.color.r);
           json.writeValue("g", point.color.g);
           json.writeValue("b", point.color.b);
           json.writeValue("pos", point.pos);
           json.writeObjectEnd();
	}
	json.writeArrayEnd();
}
 
Example #27
Source File: StateManager.java    From FruitCatcher with Apache License 2.0 5 votes vote down vote up
public void persist(GameScreenState gameScreenState, GameState gameState) {
       FileHandle stateDataFile = Gdx.files.local(STATE_DATA_FILE);
       
       StateBundle stBundle = new StateBundle();
       stBundle.gameScreenState = gameScreenState;
       stBundle.gameState = gameState;
       
       Json json = new Json();
       String state = json.toJson(stBundle);
       stateDataFile.writeString(state, false);
       
       //Gdx.app.log("GameScreen", state);
}
 
Example #28
Source File: NinePatchModule.java    From talos with Apache License 2.0 5 votes vote down vote up
@Override
public void write (Json json) {
    super.write(json);
    json.writeValue("lsplit", splits[0]);
    json.writeValue("rsplit", splits[1]);
    json.writeValue("tsplit", splits[2]);
    json.writeValue("bsplit", splits[3]);
}
 
Example #29
Source File: NinePatchModule.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);
    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 #30
Source File: OffsetModule.java    From talos with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Json json) {
    super.write(json);

    json.writeArrayStart("points");
    for (Vector2 point : getPoints()) {
        json.writeObjectStart();
        json.writeValue("x", point.x);
        json.writeValue("y", point.y);
        json.writeObjectEnd();
    }
    json.writeArrayEnd();

    json.writeObjectStart("low");
    json.writeValue("edge", lowEdge);
    json.writeValue("shape", lowShape);
    json.writeValue("side", lowSide);
    json.writeObjectStart("rect");
    json.writeValue("x", lowPos.get(0));
    json.writeValue("y", lowPos.get(1));
    json.writeValue("width", lowSize.get(0));
    json.writeValue("height", lowSize.get(1));
    json.writeObjectEnd();
    json.writeObjectEnd();

    json.writeObjectStart("high");
    json.writeValue("edge", highEdge);
    json.writeValue("shape", highShape);
    json.writeValue("side", highSide);
    json.writeObjectStart("rect");
    json.writeValue("x", highPos.get(0));
    json.writeValue("y", highPos.get(1));
    json.writeValue("width", highSize.get(0));
    json.writeValue("height", highSize.get(1));
    json.writeObjectEnd();
    json.writeObjectEnd();
}