X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fcomponents%2Ftracker%2FToggleIcon.js;h=d3e3960fa4bd00795561344ddc493e40998e9c32;hb=f18af7cfb219ab9c07635ea8bbae80f2a9cee78e;hp=49375ef97695b09f00b9998f484e5962ad21d11d;hpb=b5a50d74cf042fa7fc874d8184dc37ae20bb74dd;p=alttp.git
diff --git a/resources/js/components/tracker/ToggleIcon.js b/resources/js/components/tracker/ToggleIcon.js
index 49375ef..d3e3960 100644
--- a/resources/js/components/tracker/ToggleIcon.js
+++ b/resources/js/components/tracker/ToggleIcon.js
@@ -3,22 +3,28 @@ import React from 'react';
import ZeldaIcon from '../common/ZeldaIcon';
import {
+ addDungeonCheck,
decrement,
getDungeonBoss,
+ getDungeonRemainingItems,
getDungeonPrize,
+ getGTBoss,
hasDungeonBoss,
hasDungeonPrize,
highestActive,
increment,
+ removeDungeonCheck,
toggleBoolean,
+ toggleBossDefeated,
} from '../../helpers/tracker';
import { useTracker } from '../../hooks/tracker';
-const ToggleIcon = ({ controller, className, icons }) => {
- const { state, setState } = useTracker();
+const ToggleIcon = ({ controller, className, icons, svg, title, 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');
@@ -28,20 +34,39 @@ 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 {
- activeController.handlePrimary(state, setState, icons);
+ activeController.handlePrimary(state, setManualState, icons);
e.preventDefault();
e.stopPropagation();
}}
onContextMenu={(e) => {
- activeController.handleSecondary(state, setState, icons);
+ activeController.handleSecondary(state, setManualState, icons);
e.preventDefault();
e.stopPropagation();
}}
>
-
+
;
};
@@ -93,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,
@@ -110,23 +156,23 @@ ToggleIcon.dungeonBossController = (dungeon) => ({
handlePrimary: dungeon.bosses.length > 1
? nextString(`${dungeon.id}-boss`)
: (state, setState) => {
- setState(toggleBoolean(`${dungeon.id}-boss-defeated`));
+ setState(toggleBossDefeated(dungeon));
},
handleSecondary: dungeon.bosses.length > 1 ?
previousString(`${dungeon.id}-boss`)
: (state, setState) => {
- setState(toggleBoolean(`${dungeon.id}-boss-defeated`));
+ setState(toggleBossDefeated(dungeon));
},
});
-ToggleIcon.dungeonCheckController = (dungeon, max) => ({
- getActive: (state, icons) => state[`${dungeon.id}-checks`] < max ? icons[1] : null,
+ToggleIcon.dungeonCheckController = (dungeon) => ({
+ getActive: (state, icons) => getDungeonRemainingItems(state, dungeon) ? icons[1] : null,
getDefault: firstIcon,
handlePrimary: (state, setState) => {
- setState(increment(`${dungeon.id}-checks`, max));
+ setState(addDungeonCheck(dungeon));
},
handleSecondary: (state, setState) => {
- setState(decrement(`${dungeon.id}-checks`, max));
+ setState(removeDungeonCheck(dungeon));
},
});
@@ -159,21 +205,59 @@ 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,
handlePrimary: nextIcon,
- handleSecondary: doNothing,
+ handleSecondary: (state, setState, icons) => {
+ const mm = state['mm-medallion'];
+ const tr = state['tr-medallion'];
+ const isMM = mm === icons[0];
+ const isTR = tr === icons[0];
+ console.log({ mm, isMM, tr, isTR });
+ if (!isMM && !isTR) {
+ // empty: set as MM if mire is unset, else set as TR if TR is unset
+ if (!mm) {
+ setState(s => ({ ...s, 'mm-medallion': icons[0] }));
+ } else if (!tr) {
+ setState(s => ({ ...s, 'tr-medallion': icons[0] }));
+ }
+ } else if (isMM && !isTR) {
+ // MM: if TR is free, switch to TR, otherwise remove MM
+ if (!tr) {
+ setState(s => ({ ...s, 'mm-medallion': null, 'tr-medallion': icons[0] }));
+ } else {
+ setState(s => ({ ...s, 'mm-medallion': null }));
+ }
+ } else if (!isMM && isTR) {
+ // TR: if MM is free, switch to both, otherwise remove TR
+ if (!mm) {
+ setState(s => ({ ...s, 'mm-medallion': icons[0] }));
+ } else {
+ setState(s => ({ ...s, 'tr-medallion': null }));
+ }
+ } else {
+ // both: remove both
+ setState(s => ({ ...s, 'mm-medallion': null, 'tr-medallion': null }));
+ }
+ },
};
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));
},
});
@@ -184,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,
@@ -213,6 +304,9 @@ ToggleIcon.propTypes = {
handleSecondary: PropTypes.func,
}),
icons: PropTypes.arrayOf(PropTypes.string),
+ svg: PropTypes.bool,
+ title: PropTypes.string,
+ transform: PropTypes.string,
};
export default ToggleIcon;