From 6d8047cd424d97dc717613dce301f2c412440d3e Mon Sep 17 00:00:00 2001 From: jollygrin Date: Mon, 1 Apr 2024 15:14:41 +0200 Subject: [PATCH 01/16] remove log --- components/Game/game.modal-template.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/components/Game/game.modal-template.tsx b/components/Game/game.modal-template.tsx index 9761816..b68c10b 100644 --- a/components/Game/game.modal-template.tsx +++ b/components/Game/game.modal-template.tsx @@ -121,7 +121,6 @@ export const ModalContainer: React.FC = ({ }), ); - console.log({ modalType, isOpen }); return ( <> !isCommit && onClose()}> From 5662c20a07ea7d01eb6f7aefaff2b2a6b7dafe17 Mon Sep 17 00:00:00 2001 From: jollygrin Date: Mon, 1 Apr 2024 15:14:48 +0200 Subject: [PATCH 02/16] add classname --- components/BoardCanvas/index.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/BoardCanvas/index.tsx b/components/BoardCanvas/index.tsx index a123068..5c5c380 100644 --- a/components/BoardCanvas/index.tsx +++ b/components/BoardCanvas/index.tsx @@ -53,7 +53,14 @@ export const BoardCanvas: React.FC = ({ backgroundColor: "ghostwhite", }} > - + ); From 63ea993c37ec23f0ee2bc9a8e34cf929b87aeeea Mon Sep 17 00:00:00 2001 From: jollygrin Date: Mon, 1 Apr 2024 15:47:12 +0200 Subject: [PATCH 03/16] working with inline svg --- .../{useCanvas.ts => useCanvas.tsx} | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) rename components/BoardCanvas/{useCanvas.ts => useCanvas.tsx} (77%) diff --git a/components/BoardCanvas/useCanvas.ts b/components/BoardCanvas/useCanvas.tsx similarity index 77% rename from components/BoardCanvas/useCanvas.ts rename to components/BoardCanvas/useCanvas.tsx index 4edc065..0fe63c5 100644 --- a/components/BoardCanvas/useCanvas.ts +++ b/components/BoardCanvas/useCanvas.tsx @@ -1,6 +1,7 @@ import * as d3 from "d3"; -import { MutableRefObject, RefObject, useEffect } from "react"; +import { MutableRefObject, RefObject, cloneElement, useEffect } from "react"; import { PositionType } from "../Positions/position.type"; +import { FaBan } from "react-icons/fa"; type CanvasProps = { canvasRef: RefObject; @@ -12,6 +13,12 @@ type CanvasProps = { move?: (e: PositionType) => void; }; +const Cir = () => ( + + + +); + /** * Handles the Canvas, placing and moving the circles with the incoming data * */ @@ -44,12 +51,15 @@ export const useCanvas = ({ } const g = d3.select(gRef.current); - g.selectAll("circle") + g.selectAll("g") .data(data) - .join("circle") - .attr("cx", ({ x }) => x) - .attr("cy", ({ y }) => y) - .attr("r", ({ r }) => (r ? r : 15)) + .join((enter) => enter.append("g")) + .attr("transform", (d) => `translate(${d.x}, ${d.y})`) + .html( + ``, + ) .attr("fill", ({ color }) => color ?? "black") // TODO: replace this to limit which token the user can control .attr("opacity", ({ id }) => (id.includes(self as string) ? 1 : 0.75)) From 9beba9f2cee9dce61572e351c46518a17ae8db75 Mon Sep 17 00:00:00 2001 From: jollygrin Date: Mon, 1 Apr 2024 16:00:56 +0200 Subject: [PATCH 04/16] working with icon --- components/BoardCanvas/useCanvas.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/BoardCanvas/useCanvas.tsx b/components/BoardCanvas/useCanvas.tsx index 0fe63c5..035d070 100644 --- a/components/BoardCanvas/useCanvas.tsx +++ b/components/BoardCanvas/useCanvas.tsx @@ -55,12 +55,12 @@ export const useCanvas = ({ .data(data) .join((enter) => enter.append("g")) .attr("transform", (d) => `translate(${d.x}, ${d.y})`) + .attr("fill", ({ color }) => color ?? "black") .html( - ` ); }; + +const TokenPreview = ({ + token, + selectedColor, + setImages, +}: { + token: PositionType; + selectedColor: string; + setImages: Dispatch>; +}) => { + const setImage = (url: string) => { + setImages((prev) => { + return [...prev?.filter((p) => p.id !== token.id), { id: token.id, url }]; + }); + }; + + return ( + + {token?.imageUrl ? ( + + ) : ( + + )} + + + Tokens + + + Your Tokens (via your bag) + + + + Default Tokens + + setImage("https://picsum.photos/200")}> + + + + + + ); +}; From 689ca353cd7e28ad3b8a6b7f1f77ce7cbb284bfa Mon Sep 17 00:00:00 2001 From: jollygrin Date: Mon, 1 Apr 2024 23:32:09 +0200 Subject: [PATCH 10/16] omg now it works with sidekicks --- components/Positions/position.modal.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/Positions/position.modal.tsx b/components/Positions/position.modal.tsx index 5569750..4dfa44e 100644 --- a/components/Positions/position.modal.tsx +++ b/components/Positions/position.modal.tsx @@ -52,6 +52,7 @@ export const PositionModal: FC<{ ] as PositionType; const [images, setImages] = useState<{ id: string; url: string }[]>([]); + console.log({ images }); const [selectedColor, setSelectedColor] = useState( selectedPosition?.color ?? "#000", @@ -82,6 +83,7 @@ export const PositionModal: FC<{ sidekicks: sidekicks?.map((kick) => ({ ...kick, color: selectedColor, + imageUrl: images?.find((img) => img.id === kick?.id)?.url ?? undefined, })), }); } From 276ff2765177fbb2abe68d19856f573267c162e5 Mon Sep 17 00:00:00 2001 From: jollygrin Date: Mon, 1 Apr 2024 23:52:33 +0200 Subject: [PATCH 11/16] working custom --- components/Positions/position.modal.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/components/Positions/position.modal.tsx b/components/Positions/position.modal.tsx index 4dfa44e..3aea90e 100644 --- a/components/Positions/position.modal.tsx +++ b/components/Positions/position.modal.tsx @@ -24,6 +24,7 @@ import { MenuOptionGroup, MenuDivider, FormLabel, + HStack, } from "@chakra-ui/react"; import { Dispatch, FC, SetStateAction, useCallback, useState } from "react"; import { MoonIcon, PlusSquareIcon, SunIcon } from "@chakra-ui/icons"; @@ -52,7 +53,7 @@ export const PositionModal: FC<{ ] as PositionType; const [images, setImages] = useState<{ id: string; url: string }[]>([]); - console.log({ images }); + console.log({ selectedPosition }); const [selectedColor, setSelectedColor] = useState( selectedPosition?.color ?? "#000", @@ -61,8 +62,9 @@ export const PositionModal: FC<{ const [sidekicks, setSidekicks] = useState< PositionType["sidekicks"] | undefined >(selectedPosition?.sidekicks); - const setSize = (size: Size) => - size === "lg" ? 2 : size === "md" ? 1.65 : 1.35; + + console.log({ sidekicks }); + const handleColorChange = ({ hex }: { hex: string }) => setSelectedColor(hex); const _setGamePosition = (props: PositionType) => { @@ -169,6 +171,10 @@ const TokenPreview = ({ }); }; + const [imageUrl, setImageUrl] = useState(""); + + console.log({ token }); + return ( {token?.imageUrl ? ( @@ -189,6 +195,13 @@ const TokenPreview = ({ Your Tokens (via your bag) + + setImageUrl(e.target.value)} + /> + + Default Tokens From f371c3d752f64784cb52421f18b0aa720df584e0 Mon Sep 17 00:00:00 2001 From: jollygrin Date: Tue, 2 Apr 2024 00:03:26 +0200 Subject: [PATCH 12/16] fix sidekicks --- components/Positions/position.modal.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/components/Positions/position.modal.tsx b/components/Positions/position.modal.tsx index 3aea90e..d5e2dc9 100644 --- a/components/Positions/position.modal.tsx +++ b/components/Positions/position.modal.tsx @@ -53,7 +53,6 @@ export const PositionModal: FC<{ ] as PositionType; const [images, setImages] = useState<{ id: string; url: string }[]>([]); - console.log({ selectedPosition }); const [selectedColor, setSelectedColor] = useState( selectedPosition?.color ?? "#000", @@ -63,7 +62,7 @@ export const PositionModal: FC<{ PositionType["sidekicks"] | undefined >(selectedPosition?.sidekicks); - console.log({ sidekicks }); + console.log("xxxxxxxxxxxx", selectedPosition?.sidekicks, sidekicks); const handleColorChange = ({ hex }: { hex: string }) => setSelectedColor(hex); @@ -128,6 +127,15 @@ export const PositionModal: FC<{ selectedColor={selectedColor} setImages={setImages} /> + {selectedPosition?.sidekicks?.map((kick) => ( + + ))} + {sidekicks?.map((kick) => ( Date: Tue, 2 Apr 2024 00:35:46 +0200 Subject: [PATCH 13/16] now will not reset othere tokens when opening model --- components/Positions/position.modal.tsx | 39 +++++++++++++------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/components/Positions/position.modal.tsx b/components/Positions/position.modal.tsx index d5e2dc9..a259a1d 100644 --- a/components/Positions/position.modal.tsx +++ b/components/Positions/position.modal.tsx @@ -34,6 +34,7 @@ import { useWebGame } from "@/lib/contexts/WebGameProvider"; import { CirclePicker } from "react-color"; import { PositionType, Size } from "./position.type"; import { useRouter } from "next/router"; +import { toast } from "react-hot-toast"; export const PositionModal: FC<{ isOpen: boolean; @@ -62,8 +63,6 @@ export const PositionModal: FC<{ PositionType["sidekicks"] | undefined >(selectedPosition?.sidekicks); - console.log("xxxxxxxxxxxx", selectedPosition?.sidekicks, sidekicks); - const handleColorChange = ({ hex }: { hex: string }) => setSelectedColor(hex); const _setGamePosition = (props: PositionType) => { @@ -80,11 +79,16 @@ export const PositionModal: FC<{ color: selectedColor, r: selectedSize === "lg" ? 20 : selectedSize === "md" ? 15 : 10, imageUrl: - images?.find((img) => img.id === selected?.id)?.url ?? undefined, + images?.find((img) => img.id === selected?.id)?.url ?? + selected?.imageUrl ?? + undefined, sidekicks: sidekicks?.map((kick) => ({ ...kick, color: selectedColor, - imageUrl: images?.find((img) => img.id === kick?.id)?.url ?? undefined, + imageUrl: + images?.find((img) => img.id === kick?.id)?.url ?? + kick?.imageUrl ?? + undefined, })), }); } @@ -106,7 +110,14 @@ export const PositionModal: FC<{ } return ( - + { + setSidekicks(selectedPosition?.sidekicks); + setImages([]); + onClose(); + }} + > @@ -136,15 +147,6 @@ export const PositionModal: FC<{ /> ))} - {sidekicks?.map((kick) => ( - - ))} - @@ -177,20 +179,20 @@ const TokenPreview = ({ setImages((prev) => { return [...prev?.filter((p) => p.id !== token.id), { id: token.id, url }]; }); + toast.success("New Image Prepared. Click Apply to confirm changes"); }; const [imageUrl, setImageUrl] = useState(""); - console.log({ token }); - return ( - + {token?.imageUrl ? ( ) : ( Your Tokens (via your bag) + {imageUrl && } Date: Tue, 2 Apr 2024 00:42:07 +0200 Subject: [PATCH 14/16] remove unused --- components/Positions/position.modal.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/components/Positions/position.modal.tsx b/components/Positions/position.modal.tsx index a259a1d..3ae6bcb 100644 --- a/components/Positions/position.modal.tsx +++ b/components/Positions/position.modal.tsx @@ -19,10 +19,6 @@ import { MenuList, MenuItem, Image, - MenuItemOption, - MenuGroup, - MenuOptionGroup, - MenuDivider, FormLabel, HStack, } from "@chakra-ui/react"; From 0981d1a6575c7cee2fd12676b5dc47caed73f040 Mon Sep 17 00:00:00 2001 From: jollygrin Date: Tue, 2 Apr 2024 01:15:59 +0200 Subject: [PATCH 15/16] size works and also temp sidekicks displays --- components/BoardCanvas/Tokens/index.tsx | 4 ++- components/BoardCanvas/useCanvas.tsx | 2 +- components/Positions/position.modal.tsx | 34 ++++++++++++++++++++----- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/components/BoardCanvas/Tokens/index.tsx b/components/BoardCanvas/Tokens/index.tsx index 27a70b2..bdfeaa2 100644 --- a/components/BoardCanvas/Tokens/index.tsx +++ b/components/BoardCanvas/Tokens/index.tsx @@ -5,9 +5,11 @@ const Image = ({ imageUrl }: { imageUrl: string }) => const Circle = ({ color, + size, }: { color?: string; -}) => ` + size?: number; +}) => ` `; diff --git a/components/BoardCanvas/useCanvas.tsx b/components/BoardCanvas/useCanvas.tsx index ae01ff1..40ae561 100644 --- a/components/BoardCanvas/useCanvas.tsx +++ b/components/BoardCanvas/useCanvas.tsx @@ -52,7 +52,7 @@ export const useCanvas = ({ .html((props) => props?.imageUrl ? TokenIcon.Image({ imageUrl: props.imageUrl }) - : TokenIcon.Circle({ color: props.color }), + : TokenIcon.Circle({ color: props.color, size: props.r }), ) // NOTE: Bellow attr & filter shows and limits user to moving their own tokens .attr("opacity", ({ id }) => (id.includes(self as string) ? 1 : 0.75)) diff --git a/components/Positions/position.modal.tsx b/components/Positions/position.modal.tsx index 3ae6bcb..5a9eea0 100644 --- a/components/Positions/position.modal.tsx +++ b/components/Positions/position.modal.tsx @@ -26,9 +26,11 @@ import { Dispatch, FC, SetStateAction, useCallback, useState } from "react"; import { MoonIcon, PlusSquareIcon, SunIcon } from "@chakra-ui/icons"; import { useWebGame } from "@/lib/contexts/WebGameProvider"; +import { MdUpload as IconUpload } from "react-icons/md"; + //@ts-ignore import { CirclePicker } from "react-color"; -import { PositionType, Size } from "./position.type"; +import { PositionType } from "./position.type"; import { useRouter } from "next/router"; import { toast } from "react-hot-toast"; @@ -54,7 +56,6 @@ export const PositionModal: FC<{ const [selectedColor, setSelectedColor] = useState( selectedPosition?.color ?? "#000", ); - const [selectedSize, setSelectedSize] = useState("lg"); const [sidekicks, setSidekicks] = useState< PositionType["sidekicks"] | undefined >(selectedPosition?.sidekicks); @@ -73,7 +74,6 @@ export const PositionModal: FC<{ setGamePosition({ ...selected, color: selectedColor, - r: selectedSize === "lg" ? 20 : selectedSize === "md" ? 15 : 10, imageUrl: images?.find((img) => img.id === selected?.id)?.url ?? selected?.imageUrl ?? @@ -81,6 +81,7 @@ export const PositionModal: FC<{ sidekicks: sidekicks?.map((kick) => ({ ...kick, color: selectedColor, + r: kick?.r ?? 50, imageUrl: images?.find((img) => img.id === kick?.id)?.url ?? kick?.imageUrl ?? @@ -103,8 +104,12 @@ export const PositionModal: FC<{ }, ]; }); + + toast.success("Preparing new token. Click apply to confirm changes"); } + const gameKickIds = selectedPosition?.sidekicks?.map((kick) => kick.id); + return ( ))} + + {sidekicks + ?.filter((kick) => !gameKickIds?.includes(kick.id)) + .map((kick) => ( + + ))} - + + + Clicking apply will reset token positions + @@ -199,15 +218,18 @@ const TokenPreview = ({ Tokens - Your Tokens (via your bag) + Add Token (via url) {imageUrl && } From 0d9f3dd9eb522501449b6bf33dd7671f043f577b Mon Sep 17 00:00:00 2001 From: jollygrin Date: Tue, 2 Apr 2024 01:46:14 +0200 Subject: [PATCH 16/16] adding default icons --- components/BoardCanvas/Tokens/index.tsx | 2 +- components/BoardCanvas/defaultTokenImages.ts | 21 ++++++++++++++++++++ components/Positions/position.modal.tsx | 13 +++++++----- public/tokens/Alien.svg | 5 +++++ public/tokens/BrickWall.svg | 5 +++++ public/tokens/CloudFog.svg | 5 +++++ public/tokens/Fire.svg | 5 +++++ public/tokens/Flag.svg | 5 +++++ public/tokens/HandShield.svg | 5 +++++ public/tokens/ShieldHalf.svg | 5 +++++ public/tokens/Totem.svg | 5 +++++ public/tokens/Trap.svg | 5 +++++ 12 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 components/BoardCanvas/defaultTokenImages.ts create mode 100644 public/tokens/Alien.svg create mode 100644 public/tokens/BrickWall.svg create mode 100644 public/tokens/CloudFog.svg create mode 100644 public/tokens/Fire.svg create mode 100644 public/tokens/Flag.svg create mode 100644 public/tokens/HandShield.svg create mode 100644 public/tokens/ShieldHalf.svg create mode 100644 public/tokens/Totem.svg create mode 100644 public/tokens/Trap.svg diff --git a/components/BoardCanvas/Tokens/index.tsx b/components/BoardCanvas/Tokens/index.tsx index bdfeaa2..0ada566 100644 --- a/components/BoardCanvas/Tokens/index.tsx +++ b/components/BoardCanvas/Tokens/index.tsx @@ -1,5 +1,5 @@ const Image = ({ imageUrl }: { imageUrl: string }) => - ` Tokens - + Add Token (via url) {imageUrl && } setImageUrl(e.target.value)} /> @@ -235,9 +236,11 @@ const TokenPreview = ({ Default Tokens - setImage("https://picsum.photos/200")}> - - + {DEFAULT_TOKEN_IMAGES.map((img) => ( + setImage(img)}> + + + ))} diff --git a/public/tokens/Alien.svg b/public/tokens/Alien.svg new file mode 100644 index 0000000..96bfd17 --- /dev/null +++ b/public/tokens/Alien.svg @@ -0,0 +1,5 @@ + + + diff --git a/public/tokens/BrickWall.svg b/public/tokens/BrickWall.svg new file mode 100644 index 0000000..2955fe7 --- /dev/null +++ b/public/tokens/BrickWall.svg @@ -0,0 +1,5 @@ + + + diff --git a/public/tokens/CloudFog.svg b/public/tokens/CloudFog.svg new file mode 100644 index 0000000..f285ca3 --- /dev/null +++ b/public/tokens/CloudFog.svg @@ -0,0 +1,5 @@ + + + diff --git a/public/tokens/Fire.svg b/public/tokens/Fire.svg new file mode 100644 index 0000000..e20cf65 --- /dev/null +++ b/public/tokens/Fire.svg @@ -0,0 +1,5 @@ + + + diff --git a/public/tokens/Flag.svg b/public/tokens/Flag.svg new file mode 100644 index 0000000..12b1710 --- /dev/null +++ b/public/tokens/Flag.svg @@ -0,0 +1,5 @@ + + + diff --git a/public/tokens/HandShield.svg b/public/tokens/HandShield.svg new file mode 100644 index 0000000..4775a39 --- /dev/null +++ b/public/tokens/HandShield.svg @@ -0,0 +1,5 @@ + + + diff --git a/public/tokens/ShieldHalf.svg b/public/tokens/ShieldHalf.svg new file mode 100644 index 0000000..3061fd3 --- /dev/null +++ b/public/tokens/ShieldHalf.svg @@ -0,0 +1,5 @@ + + + diff --git a/public/tokens/Totem.svg b/public/tokens/Totem.svg new file mode 100644 index 0000000..0e0c879 --- /dev/null +++ b/public/tokens/Totem.svg @@ -0,0 +1,5 @@ + + + diff --git a/public/tokens/Trap.svg b/public/tokens/Trap.svg new file mode 100644 index 0000000..5d8c5f5 --- /dev/null +++ b/public/tokens/Trap.svg @@ -0,0 +1,5 @@ + + +