X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=resources%2Fjs%2Fcomponents%2Ftracker%2FToggleIcon.js;h=6dee8180f7be7bfdb3a80dc5819c26b68776f1ee;hb=9a4e2305bb37cb8c62e3ad332f4a2bf45f720a18;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..6dee818 100644
--- a/resources/js/components/tracker/ToggleIcon.js
+++ b/resources/js/components/tracker/ToggleIcon.js
@@ -8,6 +8,7 @@ import {
getDungeonBoss,
getDungeonRemainingItems,
getDungeonPrize,
+ getGTBoss,
hasDungeonBoss,
hasDungeonPrize,
highestActive,
@@ -18,11 +19,12 @@ import {
} from '../../helpers/tracker';
import { useTracker } from '../../hooks/tracker';
-const ToggleIcon = ({ controller, className, icons }) => {
+const ToggleIcon = ({ controller, className, icons, svg, transform }) => {
const { setManualState, state } = useTracker();
const activeController = controller || ToggleIcon.nullController;
const active = activeController.getActive(state, icons);
const defaultIcon = activeController.getDefault(state, icons);
+ const icon = active || defaultIcon || icons[0];
const classNames = ['toggle-icon'];
if (active) {
classNames.push('active');
@@ -32,6 +34,25 @@ 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();
+ }}
+ transform={transform}
+ >
+
+ ;
+ }
return {
@@ -97,6 +118,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,
@@ -163,6 +205,13 @@ ToggleIcon.dungeonPrizeController = (dungeon) => ({
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,
@@ -205,10 +254,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));
},
});
@@ -219,6 +268,13 @@ ToggleIcon.nullController = {
handleSecondary: doNothing,
};
+ToggleIcon.pinController = (pin, removePin) => ({
+ getActive: firstIcon,
+ getDefault: firstIcon,
+ handlePrimary: doNothing,
+ handleSecondary: () => removePin(pin),
+});
+
ToggleIcon.simpleController = {
getActive: highestActive,
getDefault: firstIcon,
@@ -248,6 +304,8 @@ ToggleIcon.propTypes = {
handleSecondary: PropTypes.func,
}),
icons: PropTypes.arrayOf(PropTypes.string),
+ svg: PropTypes.bool,
+ transform: PropTypes.string,
};
export default ToggleIcon;