forked from EndangeredNayla/MarioPartyOverlay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assist-misc.js
277 lines (258 loc) · 8.23 KB
/
assist-misc.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
/*
* Edits the "notification" bar at the top.
*
* @param {string} text Text it should be changed to.
* @param {boolean} error If true it prints it as a error.
*/
function shortcutNotif (text, error) {
console.log('[MPO Notif] ' + text);
editInner('shortcutNotif', text);
if (error) {
getElem('shortcutNotif').classList.add('errorAni');
setTimeout(removeAni, 500);
} else {
getElem('shortcutNotif').classList.add('notifAni');
setTimeout(removeAni, 500);
}
}
/*
* Removes the notification animation classes so it can be repeated.
*/
function removeAni () {
getElem('shortcutNotif').classList.remove('notifAni');
getElem('shortcutNotif').classList.remove('errorAni');
}
/*
* Skips to the next shortcut screen.
*/
function shortcutSkip () {
switch (shortcutState) {
case 0:
case 1:
case 4:
return;
case 2:
turnEnd();
break;
case 3:
startShortcut();
break;
}
}
/*
* Goes to the last shortcut screen.
*/
function shortcutBack () {
switch (shortcutState) {
case 0:
return;
case 1:
shortcutState = 0;
editInner('shortcutSpan', defaultText);
getElem('skipButton').disabled = 'true';
getElem('backButton').disabled = 'true';
break;
case 2:
if (turnCurPlayer === 1) {
if ((getInner('curTurnText') == getStat('maxTurn') - 4 && shortcutGame != 'smp') || (getInner('curTurnText') == getStat('maxTurn') - 2 && shortcutGame === 'smp')) { //if final 5
execOnMain('turns', ['curTurn', 1, 'M']);
shortcutState = 3;
getElem('shortcutTurn').style.display = 'none';
startShortcut();
return;
}
if (getInner('curTurnText') == 1) {
playerOrder = undefined;
shortcutState = 0;
getElem('skipButton').disabled = 'true';
} else {
execOnMain('turns', ['curTurn', 1, 'M']);
shortcutState = 2;
}
startShortcut();
} else {
turnCurPlayer = turnCurPlayer - 2;
turnEnd();
}
break;
case 3:
turnCurPlayer = 3;
shortcutState = 1;
turnEnd();
startShortcut();
turnCurPlayer = 4;
orderCurPlayer = playerOrder[turnCurPlayer];
break;
case 4:
execOnMain('turns', ['curTurn', 1, 'M']);
shortcutState = 2;
getElem('skipButton').disabled = '';
startShortcut();
break;
}
}
/*
* Opens shortcut settings and updates all variables in it.
*
* @param {boolean} close If it should be closed or not.
*/
function shortcutSettings (close) {
if (close === true) {
getElem('settingsMain').style = '';
getElem('shortcutSettings').style = '';
getElem('settingsMain').onclick = '';
getElem('shortcutSettingsPopup').style.pointerEvents = 'none';
getElem('shortcutSettingsPopup').style.visibility = 'hidden';
getElem('shortcutSettingsPopup').style.opacity = 0;
return;
}
if (shortcutState === 1 || (typeof playerOrder === 'array' && playerOrder.length != 5)) {
editInner('shortcutOrder', '<span> Player order is not decided yet. </span>');
} else {
var iconStyle = document.querySelector('input[name="icons"]:checked').value;
editInner('shortcutOrder', '<img src="img/1st.png"> <img src="img/' + iconStyle + '/' + characters[playerOrder[1]] + '.png"> <img src="img/2nd.png"> <img src="img/' + iconStyle + '/' + characters[playerOrder[2]] + '.png"> <img src="img/3rd.png"> <img src="img/' + iconStyle + '/' + characters[playerOrder[3]] + '.png"> <img src="img/4th.png"> <img src="img/' + iconStyle + '/' + characters[playerOrder[4]] + '.png">');
}
var selVar = false;
var elems = getElem('finalFiveSelect').children;
for (var num = 1; num < elems.length; num++) {
if (finalFiveEvent == elems[num].value) {
elems[num].selected = true;
selVar = true;
}
}
if (selVar != true) {
elems[0].selected = true;
}
if (starCost === 'double') {
getElem('starCostSelect').children[1].selected = true;
} else {
getElem('starCostSelect').children[0].selected = true;
}
editInner('shortcutCurGame', 'Current assist game: ' + shortcutGame.toUpperCase());
editInner('shortcutDebug', '<span> shortcutState: ' + shortcutState + '<br> spaceEventState: ' + spaceEventState.join(', ') + '<br> itemEventState: ' + itemEventState.join(', ') + '<br> diceCursor: ' + diceCursor + ' - diceRolls: ' + diceRolls.join(', ') + '<br> <br> statusEffects: <br> - P1: ' + statusEffects['p1'].join(', ') + '<br> - P2: ' + statusEffects['p2'].join(', ') + '<br> - P3: ' + statusEffects['p3'].join(', ') + '<br> - P4: ' + statusEffects['p4'].join(', ') + '<br> <br> allies: <br> - P1: ' + allies['p1'].join(', ') + '<br> - P2: ' + allies['p2'].join(', ') + '<br> - P3: ' + allies['p3'].join(', ') + '<br> - P4: ' + allies['p4'].join(', ') + '<br> bobombAlly: ' + bobombAlly.join(', ') + '</span>');
getElem('shortcutVariablesError').style.display = 'none';
getElem('shortcutVariables').style.display = 'unset';
getElem('settingsMain').style = '-webkit-filter: blur(5px); filter: blur(5px);';
getElem('shortcutSettings').style = 'pointer-events: none;'; //filter and pointer event need to be different as blur wouldn't be smooth with 'shortcutSettings' and pointer-event would remove onClick
getElem('allySelection').style.pointerEvents = 'none'; //hide ally popup
getElem('allySelection').style.visibility = 'hidden';
getElem('allySelection').style.opacity = 0;
getElem('shortcutSettingsPopup').style.pointerEvents = 'unset';
getElem('shortcutSettingsPopup').style.visibility = 'visible';
getElem('shortcutSettingsPopup').style.opacity = 1;
setTimeout(function () {getElem('settingsMain').setAttribute('onclick','shortcutSettings(true)');}, 10); //required because chrome would immediately execute the function if it was changed directly
}
/*
* Resets the current Shortcut game.
*/
function resetShortcut () {
shortcutState = 3;
var turn = getInner('curTurnText');
counterButtons(1, 'S', getStat('maxTurn'), 'curTurn');
startShortcut();
counterButtons(1, 'S', turn, 'curTurn');
shortcutSettings(true);
}
/*
* Loads the previously saved shortcut game.
*/
function loadShortcut () {
var slots2 = JSON.parse(localStorage.getItem('a' + slots.sel));
if (slots2.assistOn === true) {
slots['a' + slots.sel] = slots2;
loadAssistSlot();
shortcutNotif('Loaded previously saved assist state.');
} else {
shortcutNotif('There was no previous assist save.', true);
}
shortcutSettings(true);
}
/*
* Checks if all characters are in a game.
*
* @param {string} game The game, if empty it uses the current game.
*/
function checkChars (game) {
if (!game) {
game = curGame;
}
var arr = [];
for (var num = 1; num < 5; num++) {
for (var num2 = 0; num2 < charList[game].length; num2++) {
if (characters[num] === charList[game][num2]) {
arr.push('x');
break;
}
}
}
if (arr.length === 4) {
return true;
} else {
return false;
}
}
/*
* Gets the last place player.
*/
function getLastPlace () {
var stars = [];
for (var num = 1; num < 5; num++) {
stars.push(getStat('stars', num));
}
var last = Array.min(stars);
var arr = [];
for (var num = 1; num < 5; num++) {
if (last === stars[num - 1]) {
arr.push(num);
}
}
console.log(arr.join('+'))
if (arr.length > 1) {
stars = [];
for (var num = 0; num < arr.length; num++) {
stars.push(getStat('coins', arr[num]));
}
last = Array.min(stars);
var arr2 = [];
for (var num = 1; num < 5; num++) {
if (last === stars[num - 1]) {
arr2.push(arr[num - 1]);
}
}
arr = arr2;
}
console.log(arr)
console.log(arr2)
return arr;
}
/*
* Required to calculate last place, there was just no better way.
*/
Array.min = function (array) {
return Math.min.apply(Math, array);
}
/*
* Removes the first specified array item.
*
* @param {array} arr The array that should be changed.
* @param {string/number/boolean} item The item that should be removed.
*/
function removeArrayItem (arr, item) {
for (var num = 0; num < arr.length; num++) {
if (arr[num] == item) {
arr.splice(num, 1);
break;
}
}
return arr;
}
/*
* Removes the selected class from elements.
*
* @param {array} elems Elements that shouldn't have a selected class.
*/
function removeSelected (elems) {
for (var num = 0; num < elems.length; num++) {
elems[num].classList.remove('selected');
}
}