UNPKG

1.3 kBJavaScriptView Raw
1module.exports = () => {
2 function getObject(key) {
3 const item = localStorage.getItem(key);
4
5 if (item) {
6 return JSON.parse(item);
7 }
8
9 return {};
10 }
11
12 function storeSettings(settings) {
13 const settingsAsString = JSON.stringify(settings);
14 localStorage.setItem('ssb-chess', settingsAsString);
15 }
16
17 function setMoveConfirmation(choice) {
18 const chessSettings = getObject('ssb-chess');
19 chessSettings.moveConfirmationEnabled = choice;
20 storeSettings(chessSettings);
21 }
22
23 function getMoveConfirmation() {
24 const chessSettings = getObject('ssb-chess');
25
26 if (chessSettings.moveConfirmationEnabled === undefined
27 || chessSettings.moveConfirmationEnabled === null) {
28 return true;
29 }
30 return chessSettings.moveConfirmationEnabled;
31 }
32
33 function setPlaySounds(choice) {
34 const chessSettings = getObject('ssb-chess');
35 chessSettings.playSounds = choice;
36 storeSettings(chessSettings);
37 }
38
39 function getPlaySounds() {
40 const chessSettings = getObject('ssb-chess');
41
42 if (chessSettings.playSounds === undefined || chessSettings.playSounds === null) {
43 return true;
44 }
45 return chessSettings.playSounds;
46 }
47
48 return {
49 setMoveConfirmation,
50 getMoveConfirmation,
51 getPlaySounds,
52 setPlaySounds,
53 };
54};