added chunithm version selector in admin settings

This commit is contained in:
Polaris
2024-08-20 16:49:01 -04:00
parent 552f737650
commit d6629a72eb
37 changed files with 614 additions and 107 deletions

View File

@ -1,11 +1,12 @@
"use server";
import { getAuth } from "@/auth/queries/getauth";
import { supportedVersionNumber } from "@/lib/helpers";
import { getSupportedVersionNumber } from "@/lib/api";
import { artemis } from "@/lib/prisma";
export async function getCurrentAvatarParts() {
const { user } = await getAuth();
const supportedVersionNumber = await getSupportedVersionNumber();
if (!user || !user.accessCode) {
throw new Error("User is not authenticated or accessCode is missing");
@ -36,6 +37,7 @@ export async function updateAvatarParts(
avatarItem?: number,
) {
const { user } = await getAuth();
const supportedVersionNumber = await getSupportedVersionNumber();
if (!user || !user.accessCode) {
throw new Error("User is not authenticated or accessCode is missing");
@ -69,6 +71,7 @@ export async function updateAvatarParts(
export async function getAllAvatarParts(category: number) {
const { user } = await getAuth();
const supportedVersionNumber = await getSupportedVersionNumber();
if (!user || !user.accessCode) {
throw new Error("User is not authenticated or accessCode is missing");

View File

@ -34,11 +34,10 @@ import { toast } from "../../ui/use-toast";
import { updateAvatarParts } from "./actions";
type chunithm_avatar = chuni_static_avatar;
const getAvatarTextureSrc = (id: number | undefined) => {
if (id === undefined) return "";
return `avatarAccessory/CHU_UI_Avatar_Tex_0${id}.png`;
}
};
type AvatarSelectionProps = {
avatarHeadSelectionData: {
@ -116,18 +115,18 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
}, []);
function onSubmit(data: z.infer<typeof FormSchema>) {
// Existing state
const unchangedHeadId = avatarHeadId;
const unchangedFaceId = avatarFaceId;
const unchangedBackId = avatarBackId;
const unchangedWearId = avatarWearId;
const unchangedItemId = avatarItemId;
const defaultHeadId = avatarHeadId;
const defaultFaceId = avatarFaceId;
const defaultBackId = avatarBackId;
const defaultWearId = avatarWearId;
const defaultItemId = avatarItemId;
// either change to the new body part id or fallback to the unchanged if nothing has changed
const newHeadId = data.AvatarHeadAccessory ?? unchangedHeadId;
const newFaceId = data.AvatarFaceAccessory ?? unchangedFaceId;
const newBackId = data.AvatarBackAccessory ?? unchangedBackId;
const newWearId = data.AvatarWearAccessory ?? unchangedWearId;
const newItemId = data.AvatarItemAccessory ?? unchangedItemId;
// either change to the new body part id or fallback to the default if nothing has changed
const newHeadId = data.AvatarHeadAccessory ?? defaultHeadId;
const newFaceId = data.AvatarFaceAccessory ?? defaultFaceId;
const newBackId = data.AvatarBackAccessory ?? defaultBackId;
const newWearId = data.AvatarWearAccessory ?? defaultWearId;
const newItemId = data.AvatarItemAccessory ?? defaultItemId;
updateAvatarParts(newHeadId, newFaceId, newBackId, newWearId, newItemId)
.then(() => {
@ -265,7 +264,7 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
name="AvatarHeadAccessory"
render={({ field }) => (
<FormItem className="flex flex-col">
<FormLabel>Avatar Head Item</FormLabel>
<FormLabel className="pb-2">Avatar Head Item</FormLabel>
<Popover>
<PopoverTrigger asChild>
<FormControl>
@ -330,7 +329,7 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
name="AvatarFaceAccessory"
render={({ field }) => (
<FormItem className="flex flex-col">
<FormLabel>Avatar Face Item</FormLabel>
<FormLabel className="pb-2">Avatar Face Item</FormLabel>
<Popover>
<PopoverTrigger asChild>
<FormControl>
@ -395,7 +394,7 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
name="AvatarItemAccessory"
render={({ field }) => (
<FormItem className="flex flex-col">
<FormLabel>Avatar Hand Item</FormLabel>
<FormLabel className="pb-2">Avatar Hand Item</FormLabel>
<Popover>
<PopoverTrigger asChild>
<FormControl>
@ -460,7 +459,7 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
name="AvatarBackAccessory"
render={({ field }) => (
<FormItem className="flex flex-col">
<FormLabel>Avatar Back Item</FormLabel>
<FormLabel className="pb-2">Avatar Back Item</FormLabel>
<Popover>
<PopoverTrigger asChild>
<FormControl>
@ -525,7 +524,7 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
name="AvatarWearAccessory"
render={({ field }) => (
<FormItem className="flex flex-col">
<FormLabel>Avatar Clothing Item</FormLabel>
<FormLabel className="pb-2">Avatar Clothing Item</FormLabel>
<Popover>
<PopoverTrigger asChild>
<FormControl>