-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcardData.js
More file actions
84 lines (77 loc) · 2.41 KB
/
Copy pathcardData.js
File metadata and controls
84 lines (77 loc) · 2.41 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
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
export let allCards = [];
export let cardIndex = {};
export let parentOfMap = {};
export let veteranMap = {};
export let becomesVeteranMap = {};
export function loadData() {
const dataPath = path.join(__dirname, 'data.json');
const raw = fs.readFileSync(dataPath, 'utf8');
const data = JSON.parse(raw);
const rawCards = data.cards || [];
allCards = rawCards.map((raw, idx) => {
const j = raw.json || {};
const factionRaw = (j.faction || "").toLowerCase();
return {
id: raw.id ?? idx,
cardId: j.id || raw.cardId || "",
importId: raw.importId || j.import_id || "",
titleZh: j.title?.["zh-Hans"] || j.title?.en || "未找到",
titleEn: j.title?.["en-EN"] || "",
text_zh: j.text?.["zh-Hans"] || "",
textMap: j.text || {},
titleMap: j.title || {},
faction: factionRaw,
type: j.type || "",
rarity: j.rarity || "Standard",
cost: j.kredits ?? 0,
attack: j.attack,
defense: j.defense,
operationCost: j.operationCost,
attributes: j.attributes || [],
setName: j.set || "基础",
image: j.image || "",
reserved: raw.reserved === true,
isSpawn: j.set === "OnlySpawnable",
isVeteranSet: j.set === "Special",
canCreate: j.can_create || [],
rawJson: j,
isCustom: false,
imageData: null,
imageFit: 'cover'
};
});
// 构建索引
cardIndex = {};
for (const c of allCards) if (c.cardId) cardIndex[c.cardId] = c;
parentOfMap = {};
veteranMap = {};
becomesVeteranMap = {};
for (const c of allCards) {
if (c.canCreate && c.canCreate.length) {
for (const childId of c.canCreate) {
if (!parentOfMap[childId]) parentOfMap[childId] = [];
parentOfMap[childId].push(c.cardId);
}
}
}
for (const c of allCards) {
const attrs = c.attributes || [];
for (const a of attrs) {
if (a.startsWith("BecomesVeteran:")) {
const veteranId = a.replace("BecomesVeteran:", "");
veteranMap[c.cardId] = veteranId;
becomesVeteranMap[veteranId] = c.cardId;
}
if (a.startsWith("VeteranOf:")) {
const originalId = a.replace("VeteranOf:", "");
veteranMap[originalId] = c.cardId;
becomesVeteranMap[c.cardId] = originalId;
}
}
}
}
loadData();