-
Notifications
You must be signed in to change notification settings - Fork 3
/
saving.js
456 lines (397 loc) · 12.8 KB
/
saving.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
var backuped = false;
/*
* Saves assist
*/
function saveAssist () {
var sel = 'a' + slots.sel;
if (assistLoaded === false) {
return;
} else if (slots[sel].assistOn != true) {
slots[sel] = copyVar(defA);
} else {
slots[sel].assistOn = true;
slots[sel].assistVer = assistVer;
slots[sel].shortcutState = shortcutState;
slots[sel].setup = setup;
slots[sel].turnCurPlayer = turnCurPlayer;
slots[sel].orderCurPlayer = orderCurPlayer;
slots[sel].shortcutGame = shortcutGame;
slots[sel].minigameSpaces = minigameSpaces;
slots[sel].finalFiveEvent = finalFiveEvent;
slots[sel].playerOrder = playerOrder;
slots[sel].statusEffects = statusEffects;
slots[sel].allies = allies;
slots[sel].bobombAlly = bobombAlly;
slots[sel].diceUsed = diceUsed;
slots[sel].starCost = starCost;
slots[sel].starPrice = starPrice;
}
if (cookiesOn === false)
return;
localStorage.setItem(sel, JSON.stringify(slots[sel]));
}
function saveCurrentStats () {
if (cookiesOn != true || prepared != true) {
return;
}
localStorage.setItem('currentStats', JSON.stringify(currentStats));
}
/*
* Backups all counters.
*/
function backup () {
getElem('nvSettingsReload').classList.remove('nvReloadDisabled');
backuped = true;
var sel = 's' + slots.sel;
slots[sel].coinStar = getInner('coinStarText');
slots[sel].coinStarTie1 = getValue('p1CoinStarTie');
slots[sel].coinStarTie2 = getValue('p2CoinStarTie');
slots[sel].coinStarTie3 = getValue('p3CoinStarTie');
slots[sel].coinStarTie4 = getValue('p4CoinStarTie');
slots[sel].curTurn = getInner('curTurnText');
slots[sel].maxTurn = getInner('maxTurnText');
var num = 0;
for (let num2 = 0; num2 < 4; num2++) {
num++;
for (let num3 = 0; num3 < counters.length; num3++) {
slots[sel][counters[num3]][num2] = getInner('p' + num + countersUp[num3] + 'Text');
}
}
saveReloadAnimation('save');
if (popout != true && popoutActivated === true) {
sendMessage('updateS+' + JSON.stringify(slots[sel]));
}
createSlot(slots.sel, true);
if (cookiesOn === false)
return;
localStorage.setItem(sel, JSON.stringify(slots[sel]));
}
/*
* Restores all saved counters.
*
* @param {boolean} forceRestore If the restore should be forced.
*/
function restore (forceRestore) {
var sel = 's' + slots.sel;
//if (backuped == true || forceRestore == true) { //the whole backuped variable is barely used so it's better to just not use it all until it's fixed
editInner('coinStarText', slots[sel].coinStar);
editValue('p1CoinStarTie', slots[sel].coinStarTie1);
editValue('p2CoinStarTie', slots[sel].coinStarTie2);
editValue('p3CoinStarTie', slots[sel].coinStarTie3);
editValue('p4CoinStarTie', slots[sel].coinStarTie4);
var num = 0;
for (let num2 = 0; num2 < 4; num2++) {
num++;
for (let num3 = 0; num3 < counters.length; num3++) {
editInner('p' + num + countersUp[num3] + 'Text', slots[sel][counters[num3]][num2]);
}
}
turns('curTurn', slots[sel].curTurn, 'S');
turns('maxTurn', slots[sel].maxTurn, 'S');
coinStarTie();
callHighlight();
currentStats = slots[sel];
saveCurrentStats();
saveReloadAnimation('reload');
//}
}
/*
* Resets the backup.
*/
function resetBackup () {
if (popout === false && popoutActivated === true) {
sendMessage('resetBackup');
}
if (popout === true && assistLoaded != true) {
return;
}
if (curGame === 'smp') {
editInner('coinStarText', 5);
} else {
editInner('coinStarText', 10);
}
editValue('p1CoinStarTie', false);
editValue('p2CoinStarTie', false);
editValue('p3CoinStarTie', false);
editValue('p4CoinStarTie', false);
for (let num = 1; num < 5; num++) {
for (let num2 = 0; num2 < counters.length; num2++) {
counterButtons(num, 's', 0, counters[num2], true);
}
if (curGame === 'smp') {
counterButtons(num, 's', 5, 'coins', true);
} else {
counterButtons(num, 's', 10, 'coins', true);
}
}
turns('curTurn', 1, 'S');
coinStarTie();
callHighlight(false, true);
saveReloadAnimation('reset');
}
/*
* Creates an animation inside the settings icon in the navbar.
*
* @param {string} type What type it should be, can be either 'save', 'reload', 'reset' or 'copy'.
*/
function saveReloadAnimation (type) {
switch (type) {
case 'save':
getElem('nvSettingsImg').classList.add('nvSaveAni');
getElem('nvSavedText').style.color = '#15d415';
editInner('nvSavedText', 'Saved!');
break;
case 'reload':
getElem('nvSettingsImg').classList.add('nvReloadAni');
getElem('nvSavedText').style.color = '#dac40e';
editInner('nvSavedText', 'Reload!');
break;
case 'reset':
getElem('nvSettingsImg').classList.add('nvResetAni');
getElem('nvSavedText').style.color = '#f13c3c';
editInner('nvSavedText', 'Reset!');
break;
case 'copy':
getElem('nvSettingsImg').classList.add('nvCopyAni');
getElem('nvSavedText').style.color = '#26a6f7';
editInner('nvSavedText', 'Copied!');
break;
}
getElem('nvSavedText').classList.add('nvSavedTextAni');
setTimeout(function(){
getElem('nvSettingsImg').classList.remove('nvSaveAni');
getElem('nvSettingsImg').classList.remove('nvReloadAni');
getElem('nvSettingsImg').classList.remove('nvResetAni');
getElem('nvSettingsImg').classList.remove('nvCopyAni');
getElem('nvSavedText').classList.remove('nvSavedTextAni');
}, 600);
}
/*
* Resets all counters.
*/
function resetCounters () {
if (popoutActivated === false && popout === true) {
sendMessage('resetCounters');
return;
}
changeGame('all');
resetBackup();
updateStars();
if (cookiesOn === false)
return;
localStorage.removeItem('s0');
localStorage.removeItem('c0');
}
/*
* Saves all Characters.
*/
function savePlayers () {
var sel = 'c' + slots.sel;
slots[sel].char1 = characters[1];
slots[sel].char2 = characters[2];
slots[sel].char3 = characters[3];
slots[sel].char4 = characters[4];
slots[sel].com1 = getValue('com1');
slots[sel].com2 = getValue('com2');
slots[sel].com3 = getValue('com3');
slots[sel].com4 = getValue('com4');
for (let num = 0; num < counters.length; num++) {
slots[sel][counters[num] + 'OnOff'] = getValue(counters[num] + 'OnOff');
}
slots[sel].slowOnOff = getValue('slowOnOff');
slots[sel].unusedOnOff = getValue('unusedOnOff');
slots[sel].miniStarsOnOff = getValue('miniStarsOnOff');
slots[sel].bananasOnOff = getValue('bananasOnOff');
slots[sel].coinStarOnOff = getValue('coinStarOnOff');
slots[sel].curGame = curGame;
createSlot(slots.sel, true);
if (cookiesOn === false)
return;
localStorage.setItem(sel, JSON.stringify(slots[sel]));
}
/*
* Resets all characters.
*
* @param {boolean} noLS If true localstorage won't get updated
*/
function resetPlayers (noLS) {
editValue('happeningOnOff', true);
editValue('minigameOnOff', true);
editValue('redSpaceOnOff', false);
editValue('runningOnOff', false);
editValue('slowOnOff', false);
editValue('shoppingOnOff', false);
editValue('itemOnOff', false);
editValue('unusedOnOff', false);
editValue('friendSpaceOnOff', false);
editValue('hexOnOff', false);
editValue('spinSpaceOnOff', false);
editValue('balloonOnOff', false);
editValue('minusOnOff', false);
editValue('almostOnOff', false);
editValue('lonerOnOff', false);
editValue('duelOnOff', false);
editValue('wandererOnOff', false);
editValue('allyOnOff', false);
editValue('stompyOnOff', false);
editValue('doormatOnOff', false);
editValue('starsOnOff', false);
editValue('miniStarsOnOff', false);
editValue('bananasOnOff', false);
editValue('coinsOnOff', false);
editValue('coinStarOnOff', true);
changeCharacters(1, 'mario');
changeCharacters(2, 'luigi');
changeCharacters(3, 'yoshi');
changeCharacters(4, 'peach');
for (let num = 1; num < 5; num++) {
getElem('mario' + num).scrollIntoView(true);
}
editValue('com1', false);
editValue('com2', false);
editValue('com3', false);
editValue('com4', false);
changeCom(1);
changeCom(2);
changeCom(3);
changeCom(4);
changeGame('all');
callDisplayOnOff();
changeStars();
var sel = 'c' + slots.sel;
slots[sel].curGame = 'all';
slots[sel].char1 = 'mario';
slots[sel].char2 = 'luigi';
slots[sel].char3 = 'yoshi';
slots[sel].char4 = 'peach';
slots[sel].com1 = false;
slots[sel].com2 = false;
slots[sel].com3 = false;
slots[sel].com4 = false;
slots[sel].happeningOnOff = true;
slots[sel].minigameOnOff = true;
slots[sel].redSpaceOnOff = false;
slots[sel].runningOnOff = false;
slots[sel].slowOnOff = false;
slots[sel].shoppingOnOff = false;
slots[sel].itemOnOff = false;
slots[sel].unusedOnOff = false;
slots[sel].friendSpaceOnOff = false;
slots[sel].hexOnOff = false;
slots[sel].balloonOnOff = false;
slots[sel].spinSpaceOnOff = false;
slots[sel].minusOnOff = false;
slots[sel].almostOnOff = false;
slots[sel].lonerOnOff = false;
slots[sel].duelOnOff = false;
slots[sel].wandererOnOff = false;
slots[sel].allyOnOff = false;
slots[sel].stompyOnOff = false;
slots[sel].doormatOnOff = false;
slots[sel].starsOnOff = false;
slots[sel].miniStarsOnOff = false;
slots[sel].bananasOnOff = false;
slots[sel].coinsOnOff = false;
slots[sel].coinStarOnOff = true;
if (noLS != true && cookiesOn === true) {
localStorage.removeItem('s0');
localStorage.removeItem('c0');
}
}
/*
* Saves all settings in local storage.
*
* @param {boolean} ret Returns a object with all settings instead of saving it.
*/
function saveSettings (ret) {
var settings = copyVar(defSettings);
for (var num = 0; num < replaceOnly.length; num++) {
settings[replaceOnly[num]] = getValue(replaceOnly[num]);
}
settings.bonusStarAdd = document.querySelector('input[name="bonusStarAdd"]:checked').id;
settings.theme = curTheme;
settings.icons = document.querySelector('input[name="icons"]:checked').id;
settings.layoutType = document.querySelector('input[name="layoutType"]:checked').id;
if (ret === true)
return settings;
if (cookiesOn === false)
return;
localStorage.setItem('settings', JSON.stringify(settings));
}
/*
* Resets settings.
*
* @param {boolean} noLS If true, localStorage won't get reset
*/
function resetSettings (noLS) {
loadSettings(defSettings);
if (noLS != true && cookiesOn === true) {
localStorage.removeItem('settings');
}
}
var replaceOnly = [ 'hideAdvanced', 'settingsFullscreen',
'autoPopout', 'enableHighlight','highlightColor', 'deactivateUnused', 'noTie', 'autoSave', 'useHotkeys', 'enableInteract', 'useSW',
'customGameIcons', 'xBelow100', 'greenscreen', 'bgColor', 'textColor', 'enableAnimation',
'toBonusOnly', 'toShowNum', 'toListAllCoin', 'toP1Name', 'toP2Name', 'toP3Name', 'toP4Name', 'toSeperation', 'toUseActive', 'toCounters', 'toOutput'/*,
'shortcutSimpleMode', 'shortcutAutoEnd'*/];
/*
* Loads settings from an object.
*
* @param {object/string} obj (Stringified) Object that incl. all settings.
*/
function loadSettings (obj) {
if (typeof obj === 'string')
obj = JSON.parse(obj);
for (var num = 0; num < replaceOnly.length; num++) {
editValue(replaceOnly[num], obj[replaceOnly[num]]);
}
editValue(obj.bonusStarAdd, true);
changeTheme(obj.theme);
editValue(obj.icons, true);
editValue(obj.layoutType, true);
hideAdvancedSettings();
settingsFullscreen();
displayXBelow100();
changeTextColor('textColor');
changeLayout();
changeCharacters();
updateCounterInput();
//callHighlight(false, true);
resetHighlights();
}
/*
* Gets called on the main site when a popout is opened. Sends all the required info to properly sync it.
*/
function syncPopout () {
if (popout == false && popoutActivated == true) {
sendMessage('loadSettings+' + JSON.stringify(saveSettings(true)));
sendMessage('setSlots+' + JSON.stringify(slots));
sendMessage('changeTheme+' + curTheme);
sendMessage('changeGame+' + curGame);
sendMessage('changeCharacters+' + 1 + '+' + characters[1]);
sendMessage('changeCharacters+' + 2 + '+' + characters[2]);
sendMessage('changeCharacters+' + 3 + '+' + characters[3]);
sendMessage('changeCharacters+' + 4 + '+' + characters[4]);
sendMessage('changeCom+' + 1);
sendMessage('changeCom+' + 2);
sendMessage('changeCom+' + 3);
sendMessage('changeCom+' + 4);
sendMessage('updateCounterInput');
sendMessage('showHideSettings+' + openedSettings);
console.log('[MPO] Popout synced');
}
}
var statSynced = false;
/*
* Syncs all stats with popout.
*/
function statSync () {
for (var num = 0; num < countersUp.length; num++) {
for (var num2 = 1; num2 < 5; num2++) {
sendMessage('counterButtons+' + num2 + '+S+' + getInner('p' + num2 + countersUp[num] + 'Text') + '+' + countersUp[num]);
}
}
sendMessage('counterButtons+1+S+' + getInner('curTurnText') + '+curTurn');
sendMessage('counterButtons+1+S+' + getInner('maxTurnText') + '+maxTurn');
statSynced = true;
}