All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.flixel.system.FlxSaveData Maven / Gradle / Ivy

The newest version!
package org.flixel.system;

import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.JsonWriter;

/**
 * This represents the data object in FlxSave.
 * 
 * @author Thomas Weston
 */
public class FlxSaveData
{
	/**
	 * Internal reference to the SharedObject.
	 */
	protected Preferences _sharedObject;

	/**
	 * Internal, used for serialising Objects.
	 */
	protected Json _json;

	/**
	 * Creates a new FlxSaveData
	 * 
	 * @param	SharedObject	The Preferences to save to.
	 */
	public FlxSaveData(Preferences SharedObject)
	{
		_sharedObject = SharedObject;
		_json = new Json(JsonWriter.OutputType.json);
	}

	/**
	 * Add a value to the data.
	 * 
	 * @param	Key		A String, used to retrieve the object later.
	 * @param	Value	The object to store.
	 */
	public void put(String Key, Object Value)
	{
		_sharedObject.putString(Key, _json.toJson(Value));
	}

	/**
	 * Get a value from the shared object. Returns null if the key doesn't exist.
	 * 
	 * @param	Key		The object's key.
	 * @param	Type	The class of the object you are retrieving.
	 * 
	 * @return	The object.
	 */
	public  T get(String Key, Class Type)
	{
		return _json.fromJson(Type, _sharedObject.getString(Key));
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy