Commit 6ae9cd3b authored by timel's avatar timel

Merge branch 'dev/sort-in-deck' into 'main'

feat: sort more naturally

See merge request !257
parents df5d859d ab07addb
...@@ -113,6 +113,25 @@ export function tellCardBasicType(typeCode: number): number { ...@@ -113,6 +113,25 @@ export function tellCardBasicType(typeCode: number): number {
return basicTypes.reduce((acc, cur) => (acc | cur) & typeCode, 0); 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 { export function isToken(typeCode: number): boolean {
return (typeCode & TYPE_TOKEN) > 0; return (typeCode & TYPE_TOKEN) > 0;
......
import { type CardMeta, fetchCard } from "@/api"; import { type CardMeta, fetchCard } from "@/api";
import { tellCardBasicType } from "@/common"; import { tellCardBasicType, tellCardSecondaryType } from "@/common";
import { type IDeck } from "@/stores"; import { type IDeck } from "@/stores";
export type Type = "main" | "extra" | "side"; export type Type = "main" | "extra" | "side";
...@@ -33,6 +33,9 @@ export const compareCards = (a: CardMeta, b: CardMeta): number => { ...@@ -33,6 +33,9 @@ export const compareCards = (a: CardMeta, b: CardMeta): number => {
const aType = tellCardBasicType(a.data.type ?? 0); const aType = tellCardBasicType(a.data.type ?? 0);
const bType = tellCardBasicType(b.data.type ?? 0); const bType = tellCardBasicType(b.data.type ?? 0);
if (aType !== bType) return aType - bType; 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; 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