refactor(ui): rename & export actions from CL slice

This commit is contained in:
psychedelicious 2024-05-01 13:35:58 +10:00 committed by Kent Keirsey
parent 121918352a
commit 811e8a5a8b

View File

@ -114,8 +114,7 @@ export const controlLayersSlice = createSlice({
name: 'controlLayers', name: 'controlLayers',
initialState: initialControlLayersState, initialState: initialControlLayersState,
reducers: { reducers: {
//#region All Layers //#region Any Layer Type
layerSelected: (state, action: PayloadAction<string>) => { layerSelected: (state, action: PayloadAction<string>) => {
for (const layer of state.layers.filter(isRenderableLayer)) { for (const layer of state.layers.filter(isRenderableLayer)) {
if (layer.id === action.payload) { if (layer.id === action.payload) {
@ -199,13 +198,6 @@ export const controlLayersSlice = createSlice({
state.layers = state.layers.filter((l) => l.id !== state.selectedLayerId); state.layers = state.layers.filter((l) => l.id !== state.selectedLayerId);
state.selectedLayerId = state.layers[0]?.id ?? null; state.selectedLayerId = state.layers[0]?.id ?? null;
}, },
layerOpacityChanged: (state, action: PayloadAction<{ layerId: string; opacity: number }>) => {
const { layerId, opacity } = action.payload;
const layer = state.layers.filter(isControlAdapterLayer).find((l) => l.id === layerId);
if (layer) {
layer.opacity = opacity;
}
},
//#endregion //#endregion
//#region CA Layers //#region CA Layers
@ -307,10 +299,13 @@ export const controlLayersSlice = createSlice({
}, },
caLayerIsFilterEnabledChanged: (state, action: PayloadAction<{ layerId: string; isFilterEnabled: boolean }>) => { caLayerIsFilterEnabledChanged: (state, action: PayloadAction<{ layerId: string; isFilterEnabled: boolean }>) => {
const { layerId, isFilterEnabled } = action.payload; const { layerId, isFilterEnabled } = action.payload;
const layer = state.layers.filter(isControlAdapterLayer).find((l) => l.id === layerId); const layer = getCALayer(state, layerId);
if (layer) { layer.isFilterEnabled = isFilterEnabled;
layer.isFilterEnabled = isFilterEnabled; },
} caLayerOpacityChanged: (state, action: PayloadAction<{ layerId: string; opacity: number }>) => {
const { layerId, opacity } = action.payload;
const layer = getCALayer(state, layerId);
layer.opacity = opacity;
}, },
//#endregion //#endregion
@ -528,7 +523,7 @@ export const controlLayersSlice = createSlice({
}, },
//#endregion //#endregion
//#region Base Layer //#region Globals
positivePromptChanged: (state, action: PayloadAction<string>) => { positivePromptChanged: (state, action: PayloadAction<string>) => {
state.positivePrompt = action.payload; state.positivePrompt = action.payload;
}, },
@ -565,9 +560,6 @@ export const controlLayersSlice = createSlice({
aspectRatioChanged: (state, action: PayloadAction<AspectRatioState>) => { aspectRatioChanged: (state, action: PayloadAction<AspectRatioState>) => {
state.size.aspectRatio = action.payload; state.size.aspectRatio = action.payload;
}, },
//#endregion
//#region General
brushSizeChanged: (state, action: PayloadAction<number>) => { brushSizeChanged: (state, action: PayloadAction<number>) => {
state.brushSize = Math.round(action.payload); state.brushSize = Math.round(action.payload);
}, },
@ -650,36 +642,54 @@ class LayerColors {
} }
export const { export const {
// All layer actions // Any Layer Type
layerDeleted,
layerMovedBackward,
layerMovedForward,
layerMovedToBack,
layerMovedToFront,
layerReset,
layerSelected, layerSelected,
layerVisibilityToggled,
layerTranslated, layerTranslated,
layerBboxChanged, layerBboxChanged,
layerVisibilityToggled, layerReset,
layerDeleted,
layerMovedForward,
layerMovedToFront,
layerMovedBackward,
layerMovedToBack,
selectedLayerReset, selectedLayerReset,
selectedLayerDeleted, selectedLayerDeleted,
rgLayerAdded: regionalGuidanceLayerAdded, // CA Layers
ipaLayerAdded: ipAdapterLayerAdded, caLayerAdded,
caLayerAdded: controlAdapterLayerAdded, caLayerImageChanged,
layerOpacityChanged, caLayerProcessedImageChanged,
// CA layer actions caLayerModelChanged,
caLayerIsFilterEnabledChanged: isFilterEnabledChanged, caLayerWeightChanged,
// Mask layer actions caLayerBeginEndStepPctChanged,
rgLayerLineAdded: maskLayerLineAdded, caLayerControlModeChanged,
rgLayerPointsAdded: maskLayerPointsAdded, caLayerProcessorConfigChanged,
rgLayerRectAdded: maskLayerRectAdded, caLayerIsFilterEnabledChanged,
rgLayerNegativePromptChanged: maskLayerNegativePromptChanged, caLayerOpacityChanged,
rgLayerPositivePromptChanged: maskLayerPositivePromptChanged, // IPA Layers
rgLayerIPAdapterAdded: maskLayerIPAdapterAdded, ipaLayerAdded,
rgLayerIPAdapterDeleted: maskLayerIPAdapterDeleted, ipaLayerImageChanged,
rgLayerAutoNegativeChanged: maskLayerAutoNegativeChanged, ipaLayerWeightChanged,
rgLayerPreviewColorChanged: maskLayerPreviewColorChanged, ipaLayerBeginEndStepPctChanged,
// Base layer actions ipaLayerMethodChanged,
ipaLayerCLIPVisionModelChanged,
// RG Layers
rgLayerAdded,
rgLayerPositivePromptChanged,
rgLayerNegativePromptChanged,
rgLayerIPAdapterAdded,
rgLayerIPAdapterDeleted,
rgLayerPreviewColorChanged,
rgLayerLineAdded,
rgLayerPointsAdded,
rgLayerRectAdded,
rgLayerAutoNegativeChanged,
rgLayerIPAdapterImageChanged,
rgLayerIPAdapterWeightChanged,
rgLayerIPAdapterBeginEndStepPctChanged,
rgLayerIPAdapterMethodChanged,
rgLayerIPAdapterCLIPVisionModelChanged,
// Globals
positivePromptChanged, positivePromptChanged,
negativePromptChanged, negativePromptChanged,
positivePrompt2Changed, positivePrompt2Changed,
@ -688,9 +698,9 @@ export const {
widthChanged, widthChanged,
heightChanged, heightChanged,
aspectRatioChanged, aspectRatioChanged,
// General actions
brushSizeChanged, brushSizeChanged,
globalMaskLayerOpacityChanged, globalMaskLayerOpacityChanged,
isEnabledChanged,
undo, undo,
redo, redo,
} = controlLayersSlice.actions; } = controlLayersSlice.actions;
@ -750,9 +760,13 @@ const undoableGroupByMatcher = isAnyOf(
layerTranslated, layerTranslated,
brushSizeChanged, brushSizeChanged,
globalMaskLayerOpacityChanged, globalMaskLayerOpacityChanged,
maskLayerPositivePromptChanged, positivePromptChanged,
maskLayerNegativePromptChanged, negativePromptChanged,
maskLayerPreviewColorChanged positivePrompt2Changed,
negativePrompt2Changed,
rgLayerPositivePromptChanged,
rgLayerNegativePromptChanged,
rgLayerPreviewColorChanged
); );
// These are used to group actions into logical lines below (hate typos) // These are used to group actions into logical lines below (hate typos)
@ -764,13 +778,13 @@ export const controlLayersUndoableConfig: UndoableOptions<ControlLayersState, Un
undoType: controlLayersSlice.actions.undo.type, undoType: controlLayersSlice.actions.undo.type,
redoType: controlLayersSlice.actions.redo.type, redoType: controlLayersSlice.actions.redo.type,
groupBy: (action, state, history) => { groupBy: (action, state, history) => {
// Lines are started with `maskLayerLineAdded` and may have any number of subsequent `maskLayerPointsAdded` events. // Lines are started with `rgLayerLineAdded` and may have any number of subsequent `rgLayerPointsAdded` events.
// We can use a double-buffer-esque trick to group each "logical" line as a single undoable action, without grouping // We can use a double-buffer-esque trick to group each "logical" line as a single undoable action, without grouping
// separate logical lines as a single undo action. // separate logical lines as a single undo action.
if (maskLayerLineAdded.match(action)) { if (rgLayerLineAdded.match(action)) {
return history.group === LINE_1 ? LINE_2 : LINE_1; return history.group === LINE_1 ? LINE_2 : LINE_1;
} }
if (maskLayerPointsAdded.match(action)) { if (rgLayerPointsAdded.match(action)) {
if (history.group === LINE_1 || history.group === LINE_2) { if (history.group === LINE_1 || history.group === LINE_2) {
return history.group; return history.group;
} }