From bc4ae32eb8d650356c20300373a2b131b0890a92 Mon Sep 17 00:00:00 2001 From: Conzer Date: Wed, 4 Dec 2024 04:16:21 -0500 Subject: [PATCH] broken i give up react SUCKS! --- mapsy/src/App.css | 47 ++++++++++-------------------- mapsy/src/App.js | 2 ++ mapsy/src/components/ExportBtn.jsx | 15 ++++++++++ mapsy/src/components/MapMaker.jsx | 40 +++++++++++++++++++++++++ mapsy/src/index.js | 11 ++++--- 5 files changed, 80 insertions(+), 35 deletions(-) create mode 100644 mapsy/src/components/ExportBtn.jsx create mode 100644 mapsy/src/components/MapMaker.jsx diff --git a/mapsy/src/App.css b/mapsy/src/App.css index 74b5e05..3db22b9 100644 --- a/mapsy/src/App.css +++ b/mapsy/src/App.css @@ -1,38 +1,23 @@ -.App { - text-align: center; +body { + font-family: Arial, sans-serif; + margin: 0; + padding: 0; } -.App-logo { - height: 40vmin; - pointer-events: none; -} - -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } -} - -.App-header { - background-color: #282c34; - min-height: 100vh; +.toolbar { + margin: 10px; display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); + gap: 10px; +} + +button { + padding: 10px; + background-color: #007bff; color: white; + border: none; + cursor: pointer; } -.App-link { - color: #61dafb; -} - -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } +button:hover { + background-color: #0056b3; } diff --git a/mapsy/src/App.js b/mapsy/src/App.js index c387500..9f1135a 100644 --- a/mapsy/src/App.js +++ b/mapsy/src/App.js @@ -12,3 +12,5 @@ const App = () => { ); }; + +export default App; diff --git a/mapsy/src/components/ExportBtn.jsx b/mapsy/src/components/ExportBtn.jsx new file mode 100644 index 0000000..86ae726 --- /dev/null +++ b/mapsy/src/components/ExportBtn.jsx @@ -0,0 +1,15 @@ +import React from 'react'; + +const ExportBtn = ({ stageRef }) => { + const handleExport = () => { + const uri = stageRef.current.toDataURL(); + const link = document.createElement('a'); + link.download = 'map.png'; + link.href = uri; + link.click(); + }; + + return ; +}; + +export default ExportButton \ No newline at end of file diff --git a/mapsy/src/components/MapMaker.jsx b/mapsy/src/components/MapMaker.jsx new file mode 100644 index 0000000..2276e38 --- /dev/null +++ b/mapsy/src/components/MapMaker.jsx @@ -0,0 +1,40 @@ +import React, { useState } from 'react'; +import { Stage, Layer, Rect } from 'react-konva'; +import Grid from './Grid'; + +const MapMaker = ({ tool }) => { + const gridSize = 32; + const canvasSize = 512; + const [tiles, setTiles] = useState([]); + + const handleClick = (event) => { + const x = Math.floor(event.evt.offsetX / gridSize) * gridSize; + const y = Math.floor(event.evt.offsetY / gridSize) * gridSize; + + if (tool === 'draw') { + setTiles([...tiles, { x, y, color: 'green' }]); + } else if (tool === 'erase') { + setTiles(tiles.filter(tile => tile.x !== x || tile.y !== y)); + }; + }; + return ( + + + + {tiles.map((tile, index) => ( + + ))} + + + + ); + }; + +export default MapMaker; diff --git a/mapsy/src/index.js b/mapsy/src/index.js index aebd27d..7dd8e58 100644 --- a/mapsy/src/index.js +++ b/mapsy/src/index.js @@ -1,11 +1,14 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; -import './index.css'; +import './App.css'; import App from './App'; -ReactDOM.render( +const rootElement = document.getElementById('root'); + +const root = ReactDOM.createRoot(rootElement); + +root.render( - , - document.getElementById('root') + ); \ No newline at end of file