broken i give up react SUCKS!
This commit is contained in:
parent
99d9f34ffd
commit
bc4ae32eb8
5 changed files with 80 additions and 35 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -12,3 +12,5 @@ const App = () => {
|
|||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
||||
|
|
15
mapsy/src/components/ExportBtn.jsx
Normal file
15
mapsy/src/components/ExportBtn.jsx
Normal 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
|
40
mapsy/src/components/MapMaker.jsx
Normal file
40
mapsy/src/components/MapMaker.jsx
Normal 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;
|
|
@ -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>
|
||||
);
|
Loading…
Reference in a new issue