Commit ab07addb authored by timel's avatar timel

feat: sort more naturally

parent f0a2423d
Pipeline #23092 passed with stages
in 13 minutes and 9 seconds
......@@ -113,6 +113,25 @@ export function tellCardBasicType(typeCode: number): number {
return basicTypes.reduce((acc, cur) => (acc | cur) & typeCode, 0);
}
/** 获取更加细分的分类 */
export function tellCardSecondaryType(typeCode: number): number {
const secondaryType = [
TYPE_NORMAL,
TYPE_FUSION,
TYPE_RITUAL,
TYPE_SYNCHRO,
TYPE_XYZ,
TYPE_PENDULUM,
TYPE_LINK,
TYPE_QUICKPLAY,
TYPE_CONTINUOUS,
TYPE_EQUIP,
TYPE_FIELD,
TYPE_COUNTER,
];
return secondaryType.reduce((acc, cur) => (acc | cur) & typeCode, 0);
}
/** 是不是衍生物 */
export function isToken(typeCode: number): boolean {
return (typeCode & TYPE_TOKEN) > 0;
......
import { type CardMeta, fetchCard } from "@/api";
import { tellCardBasicType } from "@/common";
import { tellCardBasicType, tellCardSecondaryType } from "@/common";
import { type IDeck } from "@/stores";
export type Type = "main" | "extra" | "side";
......@@ -33,6 +33,9 @@ export const compareCards = (a: CardMeta, b: CardMeta): number => {
const aType = tellCardBasicType(a.data.type ?? 0);
const bType = tellCardBasicType(b.data.type ?? 0);
if (aType !== bType) return aType - bType;
const aSecondaryType = tellCardSecondaryType(a.data.type ?? 0);
const bSecondaryType = tellCardSecondaryType(b.data.type ?? 0);
if (aSecondaryType !== bSecondaryType) return aSecondaryType - bSecondaryType;
return a.id - b.id;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment