// getBaselineDiff.js
/*global adventurejs A*/
"use strict";
/**
* Get the diff between the baseline world state
* and the current world state
* to create a minimum data set for writing saved games.
* @method adventurejs.Game#getBaselineDiff
* @memberOf adventurejs.Game
* @param {Object} source_world
* @returns {String} Returns a stringified diff.
*/
adventurejs.getBaselineDiff = function Adventurejs_getBaselineDiff() {
var world_diff = {};
//var starttime = new Date().getTime();
world_diff = A.diff(this.game.baseline.world, this.game.world);
// save title for restore verification
// TODO change to int-fiction global game id
if ("undefined" === typeof world_diff._titleSerialized) {
world_diff._titleSerialized = this.game.world._titleSerialized;
}
// save timestamp
if ("undefined" === typeof world_diff._timestamp) {
world_diff._timestamp = new Date().getTime().toString();
}
// save intervals
if ("undefined" === typeof world_diff._intervals) {
world_diff._intervals = this.game.world._intervals;
}
// save vars
if ("undefined" === typeof world_diff._vars) {
world_diff._vars = this.game.world._vars;
}
// stringify
world_diff = JSON.stringify(world_diff);
//this.game.log( "log", "high", "getBaselineDiff(, 'CopyOperations' ) took "
//+ (( new Date().getTime() - starttime ) / 1000 )
//+ " seconds." );
return world_diff;
};