added trophies

This commit is contained in:
Polaris 2024-07-26 13:19:37 -04:00
parent 5cbe2c3ad2
commit 5af3b9236b
12 changed files with 515 additions and 100 deletions

View File

@ -2,10 +2,12 @@
//https://github.com/vercel/next.js/discussions/63862
import React from "react";
import { AvatarCustomization } from "@/components/avatarcustomization/page";
import { AvatarCustomization } from "@/components/(customization)/avatarcustomization/page";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import ChunithmScorePlaylog from "@/components/scoreplaylog/page";
import { getAllAvatarParts } from "@/components/avatarcustomization/actions";
import { getAllAvatarParts } from "@/components/(customization)/avatarcustomization/actions";
import { TrophyCustomization } from "@/components/(customization)/trophycustomization/page";
import { getTrophies } from "@/components/(customization)/trophycustomization/actions";
// the number is the category id for the specific part
@ -31,6 +33,10 @@ const getAvatarWearAccessories = async () => {
const avatarParts = await getAllAvatarParts(1); // wear
return { avatarParts };
};
const getAllTrophies = async () => {
const statictrophies = await getTrophies();
return { statictrophies };
};
const Page = async () => {
const AvatarHeadAccessories = await getAvatarHeadAccessories();
@ -38,7 +44,7 @@ const Page = async () => {
const AvatarItemAccessories = await getAvatarItemAccessories();
const AvatarBackAccessories = await getAvatarBackAccessories();
const AvatarWearAccessories = await getAvatarWearAccessories();
const AllPlayerTrophies = await getAllTrophies();
return (
<div className="p-10">
<Tabs defaultValue="scores">
@ -58,6 +64,9 @@ const Page = async () => {
avatarBackSelectionData={AvatarBackAccessories}
avatarWearSelectionData={AvatarWearAccessories}
/>
<div className="pt-4">
<TrophyCustomization allTrophies={AllPlayerTrophies} />
</div>
</div>
<div></div>
</TabsContent>

View File

@ -30,7 +30,7 @@ import {
import { z } from "zod";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { toast } from "../ui/use-toast";
import { toast } from "../../ui/use-toast";
const getAvatarTextureSrc = (id: number | undefined) => {
if (id === undefined) return "";

View File

@ -0,0 +1,44 @@
"use server";
import { getAuth } from "@/auth/queries/getauth";
import { artemis, daphnis } from "@/lib/prisma";
import type * as Prisma from "@prisma/client";
export async function getCurrentTrophies() {
const { user } = await getAuth();
if (!user || !user.accessCode) {
throw new Error("User is not authenticated or accessCode is missing");
}
const avatarParts = await artemis.chuni_profile_data.findMany({
where: {
user: user.UserId,
},
select: {
trophyId: true,
},
});
return avatarParts;
}
export async function getTrophies() {
const { user } = await getAuth();
if (!user || !user.accessCode) {
throw new Error("User is not authenticated or accessCode is missing");
}
const staticTrophies = await artemis.cozynet_chuni_static_trophies.findMany({
select: {
category: true,
netOpenName: true,
id: true,
str: true,
imagePath: true,
rareType: true,
sortName: true,
},
});
return staticTrophies;
}

View File

@ -0,0 +1,159 @@
"use client";
import React, { FC, useEffect, useState } from "react";
import { chuni_static_avatar } from "@/prisma/schemas/artemis/generated/artemis";
import { Check, ChevronsUpDown } from "lucide-react";
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
import {
Command,
CommandEmpty,
CommandGroup,
CommandItem,
CommandList,
} from "@/components/ui/command";
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
import { z } from "zod";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { toast } from "../../ui/use-toast";
import { getCurrentTrophies } from "./actions";
import { cozynet_chuni_static_trophies } from "@/prisma/schemas/artemis/generated/artemis";
const getAvatarTextureSrc = (id: number | undefined) => {
if (id === undefined) return "";
return `avatarAccessory/CHU_UI_Avatar_Tex_0${id}.png`;
};
type static_trophies = cozynet_chuni_static_trophies;
type AvatarSelectionProps = {
allTrophies: {
statictrophies: static_trophies[];
};
};
export const TrophyCustomization: FC<AvatarSelectionProps> = ({
allTrophies,
}) => {
const FormSchema = z.object({
trophies: z.number({
required_error: "Please select a trophy",
}),
});
const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
});
const [trophyID, setTrophyId] = useState<number | undefined>(undefined);
useEffect(() => {
const fetchAvatarParts = async () => {
try {
const data = await getCurrentTrophies();
if (data.length > 0) {
setTrophyId(data[0].trophyId!);
}
} catch (error) {
console.error("Error fetching avatar parts:", error);
}
};
fetchAvatarParts();
}, []);
function onSubmit(data: z.infer<typeof FormSchema>) {
toast({
title: "You submitted the following values:",
description: (
<pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4">
<code className="text-white">{JSON.stringify(data, null, 2)}</code>
</pre>
),
});
}
return (
<main className="flex">
<div>
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
<FormField
control={form.control}
name="trophies"
render={({ field }) => (
<FormItem className="flex flex-col">
<FormLabel>Select Trophy</FormLabel>
<Popover>
<PopoverTrigger asChild>
<FormControl>
<Button
variant="outline"
role="combobox"
className={cn(
"w-[300px] justify-between",
!field.value && "text-muted-foreground"
)}
>
{field.value
? allTrophies.statictrophies.find(
(part) => part.id === field.value
)?.str
: "Select Trophy"}
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
</Button>
</FormControl>
</PopoverTrigger>
<PopoverContent className="w-[300px] p-0">
<Command>
<CommandList>
<CommandEmpty>No avatar part found.</CommandEmpty>
<CommandGroup>
{allTrophies.statictrophies.map((part) => (
<CommandItem
value={part.id.toString()}
key={part.id}
onSelect={() => {
form.setValue("trophies", part.id);
}}
>
<Check
className={cn(
"mr-2 h-4 w-4",
part.id === field.value
? "opacity-100"
: "opacity-0"
)}
/>
{part.str}
</CommandItem>
))}
</CommandGroup>
</CommandList>
</Command>
</PopoverContent>
</Popover>
<FormMessage />
</FormItem>
)}
/>
<Button type="submit">Submit</Button>
</form>
</Form>
</div>
</main>
);
};

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
{
"name": "prisma-client-3056db8b32416c07252edb0f7313d77f3db89f1320663af66d1fe1ef3a36867d",
"name": "prisma-client-f7a2b48b408a7f3a362fd03ca4242cefade16b31cca8f5822f535e5fe24aeeca",
"main": "index.js",
"types": "index.d.ts",
"browser": "index-browser.js",

View File

@ -1022,7 +1022,7 @@ model cozynet_artemisapi_sessions {
}
model cozynet_chuni_static_accessory {
id String @id @db.VarChar(255)
id Int @id @default(autoincrement())
str String? @db.VarChar(255)
imagePath String? @db.VarChar(255)
sortName String? @db.VarChar(255)
@ -1032,7 +1032,7 @@ model cozynet_chuni_static_accessory {
}
model cozynet_chuni_static_mapicon {
id String @id @db.VarChar(255)
id Int @id @default(autoincrement())
str String? @db.VarChar(255)
imagePath String? @db.VarChar(255)
sortName String? @db.VarChar(255)
@ -1042,7 +1042,7 @@ model cozynet_chuni_static_mapicon {
}
model cozynet_chuni_static_nameplate {
id String @id @db.VarChar(255)
id Int @id @default(autoincrement())
str String? @db.VarChar(255)
imagePath String? @db.VarChar(255)
sortName String? @db.VarChar(255)
@ -1052,7 +1052,7 @@ model cozynet_chuni_static_nameplate {
}
model cozynet_chuni_static_systemvoice {
id String @id @db.VarChar(255)
id Int @id @default(autoincrement())
str String? @db.VarChar(255)
imagePath String? @db.VarChar(255)
sortName String? @db.VarChar(255)
@ -1062,7 +1062,7 @@ model cozynet_chuni_static_systemvoice {
}
model cozynet_chuni_static_trophies {
id String @id @db.VarChar(255)
id Int @id @default(autoincrement())
str String? @db.VarChar(255)
imagePath String? @db.VarChar(255)
sortName String? @db.VarChar(255)

View File

@ -179,7 +179,6 @@ const config = {
"db"
],
"activeProvider": "mysql",
"postinstall": false,
"inlineDatasources": {
"db": {
"url": {

View File

@ -180,7 +180,6 @@ const config = {
"db"
],
"activeProvider": "mysql",
"postinstall": false,
"inlineDatasources": {
"db": {
"url": {