mirror of
https://github.com/trafficlunar/blockmatic.git
synced 2026-08-12 12:29:42 +00:00
feat: shape tool
This commit is contained in:
parent
8b89e17b8f
commit
a58375fa60
13 changed files with 660 additions and 17 deletions
|
|
@ -1,8 +1,9 @@
|
|||
import { createContext, ReactNode, useState } from "react";
|
||||
import React, { createContext, ReactNode, useRef, useState } from "react";
|
||||
|
||||
interface Context {
|
||||
selectionCoords: CoordinateArray;
|
||||
selectionLayerBlocks: Block[];
|
||||
confirmHistoryEntryNameRef: React.MutableRefObject<string>;
|
||||
setSelectionCoords: React.Dispatch<React.SetStateAction<CoordinateArray>>;
|
||||
setSelectionLayerBlocks: React.Dispatch<React.SetStateAction<Block[]>>;
|
||||
isInSelection: (x: number, y: number) => boolean;
|
||||
|
|
@ -17,6 +18,7 @@ export const SelectionContext = createContext<Context>({} as Context);
|
|||
export const SelectionProvider = ({ children }: Props) => {
|
||||
const [selectionCoords, setSelectionCoords] = useState<CoordinateArray>([]);
|
||||
const [selectionLayerBlocks, setSelectionLayerBlocks] = useState<Block[]>([]);
|
||||
const confirmHistoryEntryNameRef = useRef("Move Selection");
|
||||
|
||||
const isInSelection = (x: number, y: number): boolean => {
|
||||
if (selectionCoords.length !== 0) {
|
||||
|
|
@ -30,6 +32,7 @@ export const SelectionProvider = ({ children }: Props) => {
|
|||
value={{
|
||||
selectionCoords,
|
||||
selectionLayerBlocks,
|
||||
confirmHistoryEntryNameRef,
|
||||
setSelectionCoords,
|
||||
setSelectionLayerBlocks,
|
||||
isInSelection,
|
||||
|
|
|
|||
|
|
@ -4,9 +4,13 @@ interface Context {
|
|||
tool: Tool;
|
||||
radius: number;
|
||||
selectedBlock: string;
|
||||
shape: Shape;
|
||||
filled: boolean;
|
||||
setTool: React.Dispatch<React.SetStateAction<Tool>>;
|
||||
setRadius: React.Dispatch<React.SetStateAction<number>>;
|
||||
setSelectedBlock: React.Dispatch<React.SetStateAction<string>>;
|
||||
setShape: React.Dispatch<React.SetStateAction<Shape>>;
|
||||
setFilled: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
|
|
@ -20,15 +24,22 @@ export const ToolProvider = ({ children }: Props) => {
|
|||
const [radius, setRadius] = useState(1);
|
||||
const [selectedBlock, setSelectedBlock] = useState("stone");
|
||||
|
||||
const [shape, setShape] = useState<Shape>("line");
|
||||
const [filled, setFilled] = useState(false);
|
||||
|
||||
return (
|
||||
<ToolContext.Provider
|
||||
value={{
|
||||
tool,
|
||||
radius,
|
||||
selectedBlock,
|
||||
shape,
|
||||
filled,
|
||||
setTool,
|
||||
setRadius,
|
||||
setSelectedBlock,
|
||||
setShape,
|
||||
setFilled,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue