Loading packages/client/src/components/CanvasWrapper.tsx +20 −3 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ import { PixelPulses } from "./Overlay/PixelPulses"; import { CanvasUtils } from "../lib/canvas.utils"; import { ModCanvasOverlay } from "../Moderator/ModCanvasOverlay"; import { useHasRole } from "../hooks/useHasRole"; import { toast } from "react-toastify"; export const CanvasWrapper = () => { const hasMod = useHasRole("MOD"); Loading Loading @@ -103,8 +104,8 @@ const Cursor = () => { }; const CanvasInner = () => { const canvasRef = useRef<HTMLCanvasElement | null>(); const canvas = useRef<Canvas>(); const canvasRef = useRef<HTMLCanvasElement>(null); const canvas = useRef<Canvas>(null); const { config, setCanvasPosition, setCursor, setPixelWhois } = useAppContext(); const { Loading Loading @@ -227,6 +228,20 @@ const CanvasInner = () => { [canvas.current] ); const handleSnapshot = useCallback(() => { if (!canvasRef.current) { toast.info("Unable to snapshot: can't find canvas"); return; } const $el = document.createElement("a"); $el.setAttribute("download", "canvas-" + Date.now() + ".png"); $el.setAttribute("href", canvasRef.current.toDataURL("image/png")); document.body.appendChild($el); $el.click(); $el.remove(); }, [canvasRef]); useEffect(() => { if (!canvasRef.current) return; canvas.current = new Canvas(canvasRef.current!, PanZoom); Loading @@ -236,10 +251,12 @@ const CanvasInner = () => { KeybindManager.on("PIXEL_WHOIS", handlePixelWhois); KeybindManager.on("PICK_COLOR", handlePickPixel); KeybindManager.on("SNAPSHOT", handleSnapshot); return () => { KeybindManager.off("PIXEL_WHOIS", handlePixelWhois); KeybindManager.off("PICK_COLOR", handlePickPixel); KeybindManager.off("SNAPSHOT", handleSnapshot); canvas.current!.destroy(); }; }, [PanZoom]); Loading Loading @@ -370,7 +387,7 @@ const CanvasInner = () => { width="1000" height="1000" className="pixelate" ref={(ref) => (canvasRef.current = ref)} ref={canvasRef} ></canvas> ); }; packages/client/src/lib/keybinds.ts +11 −1 Original line number Diff line number Diff line Loading @@ -2,7 +2,12 @@ import EventEmitter from "eventemitter3"; import { EnforceObjectType } from "./utils"; export interface IKeybind { key: KeyboardEvent["code"] | "LCLICK" | "RCLICK" | "MCLICK" | "LONG_PRESS"; key: | (KeyboardEvent["code"] & {}) | "LCLICK" | "RCLICK" | "MCLICK" | "LONG_PRESS"; alt?: boolean; ctrl?: boolean; Loading Loading @@ -70,6 +75,11 @@ const KEYBINDS = enforceObjectType({ ctrl: true, }, ], SNAPSHOT: [ { key: "KeyP", }, ], }); class KeybindManager_ extends EventEmitter<{ Loading Loading
packages/client/src/components/CanvasWrapper.tsx +20 −3 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ import { PixelPulses } from "./Overlay/PixelPulses"; import { CanvasUtils } from "../lib/canvas.utils"; import { ModCanvasOverlay } from "../Moderator/ModCanvasOverlay"; import { useHasRole } from "../hooks/useHasRole"; import { toast } from "react-toastify"; export const CanvasWrapper = () => { const hasMod = useHasRole("MOD"); Loading Loading @@ -103,8 +104,8 @@ const Cursor = () => { }; const CanvasInner = () => { const canvasRef = useRef<HTMLCanvasElement | null>(); const canvas = useRef<Canvas>(); const canvasRef = useRef<HTMLCanvasElement>(null); const canvas = useRef<Canvas>(null); const { config, setCanvasPosition, setCursor, setPixelWhois } = useAppContext(); const { Loading Loading @@ -227,6 +228,20 @@ const CanvasInner = () => { [canvas.current] ); const handleSnapshot = useCallback(() => { if (!canvasRef.current) { toast.info("Unable to snapshot: can't find canvas"); return; } const $el = document.createElement("a"); $el.setAttribute("download", "canvas-" + Date.now() + ".png"); $el.setAttribute("href", canvasRef.current.toDataURL("image/png")); document.body.appendChild($el); $el.click(); $el.remove(); }, [canvasRef]); useEffect(() => { if (!canvasRef.current) return; canvas.current = new Canvas(canvasRef.current!, PanZoom); Loading @@ -236,10 +251,12 @@ const CanvasInner = () => { KeybindManager.on("PIXEL_WHOIS", handlePixelWhois); KeybindManager.on("PICK_COLOR", handlePickPixel); KeybindManager.on("SNAPSHOT", handleSnapshot); return () => { KeybindManager.off("PIXEL_WHOIS", handlePixelWhois); KeybindManager.off("PICK_COLOR", handlePickPixel); KeybindManager.off("SNAPSHOT", handleSnapshot); canvas.current!.destroy(); }; }, [PanZoom]); Loading Loading @@ -370,7 +387,7 @@ const CanvasInner = () => { width="1000" height="1000" className="pixelate" ref={(ref) => (canvasRef.current = ref)} ref={canvasRef} ></canvas> ); };
packages/client/src/lib/keybinds.ts +11 −1 Original line number Diff line number Diff line Loading @@ -2,7 +2,12 @@ import EventEmitter from "eventemitter3"; import { EnforceObjectType } from "./utils"; export interface IKeybind { key: KeyboardEvent["code"] | "LCLICK" | "RCLICK" | "MCLICK" | "LONG_PRESS"; key: | (KeyboardEvent["code"] & {}) | "LCLICK" | "RCLICK" | "MCLICK" | "LONG_PRESS"; alt?: boolean; ctrl?: boolean; Loading Loading @@ -70,6 +75,11 @@ const KEYBINDS = enforceObjectType({ ctrl: true, }, ], SNAPSHOT: [ { key: "KeyP", }, ], }); class KeybindManager_ extends EventEmitter<{ Loading