-
Notifications
You must be signed in to change notification settings - Fork 3
/
assist.js
294 lines (245 loc) · 8.87 KB
/
assist.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
var assistInfo = {
state: 'intro',
curGame: 'smp',
board: '',
order: [''],
curPlayer: 1, //which players turn it is
simpleMode: false,
noCoins: false,
starPriceMultiplier: 1
}
/*
* Loads the next assist state. Calls loadAssistState().
*/
function nextAssistState () {
switch (assistInfo.state) {
case 'intro':
assistInfo.curGame = curGame; //temporary
loadAssistState('chooseOrder');
break;
case 'chooseOrder':
assistInfo.board = getValue('assistStageSelect'); //todo: should probably also be moved
loadAssistState('turn');
break;
case 'turn':
//loadAssistState('minigame');
break;
}
}
// nextAssistState()/prevAssistState()/navbar onclick > loadAssistState(state, turn)
// turn is finished in nextAssistState()/prevAssistState()
/*
* Loads the specified assist state.
*
* @param {string} state The state - view nextAssistState() for all available states.
*/
function loadAssistState (state) {
assistInfo.state = state;
var elems = document.querySelectorAll('#assistSettings > div');
updateVisibility(elems, 'hide', true); //hide all divs
var elems = document.querySelectorAll('#nvAssistMain > div');
updateVisibility(elems, 'hide', true); //hide all navbar divs
updateVisibility( 'assist' + capStr(state), null, true); //only show div for current state
updateVisibility('nv_assist' + capStr(state), null, true);
switch (state) {
case 'chooseOrder':
loadChooseOrder();
break;
case 'turn':
loadTurn();
break;
}
}
/*
* Prepares/loads the 'chooseOrder' screen.
*/
function loadChooseOrder () {
resetChooseOrder();
for (let num = 1; num < 5; num++) {
changeCharacterIcon( 'assistChooseP' + num, characters[num]);
changeCharacterIcon('nv_assistChooseP' + num, characters[num]);
}
var boards = copyVar(assist_getBoardList());
for (let num = 0; num < boards.length; num++) {
boards[num] = '<option value=' + boards[num] + '>' + boards[num] + '</option>';
}
editInner( 'assistStageSelect', boards.join());
editInner('nv_assistStageSelect', boards.join());
}
var currentChoosePlayerPosition = 1;
/*
* Chooses a character on the 'chooseOrder' screen.
*
* @param {number} player The player that should be chosen.
*/
function chooseOrder (player) {
if (assistInfo.order.indexOf(player) != -1) { //check if player was already added
return;
}
assistInfo.order.push(player);
changeCharacterIcon(getElem( 'choose' + currentChoosePlayerPosition).children[1], characters[player], true);
changeCharacterIcon(getElem('nv_choose' + currentChoosePlayerPosition).children[0], characters[player], true);
updateVisibility( 'choose' + currentChoosePlayerPosition, 'show');
updateVisibility('nv_choose' + currentChoosePlayerPosition, 'show');
currentChoosePlayerPosition++;
getElem( 'assistChooseP' + player).classList.add('chooseImgSelected');
getElem('nv_assistChooseP' + player).classList.add('chooseImgSelected');
if (currentChoosePlayerPosition >= 5) {
currentChoosePlayerPosition = 4;
updateVisibility( 'chooseContinue', 'show');
updateVisibility('nv_chooseContinue', 'show');
return;
}
if (currentChoosePlayerPosition === 4) { //automatically select the last player
for (let num = 1; num < 5; num++) {
if (assistInfo.order.indexOf(num) === -1) {
chooseOrder(num);
}
}
}
}
/*
* Resets the currently chosen order on the 'chooseOrder' screen.
* Should not be used otherwise unless a new order can be selected.
*/
function resetChooseOrder () {
assistInfo.order = [''];
currentChoosePlayerPosition = 1;
updateVisibility( 'chooseContinue', 'hide');
updateVisibility('nv_chooseContinue', 'hide');
for (let num = 1; num < 5; num++) {
getElem( 'assistChooseP' + num).classList.remove('chooseImgSelected');
getElem('nv_assistChooseP' + num).classList.remove('chooseImgSelected');
updateVisibility( 'choose' + num, 'hide');
updateVisibility('nv_choose' + num, 'hide');
}
}
/*
* Updates the player order to the order chosen in assist mode.
*/
function updateOrder () {
backup();
var sel = 's' + slots.sel;
var sBackup = copyVar(slots[sel]);
for (var num = 0; num < counters.length; num++) {
for (var num2 = 1; num2 < 5; num2++) {
slots[sel][counters[num]][num2 - 1] = sBackup[counters[num]][assistInfo.order[num2] - 1];
}
}
restore();
var cBackup = copyVar(characters);
changeCharacters(1, cBackup[assistInfo.order[1]]);
changeCharacters(2, cBackup[assistInfo.order[2]]);
changeCharacters(3, cBackup[assistInfo.order[3]]);
changeCharacters(4, cBackup[assistInfo.order[4]]);
playerOrder = ['', 1, 2, 3, 4];
orderCurPlayer = playerOrder[1];
}
/*
* Prepares/loads the 'turn' screen.
*/
function loadTurn () {
getElem('nvAssistStateIndicator').style.height = '45px';
getElem('nvAssistTurnIndicator').style.height = '35px';
loadTurn_Misc();
}
/*
* Loads the star/misc module on the turn screen.
*/
function loadTurn_Misc () {
var stars = assist_getStarList();
for (var num = 0; num < stars.length; num++) { //loop through all stars that should be added
if (stars[num].buyMultiple === true) { //add the option to buy multiple at once if needed
for (var num2 = 0; num2 < 2; num2++) { //loop twice for settings and navbar versions
if (num2 === 0) {
var elemWrapper = cElem('span', 'assistMisc');
} else {
var elemWrapper = cElem('span', 'nv_assistMisc');
}
elemWrapper.classList.add('assistMultipleStarWrapper');
var mainImg = createAssistButton(stars[num].src, elemWrapper, stars[num].name, 'assist_buyStar("' + stars[num].name + '")', 50);
var secondWrapper = cElem('span', elemWrapper);
secondWrapper.classList.add('assistMultipleStarSelectionWrapper');
var elem = cElem('img', secondWrapper);
elem.src = 'img/arrow.png';
elem.classList.add('chooseImg');
elem.setAttribute('onclick', 'assist_changeBuyMultipleStarAmount(\'' + stars[num].name + '\', \'M\', 1)');
var textWrapper = cElem('span', secondWrapper);
var elem = cElem('span', textWrapper);
editInner(elem, '1');
var elem = cElem('img', secondWrapper);
elem.src = 'img/arrow.png';
elem.classList.add('chooseImg');
elem.setAttribute('onclick', 'assist_changeBuyMultipleStarAmount(\'' + stars[num].name + '\', \'P\', 1)');
}
} else {
var elem = createAssistButton(stars[num].src, 'assistMisc', stars[num].name, 'assist_buyStar("' + stars[num].name + '")', 50);
var elem = createAssistButton(stars[num].src, 'nv_assistMisc', stars[num].name, 'assist_buyStar("' + stars[num].name + '")', 50); //navbar
}
}
}
/*
* Creates a assist button with the .chooseImg class.
*
* @param {string} src The image source.
* @param {string} parent The parentnode id that should append it.
* @param {string} id The id of the new element.
* @param {string} onclick What the onclick attribute should be.
* @param {number} size The size of the image (will be set to width as px) - optional.
*/
function createAssistButton (src, parent, id, onclick, size) {
if (typeof parent === 'string') {
parent = getElem(parent);
}
var elem = document.createElement('img');
parent.appendChild(elem);
elem.classList.add('chooseImg');
elem.src = src;
elem.setAttribute('assistName', id);
elem.setAttribute('onclick', onclick);
if (typeof size === 'number') {
elem.style.width = size + 'px';
}
}
/*
* Toggles visibility of a assist module (stars, dice, shopping etc)
*
* @elem {DOM Element} elem First child of the module that should be toggled.
*/
function toggleModuleVisibility (elem) {
elem = elem.parentNode.parentNode.children[1]; //get actual element to toggle
if (elem.parentNode.getAttribute('customHidden') === 'true') { //named customHidden because "hidden" is already a used attribute and I couldn't come up with something better
var contents = elem.children[0];
elem.style.height = contents.clientHeight + "px";
elem.parentNode.setAttribute('customHidden', 'false'); //.parentNode is required so CSS can change the titles border-radius depending on this attribute
} else {
elem.style.height = 0;
elem.parentNode.setAttribute('customHidden', 'true');
}
}
//just get it from the navbar
function chromesucks () {
elem = document.querySelector('.currentPlayer');
elem.children[0].style.width = 0;
elem.classList.remove('currentPlayer');
elem = document.querySelector('.assistCurrentPlayerTextWrapper');
elem.style.width = 0;
elem = document.querySelector('#assistPlayerList').children[1];
elem.classList.add('currentPlayer');
var contents = document.querySelectorAll('.assistCurrentPlayerTextWrapper')[1];
contents.style.width = 'auto';
elem.children[0].style.width = contents.clientWidth + 65 + 21 + "px"; //text width + img width + padding (7 on both sides and seemingly 7 between image and text)
}
/*
* Returns Array of all elements with a certain assistName.
*
* @param {string} id The name of the element
*/
function getAssistElem (id) {
try {
return document.querySelectorAll('[assistName="' + id + '"]');
} catch (e) {
console.error(e);
console.error('[MPO] getAssistElem() error, could not find: ' + id);
}
}