]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/tracker/Map.js
update dunka/muffins tracker
[alttp.git] / resources / js / components / tracker / Map.js
index cfae29c4b4a4875e0c71e087b7f7456ee511d014..3ee4b2f81458ab4eeb6190273623467406788bc1 100644 (file)
@@ -4,12 +4,13 @@ import { useTranslation } from 'react-i18next';
 
 import {
        addDungeonCheck,
+       aggregateDungeonStatus,
+       aggregateLocationStatus,
        clearAll,
        completeDungeonChecks,
        countRemainingLocations,
        getDungeonClearedItems,
        getDungeonRemainingItems,
-       hasClearedLocations,
        hasDungeonBoss,
        hasDungeonPrize,
        isDungeonCleared,
@@ -686,93 +687,87 @@ const makeBackground = (src, level) => {
 };
 
 const Map = () => {
-       const { dungeons, setState, state } = useTracker();
+       const { dungeons, logic, setManualState, state } = useTracker();
 
        const mapDungeon = React.useCallback(dungeon => {
                const definition = dungeons.find(d => d.id === dungeon.id);
                const remaining = getDungeonRemainingItems(state, definition);
-               let status = 'available';
-               if (isDungeonCleared(state, definition)) {
-                       status = 'cleared';
-               }
+               const status = aggregateDungeonStatus(definition, logic, state);
                return {
                        ...dungeon,
                        status,
                        remaining,
                        handlePrimary: () => {
                                if (getDungeonRemainingItems(state, definition)) {
-                                       setState(addDungeonCheck(definition));
+                                       setManualState(addDungeonCheck(definition));
                                } else if (
                                        !hasDungeonBoss(state, definition) || !hasDungeonPrize(state, definition)
                                ) {
                                        if (definition.boss) {
-                                               setState(setBossDefeated(definition, true));
+                                               setManualState(setBossDefeated(definition, true));
                                        }
                                        if (definition.prize) {
-                                               setState(setPrizeAcquired(definition, true));
+                                               setManualState(setPrizeAcquired(definition, true));
                                        }
                                } else {
-                                       setState(resetDungeonChecks(definition));
+                                       setManualState(resetDungeonChecks(definition));
                                        if (definition.boss) {
-                                               setState(setBossDefeated(definition, false));
+                                               setManualState(setBossDefeated(definition, false));
                                        }
                                        if (definition.prize) {
-                                               setState(setPrizeAcquired(definition, false));
+                                               setManualState(setPrizeAcquired(definition, false));
                                        }
                                }
                        },
                        handleSecondary: () => {
                                if (isDungeonCleared(state, definition)) {
                                        if (definition.items) {
-                                               setState(removeDungeonCheck(definition));
+                                               setManualState(removeDungeonCheck(definition));
                                        }
                                        if (definition.boss) {
-                                               setState(setBossDefeated(definition, false));
+                                               setManualState(setBossDefeated(definition, false));
                                        }
                                        if (definition.prize) {
-                                               setState(setPrizeAcquired(definition, false));
+                                               setManualState(setPrizeAcquired(definition, false));
                                        }
                                } else if (getDungeonClearedItems(state, definition)) {
-                                       setState(removeDungeonCheck(definition));
+                                       setManualState(removeDungeonCheck(definition));
                                } else {
-                                       setState(completeDungeonChecks(definition));
+                                       setManualState(completeDungeonChecks(definition));
                                        if (definition.boss) {
-                                               setState(setBossDefeated(definition, true));
+                                               setManualState(setBossDefeated(definition, true));
                                        }
                                        if (definition.prize) {
-                                               setState(setPrizeAcquired(definition, true));
+                                               setManualState(setPrizeAcquired(definition, true));
                                        }
                                }
                        },
                };
-       }, [dungeons, setState, state]);
+       }, [dungeons, logic, setManualState, state]);
 
        const mapLocation = React.useCallback(loc => {
                const remaining = countRemainingLocations(state, loc.checks);
-               let status = 'available';
-               if (hasClearedLocations(state, loc.checks)) {
-                       status = 'cleared';
-               }
+               const status = aggregateLocationStatus(loc.checks, logic, state);
                return {
                        ...loc,
                        remaining,
                        status,
                        handlePrimary: () => {
                                if (remaining) {
-                                       setState(clearAll(loc.checks));
+                                       setManualState(clearAll(loc.checks));
                                } else {
-                                       setState(unclearAll(loc.checks));
+                                       setManualState(unclearAll(loc.checks));
                                }
                        },
                        handleSecondary: () => {
                                if (remaining) {
-                                       setState(clearAll(loc.checks));
+                                       setManualState(clearAll(loc.checks));
                                } else {
-                                       setState(unclearAll(loc.checks));
+                                       setManualState(unclearAll(loc.checks));
                                }
                        },
                };
-       }, [setState, state]);
+       }, [logic, setManualState, state]);
 
        const lwDungeons = React.useMemo(() => LW_DUNGEONS.map(mapDungeon), [mapDungeon]);
        const lwLocations = React.useMemo(() => LW_LOCATIONS.map(mapLocation), [mapLocation]);