Dras.biz Just another WordPress site

May 14, 2012

TableSerializer Classes

Filed under: SaveIt,SaveIT API Reference — mark @ 11:34

Namespace: SaveIt.TableSerializer
Use these to serialize and deserialize the stored data from the Save and LoadContexts.

SaveIt provides some basic TableSerializers, all based upon the BinaryTableSerializer class.
All inhertied classes are able to compress and uncompress the serialized/deserialized data by setting the UseCompression property to true.

Following BinaryTableSerializers exist:

File
Loads and Saves the data to a file specified in the constructor.
Leaving away a file extension delimiter (a simple dot) will add .saveIt as file extension.

PlayerPrefs
Loads and Saves the data to the PlayerPrefs entry with the given name.

Web
Loads and Saves the data to the given URL. The load uses a GET and the save uses the POST verb.

Smart
Loads and Saves the data to the most propably source. When running a WebPlayer the PlayerPrefs will be used.
When using an URL beginning with a http: or https: the Web will be used. Otherwise a file will be written.

All SaveIt contexts (SaveContext and LoadContext) will use the Smart TableSerializer when providing a string as the first
parameter for the contexts constructor.


Example:

C#:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using SaveIt;
...
 
// This will load/save the data from/to the file "MySaveGame.dat"
TableSerializer.File tableSerializer = new TableSerializer.File("MySaveGame.dat");
 
// This will load/save the data from/to the PlayerPrefs string entry "SaveData"
TableSerializer.PlayerPrefs tableSerializer = new TableSerializer.PlayerPrefs("SaveData");
...
 
SaveContext saveContext = new SaveContext(tableSerializer);
saveContext.Save(currentLevel, "currentLevel");
saveContext.Save(score, "score");
saveContext.Flush(); // NEVER FORGET THIS!
...
 
LoadContext loadContext = new LoadContext(tableSerializer);
currentLevel = loadContext.Load<int>("currentLevel");
score = loadContext.Save<int>("score");

JS:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import SaveIt;
...
 
// This will load/save the data from/to the file "MySaveGame.dat"
var tableSerializer : TableSerializer.File = TableSerializer.File("MySaveGame.dat");
 
// This will load/save the data from/to the PlayerPrefs string entry "SaveData"
var tableSerializer : TableSerializer.PlayerPrefs = TableSerializer.PlayerPrefs("SaveData");
...
 
var saveContext : SaveContext = SaveContext(tableSerializer);
saveContext.Save(currentLevel, "currentLevel");
saveContext.Save(score, "score");
saveContext.Flush(); // NEVER FORGET THIS!
...
 
var loadContext : LoadContext = LoadContext(tableSerializer);
currentLevel = loadContext.Load.<int>("currentLevel");
score = loadContext.Save.<int>("score");

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress