mirror of
https://github.com/trafficlunar/blockmatic.git
synced 2026-06-28 06:34:13 +00:00
feat: improved move tool
This commit is contained in:
parent
9873c068e8
commit
ee02e1ae47
7 changed files with 150 additions and 39 deletions
32
src/context/Selection.tsx
Normal file
32
src/context/Selection.tsx
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { createContext, ReactNode, useState } from "react";
|
||||
|
||||
interface Context {
|
||||
coords: CoordinateArray;
|
||||
layerBlocks: Block[];
|
||||
setCoords: React.Dispatch<React.SetStateAction<CoordinateArray>>;
|
||||
setLayerBlocks: React.Dispatch<React.SetStateAction<Block[]>>;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export const SelectionContext = createContext<Context>({} as Context);
|
||||
|
||||
export const SelectionProvider = ({ children }: Props) => {
|
||||
const [coords, setCoords] = useState<CoordinateArray>([]);
|
||||
const [layerBlocks, setLayerBlocks] = useState<Block[]>([]);
|
||||
|
||||
return (
|
||||
<SelectionContext.Provider
|
||||
value={{
|
||||
coords,
|
||||
layerBlocks,
|
||||
setCoords,
|
||||
setLayerBlocks,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</SelectionContext.Provider>
|
||||
);
|
||||
};
|
||||
|
|
@ -4,12 +4,10 @@ interface Context {
|
|||
tool: Tool;
|
||||
radius: number;
|
||||
selectedBlock: string;
|
||||
selectionCoords: CoordinateArray;
|
||||
cssCursor: string;
|
||||
setTool: React.Dispatch<React.SetStateAction<Tool>>;
|
||||
setRadius: React.Dispatch<React.SetStateAction<number>>;
|
||||
setSelectedBlock: React.Dispatch<React.SetStateAction<string>>;
|
||||
setSelectionCoords: React.Dispatch<React.SetStateAction<CoordinateArray>>;
|
||||
setCssCursor: React.Dispatch<React.SetStateAction<string>>;
|
||||
}
|
||||
|
||||
|
|
@ -23,7 +21,6 @@ export const ToolProvider = ({ children }: Props) => {
|
|||
const [tool, setTool] = useState<Tool>("hand");
|
||||
const [radius, setRadius] = useState(1);
|
||||
const [selectedBlock, setSelectedBlock] = useState("stone");
|
||||
const [selectionCoords, setSelectionCoords] = useState<CoordinateArray>([]);
|
||||
const [cssCursor, setCssCursor] = useState("crosshair");
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -42,12 +39,10 @@ export const ToolProvider = ({ children }: Props) => {
|
|||
tool,
|
||||
radius,
|
||||
selectedBlock,
|
||||
selectionCoords,
|
||||
cssCursor,
|
||||
setTool,
|
||||
setRadius,
|
||||
setSelectedBlock,
|
||||
setSelectionCoords,
|
||||
setCssCursor,
|
||||
}}
|
||||
>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue