44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
export type TalentRelation = "gt" | "gte";
|
|
|
|
export interface TalentPriority {
|
|
type: "NA" | "E" | "Q";
|
|
priority: number;
|
|
level?: string;
|
|
relationToNext?: TalentRelation;
|
|
}
|
|
|
|
export function normalizeTalentPriorities(talents: readonly TalentPriority[]): TalentPriority[] {
|
|
const ordered = [...talents].sort((a, b) => a.priority - b.priority);
|
|
return ordered.map((talent, index) => ({
|
|
...talent,
|
|
priority: index + 1,
|
|
relationToNext: index < ordered.length - 1 ? talent.relationToNext ?? "gt" : undefined,
|
|
}));
|
|
}
|
|
|
|
export function reorderTalentPriorities(
|
|
talents: readonly TalentPriority[],
|
|
activeType: TalentPriority["type"],
|
|
overType: TalentPriority["type"],
|
|
): TalentPriority[] {
|
|
const ordered = normalizeTalentPriorities(talents);
|
|
const from = ordered.findIndex((talent) => talent.type === activeType);
|
|
const to = ordered.findIndex((talent) => talent.type === overType);
|
|
if (from < 0 || to < 0 || from === to) return ordered;
|
|
|
|
const relations = ordered.slice(0, -1).map((talent) => talent.relationToNext ?? "gt");
|
|
const next = [...ordered];
|
|
const [moved] = next.splice(from, 1);
|
|
next.splice(to, 0, moved);
|
|
|
|
return next.map((talent, index) => ({
|
|
...talent,
|
|
priority: index + 1,
|
|
relationToNext: index < next.length - 1 ? relations[index] : undefined,
|
|
}));
|
|
}
|
|
|
|
export function talentRelationSymbol(relation?: TalentRelation): ">" | "≥" {
|
|
return relation === "gte" ? "≥" : ">";
|
|
}
|