I've created a game based on HTML5+JS using melonJS for Windows8.
But, how do I save player's persisting game data into the disk file (preferably localFolder).
I've read the sample given in the MSDN forum, but there's no mention about saving it to JSON format file... and plus I'm a little new to Win8 app programming.
Anyways, this is what I tried (this function is called when player choose to save):
function meSave() {
//create a var to store the the persisting data during the play
var dataSaved = {
data: {
progress: game.data.progress,
HP: game.data.HP,
MP: game.data.MP,
Level: game.data.Level,
maxHP: game.data.maxHP,
maxMP: game.data.maxMP,
Money: game.data.Money,
currPos: {
x: me.game.getEntityByName('mainPlayer')[0].pos.x,
y: me.game.getEntityByName('mainPlayer')[0].pos.y,
},
currStage: me.levelDirector.getCurrentLevelId(),
}
};
var applicationData = Windows.Storage.ApplicationData.current;
var localFolder = applicationData.localFolder;
var filename = "dataFile.json";
function writeTimestamp() {
localFolder.createFileAsync("dataFile.json",
Windows.Storage.CreationCollisionOption.replaceExisting)
.then(function (file) {
return Windows.Storage.FileIO.writeTextAsync(file,
JSON.stringify(dataSaved));
}).done(function () {
game.savingDone = true;
});
}
}