Skip to content

Commit

Permalink
Remove unnecessary toolbar pentomino state variable (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
RheingoldRiver authored Oct 27, 2023
1 parent 14b7b2e commit ade2b3f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
13 changes: 2 additions & 11 deletions src/components/GameStateProvider/GameStateProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ interface GameState {
setGrid: Dispatch<SetStateAction<PlacedPentomino[][]>>;
paintedGrid: PaintedCell[][];
currentPentomino: Pentomino;
toolbarPentomino: Pentomino;
currentGridCoords: Coordinates;
currentReflection: number;
currentRotation: number;
Expand Down Expand Up @@ -54,7 +53,6 @@ const DEFAULT_GAME_STATE: GameState = {
setGrid: () => {},
paintedGrid: [],
currentPentomino: PENTOMINOES.None,
toolbarPentomino: PENTOMINOES.None,
currentGridCoords: { x: 0, y: 0 },
currentReflection: 0,
currentRotation: 0,
Expand Down Expand Up @@ -110,7 +108,6 @@ export default function GameStateProvider({ children }: { children: ReactNode })
}, []);

const [currentPentomino, setCurrentPentomino] = useState<Pentomino>(PENTOMINOES.None);
const [toolbarPentomino, setToolbarPentomino] = useState<Pentomino>(PENTOMINOES.None);
const [currentGridCoords, setCurrentGridCoords] = useState<Coordinates>({ x: -1, y: -1 });
const [currentReflection, setCurrentReflection] = useState<number>(0); // 0, 1
const [currentRotation, setCurrentRotation] = useState<number>(0); // 0, 1, 2, 3
Expand Down Expand Up @@ -189,9 +186,6 @@ export default function GameStateProvider({ children }: { children: ReactNode })

function updateCurrentPentomino(p: Pentomino) {
setCurrentPentomino(p);
// updating current pentomino when you press a hotkey is handled separately
// so we won't ever call this in the same render as we pressed a hotkey for the first time
setToolbarPentomino(p);
resetOrientation();
}

Expand Down Expand Up @@ -289,7 +283,6 @@ export default function GameStateProvider({ children }: { children: ReactNode })
drawPentomino(x, y);
} else {
setCurrentPentomino(cell.pentomino.pentomino);
setToolbarPentomino(cell.pentomino.pentomino);
erasePentomino(cell.pentomino.x, cell.pentomino.y);
setCurrentRotation(cell.pentomino.rotation);
setCurrentReflection(cell.pentomino.reflection);
Expand Down Expand Up @@ -350,14 +343,13 @@ export default function GameStateProvider({ children }: { children: ReactNode })
useHotkey(undefined, "W", reflectY);

function updateToolbarPentomino(increment: number) {
const curIndex = ALL_PENTOMINO_NAMES.indexOf(toolbarPentomino.name);
const curIndex = ALL_PENTOMINO_NAMES.indexOf(currentPentomino.name);
const nextPentomino =
toolbarPentomino.name === PENTOMINOES.None.name
currentPentomino.name === PENTOMINOES.None.name
? PENTOMINOES.R
: PENTOMINOES[
ALL_PENTOMINO_NAMES[(curIndex + increment + ALL_PENTOMINO_NAMES.length) % ALL_PENTOMINO_NAMES.length]
];
setToolbarPentomino(nextPentomino);
setCurrentPentomino(nextPentomino);
resetOrientation();
}
Expand All @@ -383,7 +375,6 @@ export default function GameStateProvider({ children }: { children: ReactNode })
setGrid,
paintedGrid,
currentPentomino,
toolbarPentomino,
currentGridCoords,
currentReflection,
currentRotation,
Expand Down
3 changes: 1 addition & 2 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const Header = ({ ...rest }) => {
currentRotation,
currentReflection,
pentominoColors,
toolbarPentomino,
showKeyboardIndicators,
} = useContext(GameStateContext);

Expand All @@ -37,7 +36,7 @@ export const Header = ({ ...rest }) => {
<div
key={l}
className={clsx(
toolbarPentomino.name === l && showKeyboardIndicators ? "border-b border-b-px border-b-slate-300" : "",
currentPentomino.name === l && showKeyboardIndicators ? "border-b border-b-px border-b-slate-300" : "",
"py-3 rounded-sm"
)}
>
Expand Down

0 comments on commit ade2b3f

Please sign in to comment.