-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
265 lines (212 loc) · 8.2 KB
/
script.js
File metadata and controls
265 lines (212 loc) · 8.2 KB
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
const changeRandomOrder = (event) => {
document.getElementById('select-num').style.display = event.checked ? 'block' : 'none';
}
const changeOrder = (event) => {
document.getElementById('ordercnt').innerText = event.value;
}
const getEgo = (id) => {
const list = [];
for (let i = 0; i < 5; ++i) {
const egoList = sinnerEgoList[id][i];
if (egoList.length > 0) {
const egoInfo = egoList[Math.floor(Math.random() * egoList.length)];
list.push(egoInfo);
} else {
list.push(undefined);
}
}
return list;
}
const sinnerOrder = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
const createDeck = () => {
currentCount = document.getElementById('randomcnt').checked ? Math.floor(Math.random() * 12) + 1 : document.getElementById('randomorder').value;
if (document.getElementById('randomcardbuilding').checked) createSelectableDeck();
else createRandomDeck();
}
const selectedBuild = [];
let remainingSinners;
let selectIndex = 0;
let currentCount = 0;
const createSelectableDeck = () => {
const modal = document.getElementById("modal");
selectedBuild.length = 0;
selectIndex = 0;
remainingSinners = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
const html = document.documentElement;
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
if (scrollbarWidth) {
html.style.setProperty('--pico-scrollbar-width', `${scrollbarWidth}px`);
}
showSelections();
html.classList.add('modal-is-open', 'modal-is-opening');
setTimeout(() => {
html.classList.remove('modal-is-opening');
}, 400);
modal.showModal();
document.activeElement.blur();
}
const showSelections = () => {
document.activeElement.blur();
const title = document.getElementById('dialog-description');
document.getElementById('reroll').removeAttribute('disabled');
// Select order
if (!document.getElementById('randomordercheck').checked) {
title.innerText = `덱 빌드 짜기 - ${sinnerNames[selectIndex]}`;
} else if (currentCount > selectIndex) {
title.innerText = `덱 빌드 짜기 - 편성 순서 ${selectIndex + 1}번`;
} else {
title.innerText = `덱 빌드 짜기 - 서포트 패시브`;
}
makeOptions();
}
const reroll = () => {
document.getElementById('reroll').disabled = true;
makeOptions();
}
const makeOptions = () => {
const noOverlap = [...identities];
for (let i = 0; i < 3; ++i) {
const sinner = document.getElementById('randomordercheck').checked ? remainingSinners[Math.floor(Math.random() * remainingSinners.length)] : selectIndex;
const egoList = document.getElementById('defaultego').checked ? [sinnerEgoList[sinner][0][0], undefined, undefined, undefined, undefined] : getEgo(sinner);
if (document.getElementById('eventonly').checked) {
if (eventPrivileged.ego[sinner + 1]) {
const egoCandidatesList = eventPrivileged.ego[sinner + 1];
for (let j = 0; j < 5; ++j) {
const egoCandidates = egoCandidatesList[j];
if (egoCandidates && egoCandidates.length > 0) {
const egoId = egoCandidates[Math.floor(Math.random() * egoCandidates.length)];
egoList[j] = sinnerEgoList[sinner][j].find(ego => ego.no === egoId);
}
}
}
if (eventPrivileged.identity[sinner + 1]) {
const idCandidates = eventPrivileged.identity[sinner + 1];
const id = identities[sinner][idCandidates[Math.floor(Math.random() * idCandidates.length)] - 1];
// console.log(sinner, id, identities[sinner], idCandidates)
setOption(i, egoList, id, sinner);
continue;
}
}
const id = noOverlap[sinner][Math.floor(Math.random() * noOverlap[sinner].length)];
noOverlap[sinner] = noOverlap[sinner].filter(e => e.no !== id.no);
setOption(i, egoList, id, sinner);
}
}
const options = [{}, {}, {}];
const setOption = (index, egos, id, sinnerId) => {
document.getElementById('i' + index).innerText = id.name;
document.getElementById('z' + index).innerText = egos[0] ? egos[0].name : '----';
document.getElementById('t' + index).innerText = egos[1] ? egos[1].name : '----';
document.getElementById('h' + index).innerText = egos[2] ? egos[2].name : '----';
document.getElementById('w' + index).innerText = egos[3] ? egos[3].name : '----';
document.getElementById('a' + index).innerText = egos[4] ? egos[4].name : '----';
options[index] = { id, egos, sinnerId };
}
const selectOption = (index) => {
const { egos: egoList, id, sinnerId } = options[index];
selectedBuild.push({
id: id.no,
ego: egoList.map(e => e ? e.no : 0),
order: document.getElementById('randomordercheck').checked && currentCount > selectIndex ? selectIndex + 1 : 0,
name: id.name,
sinnerId: sinnerId
});
remainingSinners.splice(remainingSinners.indexOf(sinnerId), 1);
if (selectIndex >= 11) {
let binary = '';
selectedBuild.sort((a, b) => a.sinnerId - b.sinnerId);
for (let i = 0; i < 12; i++) {
const { id, ego, order } = selectedBuild[i];
binary += makeSinnerBinary(id, ego, order);
}
binary += '00000000';
closeModal();
document.getElementById('hash').innerText = encryptToCode(binary);
document.getElementById('result').style.display = 'block';
return;
}
selectIndex++;
showSelections();
}
const closeModal = () => {
const modal = document.getElementById("modal");
const html = document.documentElement;
html.classList.add('modal-is-closing');
setTimeout(() => {
html.classList.remove('modal-is-closing', 'modal-is-open');
html.style.removeProperty('--pico-scrollbar-width');
modal.close();
}, 400);
};
const createRandomDeck = () => {
const isDefaultEgo = document.getElementById('defaultego').checked;
const randomOrder = document.getElementById('randomordercheck').checked;
const isEventOnly = document.getElementById('eventonly').checked;
if (randomOrder) sinnerOrder.sort(() => Math.random() - 0.5);
let binary = '';
for (let i = 0; i < 12; i++) {
const id = isEventOnly && eventPrivileged.identity[i + 1] ?
eventPrivileged.identity[i + 1][Math.floor(Math.random() * eventPrivileged.identity[i + 1].length)]
: Math.floor(Math.random() * identities[i].length) + 1;
const order = sinnerOrder.indexOf(i + 1);
const currentEgoList = isDefaultEgo ? [1, 0, 0, 0, 0] : getEgo(i).map(ego => ego?.no ?? 0);
if (isEventOnly) {
const egoCandidatesList = eventPrivileged.ego[i + 1];
if (egoCandidatesList) {
for (let j = 0; j < 5; ++j) {
const egoCandidates = egoCandidatesList[j];
if (egoCandidates && egoCandidates.length > 0) {
currentEgoList[j] = egoCandidates[Math.floor(Math.random() * egoCandidates.length)];
}
}
}
}
binary += makeSinnerBinary(
id,
currentEgoList,
randomOrder && order < currentCount ? order + 1 : 0
);
}
binary += '00000000';
document.getElementById('hash').innerText = encryptToCode(binary);
document.getElementById('result').style.display = 'block';
}
const encryptToCode = (binary) => {
let hash = '';
for (let i = 0; i < binary.length; i += 8) {
const ascii = String.fromCharCode(parseInt(binary.slice(i, i + 8), 2));
hash += ascii;
}
const cs = pako.gzip(btoa(hash), { level: 9, mtime: 0 });
return btoa(String.fromCharCode(...cs));
}
const makeSinnerBinary = (id, ego, order = 0) => {
return `${
id.toString(2).padStart(8, '0')
}${
order.toString(2).padStart(4, '0')
}${
ego.slice(0, 4).map(e => e.toString(2).padStart(7, '0')).join('')
}${
ego[4].toString(2).padStart(6, '0')
}`;
}
const copyDeckNum = () => {
const hash = document.getElementById('hash').innerText;
navigator.clipboard.writeText(hash).then(() => {
alert('덱 코드가 클립보드에 복사되었습니다.');
}).catch(err => {
console.error('클립보드 복사 실패:', err);
alert('덱 코드 복사에 실패했습니다. 콘솔을 확인하세요.');
});
}
function changeOrderCnt(event) {
const randomOrder = document.getElementById('randomorder');
if (event.checked) {
randomOrder.disabled = true;
document.getElementById('ordercnt').innerText = '1~12';
} else {
randomOrder.removeAttribute('disabled');
document.getElementById('ordercnt').innerText = randomOrder.value;
}
}