Skip to content

Commit

Permalink
Merge pull request #930 from brjens/main
Browse files Browse the repository at this point in the history
Added a toggle to filter out ammo types you can't buy based on your trader levels
  • Loading branch information
Blightbuster authored Apr 26, 2024
2 parents 8ab939a + c65493b commit e62e7af
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

## Opening a Pull Request 🌟

If you have a fix for a bug or a feature request, follow the flow below to purpose your change
If you have a fix for a bug or a feature request, follow the flow below to propose your change

> If you are new to creating pull requests from a repository fork, check out this [guide](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork)
Expand Down
31 changes: 28 additions & 3 deletions src/pages/ammo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { formatCaliber } from '../../modules/format-ammo.mjs';
import symbols from '../../symbols.json';

import './index.css';
import { useSelector } from 'react-redux';
import { selectAllTraders } from '../../features/settings/settingsSlice.js';

const MAX_DAMAGE = 170;
const MAX_PENETRATION = 70;
Expand All @@ -34,6 +36,7 @@ const skipTypes = [
];

function Ammo() {
const allTraders = useSelector(selectAllTraders);
const { currentAmmo } = useParams();
let currentAmmoList = useMemo(() => [], []);
let redirect = false;
Expand All @@ -54,7 +57,8 @@ function Ammo() {
navigate(`/ammo/${currentAmmoList.join(',')}`);
}
}, [redirect, currentAmmoList, navigate]);


const [showOnlyTraderAmmo, setShowOnlyTraderAmmo] = useState(false);
const [selectedLegendName, setSelectedLegendName] = useState(currentAmmoList);
const [showAllTraderPrices, setShowAllTraderPrices] = useState(false);
const [useAllProjectileDamage, setUseAllProjectileDamage] = useState(false);
Expand Down Expand Up @@ -158,6 +162,16 @@ function Ammo() {
!selectedLegendName ||
selectedLegendName.length === 0 ||
selectedLegendName.includes(ammo.type),
).filter(ammo => {
if (showOnlyTraderAmmo) {
if (!ammo.buyFor.some(buyForEntry =>
buyForEntry.vendor.normalizedName !== 'flea-market' &&
buyForEntry.vendor.minTraderLevel <= allTraders[buyForEntry.vendor.normalizedName])
)
return false;
}
return true;
}
).filter(ammo => {
if (minPen === 0 && maxPen === 60) {
return true;
Expand Down Expand Up @@ -194,9 +208,8 @@ function Ammo() {
chartName: `${ammo.chartName} (${ammo.fragmentationChance})`,
};
});

return returnData;
}, [selectedLegendName, shiftPress, ammoData, minPen, maxPen]);
}, [selectedLegendName, shiftPress, ammoData, minPen, maxPen, showOnlyTraderAmmo, allTraders]);

const handleLegendClick = useCallback(
(event, { datum: { name } }) => {
Expand Down Expand Up @@ -269,6 +282,18 @@ function Ammo() {
</>
}
/>
<ToggleFilter
checked={showOnlyTraderAmmo}
label={t('Trader Ammo')}
onChange={(e) =>
setShowOnlyTraderAmmo(!showOnlyTraderAmmo)
}
tooltipContent={
<>
{t('Only show ammo available from traders on your settings')}
</>
}
/>
<ToggleFilter
checked={showAllTraderPrices}
label={t('Ignore settings')}
Expand Down
4 changes: 3 additions & 1 deletion src/translations/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -600,5 +600,7 @@
"{{count}} days_other": "{{count}} days",
"Wipe Length": "Wipe Length",
"wipe-length-description": "Get the latest information on the average wipe length in Escape from Tarkov. Find out how long wipes typically last, and prepare for the next wipe.",
"Average Wipe Length among last 6 wipes:": "Average Wipe Length among last 6 wipes:"
"Average Wipe Length among last 6 wipes:": "Average Wipe Length among last 6 wipes:",
"Trader Ammo": "Trader Ammo",
"Only show ammo available from traders on your settings": "Only show ammo available from traders on your settings"
}

0 comments on commit e62e7af

Please sign in to comment.