-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
333 lines (283 loc) · 10.3 KB
/
script.js
File metadata and controls
333 lines (283 loc) · 10.3 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
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
const fileInput = document.getElementById('logFile');
const tableBody = document.querySelector('#dropsTable tbody');
const searchView = document.getElementById('searchView');
const searchInput = document.getElementById('search');
const minRateInput = document.getElementById('minRate');
const maxRateInput = document.getElementById('maxRate');
const filterOpponent = document.getElementById('filterOpponent');
const filterStrategy = document.getElementById('filterStrategy');
const typeFilterContainer = document.getElementById('typeCheckboxes');
const toggleTypeDropdown = document.getElementById('toggleTypeDropdown');
const typeArrow = document.getElementById('typeArrow');
let currentSortKey = null;
let currentSortDirection = 'asc';
let currentData = [];
let originalData = [];
let typeMapping = {};
const opponentImageMap = {};
let nextImageId = 1;
const cardTypes = [
"Dragon",
"Spellcaster",
"Zombie",
"Warrior",
"Beast-Warrior",
"Beast",
"Winged Beast",
"Fiend",
"Fairy",
"Insect",
"Dinosaur",
"Reptile",
"Fish",
"Sea Serpent",
"Machine",
"Thunder",
"Aqua",
"Pyro",
"Rock",
"Plant",
"Magic",
"Trap",
"Ritual",
"Equip"
];
function debounce(fn, delay = 200) {
let timeout;
return (...args) => {
clearTimeout(timeout);
timeout = setTimeout(() => fn(...args), delay);
};
}
async function loadTypeMapping() {
const res = await fetch('assets/types.json');
typeMapping = await res.json();
}
function parseDropData(text) {
const lines = text.split('\n');
const drops = [];
let currentOpponent = '', currentStrategy = '';
for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
const headerMatch = line.match(/^(.+?)\s+(S\/A)-(Tec|Pow) drops$/i) || line.match(/^(.+?)\s+(B\/C\/D) drops$/i);
if (headerMatch) {
currentOpponent = headerMatch[1].trim();
currentStrategy = headerMatch[2].toUpperCase();
if (currentStrategy === 'S/A') currentStrategy += ' ' + headerMatch[3].toUpperCase();
if (!(currentOpponent in opponentImageMap)) opponentImageMap[currentOpponent] = nextImageId++;
} else if (line.startsWith('=>')) {
const cardMatch = line.match(/=> #(\d+) (.+)/);
const rateLine = lines[i + 1]?.trim();
const rateMatch = rateLine?.match(/^Rate:\s+(\d+\/2048)/);
if (cardMatch && rateMatch) {
const id = cardMatch[1], card = cardMatch[2], rate = rateMatch[1];
const imageId = opponentImageMap[currentOpponent] || 0;
const typeIndex = typeMapping[id] ?? -1;
drops.push({ id, card, rate, opponent: currentOpponent, strategy: currentStrategy, imageId, typeIndex });
}
}
}
return drops;
}
function populateFilters(data) {
const opponents = [...new Set(data.map(d => d.opponent))];
const strategies = [...new Set(data.map(d => d.strategy))].sort();
filterOpponent.innerHTML = `
<option value="">All Opponents</option>
${opponents.map(op => `<option>${op}</option>`).join('')}
`;
filterStrategy.innerHTML = '';
strategies.forEach(strat => {
const label = document.createElement('label');
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.value = strat;
checkbox.checked = true;
checkbox.addEventListener('change', applySortAndFilter);
label.append(checkbox, document.createTextNode(strat));
filterStrategy.appendChild(label);
});
}
function populateTypeFilter() {
typeFilterContainer.innerHTML = '';
const controls = document.createElement('div');
controls.className = 'type-controls';
const selectAll = document.createElement('button');
selectAll.textContent = 'Select All';
selectAll.type = 'button';
selectAll.addEventListener('click', () => {
typeFilterContainer.querySelectorAll('input[type="checkbox"]').forEach(cb => cb.checked = true);
applySortAndFilter();
});
const deselectAll = document.createElement('button');
deselectAll.textContent = 'Deselect All';
deselectAll.type = 'button';
deselectAll.addEventListener('click', () => {
typeFilterContainer.querySelectorAll('input[type="checkbox"]').forEach(cb => cb.checked = false);
applySortAndFilter();
});
controls.appendChild(selectAll);
controls.appendChild(deselectAll);
typeFilterContainer.appendChild(controls);
cardTypes.forEach((type, idx) => {
const label = document.createElement('label');
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.value = idx;
checkbox.checked = true;
checkbox.addEventListener('change', applySortAndFilter);
label.append(checkbox, document.createTextNode(type));
typeFilterContainer.appendChild(label);
});
typeFilterContainer.classList.add('hidden');
typeArrow.textContent = '▼';
}
function renderTable(data) {
const limit = (data.length > 500) ? 500 : data.length;
const visibleData = data.slice(0, limit);
document.getElementById('cardCount').textContent = `Showing ${visibleData.length} cards of ${data.length}`;
let html = '';
for (let i = 0; i < visibleData.length; i++) {
const drop = visibleData[i];
const rateValue = parseInt(drop.rate.split('/')[0], 10);
const percentage = ((rateValue / 2048) * 100).toFixed(2);
const imgSrc = `assets/opponent/${drop.imageId}.png`;
const typeName = cardTypes[drop.typeIndex] || 'Unknown';
const typeImgSrc = `assets/types/${typeName}.png`;
const rowClass = i % 2 === 0 ? 'even' : 'odd';
html += `
<tr class="${rowClass}">
<td>${drop.card}</td>
<td><img src="${typeImgSrc}" alt="${typeName}" class="type-icon" /> ${typeName}</td>
<td>${drop.rate} <strong>(${percentage}%)</strong></td>
<td class="opponent-cell"><img src="${imgSrc}" alt="Opponent Icon">${drop.opponent}</td>
<td>${drop.strategy}</td>
</tr>`;
}
tableBody.innerHTML = html;
}
function applySortAndFilter() {
const rawSearch = searchInput.value.trim().toLowerCase();
let searchById = null;
if (rawSearch.startsWith('#')) {
const idMatch = rawSearch.match(/^#(\d+)$/);
if (idMatch) {
searchById = idMatch[1];
}
}
const minRate = parseInt(minRateInput.value, 10) || 1;
const maxRate = parseInt(maxRateInput.value, 10) || 2048;
const opponentVal = filterOpponent.value;
const checkedStrats = [...filterStrategy.querySelectorAll('input:checked')].map(cb => cb.value);
const checkedTypes = [...typeFilterContainer.querySelectorAll('input:checked')].map(cb => +cb.value);
let filtered = currentData.filter(drop => {
const rateNum = parseInt(drop.rate.split('/')[0], 10);
return (
(searchById ? drop.id === searchById : drop.card.toLowerCase().includes(rawSearch)) &&
rateNum >= minRate && rateNum <= maxRate &&
(opponentVal ? drop.opponent === opponentVal : true) &&
checkedStrats.includes(drop.strategy) &&
checkedTypes.includes(drop.typeIndex)
);
});
if (currentSortKey) {
filtered.sort((a, b) => {
let aVal = a[currentSortKey];
let bVal = b[currentSortKey];
if (currentSortKey === 'rate') {
aVal = parseInt(aVal.split('/')[0], 10);
bVal = parseInt(bVal.split('/')[0], 10);
} else if (currentSortKey === 'type') {
aVal = cardTypes[a.typeIndex] || '';
bVal = cardTypes[b.typeIndex] || '';
}
if (currentSortKey !== 'rate') {
aVal = aVal.toString().toLowerCase();
bVal = bVal.toString().toLowerCase();
}
if (aVal < bVal) return currentSortDirection === 'asc' ? -1 : 1;
if (aVal > bVal) return currentSortDirection === 'asc' ? 1 : -1;
return 0;
});
}
renderTable(filtered);
}
fileInput.addEventListener('change', async e => {
const file = e.target.files[0];
if (!file) return;
await loadTypeMapping();
const text = await file.text();
currentData = parseDropData(text);
originalData = [...currentData];
populateFilters(currentData);
applySortAndFilter();
searchView.classList.remove('hidden');
});
document.getElementById('loadVanilla').addEventListener('click', async () => {
await loadTypeMapping();
const res = await fetch('assets/vanilla.log');
const text = await res.text();
currentData = parseDropData(text);
originalData = [...currentData];
populateFilters(currentData);
applySortAndFilter();
searchView.classList.remove('hidden');
});
document.getElementById('resetApp').addEventListener('click', () => {
currentData = [];
tableBody.innerHTML = '';
fileInput.value = '';
searchInput.value = '';
minRateInput.value = '';
maxRateInput.value = '';
filterOpponent.value = '';
filterStrategy.innerHTML = '';
typeFilterContainer.querySelectorAll('input[type="checkbox"]').forEach(cb => cb.checked = true);
currentSortKey = null;
currentSortDirection = 'asc';
document.querySelectorAll('#dropsTable th').forEach(h =>
h.classList.remove('sorted-asc', 'sorted-desc')
);
searchView.classList.add('hidden');
});
const debouncedFilter = debounce(applySortAndFilter, 50);
[searchInput, minRateInput, maxRateInput, filterOpponent].forEach(el =>
el.addEventListener('input', debouncedFilter)
);
document.querySelectorAll('#dropsTable th').forEach(header => {
header.addEventListener('click', () => {
const key = header.dataset.key;
const isSameKey = currentSortKey === key;
if (!isSameKey) {
currentSortKey = key;
currentSortDirection = 'asc';
} else if (currentSortDirection === 'asc') {
currentSortDirection = 'desc';
} else if (currentSortDirection === 'desc') {
currentSortKey = null;
currentSortDirection = 'asc';
}
// Remove all sort indicators
document.querySelectorAll('#dropsTable th').forEach(h =>
h.classList.remove('sorted-asc', 'sorted-desc')
);
if (currentSortKey) {
header.classList.add(`sorted-${currentSortDirection}`);
}
applySortAndFilter();
});
});
toggleTypeDropdown.addEventListener('click', e => {
e.stopPropagation();
const isHidden = typeFilterContainer.classList.toggle('hidden');
typeArrow.textContent = isHidden ? '▼' : '▲';
});
document.addEventListener('click', e => {
if (!typeFilterContainer.contains(e.target) && !toggleTypeDropdown.contains(e.target)) {
if (!typeFilterContainer.classList.contains('hidden')) {
typeFilterContainer.classList.add('hidden');
typeArrow.textContent = '▼';
}
}
});
window.addEventListener('DOMContentLoaded', populateTypeFilter);