added update functions
This commit is contained in:
@ -31,7 +31,11 @@ import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { toast } from "../../ui/use-toast";
|
||||
import { cozynet_chuni_static_systemvoice } from "@/prisma/schemas/artemis/generated/artemis";
|
||||
import { getCurrentSystemVoice, getSystemVoices } from "./actions";
|
||||
import {
|
||||
getCurrentSystemVoice,
|
||||
getSystemVoices,
|
||||
updatePlayerSystemVoiceId,
|
||||
} from "./actions";
|
||||
|
||||
const getNamePlateTextures = (id: number | undefined) => {
|
||||
if (id === undefined) return "";
|
||||
@ -62,7 +66,7 @@ export const SystemVoiceCustomization: FC<SystemVoiceSelectionProps> = ({
|
||||
});
|
||||
|
||||
const [systemVoiceId, setSytemVoiceId] = useState<number | undefined>(
|
||||
undefined
|
||||
undefined,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@ -81,6 +85,14 @@ export const SystemVoiceCustomization: FC<SystemVoiceSelectionProps> = ({
|
||||
}, []);
|
||||
|
||||
function onSubmit(data: z.infer<typeof FormSchema>) {
|
||||
const unchagedSystemVoiceId = systemVoiceId;
|
||||
const newSystemVoiceId = data.PlayerSystemVoice ?? unchagedSystemVoiceId;
|
||||
|
||||
updatePlayerSystemVoiceId(newSystemVoiceId).then(() => {
|
||||
setSytemVoiceId(newSystemVoiceId);
|
||||
});
|
||||
resetFormValues();
|
||||
|
||||
toast({
|
||||
title: "You submitted the following values:",
|
||||
description: (
|
||||
@ -89,18 +101,24 @@ export const SystemVoiceCustomization: FC<SystemVoiceSelectionProps> = ({
|
||||
</pre>
|
||||
),
|
||||
});
|
||||
|
||||
function resetFormValues() {
|
||||
form.reset({
|
||||
PlayerSystemVoice: undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const getTexture = (id: number | undefined, defaultSrc: string) => {
|
||||
return id ? getNamePlateTextures(id) : defaultSrc;
|
||||
};
|
||||
|
||||
const AvatarTextures = {
|
||||
AvatarHeadAccessory: {
|
||||
const systemVoiceTextures = {
|
||||
SystemVoice: {
|
||||
src: systemVoiceId
|
||||
? getTexture(
|
||||
form.watch("PlayerSystemVoice"),
|
||||
`systemVoiceThumbnails/CHU_UI_SystemVoice_${systemVoiceId.toString().padStart(8, "0")}.png`
|
||||
`systemVoiceThumbnails/CHU_UI_SystemVoice_${systemVoiceId.toString().padStart(8, "0")}.png`,
|
||||
)
|
||||
: `systemVoiceThumbnails/CHU_UI_SystemVoice_Default.png`, // Provide a default texture or handle the case when systemVoiceId is undefined
|
||||
},
|
||||
@ -109,9 +127,9 @@ export const SystemVoiceCustomization: FC<SystemVoiceSelectionProps> = ({
|
||||
return (
|
||||
<main className="flex flex-col items-center space-y-6">
|
||||
{/* Avatar Customization Section */}
|
||||
<div className="w-full flex justify-center">
|
||||
<div className="flex w-full justify-center">
|
||||
<div className="">
|
||||
{Object.entries(AvatarTextures).map(([key, { src }]) => (
|
||||
{Object.entries(systemVoiceTextures).map(([key, { src }]) => (
|
||||
<div>
|
||||
<img className="w-[200px]" src={src} alt={""} />
|
||||
</div>
|
||||
@ -134,12 +152,12 @@ export const SystemVoiceCustomization: FC<SystemVoiceSelectionProps> = ({
|
||||
role="combobox"
|
||||
className={cn(
|
||||
"w-[300px] justify-between",
|
||||
!field.value && "text-muted-foreground"
|
||||
!field.value && "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{field.value
|
||||
? playerSystemVoiceSelectionData.systemVoices.find(
|
||||
(part) => part.id === field.value
|
||||
(part) => part.id === field.value,
|
||||
)?.str
|
||||
: "Select System Voice"}
|
||||
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
@ -165,12 +183,12 @@ export const SystemVoiceCustomization: FC<SystemVoiceSelectionProps> = ({
|
||||
"mr-2 h-4 w-4",
|
||||
part.id === field.value
|
||||
? "opacity-100"
|
||||
: "opacity-0"
|
||||
: "opacity-0",
|
||||
)}
|
||||
/>
|
||||
{part.str}
|
||||
</CommandItem>
|
||||
)
|
||||
),
|
||||
)}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
|
Reference in New Issue
Block a user