diff --git a/public/coins/algeria/596.json b/public/coins/algeria/596.json index deb32d3..bb74128 100644 --- a/public/coins/algeria/596.json +++ b/public/coins/algeria/596.json @@ -95,5 +95,5 @@ "name": "Algiers" } ], - "color": "rgb(196,172,76)" + "color": "rgb(100,100,100)" } diff --git a/public/coins/colombia/7524.json b/public/coins/colombia/7524.json index f848f87..125b986 100644 --- a/public/coins/colombia/7524.json +++ b/public/coins/colombia/7524.json @@ -82,5 +82,5 @@ "name": "Fábrica de Moneda de Ibagué" } ], - "color": "rgb(153,134.05714285714288,102)" + "color": "rgb(45, 30, 20)" } diff --git a/src/components/coin/index.tsx b/src/components/coin/index.tsx index 5358239..0274d53 100644 --- a/src/components/coin/index.tsx +++ b/src/components/coin/index.tsx @@ -1,52 +1,26 @@ import * as THREE from "three"; import { useLoader } from "@react-three/fiber"; import { CoinProps } from "@/types/coin"; -import { Suspense, useEffect, useMemo } from "react"; +import { useEffect, useMemo } from "react"; -const SafeEdgeMaterial = ({ - color, - edge, -}: Pick) => { - try { - // eslint-disable-next-line react-hooks/rules-of-hooks - const edgeTexture: THREE.Texture = useLoader( - THREE.TextureLoader, - edge.picture, - ); - edgeTexture.repeat = new THREE.Vector2(2, 1); - edgeTexture.offset = new THREE.Vector2(0.5, 0); - edgeTexture.wrapS = THREE.MirroredRepeatWrapping; - edgeTexture.wrapT = THREE.MirroredRepeatWrapping; +const SafeEdgeMaterial = ({ edge }: Pick) => { + const edgeTexture: THREE.Texture = useLoader( + THREE.TextureLoader, + edge.picture, + ); + edgeTexture.repeat = new THREE.Vector2(4, 1); + edgeTexture.offset = new THREE.Vector2(0.5, 0); + edgeTexture.wrapS = THREE.MirroredRepeatWrapping; + edgeTexture.wrapT = THREE.MirroredRepeatWrapping; - return ( - - } - > - - - ); - } catch { - return ( - - ); - } + return ( + + ); }; export const CoinInstance = ({ @@ -55,16 +29,14 @@ export const CoinInstance = ({ thickness, color, obverse, - shape, reverse, edge, }: CoinProps) => { const sides = useMemo(() => { + //const parsed = Number(/(\d+)/.exec(shape)?.[0]); + //return Math.min(32, Math.max(4, isNaN(parsed) ? 32 : parsed)); return 32; - const parsed = Number(/(\d+)/.exec(shape)?.[0]); - return Math.min(32, Math.max(4, isNaN(parsed) ? 32 : parsed)); - }, [shape]); - //const edgeTexture = useLoader(THREE.TextureLoader, edge.picture); + }, []); const obverseTexture: THREE.Texture = useLoader( THREE.TextureLoader, obverse.picture, @@ -92,13 +64,25 @@ export const CoinInstance = ({ sides, ]} /> - + + {edge?.picture ? ( + + ) : ( + + )} + + { + const didInit = useRef(false); const { count = 1, size = 16, thickness = 2, weight = 4 } = coinProps; const [ref, { at }] = useCylinder( @@ -17,7 +18,10 @@ export const CoinInstances = (coinProps: CoinProps) => { ); useEffect(() => { - console.log("resetting"); + if (didInit.current) { + return; + } + didInit.current = true; Array.from({ length: count }).forEach((_, index) => { at(index).position.set( 8 * (Math.random() * 2 - 1), @@ -33,12 +37,7 @@ export const CoinInstances = (coinProps: CoinProps) => { }, [at, count]); return ( - + ); diff --git a/src/components/pile/index.tsx b/src/components/pile/index.tsx index 376f5b3..013c977 100644 --- a/src/components/pile/index.tsx +++ b/src/components/pile/index.tsx @@ -1,4 +1,4 @@ -import { Canvas } from "@react-three/fiber"; +import { Canvas, PointLightProps } from "@react-three/fiber"; import { OrbitControls } from "@react-three/drei"; import { useRef } from "react"; import { CoinInstances } from "./coin-instances"; @@ -13,19 +13,33 @@ type Props = { const Plane = (props: PlaneProps) => { const [ref] = usePlane(() => ({ ...props }), useRef(null)); return ( - + ); }; +const Lightbulb = (props: PointLightProps) => ( + <> + + + + + + +); + export const Pile = ({ coins }: Props) => ( - + - + + + + + {coins.map((coinProps) => ( diff --git a/src/components/showcase/index.tsx b/src/components/showcase/index.tsx index 751f5ab..d67c077 100644 --- a/src/components/showcase/index.tsx +++ b/src/components/showcase/index.tsx @@ -1,9 +1,8 @@ import { CoinProps } from "@/types/coin"; import { Canvas, MeshProps, useFrame } from "@react-three/fiber"; -import { Suspense, useRef, useState } from "react"; +import { Suspense, useEffect, useRef, useState } from "react"; import { CoinInstance } from "@/components/coin"; import { Mesh } from "three"; -import { OrbitControls } from "@react-three/drei"; import { BanknoteInstance } from "@/components/banknote"; import { InfoBox } from "./info-box"; @@ -78,7 +77,7 @@ const Row = ({ {types.map( (type, index) => Math.abs(index - selectedIndex) <= 1 && ( - + { const [selectedIndex, selectIndex] = useState(0); + useEffect(() => { + const onKeyDown = ({ key }: KeyboardEvent) => { + switch (key) { + case "ArrowLeft": + return selectIndex((value) => Math.max(value - 1, 0)); + case "ArrowRight": + return selectIndex((value) => + Math.min(value + 1, props.types.length - 1), + ); + } + }; + document.addEventListener("keydown", onKeyDown); + return () => document.removeEventListener("keydown", onKeyDown); + }, [props.types.length]); + return ( <> - + - {type.issuer.name}

{type.title}

-

{type.min_year + " - " + type.max_year}

+

+ {type.min_year !== type.max_year + ? type.min_year + " - " + type.max_year + : type.min_year} +

{(type.count ?? 1) + " in collection"} {category === "coins" && ( <> -

{type.weight + "g"}

-

{type.size + "mm"}

-

{type.thickness + "mm"}

+ {type.weight &&

{type.weight + "g"}

} + {type.size &&

{type.size + "mm"}

} + {type.thickness &&

{type.thickness + "mm"}

} )} @@ -66,6 +70,8 @@ export const InfoBox = ({ {"<-"} + {selectedIndex + 1 + "/" + (maxIndex + 1)} +