feat : update mutilple apply
This commit is contained in:
@@ -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