diff --git a/js/save.js b/js/save.js index cb24367c95f8b89032cea0811679dbdfd1dfa4b2..6d4f674d5f88db58d297ae74c88b1941a6b84050 100644 --- a/js/save.js +++ b/js/save.js @@ -9,31 +9,41 @@ function mergeObjects(a, b){ return b; } for(var v in b){ - a[v] = b[v]; + if (typeof a[v] === 'object') { + a[v] = mergeObjects(a[v], b[v]) + } else { + a[v] = b[v]; + } } return a; } function Save(){ this.data = { - 'gender' : '', - 'name' : '', 'background' : 1, 'masturbationTimer' : 20, - 'name' : '', 'gender' : "male", - 'size' : "medium", 'autoFade' : 1, 'cardSuggest' : 2, 'gameDelay' : 3, 'dealAnimation' : 3, 'autoForfeit' : 4, - 'clothing' : [false, false, true, false, true, - false, true, true, false, true, - false, false, true, false, true], + 'male' : { + 'name' : '', + 'clothing' : [false, false, true, false, true, false, + false, true, true, false, false, true, + false, false, true, true, false, true], + 'size' : 'medium' + }, + 'female' : { + 'name' : '', + 'clothing' : [false, false, true, false, true, true, + false, true, true, false, false, true, + false, false, false, true, false, true], + 'size' : 'medium' + }, 'endings' : {} }; - this.saveCookie = function(){ Cookies.set('save', this.data, {expires: 3652}); }; @@ -43,17 +53,33 @@ function Save(){ if(cookie !== undefined){ this.data = mergeObjects(this.data, JSON.parse(cookie)); } - this.loadSave(); + // Copy data from older cookie to the gender-specific substructure. + if (this.data['name'] !== undefined) { + this.data[this.data['gender']]['name'] = this.data['name']; + delete this.data['name']; + } + if (this.data['clothing'] !== undefined) { + this.data[this.data['gender']]['clothing'] = this.data['clothing']; + delete this.data['clothing']; + } + if (this.data['size'] !== undefined) { + this.data[this.data['gender']]['size'] = this.data['size']; + delete this.data['size']; + } + this.loadOptions(); + this.loadPlayer(); }; - this.loadSave = function(){ + this.loadPlayer = function() { + $nameField.val(this.data[players[HUMAN_PLAYER].gender]['name']); + changePlayerSize(this.data[players[HUMAN_PLAYER].gender]['size']); + selectedChoices = this.data[players[HUMAN_PLAYER].gender]['clothing']; + updateTitleGender(); + }; + this.loadOptions = function(){ players[HUMAN_PLAYER].timer = this.data['masturbationTimer']; - $nameField.val(this.data['name']); - changePlayerGender(this.data['gender']); - changePlayerSize(this.data['size']); + players[HUMAN_PLAYER].gender = this.data['gender']; setBackground(this.data['background']); - selectedChoices = this.data['clothing'].slice(0); - updateTitleClothing(); setAutoFade(this.data['autoFade']); setCardSuggest(this.data['cardSuggest']); @@ -106,10 +132,10 @@ function Save(){ this.saveCookie(); }; this.savePlayer = function(){ - this.data['name'] = $nameField.val(); this.data['gender'] = players[HUMAN_PLAYER].gender; - this.data['size'] = players[HUMAN_PLAYER].size; - this.data['clothing'] = selectedChoices; + this.data[this.data['gender']]['name'] = $nameField.val(); + this.data[this.data['gender']]['size'] = players[HUMAN_PLAYER].size; + this.data[this.data['gender']]['clothing'] = selectedChoices.slice(); this.saveCookie(); }; diff --git a/js/spniTitle.js b/js/spniTitle.js index 30578e14363ffe0ea029a5c5d20be03ad16c6773..cb5f137dc8cd398d3a19ea3b35aa5f3bba522071 100644 --- a/js/spniTitle.js +++ b/js/spniTitle.js @@ -146,21 +146,29 @@ function holdTitleClothing () { * screen, or this was called by an internal source. ************************************************************/ function changePlayerGender (gender) { + save.savePlayer(); players[HUMAN_PLAYER].gender = gender; + save.loadPlayer(); +} +/************************************************************ + * Updates the gender dependent controls on the title screen. + ************************************************************/ +function updateTitleGender() { /* update visuals */ - if (gender == eGender.MALE) { + if (players[HUMAN_PLAYER].gender == eGender.MALE) { $genderButtons[0].css({opacity: 1}); $genderButtons[1].css({opacity: 0.4}); $playerSizeContainers[0].show(); $playerSizeContainers[1].hide(); - } else if (gender == eGender.FEMALE) { + } else if (players[HUMAN_PLAYER].gender == eGender.FEMALE) { $genderButtons[0].css({opacity: 0.4}); $genderButtons[1].css({opacity: 1}); $playerSizeContainers[0].hide(); $playerSizeContainers[1].show(); } loadClothing(); + updateTitleClothing(); } /************************************************************