Skip to content

Commit

Permalink
Change interactions on grid
Browse files Browse the repository at this point in the history
  • Loading branch information
imjoshellis committed Dec 14, 2020
1 parent 38afc04 commit f961621
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/components/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export const Grid: React.FC<GridProps> = () => {
const [, forceUpdate] = useReducer(x => x + 1, 0)
const [cur, setCur] = useState([0, 0])
const [drag, setDrag] = useState(false)
const [drawType, setDrawType] = useState('empty cells')

const newRandom = useCallback(
(t: number[]) => {
Expand Down Expand Up @@ -114,11 +113,6 @@ export const Grid: React.FC<GridProps> = () => {
e.preventDefault()
}

const toggleDrawType = () => {
if (drawType === 'empty cells') setDrawType('walls')
else setDrawType('empty cells')
}

const toggle = (i: number, j: number) => (
e: React.MouseEvent<HTMLDivElement, MouseEvent>
) => {
Expand All @@ -138,8 +132,19 @@ export const Grid: React.FC<GridProps> = () => {
setStack([[0, 0, 0]])
setFrame(0)
forceUpdate()
} else if (drag || e.buttons === 1) {
toggledCells[i][j] = drawType === 'walls' ? -1 : 1000
} else if (drag) {
toggledCells[i][j] = -1
toggledCells[0][0] = 0
toggledCells[tr][tc] = 4000
setCells(toggledCells)
setPath({})
setStart(false)
setStack([[0, 0, 0]])
setDone(false)
setFrame(0)
forceUpdate()
} else if (e.buttons === 1) {
toggledCells[i][j] = 1000
toggledCells[0][0] = 0
toggledCells[tr][tc] = 4000
setCells(toggledCells)
Expand Down Expand Up @@ -247,11 +252,9 @@ export const Grid: React.FC<GridProps> = () => {
<div className='' style={{ textAlign: 'center' }}>
<div style={{ display: 'flex', justifyContent: 'center' }}>
<p>
<strong>Left-click</strong> and <strong>drag</strong> to draw
<strong>Left-click</strong> to remove walls.{' '}
<strong>Drag w/ Left-click</strong> to draw walls.
</p>
<button className='control-item' onClick={toggleDrawType}>
{drawType} (toggle)
</button>
</div>
<p>
<strong>Right-click</strong> to move the target cell.
Expand Down

0 comments on commit f961621

Please sign in to comment.