feat : update mutilple apply
This commit is contained in:
@@ -39,7 +39,7 @@ describe("custom Traveler catalog", () => {
|
||||
{ key: "traveler_geo", name: "Geo Traveler" },
|
||||
{ key: "traveler_electro", name: "Electro Traveler" },
|
||||
{ key: "traveler_dendro", name: "Dendro Traveler" },
|
||||
{ key: "traveler_cryo", name: "Cryo Traveler" },
|
||||
{ key: "traveler_cryo", name: "Cyro Traveler" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,6 +23,24 @@ describe("team bulk tools", () => {
|
||||
expect(applyTeamFields([source], "source", new Set(["source"]), ["combo"])).toEqual([source]);
|
||||
});
|
||||
|
||||
it("copies one field for one character slot only", () => {
|
||||
const source = team("source");
|
||||
const target = team("target");
|
||||
source.members[0] = { ...source.members[0], characterKey: "mavuika", refinement: 1 };
|
||||
target.members[0] = { ...target.members[0], characterKey: "keep-character", refinement: 5 };
|
||||
|
||||
const result = applyTeamFields(
|
||||
[source, target],
|
||||
"source",
|
||||
new Set(["target"]),
|
||||
["member:0:refinement"],
|
||||
);
|
||||
|
||||
expect(result[1].members[0].refinement).toBe(1);
|
||||
expect(result[1].members[0].characterKey).toBe("keep-character");
|
||||
expect(result[1].members.slice(1)).toEqual(target.members.slice(1));
|
||||
});
|
||||
|
||||
it("deduplicates and limits presets", () => {
|
||||
const presets = Array.from({ length: 7 }, (_, index) => ({ id: String(index), name: String(index), createdAt: String(index), team: { ...team(String(index)), clientId: undefined as never } }));
|
||||
expect(limitPresets([presets[0], presets[0], ...presets.slice(1)])).toHaveLength(5);
|
||||
|
||||
@@ -19,6 +19,20 @@ export interface TeamToolValue {
|
||||
export const teamApplyFields = ["loadout", "damage", "rotation", "combo"] as const;
|
||||
export type TeamApplyField = (typeof teamApplyFields)[number];
|
||||
|
||||
export const teamMemberApplyFields = [
|
||||
"characterKey",
|
||||
"weaponKey",
|
||||
"artifactKey",
|
||||
"secondArtifactKey",
|
||||
"constellation",
|
||||
"refinement",
|
||||
"damage",
|
||||
] as const;
|
||||
export type TeamMemberApplyField = (typeof teamMemberApplyFields)[number];
|
||||
export type TeamApplySelection =
|
||||
| TeamApplyField
|
||||
| `member:${number}:${TeamMemberApplyField}`;
|
||||
|
||||
export interface TeamPreset {
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -38,7 +52,7 @@ export function applyTeamFields(
|
||||
teams: readonly TeamToolValue[],
|
||||
sourceId: string,
|
||||
targetIds: ReadonlySet<string>,
|
||||
fields: readonly TeamApplyField[],
|
||||
fields: readonly TeamApplySelection[],
|
||||
): TeamToolValue[] {
|
||||
const source = teams.find((team) => team.clientId === sourceId);
|
||||
if (!source) return teams.map(cloneTeam);
|
||||
@@ -53,6 +67,19 @@ export function applyTeamFields(
|
||||
}));
|
||||
}
|
||||
if (selected.has("damage")) next.members = source.members.map(cloneMember);
|
||||
for (const field of fields) {
|
||||
const match = /^member:(\d+):(.+)$/.exec(field);
|
||||
if (!match) continue;
|
||||
const memberIndex = Number(match[1]);
|
||||
const memberField = match[2] as TeamMemberApplyField;
|
||||
const sourceMember = source.members[memberIndex];
|
||||
const targetMember = next.members[memberIndex];
|
||||
if (!sourceMember || !targetMember || !teamMemberApplyFields.includes(memberField)) continue;
|
||||
next.members[memberIndex] = {
|
||||
...targetMember,
|
||||
[memberField]: sourceMember[memberField],
|
||||
};
|
||||
}
|
||||
if (selected.has("rotation")) next.rotationSeconds = source.rotationSeconds;
|
||||
if (selected.has("combo")) next.combo = source.combo;
|
||||
return next;
|
||||
@@ -63,7 +90,7 @@ export function applyPresetFields(
|
||||
teams: readonly TeamToolValue[],
|
||||
preset: TeamPreset,
|
||||
targetIds: ReadonlySet<string>,
|
||||
fields: readonly TeamApplyField[],
|
||||
fields: readonly TeamApplySelection[],
|
||||
): TeamToolValue[] {
|
||||
return applyTeamFields(
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user