style: run format:apply
This commit is contained in:
+156
-132
@@ -1,165 +1,189 @@
|
||||
import { fetchDLCs, fetchItems, fetchOfferings, fetchAddons, fetchPerks } from '../lib/db';
|
||||
import {
|
||||
fetchDLCs,
|
||||
fetchItems,
|
||||
fetchOfferings,
|
||||
fetchAddons,
|
||||
fetchPerks
|
||||
} from '../lib/db';
|
||||
import { DLC } from '../lib/utils';
|
||||
|
||||
export interface SpooferConfig {
|
||||
camperItems: Record<string, number>;
|
||||
camperAddons: Record<string, number>;
|
||||
slasherAddons: Record<string, number>;
|
||||
camperOfferings: Record<string, number>;
|
||||
slasherOfferings: Record<string, number>;
|
||||
globalOfferings: Record<string, number>;
|
||||
camperPerks: string[];
|
||||
slasherPerks: string[];
|
||||
catalogItemIds: string[];
|
||||
dlcListGRDK: string[];
|
||||
dlcListEGS: string[];
|
||||
dlcListSteam: string[];
|
||||
camperItems: Record<string, number>;
|
||||
camperAddons: Record<string, number>;
|
||||
slasherAddons: Record<string, number>;
|
||||
camperOfferings: Record<string, number>;
|
||||
slasherOfferings: Record<string, number>;
|
||||
globalOfferings: Record<string, number>;
|
||||
camperPerks: string[];
|
||||
slasherPerks: string[];
|
||||
catalogItemIds: string[];
|
||||
dlcListGRDK: string[];
|
||||
dlcListEGS: string[];
|
||||
dlcListSteam: string[];
|
||||
}
|
||||
|
||||
export interface Toggles {
|
||||
spoofItems: boolean;
|
||||
spoofPerks: boolean;
|
||||
spoofCatalog: boolean;
|
||||
spoofDLCs: boolean;
|
||||
spoofItems: boolean;
|
||||
spoofPerks: boolean;
|
||||
spoofCatalog: boolean;
|
||||
spoofDLCs: boolean;
|
||||
}
|
||||
|
||||
export async function mapStoreToSpooferConfig(state: {
|
||||
unlockedCharacters: string[];
|
||||
unlockedCustomizations: string[];
|
||||
unlockedDLCs: string[];
|
||||
unlockedPerks: string[];
|
||||
items: Record<string, number>;
|
||||
offerings: Record<string, number>;
|
||||
addons: Record<string, number>;
|
||||
unlockedCharacters: string[];
|
||||
unlockedCustomizations: string[];
|
||||
unlockedDLCs: string[];
|
||||
unlockedPerks: string[];
|
||||
items: Record<string, number>;
|
||||
offerings: Record<string, number>;
|
||||
addons: Record<string, number>;
|
||||
}): Promise<SpooferConfig> {
|
||||
const [dlcs, allItems, allOfferings, allAddons, allPerks] = await Promise.all([
|
||||
fetchDLCs(),
|
||||
fetchItems(),
|
||||
fetchOfferings(),
|
||||
fetchAddons(),
|
||||
fetchPerks()
|
||||
]);
|
||||
const [dlcs, allItems, allOfferings, allAddons, allPerks] = await Promise.all(
|
||||
[fetchDLCs(), fetchItems(), fetchOfferings(), fetchAddons(), fetchPerks()]
|
||||
);
|
||||
|
||||
const dlcMap = new Map<string, DLC>();
|
||||
dlcs.forEach((d: DLC) => dlcMap.set(d.id, d));
|
||||
const dlcMap = new Map<string, DLC>();
|
||||
dlcs.forEach((d: DLC) => dlcMap.set(d.id, d));
|
||||
|
||||
const itemIdSet = new Set<string>();
|
||||
allItems.forEach((i: { id: string }) => itemIdSet.add(i.id));
|
||||
const itemIdSet = new Set<string>();
|
||||
allItems.forEach((i: { id: string }) => itemIdSet.add(i.id));
|
||||
|
||||
const offeringMap = new Map<string, { role: number }>();
|
||||
allOfferings.forEach((o: { id: string; role: number }) => offeringMap.set(o.id, o));
|
||||
const offeringMap = new Map<string, { role: number }>();
|
||||
allOfferings.forEach((o: { id: string; role: number }) =>
|
||||
offeringMap.set(o.id, o)
|
||||
);
|
||||
|
||||
const addonMap = new Map<string, { role: number }>();
|
||||
allAddons.forEach((a: { id: string; role: number }) => addonMap.set(a.id, a));
|
||||
const addonMap = new Map<string, { role: number }>();
|
||||
allAddons.forEach((a: { id: string; role: number }) => addonMap.set(a.id, a));
|
||||
|
||||
const perkMap = new Map<string, { role: number }>();
|
||||
allPerks.forEach((p: { id: string; role: number }) => perkMap.set(p.id, p));
|
||||
const perkMap = new Map<string, { role: number }>();
|
||||
allPerks.forEach((p: { id: string; role: number }) => perkMap.set(p.id, p));
|
||||
|
||||
const dlcListSteam: string[] = [];
|
||||
const dlcListEGS: string[] = [];
|
||||
const dlcListGRDK: string[] = [];
|
||||
// --- DLCs ---
|
||||
const dlcListSteam: string[] = [];
|
||||
const dlcListEGS: string[] = [];
|
||||
const dlcListGRDK: string[] = [];
|
||||
|
||||
for (const id of state.unlockedDLCs) {
|
||||
const dlc = dlcMap.get(id);
|
||||
if (!dlc?.dlcIds) continue;
|
||||
if (dlc.dlcIds.steam && dlc.dlcIds.steam !== '0' && dlc.dlcIds.steam !== '-1')
|
||||
dlcListSteam.push(dlc.dlcIds.steam);
|
||||
if (dlc.dlcIds.epic && dlc.dlcIds.epic !== 'FFFFFFFFFFFFFFFF' && dlc.dlcIds.epic !== '0')
|
||||
dlcListEGS.push(dlc.dlcIds.epic);
|
||||
if (dlc.dlcIds.grdk && dlc.dlcIds.grdk !== '9ZZZZZZZZZZZ' && dlc.dlcIds.grdk !== '0')
|
||||
dlcListGRDK.push(dlc.dlcIds.grdk);
|
||||
}
|
||||
for (const id of state.unlockedDLCs) {
|
||||
const dlc = dlcMap.get(id);
|
||||
if (!dlc?.dlcIds) continue;
|
||||
if (
|
||||
dlc.dlcIds.steam &&
|
||||
dlc.dlcIds.steam !== '0' &&
|
||||
dlc.dlcIds.steam !== '-1'
|
||||
)
|
||||
dlcListSteam.push(dlc.dlcIds.steam);
|
||||
if (
|
||||
dlc.dlcIds.epic &&
|
||||
dlc.dlcIds.epic !== 'FFFFFFFFFFFFFFFF' &&
|
||||
dlc.dlcIds.epic !== '0'
|
||||
)
|
||||
dlcListEGS.push(dlc.dlcIds.epic);
|
||||
if (
|
||||
dlc.dlcIds.grdk &&
|
||||
dlc.dlcIds.grdk !== '9ZZZZZZZZZZZ' &&
|
||||
dlc.dlcIds.grdk !== '0'
|
||||
)
|
||||
dlcListGRDK.push(dlc.dlcIds.grdk);
|
||||
}
|
||||
|
||||
const camperItems: Record<string, number> = {};
|
||||
for (const [id, qty] of Object.entries(state.items))
|
||||
if (qty > 0 && itemIdSet.has(id)) camperItems[id] = qty;
|
||||
// --- Items ---
|
||||
const camperItems: Record<string, number> = {};
|
||||
for (const [id, qty] of Object.entries(state.items)) {
|
||||
if (qty > 0 && itemIdSet.has(id)) camperItems[id] = qty;
|
||||
}
|
||||
|
||||
// --- Offerings ---
|
||||
const camperOfferings: Record<string, number> = {};
|
||||
const slasherOfferings: Record<string, number> = {};
|
||||
const globalOfferings: Record<string, number> = {};
|
||||
|
||||
const camperOfferings: Record<string, number> = {};
|
||||
const slasherOfferings: Record<string, number> = {};
|
||||
const globalOfferings: Record<string, number> = {};
|
||||
for (const [id, qty] of Object.entries(state.offerings)) {
|
||||
if (qty <= 0) continue;
|
||||
const offering = offeringMap.get(id);
|
||||
if (!offering) continue;
|
||||
if (offering.role === 2) camperOfferings[id] = qty;
|
||||
else if (offering.role === 1) slasherOfferings[id] = qty;
|
||||
else globalOfferings[id] = qty;
|
||||
}
|
||||
|
||||
for (const [id, qty] of Object.entries(state.offerings)) {
|
||||
if (qty <= 0) continue;
|
||||
const offering = offeringMap.get(id);
|
||||
if (!offering) continue;
|
||||
if (offering.role === 2) camperOfferings[id] = qty;
|
||||
else if (offering.role === 1) slasherOfferings[id] = qty;
|
||||
else globalOfferings[id] = qty;
|
||||
}
|
||||
// --- Addons ---
|
||||
const camperAddons: Record<string, number> = {};
|
||||
const slasherAddons: Record<string, number> = {};
|
||||
|
||||
const camperAddons: Record<string, number> = {};
|
||||
const slasherAddons: Record<string, number> = {};
|
||||
for (const [id, qty] of Object.entries(state.addons)) {
|
||||
if (qty <= 0) continue;
|
||||
const addon = addonMap.get(id);
|
||||
if (!addon) continue;
|
||||
if (addon.role === 1) slasherAddons[id] = qty;
|
||||
else camperAddons[id] = qty;
|
||||
}
|
||||
|
||||
for (const [id, qty] of Object.entries(state.addons)) {
|
||||
if (qty <= 0) continue;
|
||||
const addon = addonMap.get(id);
|
||||
if (!addon) continue;
|
||||
if (addon.role === 1) slasherAddons[id] = qty;
|
||||
else camperAddons[id] = qty;
|
||||
}
|
||||
// --- Perks ---
|
||||
const camperPerks: string[] = [];
|
||||
const slasherPerks: string[] = [];
|
||||
|
||||
const camperPerks: string[] = [];
|
||||
const slasherPerks: string[] = [];
|
||||
for (const id of state.unlockedPerks) {
|
||||
const perk = perkMap.get(id);
|
||||
if (!perk) continue;
|
||||
if (perk.role === 1) slasherPerks.push(id);
|
||||
else camperPerks.push(id);
|
||||
}
|
||||
|
||||
for (const id of state.unlockedPerks) {
|
||||
const perk = perkMap.get(id);
|
||||
if (!perk) continue;
|
||||
if (perk.role === 1) slasherPerks.push(id);
|
||||
else camperPerks.push(id);
|
||||
}
|
||||
|
||||
return {
|
||||
camperItems,
|
||||
camperAddons,
|
||||
slasherAddons,
|
||||
camperOfferings,
|
||||
slasherOfferings,
|
||||
globalOfferings,
|
||||
camperPerks,
|
||||
slasherPerks,
|
||||
catalogItemIds: [...state.unlockedCustomizations],
|
||||
dlcListSteam,
|
||||
dlcListEGS,
|
||||
dlcListGRDK,
|
||||
};
|
||||
return {
|
||||
camperItems,
|
||||
camperAddons,
|
||||
slasherAddons,
|
||||
camperOfferings,
|
||||
slasherOfferings,
|
||||
globalOfferings,
|
||||
camperPerks,
|
||||
slasherPerks,
|
||||
catalogItemIds: [...state.unlockedCustomizations],
|
||||
dlcListSteam,
|
||||
dlcListEGS,
|
||||
dlcListGRDK
|
||||
};
|
||||
}
|
||||
|
||||
export async function mapSpooferConfigToStore(profile: SpooferConfig) {
|
||||
const dlcs = await fetchDLCs();
|
||||
const dlcs = await fetchDLCs();
|
||||
|
||||
const unlockedDLCs: string[] = [];
|
||||
for (const dlc of dlcs as DLC[]) {
|
||||
if (!dlc.dlcIds) continue;
|
||||
const hasSteam = dlc.dlcIds.steam && profile.dlcListSteam?.includes(dlc.dlcIds.steam);
|
||||
const hasEpic = dlc.dlcIds.epic && profile.dlcListEGS?.includes(dlc.dlcIds.epic);
|
||||
const hasGrdk = dlc.dlcIds.grdk && profile.dlcListGRDK?.includes(dlc.dlcIds.grdk);
|
||||
if (hasSteam || hasEpic || hasGrdk) unlockedDLCs.push(dlc.id);
|
||||
}
|
||||
const unlockedDLCs: string[] = [];
|
||||
for (const dlc of dlcs as DLC[]) {
|
||||
if (!dlc.dlcIds) continue;
|
||||
const hasSteam =
|
||||
dlc.dlcIds.steam && profile.dlcListSteam?.includes(dlc.dlcIds.steam);
|
||||
const hasEpic =
|
||||
dlc.dlcIds.epic && profile.dlcListEGS?.includes(dlc.dlcIds.epic);
|
||||
const hasGrdk =
|
||||
dlc.dlcIds.grdk && profile.dlcListGRDK?.includes(dlc.dlcIds.grdk);
|
||||
if (hasSteam || hasEpic || hasGrdk) unlockedDLCs.push(dlc.id);
|
||||
}
|
||||
|
||||
const offerings: Record<string, number> = {
|
||||
...(profile.globalOfferings || {}),
|
||||
...(profile.camperOfferings || {}),
|
||||
...(profile.slasherOfferings || {}),
|
||||
};
|
||||
const offerings: Record<string, number> = {
|
||||
...(profile.globalOfferings || {}),
|
||||
...(profile.camperOfferings || {}),
|
||||
...(profile.slasherOfferings || {})
|
||||
};
|
||||
|
||||
const addons: Record<string, number> = {
|
||||
...(profile.camperAddons || {}),
|
||||
...(profile.slasherAddons || {}),
|
||||
};
|
||||
const addons: Record<string, number> = {
|
||||
...(profile.camperAddons || {}),
|
||||
...(profile.slasherAddons || {})
|
||||
};
|
||||
|
||||
const unlockedPerks: string[] = [
|
||||
...(profile.camperPerks || []),
|
||||
...(profile.slasherPerks || []),
|
||||
];
|
||||
const unlockedPerks: string[] = [
|
||||
...(profile.camperPerks || []),
|
||||
...(profile.slasherPerks || [])
|
||||
];
|
||||
|
||||
return {
|
||||
unlockedCharacters: [] as string[],
|
||||
unlockedCustomizations: profile.catalogItemIds || [],
|
||||
unlockedDLCs,
|
||||
unlockedPerks,
|
||||
items: profile.camperItems || {},
|
||||
offerings,
|
||||
addons,
|
||||
};
|
||||
}
|
||||
return {
|
||||
unlockedCharacters: [] as string[],
|
||||
unlockedCustomizations: profile.catalogItemIds || [],
|
||||
unlockedDLCs,
|
||||
unlockedPerks,
|
||||
items: profile.camperItems || {},
|
||||
offerings,
|
||||
addons
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user