]> git.localhorst.tv Git - alttp.git/commitdiff
separate bottle tracking
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 29 Mar 2024 10:28:03 +0000 (11:28 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 29 Mar 2024 10:28:03 +0000 (11:28 +0100)
resources/js/components/tracker/Items.js
resources/js/components/tracker/ToggleIcon.js
resources/js/helpers/logic.js
resources/js/helpers/tracker.js

index 2e83565fbc07eb7e79573723b204d1ee9743794c..fb47824034ac17cf1be23badc53307222c4fa72c 100644 (file)
@@ -1,7 +1,7 @@
 import React from 'react';
 
-import CountDisplay from './CountDisplay';
 import ToggleIcon from './ToggleIcon';
+import { BOTTLE_CONTENTS } from '../../helpers/tracker';
 import { useTracker } from '../../hooks/tracker';
 
 const Items = () => {
@@ -99,8 +99,26 @@ const Items = () => {
                        <ToggleIcon controller={ToggleIcon.simpleController} icons={['book']} />
                </div>
                <div className="item">
-                       <ToggleIcon controller={ToggleIcon.countController(4)} icons={['bottle']} />
-                       <CountDisplay className="bottom-right" count={state.bottle || 0} />
+                       <ToggleIcon
+                               className="top-left"
+                               controller={ToggleIcon.bottleController('bottle-1')}
+                               icons={BOTTLE_CONTENTS}
+                       />
+                       <ToggleIcon
+                               className="top-right"
+                               controller={ToggleIcon.bottleController('bottle-2')}
+                               icons={BOTTLE_CONTENTS}
+                       />
+                       <ToggleIcon
+                               className="bottom-left"
+                               controller={ToggleIcon.bottleController('bottle-3')}
+                               icons={BOTTLE_CONTENTS}
+                       />
+                       <ToggleIcon
+                               className="bottom-right"
+                               controller={ToggleIcon.bottleController('bottle-4')}
+                               icons={BOTTLE_CONTENTS}
+                       />
                </div>
                <div className="item">
                        <ToggleIcon controller={ToggleIcon.simpleController} icons={['somaria']} />
index 3966506d2b2b815868b5553bbdce64287af992ff..c1a193c209f9540457cc7d223a6c9f54f7734430 100644 (file)
@@ -97,6 +97,27 @@ const previousString = property => (state, setState, icons) => {
        setState(s => ({ ...s, [property]: previous }));
 };
 
+ToggleIcon.bottleController = ctrl => ({
+       getActive: (state, icons) => state[ctrl] ? icons[state[ctrl] - 1] : null,
+       getDefault: () => 'bottle',
+       handlePrimary: (state, setState, icons) => {
+               if (state[ctrl] === 0) {
+                       // skip over mushroom
+                       setState(s => ({ ...s, [ctrl]: 2 }));
+               } else {
+                       setState(increment(ctrl, icons.length));
+               }
+       },
+       handleSecondary: (state, setState, icons) => {
+               if (state[ctrl] === 2) {
+                       // skip over mushroom
+                       setState(s => ({ ...s, [ctrl]: 0 }));
+               } else {
+                       setState(decrement(ctrl, icons.length));
+               }
+       },
+});
+
 ToggleIcon.countController = max => ({
        getActive: highestActive,
        getDefault: firstIcon,
index 2484dc007a08d3e05636d0c1fb606b1a35869fe4..175494178041d689479fcbd43e796d969ab6b407 100644 (file)
@@ -52,6 +52,9 @@ const hasPendants = n => (...args) => countPendants(...args) >= n;
 
 // Equipment
 
+const countBottles = (config, dungeons, state) =>
+       ['bottle-1', 'bottle-2', 'bottle-3', 'bottle-4'].filter(b => !!state[b]).length;
+
 const hasBig = dungeon => (config, dungeons, state) =>
        !config.wildBig || !!state[`${dungeon}-big-key`];
 
@@ -65,7 +68,7 @@ const hasBoom = (config, dungeons, state) => !!(state['blue-boomerang'] || state
 
 const hasBoots = (config, dungeons, state) => !!state['boots'];
 
-const hasBottle = n => (config, dungeons, state) => state['bottle'] >= (n || 1);
+const hasBottle = n => (...args) => countBottles(...args) >= (n || 1);
 
 const hasBow = (config, dungeons, state) => !!state['bow'];
 
index 4f44d3c50d3b4fac23f28a157fe5f662004fd4e9..8b210d2632f266c94e629d204ec2715436badfe9 100644 (file)
@@ -43,7 +43,10 @@ export const BOOLEAN_STATES = [
 ];
 
 export const INTEGER_STATES = [
-       'bottle',
+       'bottle-1',
+       'bottle-2',
+       'bottle-3',
+       'bottle-4',
        'heart-piece',
        'lift',
        'mail',
@@ -55,6 +58,17 @@ export const INITIAL = {
        mail: 1,
 };
 
+export const BOTTLE_CONTENTS = [
+       'mushroom',
+       'bottle',
+       'red-potion',
+       'green-potion',
+       'blue-potion',
+       'fairy',
+       'bottle-bee',
+       'bottle-bee',
+];
+
 export const BOSSES = [
        'armos',
        'lanmolas',
@@ -1789,19 +1803,10 @@ const collectInventory = (state, data, prizeMap) => {
        state.duck = !!(data[INV_ADDR.RANDO_FLUTE] & 0x01);
        state.bugnet = !!data[INV_ADDR.BUGNET];
        state.book = !!data[INV_ADDR.BOOK];
-       state.bottle = 0;
-       if (data[INV_ADDR.BOTTLE_1]) {
-               ++state.bottle;
-       }
-       if (data[INV_ADDR.BOTTLE_2]) {
-               ++state.bottle;
-       }
-       if (data[INV_ADDR.BOTTLE_3]) {
-               ++state.bottle;
-       }
-       if (data[INV_ADDR.BOTTLE_4]) {
-               ++state.bottle;
-       }
+       state['bottle-1'] = data[INV_ADDR.BOTTLE_1];
+       state['bottle-2'] = data[INV_ADDR.BOTTLE_2];
+       state['bottle-3'] = data[INV_ADDR.BOTTLE_3];
+       state['bottle-4'] = data[INV_ADDR.BOTTLE_4];
        state.somaria = !!data[INV_ADDR.SOMARIA];
        state.byrna = !!data[INV_ADDR.BYRNA];
        state.cape = !!data[INV_ADDR.CAPE];
@@ -1936,6 +1941,12 @@ export const mergeStates = (autoState, manualState) => {
                        next[loc.id] = true;
                }
        });
+       // prefer auto
+       next['bottle-1'] = autoState['bottle-1'] || manualState['bottle-1'] || 0;
+       next['bottle-2'] = autoState['bottle-2'] || manualState['bottle-2'] || 0;
+       next['bottle-3'] = autoState['bottle-3'] || manualState['bottle-3'] || 0;
+       next['bottle-4'] = autoState['bottle-4'] || manualState['bottle-4'] || 0;
+       // force manual
        next['mm-medallion'] = manualState['mm-medallion'];
        next['tr-medallion'] = manualState['tr-medallion'];
        next['gt-crystals'] = manualState['gt-crystals'];