diff --git a/src/Board.tsx b/src/Board.tsx deleted file mode 100644 index a01edd0..0000000 --- a/src/Board.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import React from "react" -import { Card, CardContent, Grid, Typography } from "@mui/material" - -function Board() { - const WIDTH = 10 - const HEIGHT = 10 - let key = 0 - - const board: string[][] = new Array(HEIGHT).fill(Array(WIDTH).fill("a")) - - return ( - <> - { - /* PRINT GRID */ - board.map((row): JSX.Element => { - return ( - - {row.map((element): JSX.Element => { - return ( - - - {element} - - - ) - })} - - ) - }) - } - - ) -} - -export default Board diff --git a/src/components/Board.tsx b/src/components/Board.tsx new file mode 100644 index 0000000..be5a1fd --- /dev/null +++ b/src/components/Board.tsx @@ -0,0 +1,75 @@ +import React, { useState } from "react" +import { Card, CardContent, Grid, Typography } from "@mui/material" +import instructions, { Instruction } from "../Instructions" + +interface Tile { + pointedAt: boolean + instruction: Instruction +} + +function Board() { + const WIDTH = 10 + const HEIGHT = 10 + let key = 0 + + const [board, setBoard] = useState( + new Array(HEIGHT).fill(0).map(() => + new Array(WIDTH).fill(0).map((): Tile => { + return { pointedAt: false, instruction: structuredClone(instructions[0]) } + }) + ) + ) + //.map(() => ({pointedAt: false, value: " ")} + const handleDrop = ( + col: number, + row: number, + event: React.DragEvent | undefined + ): void => { + if (event === undefined) { + console.log("invalid drop target") + return + } + + const data = event.dataTransfer.getData("text/plain") + console.log(data, row, col) + const x = [...board] + x[row][col].instruction.symbol = data + console.log(x) + setBoard(x) + } + + const handleOnDragOver = (event: React.DragEvent | undefined) => { + event?.preventDefault() + return false + } + + return ( + <> + { + /* PRINT GRID */ + board.map((row, rowNo): JSX.Element => { + return ( + + {row.map((element, colNo): JSX.Element => { + return ( +
handleDrop(colNo, rowNo, event)}> + + + {element.instruction.symbol} + + +
+ ) + })} +
+ ) + }) + } + + ) +} + +export default Board diff --git a/src/index.tsx b/src/index.tsx index a0f59c4..fed4bbb 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,7 +1,7 @@ import React from "react" import ReactDOM from "react-dom/client" import "./index.css" -import Board from "./Board" +import Board from "./components/Board" import reportWebVitals from "./reportWebVitals" import InstructionMenu from "./InstructionMenu"