getDungeonBoss,
getDungeonRemainingItems,
getDungeonPrize,
+ getGTBoss,
hasDungeonBoss,
hasDungeonPrize,
highestActive,
} 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);
if (className) {
classNames.push(className);
}
+ if (svg) {
+ return <g
+ className={classNames.join(' ')}
+ onClick={(e) => {
+ activeController.handlePrimary(state, setManualState, icons);
+ e.preventDefault();
+ e.stopPropagation();
+ }}
+ onContextMenu={(e) => {
+ activeController.handleSecondary(state, setManualState, icons);
+ e.preventDefault();
+ e.stopPropagation();
+ }}
+ >
+ <ZeldaIcon name={active || defaultIcon || icons[0]} svg />
+ </g>;
+ }
return <span
className={classNames.join(' ')}
onClick={(e) => {
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,
handleSecondary: previousString(`${dungeon.id}-prize`),
});
+ToggleIcon.gtBossController = (which) => ({
+ getActive: (state) => getGTBoss(state, which),
+ getDefault: (state) => getGTBoss(state, which),
+ handlePrimary: nextString(`gt-${which}-boss`),
+ handleSecondary: previousString(`gt-${which}-boss`),
+});
+
ToggleIcon.medallionController = {
getActive: highestActive,
getDefault: firstIcon,
handleSecondary: PropTypes.func,
}),
icons: PropTypes.arrayOf(PropTypes.string),
+ svg: PropTypes.bool,
};
export default ToggleIcon;