This repository has been archived by the owner on Mar 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
correction to the getter's code
- Loading branch information
Showing
2 changed files
with
127 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters