-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
114 lines (90 loc) · 3.08 KB
/
index.js
File metadata and controls
114 lines (90 loc) · 3.08 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
import axios from "axios";
import fs from "fs";
import path from "path";
import config from "./config.js";
const API_URL = "https://fortnite-api.com/v2/cosmetics/br";
// Map Fortnite API type → Item Shop tag
const typeMap = {
outfit: "AthenaCharacter",
backpack: "AthenaBackpack",
pickaxe: "AthenaPickaxe",
glider: "AthenaGlider",
contrail: "AthenaSkyDiveContrail",
emote: "AthenaDance",
emoji: "AthenaDance",
toy: "AthenaDance",
spray: "AthenaDance",
wrap: "AthenaItemWrap",
loadingscreen: "AthenaLoadingScreen",
music: "AthenaMusicPack",
banner: "HomebaseBannerIcon"
};
async function fetchCosmetics() {
const res = await axios.get(API_URL);
return res.data.data || [];
}
function filterCosmetics(all) {
return all.filter((cosmetic) => {
if (!cosmetic.id || !cosmetic.type?.value) return false;
// Skip excluded IDs
if (config.bExcludedItems.includes(cosmetic.id)) return false;
// Chapter/Season limit
const chapter = cosmetic.introduction?.chapter || "0";
const season = cosmetic.introduction?.season || "0";
if (parseInt(chapter) > parseInt(config.bChapterlimit)) return false;
if (parseInt(season) > parseInt(config.bSeasonlimit)) return false;
return true;
});
}
function pickRandom(array, amount) {
const shuffled = [...array].sort(() => 0.5 - Math.random());
return shuffled.slice(0, amount);
}
function buildEntry(cosmetic) {
const tag = typeMap[cosmetic.type.value.toLowerCase()] || "Unknown";
const grant = `${tag}:${cosmetic.id}`;
const price = config.useApiPrices
? cosmetic.price?.regularPrice || config.priceTable[tag] || config.priceTable.default
: config.priceTable[tag] || config.priceTable.default;
return {
itemGrants: [grant],
price: price
};
}
async function buildShop() {
if (!config.bEnableShop) {
console.log("Shop rotation disabled (bEnableShop = false)");
return;
}
try {
const allCosmetics = await fetchCosmetics();
const pool = filterCosmetics(allCosmetics);
const dailyItems = pickRandom(pool, config.bDailyItemsAmount);
const featuredItems = pickRandom(pool, config.bFeaturedItemsAmount);
const shop = { "//": "BR Item Shop Config" };
dailyItems.forEach((item, i) => {
shop[`daily${i + 1}`] = buildEntry(item);
});
featuredItems.forEach((item, i) => {
shop[`featured${i + 1}`] = buildEntry(item);
});
if (!fs.existsSync(config.outputPath)) {
fs.mkdirSync(config.outputPath, { recursive: true });
}
const dateSuffix = config.bDateOutput
? `_${new Date().toISOString().split("T")[0]}`
: "";
const outputFile = path.join(
config.outputPath,
config.outputFile.replace(".json", `${dateSuffix}.json`)
);
let output = JSON.stringify(shop, null, 2);
// collapse arrays like "itemGrants": [ "X" ] → "itemGrants": ["X"]
output = output.replace(/\[\s+"([^"]+)"\s+\]/g, '["$1"]');
fs.writeFileSync("./output/catalog_config.json", output);
console.log(`✅ Shop saved to ${outputFile}`);
} catch (err) {
console.error("❌ Error building shop:", err.message);
}
}
buildShop();