X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fcomponents%2Ftracker%2FToggleIcon.js;h=6de9f63632652dea775d0eca42259e5f15d0425d;hb=1a3d040147c19d24b8d02ec8e594eb06b8efc1ff;hp=da1a18139e8f90bac57e1edb502b0f57e029caff;hpb=5fe70ee6bc5380c556169756a375956799093604;p=alttp.git diff --git a/resources/js/components/tracker/ToggleIcon.js b/resources/js/components/tracker/ToggleIcon.js index da1a181..6de9f63 100644 --- a/resources/js/components/tracker/ToggleIcon.js +++ b/resources/js/components/tracker/ToggleIcon.js @@ -18,7 +18,7 @@ import { } from '../../helpers/tracker'; import { useTracker } from '../../hooks/tracker'; -const ToggleIcon = ({ controller, className, icons }) => { +const ToggleIcon = ({ controller, className, icons, svg }) => { const { setManualState, state } = useTracker(); const activeController = controller || ToggleIcon.nullController; const active = activeController.getActive(state, icons); @@ -32,6 +32,23 @@ const ToggleIcon = ({ controller, className, icons }) => { if (className) { classNames.push(className); } + if (svg) { + return { + activeController.handlePrimary(state, setManualState, icons); + e.preventDefault(); + e.stopPropagation(); + }} + onContextMenu={(e) => { + activeController.handleSecondary(state, setManualState, icons); + e.preventDefault(); + e.stopPropagation(); + }} + > + + ; + } return { @@ -97,6 +114,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, @@ -205,10 +243,10 @@ ToggleIcon.modulusController = ctrl => ({ getActive: (state, icons) => icons[(state[ctrl] || 0) % icons.length], getDefault: firstIcon, handlePrimary: (state, setState, icons) => { - setState(increment(icons[0], icons.length)); + setState(increment(ctrl, icons.length)); }, handleSecondary: (state, setState, icons) => { - setState(decrement(icons[0], icons.length)); + setState(decrement(ctrl, icons.length)); }, }); @@ -248,6 +286,7 @@ ToggleIcon.propTypes = { handleSecondary: PropTypes.func, }), icons: PropTypes.arrayOf(PropTypes.string), + svg: PropTypes.bool, }; export default ToggleIcon;