diff --git a/src/components/BottomToolbar/BottomToolbar.tsx b/src/components/BottomToolbar/BottomToolbar.tsx index b788c5c..06da149 100644 --- a/src/components/BottomToolbar/BottomToolbar.tsx +++ b/src/components/BottomToolbar/BottomToolbar.tsx @@ -13,7 +13,7 @@ const BottomToolbar = forwardRef(({ style }: { style: CSSProperties }, ref) => { return ( {
+ {ALL_PENTOMINO_NAMES.map((l) => ( +
+ { + updateCurrentPentomino(PENTOMINOES[l]); + }} + style={{ + cursor: "pointer", + }} + > +
+ ))}
- {ALL_PENTOMINO_NAMES.map((l) => ( -
- { - updateCurrentPentomino(PENTOMINOES[l]); - }} - style={{ - cursor: "pointer", - }} - > -
- ))} -
-
diff --git a/src/components/Information/Information.tsx b/src/components/Information/Information.tsx index 05a3a0b..30e93d0 100644 --- a/src/components/Information/Information.tsx +++ b/src/components/Information/Information.tsx @@ -104,7 +104,7 @@ export const Information = () => { return ( }> About Pentominoes -
+

Pentominoes are tiles of area 5. There are 12 distinct pentominoes, up to rotation & reflection, with each tile having somewhere between 2 (the {} tile) and 8 ( diff --git a/src/components/Modal/Modal.tsx b/src/components/Modal/Modal.tsx index 3f29a7a..5289c74 100644 --- a/src/components/Modal/Modal.tsx +++ b/src/components/Modal/Modal.tsx @@ -28,7 +28,7 @@ export const Modal = ({ className={clsx( "bg-gray-300 dark:bg-gray-800 dark:text-gray-50", "rounded-lg pt-8 pb-0 shadow-md shadow-gray-500 dark:shadow-none", - "fixed top-1/2 left-1/2 translate-x-[-50%] translate-y-[-50%]", + "fixed top-[5vw] left-[5vw] sm:top-1/2 sm:left-1/2 sm:translate-x-[-50%] sm:translate-y-[-50%]", "max-h-[90vh] overflow-y-auto w-[min(90vw,_40rem)]" )} > diff --git a/src/components/Settings/Settings.tsx b/src/components/Settings/Settings.tsx index 53a6c42..98b8c6c 100644 --- a/src/components/Settings/Settings.tsx +++ b/src/components/Settings/Settings.tsx @@ -6,6 +6,7 @@ import { AppStateContext } from "../AppStateProvider/AppStateProvider"; import { Colors, DEFAULT_DISPLAY_COLORS, + Dimensions, EMPTY_PENTOMINO, MAX_DIMENSION_SIZE, MAX_NUM_COLORS, @@ -58,6 +59,29 @@ export const Settings = () => { const [open, setOpen] = useState(false); const [warnGridReset, setWarnGridReset] = useState(false); + const PRESET_SIZES: Dimensions[] = [ + { + height: 8, + width: 8, + }, + { + height: 5, + width: 12, + }, + { + height: 6, + width: 10, + }, + { + height: 12, + width: 5, + }, + { + height: 10, + width: 6, + }, + ]; + function nextColorsOnMaxChange(newMax: number) { return Object.entries(currentState.pentominoColors).reduce((acc: Colors, [p, c]) => { acc[p] = c >= newMax ? 0 : c; @@ -65,9 +89,16 @@ export const Settings = () => { }, {}); } + function updateCurrentState(newState: Partial) { + const nextState = { ...currentState, ...newState }; + setCurrentState(nextState); + if (warnGridReset) { + setWarnGridReset(gridChangeNeeded(nextState, grid.length, grid[0].length)); + } + } return ( } + trigger={} onOpenAutoFocus={() => { setCurrentState({ height: grid.length, @@ -130,7 +161,7 @@ export const Settings = () => { setOpen(false); }} > -

+
Tile Size
Grid shape -
- - { - const valAsNum = toNumber(e.target.value); - if (isNaN(valAsNum)) return; - setCurrentState({ ...currentState, width: valAsNum }); - setWarnGridReset(!gridChangeNeeded); - }} - /> -
- {showErrors && errorWidth(currentState) && ( - Width must be between 3 & {MAX_DIMENSION_SIZE}, inclusive - )} -
- - { - const valAsNum = toNumber(e.target.value); - if (isNaN(valAsNum)) return; - setCurrentState({ ...currentState, height: valAsNum }); - setWarnGridReset(!gridChangeNeeded); - }} - /> -
+
+
+ + { + const valAsNum = toNumber(e.target.value); + if (isNaN(valAsNum)) return; + updateCurrentState({ width: valAsNum }); + }} + /> +
+ {showErrors && errorWidth(currentState) && ( + Width must be between 3 & {MAX_DIMENSION_SIZE}, inclusive + )} +
+ + { + const valAsNum = toNumber(e.target.value); + if (isNaN(valAsNum)) return; + updateCurrentState({ height: valAsNum }); + }} + /> +
+
+
+ {PRESET_SIZES.map((size) => ( + + ))} +
{showErrors && errorHeight(currentState) && ( Height must be between 3 & {MAX_DIMENSION_SIZE}, inclusive )} @@ -373,7 +414,7 @@ export const Settings = () => {
{/* End of settings area */} {/* Start confirmation area */} -
+
{warnGridReset && Saving will clear your current board! Submit again to proceed.} {showErrors && errorConfig(currentState) && ( One or more errors detected, see field-specific warnings. diff --git a/src/components/TopToolbar/TopToolbar.tsx b/src/components/TopToolbar/TopToolbar.tsx index b07cf67..ff18f64 100644 --- a/src/components/TopToolbar/TopToolbar.tsx +++ b/src/components/TopToolbar/TopToolbar.tsx @@ -13,7 +13,7 @@ import { const TopToolbar = ({ ...rest }) => { const { orientationDispatch } = useContext(GameStateContext); return ( - + { orientationDispatch({ type: OrientationActionType.rotate, direction: RotationDirection.Left }); diff --git a/src/constants.ts b/src/constants.ts index 507530f..6681c29 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -29,6 +29,11 @@ export const PENTOMINO_DIMENSIONS: PentominoDimensions = { 5: "grid-cols-5", }; +export interface Dimensions { + height: number; // corresponds to the x-coordinate + width: number; // corresponds to the y-coordinate +} + export interface Orientation { rotation: number; reflection: number;