Newer
Older
taehui / qwilight-fe / src / utilities / Utility.ts
@Taehui Taehui on 26 Mar 4 KB v1.0.0
import { AbilitySiteYell } from "@/app/[language]/site/type";
import i10 from "@/assets/i10.png";
import i11 from "@/assets/i11.png";
import i12 from "@/assets/i12.png";
import i13 from "@/assets/i13.png";
import i14 from "@/assets/i14.png";
import i15 from "@/assets/i15.png";
import i16 from "@/assets/i16.png";
import i4 from "@/assets/i4.png";
import i5 from "@/assets/i5.png";
import i6 from "@/assets/i6.png";
import i7 from "@/assets/i7.png";
import i8 from "@/assets/i8.png";
import i9 from "@/assets/i9.png";
import m00 from "@/assets/m00.png";
import m01 from "@/assets/m01.png";
import m10 from "@/assets/m10.png";
import m11 from "@/assets/m11.png";
import m111 from "@/assets/m111.png";
import m113 from "@/assets/m113.png";
import m12 from "@/assets/m12.png";
import m120 from "@/assets/m120.png";
import m121 from "@/assets/m121.png";
import m14 from "@/assets/m14.png";
import m20 from "@/assets/m20.png";
import m21 from "@/assets/m21.png";
import m22 from "@/assets/m22.png";
import m23 from "@/assets/m23.png";
import m30 from "@/assets/m30.png";
import m31 from "@/assets/m31.png";
import m32 from "@/assets/m32.png";
import m33 from "@/assets/m33.png";
import m34 from "@/assets/m34.png";
import m40 from "@/assets/m40.png";
import m41 from "@/assets/m41.png";
import m42 from "@/assets/m42.png";
import m43 from "@/assets/m43.png";
import m44 from "@/assets/m44.png";
import m45 from "@/assets/m45.png";
import m47 from "@/assets/m47.png";
import m50 from "@/assets/m50.png";
import m51 from "@/assets/m51.png";
import m53 from "@/assets/m53.png";
import m54 from "@/assets/m54.png";
import m55 from "@/assets/m55.png";
import m60 from "@/assets/m60.png";
import m61 from "@/assets/m61.png";
import m70 from "@/assets/m70.png";
import m710 from "@/assets/m710.png";
import m711 from "@/assets/m711.png";
import m712 from "@/assets/m712.png";
import m713 from "@/assets/m713.png";
import m714 from "@/assets/m714.png";
import m715 from "@/assets/m715.png";
import m716 from "@/assets/m716.png";
import m74 from "@/assets/m74.png";
import m75 from "@/assets/m75.png";
import m76 from "@/assets/m76.png";
import m77 from "@/assets/m77.png";
import m78 from "@/assets/m78.png";
import m79 from "@/assets/m79.png";
import m80 from "@/assets/m80.png";
import m81 from "@/assets/m81.png";
import { useTranslations } from "next-intl";

export const is = [
  "",
  "",
  "",
  "",
  i4,
  i5,
  i6,
  i7,
  i8,
  i9,
  i10,
  i11,
  i12,
  i13,
  i14,
  i15,
  i16,
];
export const m0s = [m00, m01];
export const m1s = [
  m10,
  m11,
  m12,
  "",
  m14,
  "",
  "",
  "",
  "",
  "",
  "",
  m111,
  "",
  m113,
  "",
];
export const m2s = [m20, m21, m22, m23];
export const m3s = [m30, m31, m32, m33, m34];
export const m4s = [m40, m41, m42, m43, m44, m45, "", m47];
export const m5s = [m50, m51, "", m53, m54, m55];
export const m6s = [m60, m61];
export const m7s = [
  m70,
  "",
  "",
  "",
  m74,
  m75,
  m76,
  m77,
  m78,
  m79,
  m710,
  m711,
  m712,
  m713,
  m714,
  m715,
  m716,
];
export const m8s = [m80, m81];
export const m12s = [m120, m121];

export const formatText = (value: number) => {
  return Number(value.toFixed(2))
    .toString()
    .replace(/\B(?=(\d{3})+(?!\d))/g, ",");
};

export const getGenreText = (genre: string) =>
  genre.length === 0 || genre.startsWith("#") ? genre : `#${genre}`;

export const getAbilityUpText = (
  t: ReturnType<typeof useTranslations>,
  { inputMode, ability }: AbilitySiteYell,
) => {
  let inputModeText = "";
  switch (inputMode) {
    case 10:
      inputModeText = "⑤K";
      break;
    case 11:
      inputModeText = "⑦K";
      break;
    case 9:
      inputModeText = "9K";
      break;
  }
  return ability < 0.01
    ? `${inputModeText} < 0.01 Point ↑`
    : `${inputModeText} ${ability.toFixed(2)} Point ↑`;
};

export const getSiteName = (
  siteName: string,
  t: ReturnType<typeof useTranslations<string>>,
) => {
  switch (siteName) {
    case "@Comment":
      return t("commentSiteName");
    case "@Notify":
      return t("toNotifySiteName");
    case "@Default":
      return t("defaultSiteName");
    case "@Platform":
      return t("platformSiteName");
    default:
      return siteName;
  }
};

export const getQuitStatusValue = (
  point: number,
  stand: number,
): {
  quitCss: "S+" | "S" | "A+" | "A" | "B" | "C" | "D";
  quit: string;
} => {
  const quitCss =
    point < 0.8
      ? "D"
      : point < 0.85
        ? "C"
        : point < 0.9
          ? "B"
          : point < 0.95
            ? "A"
            : stand < 900000
              ? "A+"
              : point < 1.0
                ? "S"
                : "S+";

  return {
    quitCss,
    quit: quitCss,
  };
};

export const getDefaultAvatarID = (avatarID: string) =>
  avatarID.substring(avatarID.indexOf("@") + 1);