forked from EndangeredNayla/MarioPartyOverlay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
textoutput.js
303 lines (260 loc) · 8.97 KB
/
textoutput.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
/*
* Returns the correct name of a character.
*
* @param {string} character The shortened name of the character.
*/
function getCharName (character) {
if (isNaN(character) == false) {
character = characters[character];
}
switch (character) {
case 'bowserjr':
return 'Bowser Jr.';
break;
case 'dk':
return 'Donkey Kong';
break;
case 'koopakid':
return 'Koopa Kid';
break;
case 'pompom':
return 'Pom Pom';
break;
case 'drybones':
return 'Dry Bones';
break;
case 'dk':
return 'Donkey Kong';
break;
case 'shyguy':
return 'Shy Guy';
break;
case 'hammerbro':
return 'Hammer Bro';
break;
default:
return character.charAt(0).toUpperCase() + character.slice(1);
}
}
/*
* Outputs all counters as text.
*/
function textOutput () {
var playerName = ['', '', '', '', ''];
//Checks if a custom name has been assigned, if not it uses the characters name
for (let num = 1; num < 5; num++) {
if (getValue('toP' + num + 'Name') == '') {
playerName[num] = getCharName(characters[num]);
} else {
playerName[num] = getValue('toP' + num + 'Name');
}
}
var joinString = getValue('toSeperation');
if (getValue('toUseActive') === false) {
var toCounters = getValue('toCounters').split(', ');
var counterNames = getValue('toOutput').split(', ');
} else {
var toCounters = [];
var counterNames = [];
toCounters.push('turns');
counterNames.push('Turns');
if (getValue('coinStarOnOff') === true) {
toCounters.push('coinstar');
counterNames.push('Coin Star');
}
var str;
for (let num = 0; num < counters.length; num++) {
if (getValue(counters[num] + 'OnOff') === true) {
str = undefined;
toCounters.push(countersUp[num]);
if (curGame != 'all')
str = counterNameList[curGame][counters[num]];
if (str === undefined) {
switch (countersUp[num]) {
case 'RedSpace':
str = 'Red Space';
break;
case 'FriendSpace':
str = 'Friendship';
break;
case 'SpinSpace':
str = 'Spin';
break;
default:
str = countersUp[num];
}
}
counterNames.push(str);
}
}
}
var output = [];
var forResult = [];
for (let num = 0; num < toCounters.length; num++) {
toCounters[num] = toCounters[num].replace(/\s/g, '');
//Add all specified counters to output array
switch (toCounters[num].toLowerCase()) {
case 'turn':
case 'turns':
output[num] = counterNames[num] + ': ' + getInner('curTurnText') + '/' + getInner('maxTurnText');
break;
case 'coin':
case 'coinstar':
var coinStarP1 = getValue('p1CoinStarTie');
var coinStarP2 = getValue('p2CoinStarTie');
var coinStarP3 = getValue('p3CoinStarTie');
var coinStarP4 = getValue('p4CoinStarTie');
var coinStar = [];
if (coinStarP1 == true) {
coinStar.push(playerName[1]);
}
if (coinStarP2 == true) {
coinStar.push(playerName[2]);
}
if (coinStarP3 == true) {
coinStar.push(playerName[3]);
}
if (coinStarP4 == true) {
coinStar.push(playerName[4]);
}
var coinStarString = coinStar.join(' & ');
if (getValue('noTie') == true && (coinStar.length > 1 || coinStar.length == 0)) {
coinStarString = 'multiple';
} else if (coinStar.length == 4 || coinStar.length == 0) {
if (getValue('toListAllCoin') == false) {
coinStarString = 'everyone';
} else {
coinStar.push(playerName[1]);
coinStar.push(playerName[2]);
coinStar.push(playerName[3]);
coinStar.push(playerName[4]);
coinStarString = coinStar.join(' & ');
}
}
output[num] = counterNames[num] + ': ' + getInner('coinStarText') + ' ' + coinStarString;
break;
default: //Add everything new to textOutputTest() too
if (toCounters[num] == 'Friendship') {
toCounters[num] = 'FriendSpace';
}
if (getValue('toBonusOnly') === true) {
var result = [];
var resultNum = [];
var counterP1 = getInner('p1' + toCounters[num] + 'Text');
var counterP2 = getInner('p2' + toCounters[num] + 'Text');
var counterP3 = getInner('p3' + toCounters[num] + 'Text');
var counterP4 = getInner('p4' + toCounters[num] + 'Text');
var counterNum = Math.max(counterP1, counterP2, counterP3, counterP4);
if (counterP1 == counterP2 && counterP1 == counterP3 && counterP1 == counterP4 && getValue('toListAllCoin') == false) {
result.push('everyone');
resultNum.push(getInner('p1' + toCounters[num] + 'Text'));
} else {
if (counterNum == counterP1) {
result.push(playerName[1]);
resultNum.push(getInner('p1' + toCounters[num] + 'Text'));
}
if (counterNum == counterP2) {
result.push(playerName[2]);
resultNum.push(getInner('p2' + toCounters[num] + 'Text'));
}
if (counterNum == counterP3) {
result.push(playerName[3]);
resultNum.push(getInner('p3' + toCounters[num] + 'Text'));
}
if (counterNum == counterP4) {
result.push(playerName[4]);
resultNum.push(getInner('p4' + toCounters[num] + 'Text'));
}
}
if (getValue('toShowNum') == false) { //if a number should be displayed next to the player that got the bonus star
var resultString = result.join(' & ');
output[num] = counterNames[num] + ': ' + resultString;
} else {
switch (result.length) {
case 1:
forResult.push(counterNames[num] + ': ' + result[0] + ' ' + resultNum[0].replace(/ /g,''));
break;
case 2:
forResult.push(counterNames[num] + ': ' + result[0] + ' & ' + result[1] + ' ' + resultNum[0].replace(/ /g,''));
break;
case 3:
forResult.push(counterNames[num] + ': ' + result[0] + ' & ' + result[1] + ' & ' + result[2] + ' ' + resultNum[0].replace(/ /g,''));
break;
case 4:
forResult.push(counterNames[num] + ': ' + result[0] + ' & ' + result[1] + ' & ' + result[2] + ' & ' + result[3] + ' ' + resultNum[0].replace(/ /g,''));
break;
}
output[num] = forResult.join('');
forResult = [];
}
} else {
output[num] = counterNames[num] + ': ' + playerName[1] + ' ' + getInner('p1' + toCounters[num] + 'Text').replace(/ /g,'') + ', ' + playerName[2] + ' ' + getInner('p2' + toCounters[num] + 'Text').replace(/ /g,'') + ', ' + playerName[3] + ' ' + getInner('p3' + toCounters[num] + 'Text').replace(/ /g,'') + ', ' + playerName[4] + ' ' + getInner('p4' + toCounters[num] + 'Text').replace(/ /g,'');
}
}
}
var outputString = output.join(joinString);
var outputElement = getElem('textOutput');
outputElement.value = outputString;
outputElement.select();
outputElement.focus();
document.execCommand("copy");
saveReloadAnimation('copy');
console.log('[MPO Text Output] ' + outputString);
}
/*
* Checks if the counters inserted in the settings for the text output feature are correct, if not it removes them.
*
* @param {boolean} nameonly If true it won't check if everything inside the counters textarea is correct.
*/
function textOutputTest (nameonly) {
var toCounters = getValue('toCounters').split(', ');
var counterNames = getValue('toOutput').split(', ');
var error = [];
if (nameonly != true) {
for (let num = 0; num < toCounters.length; num++) {
toCounters[num] = toCounters[num].replace(/\s/g, '');
switch (toCounters[num].toLowerCase()) {
case 'turn':
case 'turns':
break;
case 'coin':
case 'coinstar':
break;
default: //Add everything new to textOutput() too
if (toCounters[num] == 'Friendship') {
toCounters[num] = 'FriendSpace';
}
if (getElem('p1' + toCounters[num] + 'Text')) {} else {
error.push(toCounters[num]);
}
break;
}
}
}
if (error.length == 1) {
editInner('textOutputWarning', '"' + error.join(', ') + '" isn\'t a valid counter.');
getElem('textOutputWarning').style = 'visibility: visible;';
} else if (error.length > 1) {
editInner('textOutputWarning', '"' + error.join(', ') + '" aren\'t valid counters.');
getElem('textOutputWarning').style = 'visibility: visible;';
} else if (toCounters.length > counterNames.length) {
editInner('textOutputWarning', 'Counter name(s) missing.');
getElem('textOutputWarning').style = 'visibility: visible;';
} else if (toCounters.length < counterNames.length) {
editInner('textOutputWarning', 'Too many counter counterNames.');
getElem('textOutputWarning').style = 'visibility: visible;';
} else {
getElem('textOutputWarning').style = 'visibility: hidden;';
}
}
/*
* Hides and shows the counter input for the Text Output setti
*/
function updateCounterInput () {
if (getValue('toUseActive') == false) {
getElem('customTOCounters').style.display = 'block';
} else {
getElem('customTOCounters').style.display = 'none';
editValue('toUseActive', true);
}
}