Skip to content

Commit

Permalink
chore: convert rewards to constant strings
Browse files Browse the repository at this point in the history
  • Loading branch information
feildmaster committed Oct 17, 2023
1 parent 9397e80 commit dd6833f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# UnderScript Changelog

## Version 0.55.4 (2023-10-17)
1. Fix quest reward bug

## Version 0.55.3 (2023-10-16)
1. Fixed another quest bug

Expand Down
42 changes: 27 additions & 15 deletions src/structures/quests/Reward.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { translateText } from '../../utils/translate.js';

export default class Reward {
#reward;
#type;
Expand Down Expand Up @@ -37,7 +35,7 @@ function rewardType(el) {
let temp = el.querySelector('[data-i18n-tips]');
if (temp) { // Generic reward
return {
type: translateText(temp.dataset.i18nTips),
type: getRewardType(temp.dataset.i18nTips),
value: temp.parentElement.textContent.trim().substring(1),
};
}
Expand Down Expand Up @@ -73,35 +71,35 @@ function rewardType(el) {
};
}

temp = el.querySelector('.standard-skin');
temp = el.querySelector('.avatar');
if (temp) {
return {
type: 'card skin',
value: getStyleUrl(temp),
type: 'avatar',
value: temp.src,
};
}

temp = el.querySelector('.full-skin');
temp = el.querySelector('[src*="/profiles/"]');
if (temp) {
return {
type: 'card skin full',
value: getStyleUrl(temp),
type: 'profile',
value: temp.src,
};
}

temp = el.querySelector('.avatar');
temp = el.querySelector('.standard-skin');
if (temp) {
return {
type: 'avatar',
value: temp.src,
type: 'card skin',
value: getStyleUrl(temp),
};
}

temp = el.querySelector('[src*="/profiles/"]');
temp = el.querySelector('.full-skin');
if (temp) {
return {
type: 'profile',
value: temp.src,
type: 'card skin full',
value: getStyleUrl(temp),
};
}

Expand All @@ -113,3 +111,17 @@ function getStyleUrl(el) {
const style = img.currentStyle || window.getComputedStyle(img, true) || img.style;
return style.backgroundImage.slice(4, -1).replace(/"/g, '');
}

function getRewardType(string) {
switch (string) {
// TODO: Convert to constants
case 'reward-gold': return 'Gold';
case 'reward-shiny-pack': return 'Shiny Pack';
case 'reward-pack': return 'Pack';
case 'reward-dr-pack': return 'DR Pack';
case 'reward-dust': return 'Dust';
case 'reward-dt-fragment': return 'DT Fragment';
// If anything new comes through
default: return string;
}
}

0 comments on commit dd6833f

Please sign in to comment.