<commit_before>Storage.prototype.setObject = function(key, value){
	this.setItem(key, JSON.stringify(value));
}

Storage.prototype.getObject = function(key){
	var value = this.getItem(key);
	return value && JSON.parse(value);
}

function saveBattleMapLocal(){
	var mapForStorage = {
		name: battleMap.name,
		zoom: battleMap.zoom,
		translateX: battleMap.translateX,
		translateY: battleMap.translateY,
		gridSpacing: battleMap.gridSpacing,
		combatants: [],
		zones: []
	};
	var storeCombatant = function(combatDude){
		var tmpCombat = {
			name: combatDude.name,
			zIndex: combatDude.zIndex,
			color: combatDude.color,
			cellX: combatDude.cellX,
			cellY: combatDude.cellY,
			size: combatDude.size,
			hp: combatDude.hp,
			initiative: combatDude.initiative,
			conditions: combatDude.conditions
		};
		mapForStorage.combatants.push(tmpCombat);
	}
	for(var cname in combatants){
		storeCombatant(combatants[cname]);
	}
	mapForStorage.zones = zoneList.map(function(zone){
		var tmpZone = {
			startCell: zone.startCell,
			name: zone.name,
			color: zone.color,
			layer: zone.layer,
			zIndex: zone.zIndex,
			rotation: zone.rotation,
			path: zone.path,
			strokeOpacity: zone.strokeOpacity,
			strokeColor: zone.strokeColor
		};
		return tmpZone;
	});<commit_msg>Added saving to cloud on client side.<commit_after>Storage.prototype.setObject = function(key, value){
	this.setItem(key, JSON.stringify(value));
}

Storage.prototype.getObject = function(key){
	var value = this.getItem(key);
	return value && JSON.parse(value);
}

function mapToSerializableObj(){
	var mapForStorage = {
		name: battleMap.name,
		zoom: battleMap.zoom,
		translateX: battleMap.translateX,
		translateY: battleMap.translateY,
		gridSpacing: battleMap.gridSpacing,
		combatants: [],
		zones: []
	};
	if(battleMap.url){
		mapForStorage.url = battleMap.url;
	}
	var storeCombatant = function(combatDude){
		var tmpCombat = {
			name: combatDude.name,
			zIndex: combatDude.zIndex,
			color: combatDude.color,
			cellX: combatDude.cellX,
			cellY: combatDude.cellY,
			size: combatDude.size,
			hp: combatDude.hp,
			initiative: combatDude.initiative,
			conditions: combatDude.conditions
		};
		mapForStorage.combatants.push(tmpCombat);
	}
	for(var cname in combatants){
		storeCombatant(combatants[cname]);
	}
	mapForStorage.zones = zoneList.map(function(zone){
		var tmpZone = {
			startCell: zone.startCell,
			name: zone.name,
			color: zone.color,
			layer: zone.layer,
			zIndex: zone.zIndex,
			rotation: zone.rotation,
			path: zone.path,
			strokeOpacity: zone.strokeOpacity,
			strokeColor: zone.strokeColor
		};
		return tmpZone;
	});
	return mapForStorage;
}

function saveBattleMapCloud(){
	var mapForStorage = mapToSerializableObj();
	if(! mapForStorage.url){
		// TODO Try not to make this on our own.
		mapForStorage.url = "/battles/new/slug";
	}
	$.ajax(mapForStorage.url, {
		'contents':'json',
		'contentType':'application/json',
		'data':JSON.stringify(mapForStorage),
		'error':function(){
			console.log('save error', arguments);
		},
		'processData':false,
		'success':function(){
			console.log('save success', arguments);
		},
		'type':'PUT'
	});
}

function saveBattleMapLocal(){
	var mapForStorage = mapToSerializableObj();
{'fraction_non_alphanumeric': 0.13114754098360656, 'fraction_numerical': 0.0, 'mean_word_length': 4.509369676320272, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2805669', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1134, 'n_words': 212}