Skip to content

Commit

Permalink
remove distinction between null and undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
tnfAngel committed Dec 1, 2024
1 parent 9db0277 commit 75ba03d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
4 changes: 2 additions & 2 deletions resources/structs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -996,9 +996,9 @@ export interface Island {

export interface Cosmetics {
outfit?: { id: string; variants?: CosmeticVariant[]; enlightment?: CosmeticEnlightment };
backpack?: { id: string; variants?: CosmeticVariant[]; path?: string } | null;
backpack?: { id: string; variants?: CosmeticVariant[]; path?: string };
pickaxe?: { id: string; variants?: CosmeticVariant[]; path?: string };
shoes?: { id: string; path?: string } | null;
shoes?: { id: string; path?: string };
}

export interface CosmeticVariant {
Expand Down
29 changes: 13 additions & 16 deletions src/structures/party/ClientPartyMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,27 +189,24 @@ class ClientPartyMember extends PartyMember {

/**
* Updates multiple cosmetics for the client party member.
* If a cosmetic is set to `null`, it will be cleared.
* If a cosmetic is set to `undefined` or not provided, it will remain unchanged.
*
* If a cosmetic is set to `undefined` or any falsy value, it will be cleared.
* If a cosmetic is not provided, it will remain unchanged.
* @param cosmetics An object specifying the cosmetics to update. Can be outfit, backpack, pickaxe or shoes.
* @throws {EpicgamesAPIError}
*/
public async setCosmetics({
outfit,
backpack,
pickaxe,
shoes,
}: Cosmetics = {}) {
public async setCosmetics(cosmetics: Cosmetics = {}) {
const {
outfit, backpack, pickaxe, shoes,
} = cosmetics;
const patches: Schema = {};

if (outfit !== undefined) {
if (outfit) {
let data = this.meta.get('Default:AthenaCosmeticLoadout_j');
let variantData = this.meta.get('Default:AthenaCosmeticLoadoutVariants_j');

const parsedVariants: CosmeticsVariantMeta = {
athenaCharacter: {
i: outfit.variants?.map((v) => ({
i: outfit?.variants?.map((v) => ({
c: v.channel,
v: v.variant,
dE: v.dE || 0,
Expand Down Expand Up @@ -251,8 +248,8 @@ class ClientPartyMember extends PartyMember {
}
}

if (backpack !== undefined) {
if (backpack === null) {
if (Object.hasOwn(cosmetics, 'backpack')) {
if (!backpack) {
let data = this.meta.get('Default:AthenaCosmeticLoadout_j');

data = this.meta.set('Default:AthenaCosmeticLoadout_j', {
Expand Down Expand Up @@ -304,7 +301,7 @@ class ClientPartyMember extends PartyMember {
}
}

if (pickaxe !== undefined) {
if (pickaxe) {
let data = this.meta.get('Default:AthenaCosmeticLoadout_j');
let variantData = this.meta.get('Default:AthenaCosmeticLoadoutVariants_j');

Expand Down Expand Up @@ -343,8 +340,8 @@ class ClientPartyMember extends PartyMember {
}
}

if (shoes !== undefined) {
if (shoes === null) {
if (Object.hasOwn(cosmetics, 'shoes')) {
if (!shoes) {
let data = this.meta.get('Default:AthenaCosmeticLoadout_j');

data = this.meta.set('Default:AthenaCosmeticLoadout_j', {
Expand Down

0 comments on commit 75ba03d

Please sign in to comment.