Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dog-ears to show symmetrical cell #453

Merged
merged 7 commits into from
Sep 19, 2023
1 change: 1 addition & 0 deletions app/components/Builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,7 @@ const GridMode = ({
dispatch={dispatch}
allowBlockEditing={true}
autofill={props.autofillEnabled ? props.autofilledGrid : []}
symmetry={state.symmetry}
/>
}
left={fillLists.left}
Expand Down
15 changes: 15 additions & 0 deletions app/components/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type CellProps = {
isWrong: boolean | undefined;
wasRevealed: boolean | undefined;
cellColor?: number;
isOpposite: boolean;
};

export const Cell = memo(function Cell(props: CellProps) {
Expand Down Expand Up @@ -268,6 +269,20 @@ export const Cell = memo(function Cell(props: CellProps) {
) : (
''
)}
{props.isOpposite ? (
<div className="oppositeIcon"
css={{
position: 'absolute',
top: '0%',
right: '0%',
borderTop: '.3em solid var(--primary)',
borderLeft: '.3em solid rgba(0, 0, 0, 0)',
}}
>
</div>
) : (
''
)}
</div>
</div>
);
Expand Down
9 changes: 7 additions & 2 deletions app/components/Grid.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Dispatch, ReactNode, useCallback, useEffect, useState } from 'react';

import { PosAndDir, Position, BLOCK } from '../lib/types';
import { PosAndDir, Position, BLOCK, Symmetry } from '../lib/types';
import { Cell } from './Cell';
import { PuzzleAction, SetActivePositionAction } from '../reducers/reducer';
import { ViewableGrid, ViewableEntry } from '../lib/viewableGrid';
import { ViewableGrid, ViewableEntry, flipped } from '../lib/viewableGrid';
import {
cellIndex,
getEntryCells,
Expand All @@ -27,6 +27,7 @@ type GridViewProps = {
entryRefs?: Array<Set<number>>;
showAlternates?: Array<Array<[number, string]>> | null;
answers?: Array<string> | null;
symmetry?: Symmetry | null;
};

export const GridView = ({
Expand Down Expand Up @@ -119,6 +120,9 @@ export const GridView = ({
const col = idx % grid.width;
const row = Math.floor(idx / grid.height);

const symmetricalCell = (props.symmetry != Symmetry.None && props.symmetry != null) ? flipped(grid, active, props.symmetry) : null;
const isOpposite = !isActive && (symmetricalCell === idx)

cells.push(
<Cell
barRight={grid.vBars.has(idx)}
Expand All @@ -144,6 +148,7 @@ export const GridView = ({
onClick={onClick}
value={toDisplay}
isBlock={cellValue === BLOCK}
isOpposite={isOpposite}
isVerified={props.verifiedCells?.has(idx) || showAsVerified}
isWrong={props.wrongCells?.has(idx)}
wasRevealed={props.revealedCells?.has(idx)}
Expand Down
2 changes: 1 addition & 1 deletion app/lib/viewableGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ export function gridWithNewChar<
return fromCells({ ...grid, cells, hidden });
}

function flipped<Entry extends ViewableEntry, Grid extends ViewableGrid<Entry>>(
export function flipped<Entry extends ViewableEntry, Grid extends ViewableGrid<Entry>>(
grid: Grid,
pos: Position,
sym: Symmetry
Expand Down
Loading