-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmissingImport.js
More file actions
77 lines (67 loc) · 2.22 KB
/
missingImport.js
File metadata and controls
77 lines (67 loc) · 2.22 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
import eventManager from 'src/utils/eventManager.js';
import { global } from 'src/utils/global.js';
import style from 'src/utils/style.js';
import { dismissable } from 'src/utils/2.toasts.js';
import Translation from 'src/structures/constants/translation';
style.add(
'.missingArt { color: yellow; }',
'.missing { color: orange; }',
'.missingDT { color: red; }',
);
function init() {
eventManager.on('ShowPage', (page) => thing(page * 10));
dismissable({
title: Translation.INFO,
// TODO: translation
text: `The import arrow is colored to symbolize <span class="missingDT">missing DT(s)</span>, <span class="missing">missing card(s)</span>, and <span class="missingArt">missing artifact(s)</span>`,
key: 'underscript.notice.hubImport',
value: '2',
});
}
function thing(start) {
const pages = global('pages');
for (let i = start; i < start + 10 && i < pages.length; i++) {
check(pages[i]);
}
}
function check({ code, id }) {
const checkArt = global('ownArtifactHub');
const deck = JSON.parse(atob(code));
const allCards = toObject(global('allCards'));
const missingCards = getMissingCards(deck.cardIds);
const missingDT = missingCards.some((i) => allCards[i].rarity === ' ');
const missingCard = missingCards.length > 0;
const missingArt = deck.artifactIds.filter((art) => !checkArt(art));
$(`#hub-deck-${id} .show-button`)
.toggleClass('missingArt', missingArt.length > 0)
.toggleClass('missing', missingCard)
.toggleClass('missingDT', missingDT);
missingArt.forEach((i) => {
$(`#hub-deck-${id} .hubDeckArtifacts span[onclick$="(${i});"] img`)
.toggleClass('notOwnedArtifact', true);
});
}
function getMissingCards(ids = []) {
const collection = toObject(global('collection').filter(({ id }) => ids.includes(id)));
return ids.filter((id) => {
const card = collection[id];
if (!card) {
return true;
}
const ret = card.quantity <= 0;
card.quantity -= 1;
return ret;
});
}
function toObject(cards = []) {
return cards.reduce((o, card) => {
const exists = o[card.id];
if (exists) {
exists.quantity += card.quantity;
} else {
o[card.id] = { ...card };
}
return o;
}, {});
}
eventManager.on(':preload:Hub', init);