Skip to content

Commit

Permalink
Merge pull request #973 from the-hideout/ammo-armor
Browse files Browse the repository at this point in the history
Fix Ammo Page, Add Armor Info and more
  • Loading branch information
Razzmatazzz authored Aug 29, 2024
2 parents 94b9d88 + 1bf9660 commit aae1ca3
Show file tree
Hide file tree
Showing 21 changed files with 396 additions and 184 deletions.
31 changes: 17 additions & 14 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-restricted-globals */
import React, { useEffect, useCallback, Suspense } from 'react';
import React, { useEffect, useCallback, useRef, Suspense } from 'react';
import { Routes, Route, useNavigate, Navigate } from 'react-router-dom';
import { Helmet } from 'react-helmet';
import { useDispatch, useSelector } from 'react-redux';
Expand Down Expand Up @@ -87,7 +87,6 @@ const socketServer = 'wss://socket.tarkov.dev';
//const socketServer = 'ws://localhost:8080';

let socket = false;
let tarkovTrackerProgressInterval = false;

loadPolyfills();

Expand Down Expand Up @@ -122,6 +121,8 @@ function App() {
const controlId = useSelector((state) => state.sockets.controlId);
let navigate = useNavigate();
const dispatch = useDispatch();
const retrievedTarkovTrackerToken = useRef(false);
const tarkovTrackerProgressInterval = useRef(false);

if (connectToId) {
dispatch(enableConnection());
Expand All @@ -140,26 +141,28 @@ function App() {
);

useEffect(() => {
if (useTarkovTracker && progressStatus !== 'loading' && !tarkovTrackerProgressInterval) {
dispatch(fetchTarkovTrackerProgress(tarkovTrackerAPIKey));
}

if (!tarkovTrackerProgressInterval && useTarkovTracker) {
tarkovTrackerProgressInterval = setInterval(() => {
if (!tarkovTrackerProgressInterval.current && useTarkovTracker) {
tarkovTrackerProgressInterval.current = setInterval(() => {
retrievedTarkovTrackerToken.current = tarkovTrackerAPIKey;
dispatch(fetchTarkovTrackerProgress(tarkovTrackerAPIKey));
}, 1000 * 60 * 5);
}

if (tarkovTrackerProgressInterval && !useTarkovTracker) {
clearInterval(tarkovTrackerProgressInterval);
tarkovTrackerProgressInterval = false;
if (useTarkovTracker && progressStatus !== 'loading' && retrievedTarkovTrackerToken.current !== tarkovTrackerAPIKey) {
retrievedTarkovTrackerToken.current = tarkovTrackerAPIKey;
dispatch(fetchTarkovTrackerProgress(tarkovTrackerAPIKey));
}

if (tarkovTrackerProgressInterval.current && !useTarkovTracker) {
clearInterval(tarkovTrackerProgressInterval.current);
tarkovTrackerProgressInterval.current = false;
}

return () => {
clearInterval(tarkovTrackerProgressInterval);
tarkovTrackerProgressInterval = false;
clearInterval(tarkovTrackerProgressInterval.current);
tarkovTrackerProgressInterval.current = false;
};
}, [progressStatus, dispatch, tarkovTrackerAPIKey, useTarkovTracker]);
}, [progressStatus, dispatch, tarkovTrackerAPIKey, useTarkovTracker, tarkovTrackerProgressInterval, retrievedTarkovTrackerToken]);

useEffect(() => {
const handleDisplayMessage = (rawMessage) => {
Expand Down
26 changes: 16 additions & 10 deletions src/components/items-for-hideout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';

import useHideoutData from '../../features/hideout/index.js';
import useItemsData from '../../features/items/index.js';

import './index.css';

Expand All @@ -13,6 +14,7 @@ function ItemsForHideout(props) {
const settings = useSelector((state) => state.settings[state.settings.gameMode]);

const { data: hideout } = useHideoutData();
const { data: items } = useItemsData();

// Data manipulation section
const data = useMemo(() => {
Expand Down Expand Up @@ -89,21 +91,25 @@ function ItemsForHideout(props) {
</td>
</tr>
)}
{displayList.map((item, k) => {
{displayList.map((hideoutModule, k) => {
const item = items.find(i => i.id === hideoutModule.item.id);
if (!item) {
return false;
}
return (
<tr key={k} className="hideout-item-list-row">
<td className="hideout-item-list-column">
<div className="hideout-name-wrapper">
<img
alt={item.moduleName}
alt={hideoutModule.moduleName}
className="quest-giver-image"
loading="lazy"
src={item.imageLink}
src={hideoutModule.imageLink}
/>
<div>
{item.moduleName}
{hideoutModule.moduleName}
<div>
{t('Level')} {item.level}
{t('Level')} {hideoutModule.level}
</div>
</div>
</div>
Expand All @@ -112,22 +118,22 @@ function ItemsForHideout(props) {
<div className="hideout-item-wrapper">
<div className="hideout-item-image-wrapper">
<img
alt={item.item.name}
alt={item.name}
loading="lazy"
src={item.item.iconLink}
src={item.iconLink}
/>
</div>
<div className="hideout-item-text-wrapper">
{item.item.name}
{item.name}
<div className="amount-wrapper">
{t('Amount')}: {item.quantity}
{t('Amount')}: {hideoutModule.quantity}
</div>
</div>
</div>
</td>
</tr>
);
})}
}).filter(Boolean)}
</tbody>
</table>
</div>
Expand Down
8 changes: 4 additions & 4 deletions src/components/menu/alert-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const alertConfig = {
// set this bool if the site alert should be enabled or not
alertEnabled: true,
alertEnabled: false,

// valid alert colors
alertColors: {
Expand All @@ -14,8 +14,8 @@ const alertConfig = {
alertLevel: 'info',

// The text to display in the alert banner
text: '🌟 Flea market scanners are currently being leveled, and data for the {{patchVersion}} patch should be appearing soon! 🌟 If you enjoy using tarkov.dev, please consider donating to help keep it running. All donations go directly towards server costs and operational expenses. This banner will only be up for a week. Thank you! ❤️',
//text: '🌟 Flea market scanners have been leveled, and flea market prices are being updated for patch {{patchVersion}}! 🌟 If you enjoy using tarkov.dev, please consider donating to help keep it running. All donations go directly towards server costs and operational expenses. This banner will only be up for a week. Thank you! ❤️',
//text: '🌟 Flea market scanners are currently being leveled, and data for the {{patchVersion}} patch should be appearing soon! 🌟 If you enjoy using tarkov.dev, please consider donating to help keep it running. All donations go directly towards server costs and operational expenses. This banner will only be up for a week. Thank you! ❤️',
text: '🌟 Flea market scanners have been leveled, and flea market prices are being updated for patch {{patchVersion}}! 🌟 If you enjoy using tarkov.dev, please consider donating to help keep it running. All donations go directly towards server costs and operational expenses. This banner will only be up for a week. Thank you! ❤️',
textVariables: {patchVersion: '0.15.0'},
linkEnabled: true,
linkText: 'Donate',
Expand All @@ -24,7 +24,7 @@ const alertConfig = {
// when a banner with a specific key is hidden, it never shows for that user again
// (unless they clear their browser cache)
// use a different key to force new banners to display again
bannerKey: 'alertBanner-0.15.0-wipe'
bannerKey: 'alertBanner-0.15.0-scanning'
}

export default alertConfig
2 changes: 1 addition & 1 deletion src/components/property-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Tippy from '@tippyjs/react';

import './index.css';

const skipProps = ['grid', 'ConflictingItems', '__typename', 'slots', 'presets'];
const skipProps = ['grid', 'ConflictingItems', '__typename', 'slots', 'presets', 'armorSlots'];

const ConditionalWrapper = ({ condition, wrapper, children }) => {
return condition ? wrapper(children) : children;
Expand Down
54 changes: 53 additions & 1 deletion src/components/small-item-table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ function SmallItemTable(props) {
defaultRandom,
typeFilter,
containedInFilter,
armorSlotFilter,
sortBy,
sortByDesc,
// columns
Expand Down Expand Up @@ -271,6 +272,9 @@ function SmallItemTable(props) {
minPenetration,
maxPenetration,
distance,
softArmorFilter,
plateArmorFilter,
customFilter,
} = props;
const { t } = useTranslation();
const settings = useSelector((state) => state.settings[state.settings.gameMode]);
Expand Down Expand Up @@ -449,6 +453,15 @@ function SmallItemTable(props) {

formattedItem.count = containedItems[itemData.id] || 1;

if (armorSlotFilter && armorZones) {
formattedItem.armorZone = getArmorZoneString(armorSlotFilter.reduce((zones, slot) => {
if (slot.allowedPlates.some(plate => plate.id === formattedItem.id)) {
zones.push(...slot.zones);
}
return zones;
}, []));
}

return formattedItem;
};
let returnData = items
Expand Down Expand Up @@ -559,6 +572,12 @@ function SmallItemTable(props) {
}
return containedItems[item.id];
})
.filter(item => {
if (!armorSlotFilter) {
return true;
}
return armorSlotFilter.some(slot => slot.allowedPlates.some(plate => plate.id === item.id));
})
.filter(item => {
if (includeBlockingHeadset) {
return true;
Expand Down Expand Up @@ -593,6 +612,12 @@ function SmallItemTable(props) {
return false;
}
return pen >= min && pen <= max;
})
.filter(item => {
if (typeof customFilter !== 'function') {
return true;
}
return customFilter(item);
});

if (nameFilter) {
Expand Down Expand Up @@ -690,6 +715,28 @@ function SmallItemTable(props) {
returnData = returnData.filter(item => item.properties?.grids?.some(grid => grid.width * grid.height >= 4));
}

if (softArmorFilter) {
returnData = returnData.filter(item => item.properties?.armorSlots?.some(slot => slot.durability && slot.class >= softArmorFilter[0] && slot.class <= softArmorFilter[1]));
}
if (plateArmorFilter && (plateArmorFilter[0] !== 0 || plateArmorFilter[1] !== 6)) {
returnData = returnData.filter(item => item.properties?.armorSlots?.some(slot => {
if (!slot.allowedPlates && plateArmorFilter[1] === 0) {
return true;
}
if (!slot.allowedPlates) {
return false;
}
const plateArmorClass = slot.allowedPlates?.reduce((highestClass, current) => {
const plate = items.find(i => i.id === current.id);
if (plate?.properties.class > highestClass) {
return plate.properties.class;
}
return highestClass;
}, 0);
return plateArmorClass >= plateArmorFilter[0] && plateArmorClass <= plateArmorFilter[1];
}));
}

if (caliberFilter) {
let filterArray = [];
if (!Array.isArray(caliberFilter)) {
Expand Down Expand Up @@ -854,7 +901,12 @@ function SmallItemTable(props) {
maxPenetration,
traderValue,
traderBuyback,
traderOffer
traderOffer,
armorSlotFilter,
armorZones,
softArmorFilter,
plateArmorFilter,
customFilter,
]);
const lowHydrationCost = useMemo(() => {
if (!totalEnergyCost && !provisionValue) {
Expand Down
8 changes: 4 additions & 4 deletions src/data/maps.json
Original file line number Diff line number Diff line change
Expand Up @@ -718,12 +718,12 @@
"heightRange": [-1, 3],
"author": "Tarkov.dev",
"authorLink": "https://tarkov.dev",
"tilePath": "https://assets.tarkov.dev/maps/factory_v2/main/{z}/{x}/{y}.png",
"tilePath": "https://assets.tarkov.dev/maps/factory/main/{z}/{x}/{y}.png",
"svgPath": "https://assets.tarkov.dev/maps/svg/Factory-Ground_Floor.svg",
"layers": [
{
"name": "2nd Floor",
"tilePath": "https://assets.tarkov.dev/maps/factory_v2/2nd_notint/{z}/{x}/{y}.png",
"tilePath": "https://assets.tarkov.dev/maps/factory/2nd/{z}/{x}/{y}.png",
"svgPath": "https://assets.tarkov.dev/maps/svg/Factory-Second_Floor.svg",
"show": false,
"extents": [
Expand All @@ -734,7 +734,7 @@
},
{
"name": "3rd Floor",
"tilePath": "https://assets.tarkov.dev/maps/factory_v2/3rd_notint/{z}/{x}/{y}.png",
"tilePath": "https://assets.tarkov.dev/maps/factory/3rd/{z}/{x}/{y}.png",
"svgPath": "https://assets.tarkov.dev/maps/svg/Factory-Third_Floor.svg",
"show": false,
"extents": [
Expand All @@ -745,7 +745,7 @@
},
{
"name": "Tunnels",
"tilePath": "https://assets.tarkov.dev/maps/factory_v2/tunnels_notint/{z}/{x}/{y}.png",
"tilePath": "https://assets.tarkov.dev/maps/factory/tunnels/{z}/{x}/{y}.png",
"svgPath": "https://assets.tarkov.dev/maps/svg/Factory-Basement.svg",
"show": false,
"extents": [
Expand Down
40 changes: 40 additions & 0 deletions src/features/items/do-fetch-items.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class ItemsQuery extends APIQuery {
ergoPenalty
speedPenalty
turnPenalty
armorSlots {
...ArmorSlotFragment
}
}
...on ItemPropertiesArmorAttachment {
class
Expand Down Expand Up @@ -121,6 +124,9 @@ class ItemsQuery extends APIQuery {
grids {
...GridFragment
}
armorSlots {
...ArmorSlotFragment
}
}
...on ItemPropertiesContainer {
capacity
Expand Down Expand Up @@ -313,6 +319,39 @@ class ItemsQuery extends APIQuery {
}
}
}
fragment SoftArmorSlotFragment on ItemArmorSlotLocked {
nameId
name
class
durability
speedPenalty
turnPenalty
ergoPenalty
material {
id
name
}
zones
armorType
}
fragment PlateArmorSlotFragment on ItemArmorSlotOpen {
nameId
name
zones
allowedPlates {
id
}
}
fragment ArmorSlotFragment on ItemArmorSlot {
nameId
zones
...on ItemArmorSlotLocked {
...SoftArmorSlotFragment
}
...on ItemArmorSlotOpen {
...PlateArmorSlotFragment
}
}
fragment ItemPriceFragment on ItemPrice {
vendor {
name
Expand All @@ -327,6 +366,7 @@ class ItemsQuery extends APIQuery {
id
tarkovDataId
name
normalizedName
}
}
}
Expand Down
Loading

0 comments on commit aae1ca3

Please sign in to comment.