Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support multiple game modes #955

Merged
merged 5 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions scripts/cache-api-data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,22 @@ try {
const apiPromises = [];

apiPromises.push(Promise.all([
doFetchBarters('en', true).then(barters => {
doFetchBarters({prebuild: true}).then(barters => {
for (const barter of barters) {
barter.cached = true;
}
fs.writeFileSync('./src/data/barters.json', JSON.stringify(barters));
return barters;
}),
doFetchCrafts('en', true).then(crafts => {
doFetchCrafts({prebuild: true}).then(crafts => {
for (const craft of crafts) {
craft.cached = true;
}
fs.writeFileSync('./src/data/crafts.json', JSON.stringify(crafts));
return crafts;
})
]).then((bartersAndCrafts) => {
return doFetchItems('en', true).then(items => {
return doFetchItems({prebuild: true}).then(items => {
const filteredItems = [];
for (const bartersCrafts of bartersAndCrafts) {
bartersCrafts.forEach(bc => {
Expand Down Expand Up @@ -203,11 +203,11 @@ try {
});
}));

apiPromises.push(doFetchHideout('en', true).then(hideout => {
apiPromises.push(doFetchHideout({prebuild: true}).then(hideout => {
fs.writeFileSync('./src/data/hideout.json', JSON.stringify(hideout));
}));

apiPromises.push(doFetchTraders('en', true).then(traders => {
apiPromises.push(doFetchTraders({prebuild: true}).then(traders => {
for (const trader of traders) {
delete trader.resetTime;
}
Expand All @@ -231,7 +231,7 @@ try {
});
}));

apiPromises.push(doFetchMaps('en', true).then(maps => {
apiPromises.push(doFetchMaps({prebuild: true}).then(maps => {
fs.writeFileSync('./src/data/maps_cached.json', JSON.stringify(maps));

return getMapNames(langs).then(mapResults => {
Expand All @@ -250,7 +250,7 @@ try {
});
}));

apiPromises.push(doFetchBosses('en', true).then(bosses => {
apiPromises.push(doFetchBosses({prebuild: true}).then(bosses => {
fs.writeFileSync('./src/data/bosses.json', JSON.stringify(bosses));

return getBossNames(langs).then(bossResults => {
Expand All @@ -268,11 +268,11 @@ try {
});
}));

apiPromises.push(doFetchMeta('en', true).then(meta => {
apiPromises.push(doFetchMeta({prebuild: true}).then(meta => {
fs.writeFileSync('./src/data/meta.json', JSON.stringify(meta));
}));

apiPromises.push(doFetchQuests('en', true).then(quests => {
apiPromises.push(doFetchQuests({prebuild: true}).then(quests => {
const groupedQuestsDic = quests.reduce((acc, item) => {
if (!acc[item.trader.normalizedName]) {
acc[item.trader.normalizedName] = [];
Expand Down
4 changes: 3 additions & 1 deletion src/components/price-graph/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useMemo, useState } from 'react';
import { useSelector } from 'react-redux';
import {
VictoryChart,
VictoryLine,
Expand Down Expand Up @@ -27,10 +28,11 @@ function PriceGraph({ item, itemId }) {
const [filterRange, setFilterRange] = useState([0,0]);

const { t } = useTranslation();
const gameMode = useSelector((state) => state.settings.gameMode);
const { status, data } = useQuery(
`historical-price-${itemId}`,
`{
historicalItemPrices(id:"${itemId}"){
historicalItemPrices(id:"${itemId}", gameMode: ${gameMode}){
price
priceMin
timestamp
Expand Down
4 changes: 4 additions & 0 deletions src/data/game-modes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"regular",
"pve"
]
9 changes: 5 additions & 4 deletions src/features/achievements/do-fetch-achievements.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ class AchievementsQuery extends APIQuery {
super('achievements');
}

async query(language, prebuild = false) {
async query(options) {
const { language, gameMode, prebuild} = options;
const query = `query TarkovDevAchievements {
achievements(lang: ${language}) {
achievements(lang: ${language}, gameMode: ${gameMode}) {
id
name
description
Expand Down Expand Up @@ -52,8 +53,8 @@ class AchievementsQuery extends APIQuery {

const achievementsQuery = new AchievementsQuery();

const doFetchAchievements = async (language, prebuild = false) => {
return achievementsQuery.run(language, prebuild);
const doFetchAchievements = async (options) => {
return achievementsQuery.run(options);
};

export default doFetchAchievements;
15 changes: 10 additions & 5 deletions src/features/achievements/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ const initialState = {
error: null,
};

export const fetchAchievements = createAsyncThunk('achievements/fetchAchievements', () =>
doFetchAchievements(langCode()),
);
export const fetchAchievements = createAsyncThunk('achievements/fetchAchievements', (arg, { getState }) => {
const state = getState();
const gameMode = state.settings.gameMode;
return doFetchAchievements({language: langCode(), gameMode});
});
const achievementsSlice = createSlice({
name: 'achievements',
initialState,
Expand All @@ -41,6 +43,7 @@ const achievementsSlice = createSlice({
export const achievementsReducer = achievementsSlice.reducer;

let fetchedLang = false;
let fetchedGameMode = false;
let refreshInterval = false;

const clearRefreshInterval = () => {
Expand All @@ -52,10 +55,12 @@ export default function useAchievementsData() {
const dispatch = useDispatch();
const { data, status, error } = useSelector((state) => state.achievements);
const lang = useLangCode();
const gameMode = useSelector((state) => state.settings.gameMode);

useEffect(() => {
if (fetchedLang !== lang) {
if (fetchedLang !== lang || fetchedGameMode !== gameMode) {
fetchedLang = lang;
fetchedGameMode = gameMode;
dispatch(fetchAchievements());
clearRefreshInterval();
}
Expand All @@ -67,7 +72,7 @@ export default function useAchievementsData() {
return () => {
clearRefreshInterval();
};
}, [dispatch, lang]);
}, [dispatch, lang, gameMode]);

return { data, status, error };
};
9 changes: 5 additions & 4 deletions src/features/barters/do-fetch-barters.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ class BartersQuery extends APIQuery {
super('barters');
}

async query(language, prebuild = false) {
async query(options) {
const { language, gameMode, prebuild} = options;
const query = `query TarkovDevBarters {
barters(lang: ${language}) {
barters(lang: ${language}, gameMode: ${gameMode}) {
rewardItems {
item {
id
Expand Down Expand Up @@ -80,8 +81,8 @@ class BartersQuery extends APIQuery {

const bartersQuery = new BartersQuery();

const doFetchBarters = async (language, prebuild = false) => {
return bartersQuery.run(language, prebuild);
const doFetchBarters = async (options) => {
return bartersQuery.run(options);
};

export default doFetchBarters;
17 changes: 10 additions & 7 deletions src/features/barters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ const initialState = {
error: null,
};

export const fetchBarters = createAsyncThunk('barters/fetchBarters', () =>
doFetchBarters(langCode())
);
export const fetchBarters = createAsyncThunk('barters/fetchBarters', (arg, { getState }) => {
const state = getState();
const gameMode = state.settings.gameMode;
return doFetchBarters({language: langCode(), gameMode});
});

const bartersSlice = createSlice({
name: 'barters',
Expand Down Expand Up @@ -146,7 +148,7 @@ export const selectAllBarters = createSelector([selectBarters, selectQuests, sel
}).filter(barter => barter.rewardItems.length > 0 && barter.requiredItems.length > 0);
});

let fetchedData = false;
let fetchedGameMode = false;
let refreshInterval = false;

const clearRefreshInterval = () => {
Expand All @@ -158,12 +160,13 @@ export default function useBartersData() {
const dispatch = useDispatch();
const { status, error } = useSelector((state) => state.barters);
const data = useSelector(selectAllBarters);
const gameMode = useSelector((state) => state.settings.gameMode);

useItemsData();
useQuestsData();
useEffect(() => {
if (!fetchedData) {
fetchedData = true;
if (fetchedGameMode !== gameMode) {
fetchedGameMode = true;
dispatch(fetchBarters());
clearRefreshInterval();
}
Expand All @@ -175,7 +178,7 @@ export default function useBartersData() {
return () => {
clearRefreshInterval();
};
}, [dispatch]);
}, [dispatch, gameMode]);

return { data, status, error };
};
9 changes: 5 additions & 4 deletions src/features/bosses/do-fetch-bosses.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ class BossesQuery extends APIQuery {
super('bosses');
}

async query(language, prebuild = false) {
async query(options) {
const { language, gameMode, prebuild} = options;
const query = `query TarkovDevBosses {
bosses(lang: ${language}) {
bosses(lang: ${language}, gameMode: ${gameMode}) {
name
normalizedName
imagePortraitLink
Expand Down Expand Up @@ -69,8 +70,8 @@ class BossesQuery extends APIQuery {

const bossesQuery = new BossesQuery();

const doFetchBosses = async (language = 'en', prebuild = false) => {
return bossesQuery.run(language, prebuild);
const doFetchBosses = async (options) => {
return bossesQuery.run(options);
};

export default doFetchBosses;
15 changes: 10 additions & 5 deletions src/features/bosses/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ const initialState = {
error: null,
};

export const fetchBosses = createAsyncThunk('bosses/fetchBosses', () =>
doFetchBosses(langCode()),
);
export const fetchBosses = createAsyncThunk('bosses/fetchBosses', (arg, { getState }) => {
const state = getState();
const gameMode = state.settings.gameMode;
return doFetchBosses({language: langCode(), gameMode});
});
const bossesSlice = createSlice({
name: 'bosses',
initialState,
Expand Down Expand Up @@ -90,6 +92,7 @@ export const selectAllBosses = createSelector([selectBosses, selectMaps], (bosse
});

let fetchedLang = false;
let fetchedGameMode = false;
let refreshInterval = false;

const clearRefreshInterval = () => {
Expand All @@ -103,10 +106,12 @@ export default function useBossesData() {
const data = useSelector(selectAllBosses);
useMapsData();
const lang = useLangCode();
const gameMode = useSelector((state) => state.settings.gameMode);

useEffect(() => {
if (fetchedLang !== lang) {
if (fetchedLang !== lang || fetchedGameMode !== gameMode) {
fetchedLang = lang;
fetchedGameMode = gameMode;
dispatch(fetchBosses());
clearRefreshInterval();
}
Expand All @@ -118,7 +123,7 @@ export default function useBossesData() {
return () => {
clearRefreshInterval();
};
}, [dispatch, lang]);
}, [dispatch, lang, gameMode]);

return { data, status, error };
};
9 changes: 5 additions & 4 deletions src/features/crafts/do-fetch-crafts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ class CraftsQuery extends APIQuery {
super('crafts');
}

async query(language, prebuild = false) {
async query(options) {
const { language, gameMode, prebuild} = options;
const query = `query TarkovDevCrafts {
crafts(lang: ${language}) {
crafts(lang: ${language}, gameMode: ${gameMode}) {
station {
id
normalizedName
Expand Down Expand Up @@ -78,6 +79,6 @@ class CraftsQuery extends APIQuery {

const craftsQuery = new CraftsQuery();

export default async function doFetchCrafts(language, prebuild = false) {
return craftsQuery.run(language, prebuild);
export default async function doFetchCrafts(options) {
return craftsQuery.run(options);
};
17 changes: 10 additions & 7 deletions src/features/crafts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ const initialState = {
error: null,
};

export const fetchCrafts = createAsyncThunk('crafts/fetchCrafts', async () =>
doFetchCrafts(langCode()),
);
export const fetchCrafts = createAsyncThunk('crafts/fetchCrafts', (arg, { getState }) => {
const state = getState();
const gameMode = state.settings.gameMode;
return doFetchCrafts({language: langCode(), gameMode});
});

const craftsSlice = createSlice({
name: 'crafts',
Expand Down Expand Up @@ -158,7 +160,7 @@ export const selectAllCrafts = createSelector([selectCrafts, selectQuests, selec
}).filter(craft => craft.rewardItems.length > 0 && craft.requiredItems.length > 0);
});

let fetchedData = false;
let fetchedGamMode = false;
let refreshInterval = false;

const clearRefreshInterval = () => {
Expand All @@ -170,12 +172,13 @@ export default function useCraftsData() {
const dispatch = useDispatch();
const { status, error } = useSelector((state) => state.crafts);
const data = useSelector(selectAllCrafts);
const gameMode = useSelector((state) => state.settings.gameMode);

useItemsData();
useQuestsData();
useEffect(() => {
if (!fetchedData) {
fetchedData = true;
if (fetchedGamMode !== gameMode) {
fetchedGamMode = gameMode;
dispatch(fetchCrafts());
clearRefreshInterval();
}
Expand All @@ -187,7 +190,7 @@ export default function useCraftsData() {
return () => {
clearRefreshInterval();
};
}, [dispatch]);
}, [dispatch, gameMode]);

return { data, status, error };
};
Loading