Skip to content
This repository has been archived by the owner on Mar 29, 2021. It is now read-only.

Commit

Permalink
fixes #176
Browse files Browse the repository at this point in the history
correction to the getter's code
  • Loading branch information
Idrinth committed Oct 9, 2016
1 parent 316c552 commit da0d31a
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 127 deletions.
232 changes: 125 additions & 107 deletions src/mods/settings.js
Original file line number Diff line number Diff line change
@@ -1,108 +1,126 @@
idrinth.settings = {
raids: false,
favs: '',
factor: true,
moveLeft: false,
minimalist: false,
chatHiddenOnStart: true,
names: true,
timeout: 5000,
loadtime: 5000,
windows: 3,
warBottom: false,
landMax: true,
chatting: true,
chatuser: '',
newgroundLoad: 30,
chatpass: '',
isWorldServer: false,
alarmTime: '8:0',
alarmActive: false,
bannedRaids: { },
notification: {
mention: true,
message: true,
raid: true
},
land: {
cornfield: 0,
stable: 0,
barn: 0,
store: 0,
pub: 0,
inn: 0,
tower: 0,
fort: 0,
castle: 0,
gold: 0
},
save: function ( ) {
'use strict';
var store = function ( prefix, list, store ) {
for (var key in list) {
if ( list.hasOwnProperty ( key ) && typeof list[key] !== 'object' && typeof list[key] !== 'function' ) {
window.localStorage.setItem ( prefix + key, list[key] );
} else if ( list.hasOwnProperty ( key ) && typeof list[key] === 'object' ) {
store ( prefix + key + '-', list[key], store );
}
}
};
store ( 'idrinth-dotd-', idrinth.settings, store );
},
change: function ( field, value ) {
'use strict';
var setValue = function ( parent, field, value ) {
if ( idrinth.core.fieldIsSetting ( parent, field ) ) {
parent[field] = value;
idrinth.settings.save ( );
return true;
}
return false;
};
if ( !field ) {
return;
}
if ( setValue ( idrinth.settings, field, value ) ) {
return;
}
field = field.split ( '#' );
if ( !idrinth.settings[field[0]] || !field[1] ) {
return;
}
if ( setValue ( idrinth.settings[field[0]], field[1], value ) ) {
return;
}
},
start: function ( ) {
'use strict';
if ( window.localStorage ) {
var objectIterator = function ( object, prefix, objectIterator ) {
var itemHandler = function ( prefix, key, item ) {
if ( typeof item !== 'function' ) {
var tmp = window.localStorage.getItem ( 'idrinth-dotd-' + prefix + key );
if ( tmp ) {
if ( tmp === 'false' ) {
tmp = false;
} else if ( tmp === 'true' ) {
tmp = true;
}
item = tmp;
}
}
return item;
};
for (var key in object) {
if ( object.hasOwnProperty ( key ) ) {
if ( typeof object[key] !== 'object' ) {
object[key] = itemHandler ( prefix, key, object[key] );
} else {
object[key] = objectIterator ( object[key], prefix + key + '-', itemHandler, objectIterator );
}
}
}
return object;
};
objectIterator ( idrinth.settings, '', objectIterator );
}
}
idrinth.settings = {
raids: false,
favs: '',
factor: true,
moveLeft: false,
minimalist: false,
chatHiddenOnStart: true,
names: true,
timeout: 5000,
loadtime: 5000,
windows: 3,
warBottom: false,
landMax: true,
chatting: true,
chatuser: '',
newgroundLoad: 30,
chatpass: '',
isWorldServer: false,
alarmTime: '8:0',
alarmActive: false,
bannedRaids: { },
notification: {
mention: true,
message: true,
raid: true
},
land: {
cornfield: 0,
stable: 0,
barn: 0,
store: 0,
pub: 0,
inn: 0,
tower: 0,
fort: 0,
castle: 0,
gold: 0
},
save: function ( ) {
'use strict';
var store = function ( prefix, list, store ) {
for (var key in list) {
if ( list.hasOwnProperty ( key ) && typeof list[key] !== 'object' && typeof list[key] !== 'function' ) {
window.localStorage.setItem ( prefix + key, list[key] );
} else if ( list.hasOwnProperty ( key ) && typeof list[key] === 'object' ) {
store ( prefix + key + '-', list[key], store );
}
}
};
store ( 'idrinth-dotd-', idrinth.settings, store );
},
get: function ( field ) {
'use strict';
var getValue = function ( parent, field ) {
if ( idrinth.core.fieldIsSetting ( parent, field ) ) {
return parent[field];
}
return null;
};
if ( !field ) {
return;
}
var value = getValue ( idrinth.settings, field );
if ( value !== null && typeof value !== 'object' ) {
return value;
}
field = field.split ( '#' );
return getValue ( idrinth.settings[field[0]], field[1] );
},
change: function ( field, value ) {
'use strict';
var setValue = function ( parent, field, value ) {
if ( idrinth.core.fieldIsSetting ( parent, field ) ) {
parent[field] = value;
idrinth.settings.save ( );
return true;
}
return false;
};
if ( !field ) {
return;
}
if ( setValue ( idrinth.settings, field, value ) ) {
return;
}
field = field.split ( '#' );
if ( !idrinth.settings[field[0]] || !field[1] ) {
return;
}
if ( setValue ( idrinth.settings[field[0]], field[1], value ) ) {
return;
}
},
start: function ( ) {
'use strict';
if ( window.localStorage ) {
var objectIterator = function ( object, prefix, objectIterator ) {
var itemHandler = function ( prefix, key, item ) {
if ( typeof item !== 'function' ) {
var tmp = window.localStorage.getItem ( 'idrinth-dotd-' + prefix + key );
if ( tmp ) {
if ( tmp === 'false' ) {
tmp = false;
} else if ( tmp === 'true' ) {
tmp = true;
}
item = tmp;
}
}
return item;
};
for (var key in object) {
if ( object.hasOwnProperty ( key ) ) {
if ( typeof object[key] !== 'object' ) {
object[key] = itemHandler ( prefix, key, object[key] );
} else {
object[key] = objectIterator ( object[key], prefix + key + '-', itemHandler, objectIterator );
}
}
}
return object;
};
objectIterator ( idrinth.settings, '', objectIterator );
}
}
};
22 changes: 2 additions & 20 deletions src/mods/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,29 +143,11 @@ idrinth.ui = {
}
return list.indexOf ( value ) > -1;
};
var get = function ( field ) {
'use strict';
var getValue = function ( parent, field ) {
if ( idrinth.core.fieldIsSetting ( parent, field ) ) {
return parent[field];
}
return null;
};
if ( !field ) {
return;
}
var value = getValue ( idrinth.settings, field );
if ( value !== null ) {
return value;
}
field = field.split ( '#' );
return getValue ( idrinth.settings[field[0]], field[1] );
};
var input = [ {
name: 'type',
value: config.type
} ];
if ( get ( config.name ) && config.type === 'checkbox' ) {
if ( idrinth.settings.get ( config.name ) && config.type === 'checkbox' ) {
input.push ( {
name: 'checked',
value: 'checked'
Expand All @@ -174,7 +156,7 @@ idrinth.ui = {
if ( config.type !== 'checkbox' ) {
input.push ( {
name: 'value',
value: get ( config.name )
value: idrinth.settings.get ( config.name )
} );
input.push ( {
name: 'onchange',
Expand Down

0 comments on commit da0d31a

Please sign in to comment.