From 6a65eac02f94f00fdd2d56ad8feddf5d9476aa1e Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Fri, 29 Mar 2024 11:28:03 +0100 Subject: [PATCH] separate bottle tracking --- resources/js/components/tracker/Items.js | 24 ++++++++++-- resources/js/components/tracker/ToggleIcon.js | 21 ++++++++++ resources/js/helpers/logic.js | 5 ++- resources/js/helpers/tracker.js | 39 ++++++++++++------- 4 files changed, 71 insertions(+), 18 deletions(-) diff --git a/resources/js/components/tracker/Items.js b/resources/js/components/tracker/Items.js index 2e83565..fb47824 100644 --- a/resources/js/components/tracker/Items.js +++ b/resources/js/components/tracker/Items.js @@ -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 = () => {
- - + + + +
diff --git a/resources/js/components/tracker/ToggleIcon.js b/resources/js/components/tracker/ToggleIcon.js index 3966506..c1a193c 100644 --- a/resources/js/components/tracker/ToggleIcon.js +++ b/resources/js/components/tracker/ToggleIcon.js @@ -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, diff --git a/resources/js/helpers/logic.js b/resources/js/helpers/logic.js index 2484dc0..1754941 100644 --- a/resources/js/helpers/logic.js +++ b/resources/js/helpers/logic.js @@ -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']; diff --git a/resources/js/helpers/tracker.js b/resources/js/helpers/tracker.js index 4f44d3c..8b210d2 100644 --- a/resources/js/helpers/tracker.js +++ b/resources/js/helpers/tracker.js @@ -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']; -- 2.39.2