diff --git a/components/avatarcustomization/page.tsx b/components/avatarcustomization/page.tsx index 4fbfdfb..84a4070 100644 --- a/components/avatarcustomization/page.tsx +++ b/components/avatarcustomization/page.tsx @@ -1,6 +1,6 @@ "use client"; -import React, { FC, useEffect, useState } from "react"; +import React, { FC } from "react"; import { chuni_static_avatar } from "@/prisma/schemas/artemis/generated/artemis"; import { Check, ChevronsUpDown } from "lucide-react"; @@ -10,7 +10,6 @@ import { Command, CommandEmpty, CommandGroup, - CommandInput, CommandItem, CommandList, } from "@/components/ui/command"; @@ -34,6 +33,11 @@ import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { toast } from "../ui/use-toast"; +const getAvatarTextureSrc = (id: number | undefined) => { + if (id === undefined) return ""; + return `avatarAccessory/CHU_UI_Avatar_Tex_0${id}.png`; +}; + type AvatarSelectionProps = { avatarHeadSelectionData: { avatarParts: chunithm_avatar[]; @@ -62,19 +66,19 @@ export const AvatarCustomization: FC = ({ }) => { const FormSchema = z.object({ AvatarHeadAccessory: z.number({ - required_error: "Please select a language.", + required_error: "Please select an Avatar Head Item.", }), AvatarFaceAccessory: z.number({ - required_error: "Please select a language.", + required_error: "Please select an Avatar Face Item.", }), AvatarItemAccessory: z.number({ - required_error: "Please select a language.", + required_error: "Please select an Avatar Item.", }), AvatarBackAccessory: z.number({ - required_error: "Please select a language.", + required_error: "Please select an Avatar Back Item.", }), AvatarWearAccessory: z.number({ - required_error: "Please select a language.", + required_error: "Please select an Avatar Wear Item.", }), }); @@ -93,13 +97,57 @@ export const AvatarCustomization: FC = ({ }); } - const AvatarTextures: Record = { - AvatarFaceStatic: { - src: "avatarStatic/CHU_UI_Avatar_Tex_Face.png", - className: "avatar_face_static", + const getTexture = (id: number | undefined, defaultSrc: string) => { + return id ? getAvatarTextureSrc(id) : defaultSrc; + }; + + const AvatarTextures = { + AvatarHeadAccessory: { + src: getTexture( + form.watch("AvatarHeadAccessory"), + "avatarAccessory/CHU_UI_Avatar_Tex_DefaultHead.png" + ), + className: "avatar_head", }, - AvatarSkin: { - src: `avatarAccessory/CHU_UI_Avatar_Tex_0${1400001}.png`, + AvatarFaceAccessory: { + src: getTexture( + form.watch("AvatarFaceAccessory"), + "avatarAccessory/CHU_UI_Avatar_Tex_DefaultFace.png" + ), + className: "avatar_face", + }, + AvatarItemAccessoryR: { + src: getTexture( + form.watch("AvatarItemAccessory"), + "avatarAccessory/CHU_UI_Avatar_Tex_DefaultItem.png" + ), + className: "avatar_item_r ", + }, + + AvatarItemAccessoryL: { + src: getTexture( + form.watch("AvatarItemAccessory"), + "avatarAccessory/CHU_UI_Avatar_Tex_DefaultItem.png" + ), + className: "avatar_item_l ", + }, + + AvatarBackAccessory: { + src: getTexture( + form.watch("AvatarBackAccessory"), + "avatarAccessory/CHU_UI_Avatar_Tex_DefaultBack.png" + ), + className: "avatar_back", + }, + AvatarWearAccessory: { + src: getTexture( + form.watch("AvatarWearAccessory"), + "avatarAccessory/CHU_UI_Avatar_Tex_DefaultWear.png" + ), + className: "avatar_wear", + }, + avatarSkinAccessory: { + src: "avatarAccessory/CHU_UI_Avatar_Tex_01400001.png", className: "avatar_skin", }, AvatarRightHand: { @@ -118,43 +166,14 @@ export const AvatarCustomization: FC = ({ src: "avatarAccessory/CHU_UI_Avatar_Tex_01400001.png", className: "avatar_skinfoot_r", }, - - AvatarHeadAccessory: { - src: "avatarAccessory/CHU_UI_Avatar_Tex_06202301.png", - className: "avatar_head", - }, - - AvatarItemAccessoryR: { - src: "avatarAccessory/CHU_UI_Avatar_Tex_06502401.png", - className: "avatar_item_r", - }, - AvatarItemAccessoryL: { - src: "avatarAccessory/CHU_UI_Avatar_Tex_06502401.png", - className: "avatar_item_l", - }, - AvatarBackAccessory: { - src: "avatarAccessory/CHU_UI_Avatar_Tex_06703301.png", - className: "avatar_back", - }, - AvatarWearAccessory: { - src: "avatarAccessory/CHU_UI_Avatar_Tex_04103101.png", - className: "avatar_wear", - }, - - AvatarFace: { - src: "avatarAccessory/CHU_UI_Avatar_Tex_02300003.png", - className: "avatar_face", - }, - // not in use - AvatarFront: { - src: "avatarAccessory/CHU_UI_Avatar_Tex_01600001.png", - className: "avatar_front", + AvatarFaceStatic: { + src: "avatarStatic/CHU_UI_Avatar_Tex_Face.png", + className: "avatar_face_static", }, }; return (
- {" "}
@@ -186,8 +205,6 @@ export const AvatarCustomization: FC = ({ - {/* bugged */} - {/* */} No avatar part found. @@ -200,7 +217,6 @@ export const AvatarCustomization: FC = ({ "AvatarHeadAccessory", part.avatarAccessoryId! ); - console.log(part.avatarAccessoryId); }} > = ({ )} /> + = ({ - {/* bugged */} - {/* */} - No language found. + No avatar part found. {avatarFaceSelectionData.avatarParts.map((part) => ( = ({ )} /> + = ({ ? avatarItemSelectionData.avatarParts.find( (part) => part.avatarAccessoryId === field.value )?.name - : "Select Avatar Head Item"} + : "Select Avatar Face Item"} - {/* bugged */} - {/* */} No avatar part found. @@ -354,6 +368,7 @@ export const AvatarCustomization: FC = ({ )} /> + = ({ - {/* bugged */} - {/* */} No avatar part found. @@ -419,12 +432,13 @@ export const AvatarCustomization: FC = ({ )} /> + ( - Avatar Body Item + Avatar Clothing Item @@ -440,15 +454,13 @@ export const AvatarCustomization: FC = ({ ? avatarWearSelectionData.avatarParts.find( (part) => part.avatarAccessoryId === field.value )?.name - : "Select Avatar Body Item"} + : "Select Avatar Clothing Item"} - {/* bugged */} - {/* */} No avatar part found. @@ -493,7 +505,7 @@ export const AvatarCustomization: FC = ({
{Object.entries(AvatarTextures).map(([key, { className, src }]) => (
- {key} + {""}
))}