]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/tracker/Dungeons.js
tracker layout
[alttp.git] / resources / js / components / tracker / Dungeons.js
index 07b66389dd0b7f7e5830c09edcca060af7dd8c53..9c6e122f382f6792bae71f5e7fd99febe4da5900 100644 (file)
+import PropTypes from 'prop-types';
 import React from 'react';
 
 import CountDisplay from './CountDisplay';
 import ToggleIcon from './ToggleIcon';
+import {
+       BOSSES,
+       getDungeonAcquiredSKs,
+       getDungeonRemainingItems,
+       shouldShowDungeonItem,
+} from '../../helpers/tracker';
 import { useTracker } from '../../hooks/tracker';
 
-const Dungeons = () => {
-       const { dungeons, state } = useTracker();
+const Dungeons = ({ columns }) => {
+       const { config, dungeons, state } = useTracker();
 
-       return <div className="dungeons">
+       const layout = React.useMemo(() => {
+               const mapX = 1;
+               const compassX = shouldShowDungeonItem(config, 'Map') ? mapX + 1 : mapX;
+               const smallX = shouldShowDungeonItem(config, 'Compass') ? compassX + 1 : compassX;
+               const bigX =  shouldShowDungeonItem(config, 'Small') ? smallX + 1 : smallX;
+               const countX = shouldShowDungeonItem(config, 'Big') ? bigX + 1 : bigX;
+               const bossX = countX + 1;
+               const prizeX = bossX + 1;
+               const dungeonWidth = Math.max(5, prizeX + 1);
+               const width = (columns * dungeonWidth) + Math.max(0, columns - 1);
+               const height = 4;
+
+               const transform = (col, row) =>
+                       `scale(${1 / width}) translate(${
+                               (col * dungeonWidth) + 0.5 + (col ? col - (columns > 3 ? 1 : 0) : 0)
+                       } ${row + 0.5})`;
+
+               const transforms = {
+                       tag: '',
+                       map: `translate(${mapX} 0) scale(0.9)`,
+                       compass: `translate(${compassX} 0) scale(0.9)`,
+                       small: `translate(${smallX} 0) scale(0.9)`,
+                       big: `translate(${bigX} 0) scale(0.9)`,
+                       checks: `translate(${countX} 0) scale(0.9)`,
+                       boss: `translate(${bossX} 0)`,
+                       prize: `translate(${prizeX} 0)`,
+                       hc: transform(0, 0),
+                       ct: transform(0, 1),
+                       gt: transform(0, 2),
+                       gtBoss1: `translate(${bossX - 2} 1)`,
+                       gtBoss2: `translate(${bossX - 1} 1)`,
+                       gtBoss3: `translate(${bossX} 1)`,
+               };
+
+               if (columns === 1) {
+                       transforms.ep = transform(0, 4);
+                       transforms.dp = transform(0, 5);
+                       transforms.th = transform(0, 6);
+                       transforms.pd = transform(0, 8);
+                       transforms.sp = transform(0, 9);
+                       transforms.sw = transform(0, 10);
+                       transforms.tt = transform(0, 11);
+                       transforms.ip = transform(0, 12);
+                       transforms.mm = transform(0, 13);
+                       transforms.tr = transform(0, 14);
+               } else if (columns === 2) {
+                       transforms.ep = transform(0, 4);
+                       transforms.dp = transform(0, 5);
+                       transforms.th = transform(0, 6);
+                       transforms.pd = transform(1, 0);
+                       transforms.sp = transform(1, 1);
+                       transforms.sw = transform(1, 2);
+                       transforms.tt = transform(1, 3);
+                       transforms.ip = transform(1, 4);
+                       transforms.mm = transform(1, 5);
+                       transforms.tr = transform(1, 6);
+               } else {
+                       transforms.ep = transform(1, 0);
+                       transforms.dp = transform(1, 1);
+                       transforms.th = transform(1, 2);
+                       transforms.pd = transform(2, 0);
+                       transforms.sp = transform(2, 1);
+                       transforms.sw = transform(2, 2);
+                       transforms.tt = transform(2, 3);
+                       transforms.ip = transform(3, 0);
+                       transforms.mm = transform(3, 1);
+                       transforms.tr = transform(3, 2);
+               }
+
+               return {
+                       width,
+                       height,
+                       transforms,
+               };
+       }, [config, dungeons]);
+
+       return <>
                {dungeons.map(dungeon =>
-                       <div className={`dungeon dungeon-${dungeon.id}`} key={dungeon.id}>
-                               <span className="dungeon-tag">{dungeon.id.toUpperCase()}</span>
-                               <ToggleIcon
-                                       controller={ToggleIcon.dungeonController(dungeon)}
-                                       icons={['map']}
-                               />
-                               <ToggleIcon
-                                       controller={ToggleIcon.dungeonController(dungeon)}
-                                       icons={['compass']}
-                               />
-                               <span className="dungeon-smalls">
-                                       <ToggleIcon
-                                               controller={ToggleIcon.dungeonCountController(dungeon, dungeon.sk)}
-                                               icons={['small-key']}
-                                       />
-                                       <CountDisplay count={state[`${dungeon.id}-small-key`] || 0} />
-                               </span>
-                               <ToggleIcon
-                                       controller={ToggleIcon.dungeonController(dungeon)}
-                                       icons={['big-key']}
-                               />
-                               <span className="dungeon-checks">
+                       <g
+                               className={`dungeon dungeon-${dungeon.id}`}
+                               key={dungeon.id}
+                               transform={layout.transforms[dungeon.id]}
+                       >
+                               <g transform={layout.transforms.tag}>
+                                       <text className="dungeon-tag">{dungeon.id.toUpperCase()}</text>
+                               </g>
+                               {shouldShowDungeonItem(config, 'Map') ?
+                                       <g transform={layout.transforms.map}>
+                                               <ToggleIcon
+                                                       controller={ToggleIcon.dungeonController(dungeon)}
+                                                       icons={['map']}
+                                                       svg
+                                               />
+                                       </g>
+                               : null}
+                               {shouldShowDungeonItem(config, 'Compass') ?
+                                       <g transform={layout.transforms.compass}>
+                                               <ToggleIcon
+                                                       controller={ToggleIcon.dungeonController(dungeon)}
+                                                       icons={['compass']}
+                                                       svg
+                                               />
+                                       </g>
+                               : null}
+                               {shouldShowDungeonItem(config, 'Small') ?
+                                       <g transform={layout.transforms.small}>
+                                               <ToggleIcon
+                                                       controller={ToggleIcon.dungeonCountController(dungeon, dungeon.sk)}
+                                                       icons={['small-key']}
+                                                       svg
+                                               />
+                                               <CountDisplay
+                                                       count={getDungeonAcquiredSKs(state, dungeon)}
+                                                       full={dungeon.sk}
+                                               />
+                                       </g>
+                               : null}
+                               {shouldShowDungeonItem(config, 'Big') ?
+                                       <g transform={layout.transforms.big}>
+                                               <ToggleIcon
+                                                       controller={ToggleIcon.dungeonController(dungeon)}
+                                                       icons={['big-key']}
+                                                       svg
+                                               />
+                                       </g>
+                               : null}
+                               <g transform={layout.transforms.checks}>
                                        <ToggleIcon
-                                               controller={ToggleIcon.dungeonCheckController(dungeon, dungeon.items)}
+                                               controller={ToggleIcon.dungeonCheckController(dungeon)}
                                                icons={['open-chest', 'chest']}
+                                               svg
                                        />
-                                       <CountDisplay count={dungeon.items - (state[`${dungeon.id}-checks`] || 0)} />
-                               </span>
+                                       <CountDisplay count={getDungeonRemainingItems(state, dungeon)} />
+                               </g>
                                {dungeon.boss ?
-                                       <ToggleIcon
-                                               controller={ToggleIcon.dungeonBossController(dungeon)}
-                                               icons={dungeon.bosses}
-                                       />
+                                       <g transform={layout.transforms.boss}>
+                                               <ToggleIcon
+                                                       controller={ToggleIcon.dungeonBossController(dungeon)}
+                                                       icons={dungeon.bosses}
+                                                       svg
+                                               />
+                                       </g>
                                : null}
                                {dungeon.prize ?
-                                       <ToggleIcon
-                                               controller={ToggleIcon.dungeonPrizeController(dungeon)}
-                                               icons={[
-                                                       'crystal',
-                                                       'red-crystal',
-                                                       'green-pendant',
-                                                       'red-pendant',
-                                               ]}
-                                       />
+                                       <g transform={layout.transforms.prize}>
+                                               <ToggleIcon
+                                                       controller={ToggleIcon.dungeonPrizeController(dungeon)}
+                                                       icons={[
+                                                               'crystal',
+                                                               'red-crystal',
+                                                               'green-pendant',
+                                                               'red-pendant',
+                                                       ]}
+                                                       svg
+                                               />
+                                       </g>
                                : null}
-                       </div>
+                               {dungeon.id === 'gt' && config.bossShuffle ? <>
+                                       <g transform={layout.transforms.gtBoss1}>
+                                               <ToggleIcon
+                                                       controller={ToggleIcon.gtBossController('bot')}
+                                                       icons={BOSSES}
+                                                       svg
+                                               />
+                                       </g>
+                                       <g transform={layout.transforms.gtBoss2}>
+                                               <ToggleIcon
+                                                       controller={ToggleIcon.gtBossController('mid')}
+                                                       icons={BOSSES}
+                                                       svg
+                                               />
+                                       </g>
+                                       <g transform={layout.transforms.gtBoss3}>
+                                               <ToggleIcon
+                                                       controller={ToggleIcon.gtBossController('top')}
+                                                       icons={BOSSES}
+                                                       svg
+                                               />
+                                       </g>
+                               </> : null}
+                       </g>
                )}
-       </div>;
+       </>;
+};
+
+Dungeons.propTypes = {
+       columns: PropTypes.number,
+};
+
+Dungeons.defaultProps = {
+       columns: 4,
 };
 
 export default Dungeons;