Changed CM.Config into CM.Options
This commit is contained in:
@@ -9,59 +9,59 @@
|
||||
* This function saves the config of CookieMonster to localStorage
|
||||
* It is called by CM.LoadConfig(), CM.RestoreDefault(),
|
||||
* any of the CM.ToggleConfig() functions and upon changes to URL or volume settings
|
||||
* @param {object} config The Config to be saved (normally CM.Config)
|
||||
* @param {object} config The Config to be saved (normally CM.Options)
|
||||
*/
|
||||
CM.SaveConfig = function(config) {
|
||||
localStorage.setItem(CM.ConfigPrefix, JSON.stringify(config));
|
||||
}
|
||||
|
||||
/**
|
||||
* This function loads the config of CookieMonster saved in localStorage and loads it into CM.Config
|
||||
* This function loads the config of CookieMonster saved in localStorage and loads it into CM.Options
|
||||
* It is called by CM.DelayInit() and CM.RestoreDefault()
|
||||
*/
|
||||
CM.LoadConfig = function() {
|
||||
if (localStorage.getItem(CM.ConfigPrefix) != null) {
|
||||
CM.Config = JSON.parse(localStorage.getItem(CM.ConfigPrefix));
|
||||
CM.Options = JSON.parse(localStorage.getItem(CM.ConfigPrefix));
|
||||
|
||||
// Check values
|
||||
var mod = false;
|
||||
for (var i in CM.Data.ConfigDefault) {
|
||||
if (typeof CM.Config[i] === 'undefined') {
|
||||
if (typeof CM.Options[i] === 'undefined') {
|
||||
mod = true;
|
||||
CM.Config[i] = CM.Data.ConfigDefault[i];
|
||||
CM.Options[i] = CM.Data.ConfigDefault[i];
|
||||
}
|
||||
else if (i != 'StatsPref' && i != 'Colors') {
|
||||
if (i.indexOf('SoundURL') == -1) {
|
||||
if (!(CM.Config[i] > -1 && CM.Config[i] < CM.ConfigData[i].label.length)) {
|
||||
if (!(CM.Options[i] > -1 && CM.Options[i] < CM.ConfigData[i].label.length)) {
|
||||
mod = true;
|
||||
CM.Config[i] = CM.Data.ConfigDefault[i];
|
||||
CM.Options[i] = CM.Data.ConfigDefault[i];
|
||||
}
|
||||
}
|
||||
else { // Sound URLs
|
||||
if (typeof CM.Config[i] != 'string') {
|
||||
if (typeof CM.Options[i] != 'string') {
|
||||
mod = true;
|
||||
CM.Config[i] = CM.Data.ConfigDefault[i];
|
||||
CM.Options[i] = CM.Data.ConfigDefault[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (i == 'StatsPref') {
|
||||
for (var j in CM.Data.ConfigDefault.StatsPref) {
|
||||
if (typeof CM.Config[i][j] === 'undefined' || !(CM.Config[i][j] > -1 && CM.Config[i][j] < 2)) {
|
||||
if (typeof CM.Options[i][j] === 'undefined' || !(CM.Options[i][j] > -1 && CM.Options[i][j] < 2)) {
|
||||
mod = true;
|
||||
CM.Config[i][j] = CM.Data.ConfigDefault[i][j];
|
||||
CM.Options[i][j] = CM.Data.ConfigDefault[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
else { // Colors
|
||||
for (var j in CM.Data.ConfigDefault.Colors) {
|
||||
if (typeof CM.Config[i][j] === 'undefined' || typeof CM.Config[i][j] != 'string') {
|
||||
if (typeof CM.Options[i][j] === 'undefined' || typeof CM.Options[i][j] != 'string') {
|
||||
mod = true;
|
||||
CM.Config[i][j] = CM.Data.ConfigDefault[i][j];
|
||||
CM.Options[i][j] = CM.Data.ConfigDefault[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mod) CM.SaveConfig(CM.Config);
|
||||
if (mod) CM.SaveConfig(CM.Options);
|
||||
CM.Loop(); // Do loop once
|
||||
for (var i in CM.Data.ConfigDefault) {
|
||||
if (i != 'StatsPref' && i != 'OptionsPref' && typeof CM.ConfigData[i].func !== 'undefined') {
|
||||
@@ -79,7 +79,7 @@ CM.LoadConfig = function() {
|
||||
* It is called by resDefBut.onclick loaded in the options page or by CM.LoadConfig is no localStorage is found
|
||||
*/
|
||||
CM.RestoreDefault = function() {
|
||||
CM.Config = {};
|
||||
CM.Options = {};
|
||||
CM.SaveConfig(CM.Data.ConfigDefault);
|
||||
CM.LoadConfig();
|
||||
Game.UpdateMenu();
|
||||
@@ -97,7 +97,7 @@ CM.RestoreDefault = function() {
|
||||
CM.ToggleConfig = function(config) {
|
||||
CM.ToggleConfigUp(config);
|
||||
if (CM.ConfigData[config].toggle) {
|
||||
if (CM.Config[config] == 0) {
|
||||
if (CM.Options[config] == 0) {
|
||||
l(CM.ConfigPrefix + config).className = 'option off';
|
||||
}
|
||||
else {
|
||||
@@ -107,15 +107,15 @@ CM.ToggleConfig = function(config) {
|
||||
}
|
||||
|
||||
CM.ToggleConfigUp = function(config) {
|
||||
CM.Config[config]++;
|
||||
if (CM.Config[config] == CM.ConfigData[config].label.length) {
|
||||
CM.Config[config] = 0;
|
||||
CM.Options[config]++;
|
||||
if (CM.Options[config] == CM.ConfigData[config].label.length) {
|
||||
CM.Options[config] = 0;
|
||||
}
|
||||
if (typeof CM.ConfigData[config].func !== 'undefined') {
|
||||
CM.ConfigData[config].func();
|
||||
}
|
||||
l(CM.ConfigPrefix + config).innerHTML = CM.ConfigData[config].label[CM.Config[config]];
|
||||
CM.SaveConfig(CM.Config);
|
||||
l(CM.ConfigPrefix + config).innerHTML = CM.ConfigData[config].label[CM.Options[config]];
|
||||
CM.SaveConfig(CM.Options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,29 +126,29 @@ CM.ToggleConfigUp = function(config) {
|
||||
CM.ToggleConfigVolume = function(config) {
|
||||
if (l("slider" + config) != null) {
|
||||
l("slider" + config + "right").innerHTML = l("slider" + config).value + "%";
|
||||
CM.Config[config] = Math.round(l("slider" + config).value);
|
||||
CM.Options[config] = Math.round(l("slider" + config).value);
|
||||
}
|
||||
CM.SaveConfig(CM.Config);
|
||||
CM.SaveConfig(CM.Options);
|
||||
}
|
||||
|
||||
CM.ToggleStatsConfig = function(config) {
|
||||
if (CM.Config.StatsPref[config] == 0) {
|
||||
CM.Config.StatsPref[config]++;
|
||||
if (CM.Options.StatsPref[config] == 0) {
|
||||
CM.Options.StatsPref[config]++;
|
||||
}
|
||||
else {
|
||||
CM.Config.StatsPref[config]--;
|
||||
CM.Options.StatsPref[config]--;
|
||||
}
|
||||
CM.SaveConfig(CM.Config);
|
||||
CM.SaveConfig(CM.Options);
|
||||
}
|
||||
|
||||
CM.ToggleOptionsConfig = function(config) {
|
||||
if (CM.Config.OptionsPref[config] == 0) {
|
||||
CM.Config.OptionsPref[config]++;
|
||||
if (CM.Options.OptionsPref[config] == 0) {
|
||||
CM.Options.OptionsPref[config]++;
|
||||
}
|
||||
else {
|
||||
CM.Config.OptionsPref[config]--;
|
||||
CM.Options.OptionsPref[config]--;
|
||||
}
|
||||
CM.SaveConfig(CM.Config);
|
||||
CM.SaveConfig(CM.Options);
|
||||
}
|
||||
|
||||
// Checks if the browsers has permissions to produce notifications
|
||||
|
||||
Reference in New Issue
Block a user