Skip to content

Commit

Permalink
Merge pull request #398 from danocmx/fix/pumpkin-patch-exception
Browse files Browse the repository at this point in the history
  • Loading branch information
danocmx authored Oct 16, 2024
2 parents b4df947 + 216ee25 commit 8afd0b3
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 16 deletions.
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 18 additions & 11 deletions src/parseString/Attributes/getEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ export default function (name: string, attributes: Attributes): string | void {
for (let i = 0; i < effectsKeys.length; i++) {
let effect: string | number = effectsKeys[i];

if (!name.includes(`${effect} `)) {
continue;
}

// New type of exception
if (effect === 'Smoking' && name.includes('Smoking Smoking Skid Lid')) {
return 'Smoking';
}

if (
effect === 'Haunted Ghosts' &&
name.includes('Haunted Ghosts ') &&
attributes.wear
) {
if (isEffectTexture(attributes, effect)) {
continue;
}

Expand All @@ -38,11 +38,7 @@ export default function (name: string, attributes: Attributes): string | void {
return exception[1];
}

if (
!isNumber(effect) &&
name.includes(`${effect} `) &&
!isException(name, effect)
) {
if (!isNumber(effect) && !isHatNameException(name, effect)) {
return effect;
}
}
Expand Down Expand Up @@ -72,9 +68,20 @@ const HAT_NAME_EXCEPTIONS: [string, string][] = [
['Cool Warm Sweater', 'Cool'],
];

function isException(name: string, effect: string): boolean {
function isHatNameException(name: string, effect: string): boolean {
return HAT_NAME_EXCEPTIONS.some((exception) => {
const [exceptionName, exceptionEffect] = exception;
return name.includes(exceptionName) && effect === exceptionEffect;
});
}

export const TEXTURE_EFFECT_EXCEPTION: string[] = ['Haunted Ghosts', 'Pumpkin Patch'];

function isEffectTexture(
attributes: Attributes,
effectOrTexture: string
): boolean {
return !!(
TEXTURE_EFFECT_EXCEPTION.includes(effectOrTexture) && attributes.wear
);
}
20 changes: 15 additions & 5 deletions src/shared/getTexture.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import isNumber from '../util/isNumber';

import { ISchema } from '../types/schema';
import { TEXTURE_EFFECT_EXCEPTION } from '../parseString/Attributes/getEffect';

const TEXTURE_EXCEPTIONS = [['Health and Hell', 'Health and Hell (Green)']];

Expand All @@ -19,11 +20,11 @@ export default function (
for (let i = 0; i < textureKeys.length; i++) {
const texture: number | string = textureKeys[i];

if (
texture === 'Haunted Ghosts' &&
name.includes('Haunted Ghosts') &&
!attributes.wear
) {
if (!name.includes(`${texture} `)) {
continue;
}

if (isTextureEffect(attributes, texture)) {
continue;
}

Expand Down Expand Up @@ -55,3 +56,12 @@ function isTextureToEffectException(name: string, texture: string): boolean {
}
return false;
}

function isTextureEffect(
attributes: { wear: any | null },
effectOrTexture: string
): boolean {
return !!(
TEXTURE_EFFECT_EXCEPTION.includes(effectOrTexture) && !attributes.wear
);
}
23 changes: 23 additions & 0 deletions test/parseString.js
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,29 @@ describe('parseString with numbers', () => {
quality: 6,
});
});

it('Case #52 - Pumpking Patch #1', () => {
const itemObject = parseString('Pumpkin Patch Taunt: Most Wanted', true, false);

assert.deepEqual(itemObject, {
name: 'Taunt: Most Wanted',
craftable: true,
effect: 3184,
quality: 5,
});
});

it('Case #52 - Pumpking Patch #1', () => {
const itemObject = parseString('Strange Pumpkin Patch Minigun (Factory New)', true, false);

assert.deepEqual(itemObject, {
name: 'Minigun',
craftable: true,
quality: 11,
wear: 1,
texture: 62
});
});
});

describe('parseString with defindexes and numbers.', () => {
Expand Down

0 comments on commit 8afd0b3

Please sign in to comment.