Refactor sequence effect handling for setVisibility

This commit is contained in:
2026-04-15 01:40:41 +02:00
parent d8161e8695
commit 9f5daa8b8a

View File

@@ -3564,19 +3564,69 @@ function readProjectSequenceEffect(value: unknown, label: string): SequenceClip
) )
}; };
case "toggleVisibility": case "toggleVisibility":
case "setVisibility": {
const isLegacyToggle = value.type === "toggleVisibility";
if (stepClass !== "impulse") { if (stepClass !== "impulse") {
throw new Error(`${label}.toggleVisibility effects must use the impulse class.`); throw new Error(`${label}.${String(value.type)} effects must use the impulse class.`);
}
if (isLegacyToggle) {
const visible =
value.visible === undefined
? undefined
: expectBoolean(value.visible, `${label}.visible`);
return {
stepClass: "impulse",
type: "setVisibility",
target: {
kind: "brush",
brushId: expectString(value.targetBrushId, `${label}.targetBrushId`)
},
mode:
visible === undefined ? "toggle" : visible ? "show" : "hide"
};
}
if (!isRecord(value.target)) {
throw new Error(`${label}.target must be an object.`);
}
const targetKind = expectString(value.target.kind, `${label}.target.kind`);
if (targetKind !== "brush" && targetKind !== "modelInstance") {
throw new Error(`${label}.target.kind must be brush or modelInstance.`);
}
const mode = expectString(value.mode, `${label}.mode`);
if (mode !== "toggle" && mode !== "show" && mode !== "hide") {
throw new Error(`${label}.mode must be toggle, show, or hide.`);
} }
return { return {
stepClass: "impulse", stepClass: "impulse",
type: "toggleVisibility", type: "setVisibility",
targetBrushId: expectString(value.targetBrushId, `${label}.targetBrushId`), target:
visible: targetKind === "brush"
value.visible === undefined ? {
? undefined kind: "brush",
: expectBoolean(value.visible, `${label}.visible`) brushId: expectString(
value.target.brushId,
`${label}.target.brushId`
)
}
: {
kind: "modelInstance",
modelInstanceId: expectString(
value.target.modelInstanceId,
`${label}.target.modelInstanceId`
)
},
mode
}; };
}
default: default:
throw new Error(`${label}.type must be a supported sequence effect.`); throw new Error(`${label}.type must be a supported sequence effect.`);
} }