broken i give up react SUCKS!

This commit is contained in:
Conzer 2024-12-04 04:16:21 -05:00
parent 99d9f34ffd
commit bc4ae32eb8
5 changed files with 80 additions and 35 deletions

View file

@ -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;
}

View file

@ -12,3 +12,5 @@ const App = () => {
</div>
);
};
export default App;

View file

@ -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 <button onClick={handleExport}>Export Map</button>;
};
export default ExportButton

View file

@ -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 (
<Stage width={canvasSize} height={canvasSize} onClick={handleClick}>
<Layer>
<Grid gridSize={gridSize} canvasSize={canvasSize} />
{tiles.map((tile, index) => (
<Rect
key={index}
x={tile.x}
y={tile.y}
width={gridSize}
height={gridSize}
fill={tile.color}
/>
))}
</Layer>
</Stage>
);
};
export default MapMaker;

View file

@ -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(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
</React.StrictMode>
);