1 import PropTypes from 'prop-types';
2 import React from 'react';
4 import { CONFIG, DUNGEONS, makeEmptyState } from '../helpers/tracker';
6 const context = React.createContext({});
8 export const useTracker = () => React.useContext(context);
10 export const TrackerProvider = ({ children }) => {
11 const [config, setConfig] = React.useState(CONFIG);
12 const [state, setState] = React.useState(makeEmptyState());
13 const [dungeons, setDungeons] = React.useState(DUNGEONS);
15 React.useEffect(() => {
16 const newDungeons = DUNGEONS.map(dungeon => {
17 const newDungeon = JSON.parse(JSON.stringify(dungeon));
18 if (config.wildMap && dungeon.map) {
21 if (config.wildCompass && dungeon.compass) {
24 if (config.wildSmall) {
25 newDungeon.items += dungeon.sk;
27 if (config.wildBig && dungeon.bk && !dungeon.dropBk) {
30 if (!config.bossShuffle && dungeon.boss) {
31 newDungeon.bosses = [dungeon.boss];
35 setDungeons(newDungeons);
38 const value = React.useMemo(() => {
39 return { config, setConfig, dungeons, setState, state };
40 }, [config, dungeons, state]);
42 return <context.Provider value={value}>
47 TrackerProvider.propTypes = {
48 children: PropTypes.node,