Files
discord-decomp/modules/collectibles/nameplates/utils.tsx
T
2026-11-01 12:12:55 +02:00

102 lines
3.4 KiB
TypeScript

// Metro module 1898 (f1899).
import { isNameplateRecord } from "../records/NameplateRecord";
import { ThemeTypes } from "../../../_bundle/Module505";
import { NAMEPLATE_PALETTES, INVALID_NAMEPLATE_PALETTE, INVALID_PALETTE_KEY, CUSTOM_PALETTE_KEY } from "./constants";
import decodeImage from "../../../_bundle/decodeImage";
import { intl, t } from "../../../intl/index.native";
export function getNameplateData(a0) {
const r0 = a0 == null;
let r2 = null;
if (!r0) {
let palette = NAMEPLATE_PALETTES[a0.palette];
if (palette == null) {
palette = INVALID_NAMEPLATE_PALETTE;
}
r2 = {
skuId: a0.skuId,
src: a0.asset,
imgAlt: a0.label,
palette
};
}
return r2;
}
export function getNameplateDataFromProductRecord(a0) {
if (a0.items.length === 0) {
return null;
}
const r8 = a0.items[0];
const isNameplateRecord2 = isNameplateRecord(r8);
let r15 = null;
if (isNameplateRecord2) {
const r3 = r8 == null;
let r16 = null;
if (!r3) {
let palette = NAMEPLATE_PALETTES[r8.palette];
if (palette == null) {
palette = INVALID_NAMEPLATE_PALETTE;
}
r16 = {
skuId: r8.skuId,
src: r8.asset,
imgAlt: r8.label,
palette
};
}
r15 = r16;
}
return r15;
}
export function getBackgroundGradientColors(a0, a1) {
if (a0.name !== INVALID_PALETTE_KEY && (a0.name !== CUSTOM_PALETTE_KEY || /^#([0-9a-fA-F]{6})$/.test(a0.darkBackground) && /^#([0-9a-fA-F]{6})$/.test(a0.lightBackground))) {
const r25 = a1 === ThemeTypes.LIGHT ? a0.lightBackground : a0.darkBackground;
return {
left: `${r25}00`,
right: `${r25}4D`
};
}
}
export function isValidPalette(a0) {
return a0.name !== INVALID_PALETTE_KEY && (a0.name !== CUSTOM_PALETTE_KEY || /^#([0-9a-fA-F]{6})$/.test(a0.darkBackground) && /^#([0-9a-fA-F]{6})$/.test(a0.lightBackground));
}
export function getNameplatePalette(a0) {
let r9 = NAMEPLATE_PALETTES[a0];
if (r9 == null) {
r9 = INVALID_NAMEPLATE_PALETTE;
}
return r9;
}
export function parseFirstFrame(a0) {
const r16 = decodeImage.decode(a0);
const r21 = decodeImage.toRGBA8(r16)[0];
const element = document.createElement("canvas");
element.width = r16.width;
element.height = r16.height;
element.getContext("2d").putImageData(new ImageData(new Uint8ClampedArray(r21), r16.width, r16.height), 0, 0);
return element.toDataURL("image/png");
}
export function getNameplateSampleUsers() {
return {
mallow: {
name: intl.string(t.SbKDHi),
avatarSrc: "https://cdn.discordapp.com/assets/content/6dcafe1231097505560fd098f0e6698990f0082369d34c35d8c3ee9615709f84.png"
},
phibi: {
name: intl.string(t["LMSo+F"]),
avatarSrc: "https://cdn.discordapp.com/assets/content/17ae2ee3b8476755370ca9fa4d776d0bb811e50962409a7ae2dedd1b96c95eab.png"
},
locke: {
name: intl.string(t.g5Dumi),
avatarSrc: "https://cdn.discordapp.com/assets/content/a82a9daadc5c7842f183c0f61966b07d3aeeea478b7c8a4b8af48334eb1ce15f.png"
},
cherry: {
name: intl.string(t.p5Z3Ol),
avatarSrc: "https://cdn.discordapp.com/assets/content/afc2e8306ce540dccac7da1ca0871684d0bf67e77967ff0f679be84a0a6e51b7.png"
},
boom: {
name: intl.string(t.ncslie),
avatarSrc: "https://cdn.discordapp.com/assets/content/e264a2b0b8d963edd255c223abf1c0554f00a2f3a38640e509a38bc03d73b606.png"
}
};
}