Skip to content

Commit

Permalink
Merge pull request #960 from the-hideout/multi-settings
Browse files Browse the repository at this point in the history
Multi settings
  • Loading branch information
Razzmatazzz authored Jul 4, 2024
2 parents 2f9afd5 + 6e95c43 commit 4e22953
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 101 deletions.
4 changes: 2 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ function App() {
}

const useTarkovTracker = useSelector(
(state) => state.settings.useTarkovTracker,
(state) => state.settings[state.settings.gameMode].useTarkovTracker,
);

const progressStatus = useSelector((state) => {
return state.settings.progressStatus;
});

const tarkovTrackerAPIKey = useSelector(
(state) => state.settings.tarkovTrackerAPIKey,
(state) => state.settings[state.settings.gameMode].tarkovTrackerAPIKey,
);

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/barter-tooltip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import useTraderData from '../../features/traders/index.js';
import './index.css';

function BarterTooltip({ barter, showTitle = true, title, allowAllSources = false, crafts, barters, useBarterIngredients, useCraftIngredients }) {
const settings = useSelector((state) => state.settings);
const settings = useSelector((state) => state.settings[state.settings.gameMode]);
const { t } = useTranslation();
const { data: hideout } = useHideoutData();
const { data: traders } = useTraderData();
Expand Down
2 changes: 1 addition & 1 deletion src/components/barters-table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import './index.css';

function BartersTable({ selectedTrader, nameFilter, itemFilter, showAll, useBarterIngredients, useCraftIngredients }) {
const { t } = useTranslation();
const settings = useSelector((state) => state.settings);
const settings = useSelector((state) => state.settings[state.settings.gameMode]);
const { hasJaeger, removeDogtags, completedQuests } = useMemo(() => {
return {hasJaeger: settings.jaeger !== 0, removeDogtags: settings.hideDogtagBarters, completedQuests: settings.completedQuests};
}, [settings]);
Expand Down
2 changes: 1 addition & 1 deletion src/components/crafts-table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import FleaMarketLoadingIcon from '../FleaMarketLoadingIcon.jsx';

function CraftTable({ selectedStation, freeFuel, nameFilter, itemFilter, showAll, averagePrices, useBarterIngredients, useCraftIngredients }) {
const { t } = useTranslation();
const settings = useSelector((state) => state.settings);
const settings = useSelector((state) => state.settings[state.settings.gameMode]);
const { includeFlea, hasJaeger, completedQuests } = useMemo(() => {
return {includeFlea: settings.hasFlea, hasJaeger: settings.jaeger !== 0, completedQuests: settings.completedQuests};
}, [settings]);
Expand Down
2 changes: 1 addition & 1 deletion src/components/items-for-hideout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import './index.css';
function ItemsForHideout(props) {
const { itemFilter, showAll } = props;
const { t } = useTranslation();
const settings = useSelector((state) => state.settings);
const settings = useSelector((state) => state.settings[state.settings.gameMode]);

const { data: hideout } = useHideoutData();

Expand Down
2 changes: 1 addition & 1 deletion src/components/items-summary-table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const ConditionalWrapper = ({ condition, wrapper, children }) => {
function ItemsSummaryTable({includeItems, includeTraders, includeStations}) {
const { t } = useTranslation();

const settings = useSelector((state) => state.settings);
const settings = useSelector((state) => state.settings[state.settings.gameMode]);
const { data: items } = useItemsData();
const { data: barters } = useBartersData();
const { data: crafts } = useCraftsData();
Expand Down
2 changes: 1 addition & 1 deletion src/components/quest-table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function QuestTable({
requiredForEndGame,
}) {
const { t } = useTranslation();
const settings = useSelector((state) => state.settings);
const settings = useSelector((state) => state.settings[state.settings.gameMode]);

const { data: items } = useItemsData();

Expand Down
2 changes: 1 addition & 1 deletion src/components/small-item-table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function SmallItemTable(props) {
distance,
} = props;
const { t } = useTranslation();
const settings = useSelector((state) => state.settings);
const settings = useSelector((state) => state.settings[state.settings.gameMode]);

const { data: meta } = useMetaData();
const { materialDestructibilityMap, materialRepairabilityMap } = useMemo(
Expand Down
12 changes: 6 additions & 6 deletions src/features/quests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ const selectSettings = state => state.settings;
export const selectQuestsWithActive = createSelector([selectQuests, selectTraders, selectSettings], (quests, traders, settings) => {
const questStatus = {
complete: (id) => {
return settings.completedQuests.includes(id);
return settings[settings.gameMode].completedQuests.includes(id);
},
failed: (id) => {
return settings.failedQuests.includes(id);
return settings[settings.gameMode].failedQuests.includes(id);
},
active: (id) => {
if (questStatus.complete(id)) {
Expand All @@ -63,7 +63,7 @@ export const selectQuestsWithActive = createSelector([selectQuests, selectTrader
return false;
}
const quest = quests.find(q => q.id === id);
if (settings.playerLevel < quest.minPlayerLevel) {
if (settings[settings.gameMode].playerLevel < quest.minPlayerLevel) {
//return false;
}
for (const req of quest.taskRequirements) {
Expand All @@ -84,7 +84,7 @@ export const selectQuestsWithActive = createSelector([selectQuests, selectTrader
}
for (const req of quest.traderRequirements.filter(req => req.requirementType === 'level')) {
const trader = traders.find(t => t.id === req.trader.id);
if (settings[trader.normalizedName] < req.value) {
if (settings[settings.gameMode][trader.normalizedName] < req.value) {
//return false;
}
}
Expand All @@ -97,11 +97,11 @@ export const selectQuestsWithActive = createSelector([selectQuests, selectTrader
objectives: quest.objectives.map(obj => {
return {
...obj,
complete: settings.objectivesCompleted?.includes(obj.id) || false,
complete: settings[settings.gameMode].objectivesCompleted?.includes(obj.id) || false,
};
}),
active: (() => {
if (!settings.useTarkovTracker) {
if (!settings[settings.gameMode].useTarkovTracker) {
return true;
}
return questStatus.active(quest.id);
Expand Down
158 changes: 83 additions & 75 deletions src/features/settings/settingsSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,77 +99,79 @@ const localStorageWriteJson = (key, value) => {
}
};

const defaultSettings = {hasFlea: localStorageReadJson('useFlea', true),
playerLevel: 72,
tarkovTrackerAPIKey: localStorageReadJson('tarkovTrackerAPIKey', ''),
prapor: localStorageReadJson('prapor', 4),
therapist: localStorageReadJson('therapist', 4),
fence: localStorageReadJson('fence', 0),
skier: localStorageReadJson('skier', 4),
peacekeeper: localStorageReadJson('peacekeeper', 4),
mechanic: localStorageReadJson('mechanic', 4),
ragman: localStorageReadJson('ragman', 4),
jaeger: localStorageReadJson('jaeger', 4),
ref: localStorageReadJson('ref', 4),
'bitcoin-farm': localStorageReadJson('bitcoin-farm', 3),
'booze-generator': localStorageReadJson('booze-generator', 1),
'christmas-tree': localStorageReadJson('christmas-tree', 1),
'intelligence-center': localStorageReadJson('intelligence-center', 3),
lavatory: localStorageReadJson('lavatory', 3),
medstation: localStorageReadJson('medstation', 3),
'nutrition-unit': localStorageReadJson('nutrition-unit', 3),
'water-collector': localStorageReadJson('water-collector', 3),
workbench: localStorageReadJson('workbench', 3),
'solar-power': localStorageReadJson('solar-power', 0),
crafting: localStorageReadJson('crafting', 0),
'hideout-management': localStorageReadJson('hideout-management', 0),
completedQuests: [],
failedQuests: [],
useTarkovTracker: localStorageReadJson('useTarkovTracker', false),
tarkovTrackerModules: [],
minDogtagLevel: localStorageReadJson('minDogtagLevel', 1),
hideDogtagBarters: localStorageReadJson('hideDogtagBarters', false),
};

const settingsSlice = createSlice({
name: 'settings',
initialState: {
progressStatus: 'idle',
hasFlea: localStorageReadJson('useFlea', true),
playerLevel: 72,
tarkovTrackerAPIKey: localStorageReadJson('tarkovTrackerAPIKey', ''),
prapor: localStorageReadJson('prapor', 4),
therapist: localStorageReadJson('therapist', 4),
fence: localStorageReadJson('fence', 0),
skier: localStorageReadJson('skier', 4),
peacekeeper: localStorageReadJson('peacekeeper', 4),
mechanic: localStorageReadJson('mechanic', 4),
ragman: localStorageReadJson('ragman', 4),
jaeger: localStorageReadJson('jaeger', 4),
ref: localStorageReadJson('ref', 4),
'bitcoin-farm': localStorageReadJson('bitcoin-farm', 3),
'booze-generator': localStorageReadJson('booze-generator', 1),
'christmas-tree': localStorageReadJson('christmas-tree', 1),
'intelligence-center': localStorageReadJson('intelligence-center', 3),
lavatory: localStorageReadJson('lavatory', 3),
medstation: localStorageReadJson('medstation', 3),
'nutrition-unit': localStorageReadJson('nutrition-unit', 3),
'water-collector': localStorageReadJson('water-collector', 3),
workbench: localStorageReadJson('workbench', 3),
'solar-power': localStorageReadJson('solar-power', 0),
crafting: localStorageReadJson('crafting', 0),
'hideout-management': localStorageReadJson('hideout-management', 0),
completedQuests: [],
failedQuests: [],
useTarkovTracker: localStorageReadJson('useTarkovTracker', false),
tarkovTrackerModules: [],
regular: localStorageReadJson('regularSettings', {...defaultSettings}),
pve: localStorageReadJson('pveSettings', {
...defaultSettings,
tarkovTrackerAPIKey: '',
useTarkovTracker: false,
}),
hideRemoteControl: localStorageReadJson('hide-remote-control', false),
minDogtagLevel: localStorageReadJson('minDogtagLevel', 1),
hideDogtagBarters: localStorageReadJson('hideDogtagBarters', false),
playerPosition: localStorageReadJson('playerPosition', null),
gameMode: localStorageReadJson('gameMode', 'regular'),
},
reducers: {
setTarkovTrackerAPIKey: (state, action) => {
state.tarkovTrackerAPIKey = action.payload;
state[state.gameMode].tarkovTrackerAPIKey = action.payload;
localStorageWriteJson(
'tarkovTrackerAPIKey',
action.payload,
`${state.gameMode}Settings`,
state[state.gameMode],
);
},
toggleFlea: (state, action) => {
state.hasFlea = action.payload;
localStorageWriteJson('useFlea', action.payload);
state[state.gameMode].hasFlea = action.payload;
localStorageWriteJson(`${state.gameMode}Settings`, state[state.gameMode]);
},
setMinDogtagLevel: (state, action) => {
state.minDogtagLevel = parseInt(action.payload);
localStorageWriteJson('minDogtagLevel', parseInt(action.payload));
state[state.gameMode].minDogtagLevel = parseInt(action.payload);
localStorageWriteJson(`${state.gameMode}Settings`, state[state.gameMode]);
},
toggleHideDogtagBarters: (state, action) => {
state.hideDogtagBarters = action.payload;
localStorageWriteJson('hideDogtagBarters', action.payload);
state[state.gameMode].hideDogtagBarters = action.payload;
localStorageWriteJson(`${state.gameMode}Settings`, state[state.gameMode]);
},
setStationOrTraderLevel: (state, action) => {
state[action.payload.target] = action.payload.value;
localStorageWriteJson(
action.payload.target,
action.payload.value,
);
state[state.gameMode][action.payload.target] = action.payload.value;
localStorageWriteJson(`${state.gameMode}Settings`, state[state.gameMode]);
},
toggleTarkovTracker: (state, action) => {
state.useTarkovTracker = action.payload;
localStorageWriteJson(
'useTarkovTracker',
action.payload,
);
state[state.gameMode].useTarkovTracker = action.payload;
localStorageWriteJson(`${state.gameMode}Settings`, state[state.gameMode]);
},
toggleHideRemoteControl: (state, action) => {
state.hideRemoteControl = !state.hideRemoteControl;
Expand All @@ -193,6 +195,12 @@ const settingsSlice = createSlice({
action.payload,
);
},
getGameModeSettings: (state, action) => {
return {
...state,
...state[state.gameMode],
};
},
},
extraReducers: (builder) => {
builder.addCase(fetchTarkovTrackerProgress.pending, (state, action) => {
Expand All @@ -202,11 +210,11 @@ const settingsSlice = createSlice({
state.progressStatus = 'succeeded';

if (action.payload) {
state.completedQuests = action.payload.quests;
state.failedQuests = action.payload.questsFailed;
state.objectivesCompleted = action.payload.objectivesCompleted;
state.hasFlea = action.payload.flea;
state.playerLevel = action.payload.level;
state[state.gameMode].completedQuests = action.payload.quests;
state[state.gameMode].failedQuests = action.payload.questsFailed;
state[state.gameMode].objectivesCompleted = action.payload.objectivesCompleted;
state[state.gameMode].hasFlea = action.payload.flea;
state[state.gameMode].playerLevel = action.payload.level;

for (const stationKey in action.payload.hideout) {
settingsSlice.caseReducers.setStationOrTraderLevel(state, {
Expand All @@ -229,41 +237,41 @@ const selectSettings = state => state.settings;

export const selectAllTraders = createSelector([selectSettings], (settings) => {
return {
prapor: settings.prapor,
therapist: settings.therapist,
fence: settings.fence,
skier: settings.skier,
peacekeeper: settings.peacekeeper,
mechanic: settings.mechanic,
ragman: settings.ragman,
jaeger: settings.jaeger,
prapor: settings[settings.gameMode].prapor,
therapist: settings[settings.gameMode].therapist,
fence: settings[settings.gameMode].fence,
skier: settings[settings.gameMode].skier,
peacekeeper: settings[settings.gameMode].peacekeeper,
mechanic: settings[settings.gameMode].mechanic,
ragman: settings[settings.gameMode].ragman,
jaeger: settings[settings.gameMode].jaeger,
};
});

export const selectAllStations = createSelector([selectSettings], (settings) => {
return {
'bitcoin-farm': settings['bitcoin-farm'],
'booze-generator': settings['booze-generator'],
'christmas-tree': settings['christmas-tree'],
'intelligence-center': settings['intelligence-center'],
lavatory: settings.lavatory,
medstation: settings.medstation,
'nutrition-unit': settings['nutrition-unit'],
'water-collector': settings['water-collector'],
workbench: settings.workbench,
'solar-power': settings['solar-power'],
'bitcoin-farm': settings[settings.gameMode]['bitcoin-farm'],
'booze-generator': settings[settings.gameMode]['booze-generator'],
'christmas-tree': settings[settings.gameMode]['christmas-tree'],
'intelligence-center': settings[settings.gameMode]['intelligence-center'],
lavatory: settings[settings.gameMode].lavatory,
medstation: settings[settings.gameMode].medstation,
'nutrition-unit': settings[settings.gameMode]['nutrition-unit'],
'water-collector': settings[settings.gameMode]['water-collector'],
workbench: settings[settings.gameMode].workbench,
'solar-power': settings[settings.gameMode]['solar-power'],
};
});

export const selectAllSkills = createSelector([selectSettings], (settings) => {
return {
crafting: settings.crafting,
'hideout-management': settings['hideout-management'],
crafting: settings[settings.gameMode].crafting,
'hideout-management': settings[settings.gameMode]['hideout-management'],
};
});

export const selectCompletedQuests = createSelector([selectSettings], (settings) => {
return settings.completedQuests;
return settings[settings.gameMode].completedQuests;
});

export const {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/hideout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Hideout() {
'all',
);
const { t } = useTranslation();
const settings = useSelector((state) => state.settings);
const settings = useSelector((state) => state.settings[state.settings.gameMode]);

const { data: hideout } = useHideoutData();

Expand Down
2 changes: 1 addition & 1 deletion src/pages/item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function priceIsLocked(buyFor, settings) {
}

function Item() {
const settings = useSelector((state) => state.settings);
const settings = useSelector((state) => state.settings[state.settings.gameMode]);
const navigate = useNavigate();
const { itemName } = useParams();
const { t } = useTranslation();
Expand Down
2 changes: 1 addition & 1 deletion src/pages/loot-tiers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const arrayChunk = (inputArray, chunkLength) => {
function LootTier(props) {
const [numberFilter, setNumberFilter] = useState(DEFAULT_MAX_ITEMS);
const [minPrice, setMinPrice] = useStateWithLocalStorage('minPrice', 0);
const hasFlea = useSelector((state) => state.settings.hasFlea);
const hasFlea = useSelector((state) => state.settings[state.setttings.gameMode].hasFlea);
const [includeMarked, setIncludeMarked] = useStateWithLocalStorage(
'includeMarked',
false,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ function Map() {
const [searchParams] = useSearchParams();
const navigate = useNavigate();

const settings = useSelector((state) => state.settings);
const settings = useSelector((state) => state.settings[state.settings.gameMode]);

const focusItem = useRef(searchParams.get('q') ? searchParams.get('q').split(',') : []);

Expand Down
2 changes: 1 addition & 1 deletion src/pages/quest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const intelCashMultiplier = {
};

function Quest() {
const settings = useSelector((state) => state.settings);
const settings = useSelector((state) => state.settings[state.settings.gameMode]);
const { taskIdentifier } = useParams();
const { t } = useTranslation();

Expand Down
Loading

0 comments on commit 4e22953

Please sign in to comment.