diff --git a/src/components/toolbar/SelectedBlock.tsx b/src/components/toolbar/SelectedBlock.tsx new file mode 100644 index 0000000..6c58144 --- /dev/null +++ b/src/components/toolbar/SelectedBlock.tsx @@ -0,0 +1,60 @@ +import { useContext } from "react"; + +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; + +import { TexturesContext } from "@/context/Textures"; +import { ToolContext } from "@/context/Tool"; + +function SelectedBlock() { + const textures = useContext(TexturesContext); + const { selectedBlock } = useContext(ToolContext); + + const convertToDataUrl = (textureName: string): string => { + const texture = textures[textureName]; + + const canvas = document.createElement("canvas"); + const context = canvas.getContext("2d"); + + canvas.width = texture.frame.width; + canvas.height = texture.frame.height; + + if (!context) return ""; + + const image = new Image(); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + image.src = (texture.baseTexture.resource as any).url; + + context.drawImage( + image, + texture.frame.x, + texture.frame.y, + texture.frame.width, + texture.frame.height, + 0, + 0, + texture.frame.width, + texture.frame.height + ); + + return canvas.toDataURL(); + }; + + return ( + + + + + + +

{selectedBlock}

+
+
+
+ ); +} + +export default SelectedBlock; diff --git a/src/components/toolbar/index.tsx b/src/components/toolbar/index.tsx index 78afbe0..7d87e21 100644 --- a/src/components/toolbar/index.tsx +++ b/src/components/toolbar/index.tsx @@ -3,8 +3,11 @@ import { EraserIcon, HandIcon, PencilIcon, ZoomInIcon } from "lucide-react"; import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; + import { ToolContext } from "@/context/Tool"; +import SelectedBlock from "./SelectedBlock"; + function Toolbar() { const { tool, setTool } = useContext(ToolContext); @@ -65,6 +68,8 @@ function Toolbar() {

Zoom (4)

+ + );