mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
tidy(ui): isRegionalPromptLayer
-> isRPLayer
This commit is contained in:
parent
eb781272f7
commit
9b5c47748d
@ -11,7 +11,7 @@ import {
|
||||
PROMPT_REGION_POSITIVE_COND_INVERTED_PREFIX,
|
||||
PROMPT_REGION_POSITIVE_COND_PREFIX,
|
||||
} from 'features/nodes/util/graph/constants';
|
||||
import { isRegionalPromptLayer } from 'features/regionalPrompts/store/regionalPromptsSlice';
|
||||
import { isRPLayer } from 'features/regionalPrompts/store/regionalPromptsSlice';
|
||||
import { getRegionalPromptLayerBlobs } from 'features/regionalPrompts/util/getLayerBlobs';
|
||||
import { size } from 'lodash-es';
|
||||
import { imagesApi } from 'services/api/endpoints/images';
|
||||
@ -23,7 +23,7 @@ export const addRegionalPromptsToGraph = async (state: RootState, graph: NonNull
|
||||
// TODO: Handle non-SDXL
|
||||
// const isSDXL = state.generation.model?.base === 'sdxl';
|
||||
const layers = state.regionalPrompts.present.layers
|
||||
.filter(isRegionalPromptLayer) // We only want the prompt region layers
|
||||
.filter(isRPLayer) // We only want the prompt region layers
|
||||
.filter((l) => l.isVisible) // Only visible layers are rendered on the canvas
|
||||
.filter((l) => l.negativePrompt || l.positivePrompt); // Only layers with prompts get added to the graph
|
||||
|
||||
|
@ -4,7 +4,7 @@ import { createSelector } from '@reduxjs/toolkit';
|
||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||
import { isParameterAutoNegative } from 'features/parameters/types/parameterSchemas';
|
||||
import {
|
||||
isRegionalPromptLayer,
|
||||
isRPLayer,
|
||||
rpLayerAutoNegativeChanged,
|
||||
selectRegionalPromptsSlice,
|
||||
} from 'features/regionalPrompts/store/regionalPromptsSlice';
|
||||
@ -26,7 +26,7 @@ const useAutoNegative = (layerId: string) => {
|
||||
() =>
|
||||
createSelector(selectRegionalPromptsSlice, (regionalPrompts) => {
|
||||
const layer = regionalPrompts.present.layers.find((l) => l.id === layerId);
|
||||
assert(isRegionalPromptLayer(layer), `Layer ${layerId} not found or not an RP layer`);
|
||||
assert(isRPLayer(layer), `Layer ${layerId} not found or not an RP layer`);
|
||||
return layer.autoNegative;
|
||||
}),
|
||||
[layerId]
|
||||
|
@ -3,7 +3,7 @@ import { createMemoizedSelector } from 'app/store/createMemoizedSelector';
|
||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||
import RgbColorPicker from 'common/components/RgbColorPicker';
|
||||
import {
|
||||
isRegionalPromptLayer,
|
||||
isRPLayer,
|
||||
rpLayerColorChanged,
|
||||
selectRegionalPromptsSlice,
|
||||
} from 'features/regionalPrompts/store/regionalPromptsSlice';
|
||||
@ -21,7 +21,7 @@ export const RPLayerColorPicker = memo(({ layerId }: Props) => {
|
||||
() =>
|
||||
createMemoizedSelector(selectRegionalPromptsSlice, (regionalPrompts) => {
|
||||
const layer = regionalPrompts.present.layers.find((l) => l.id === layerId);
|
||||
assert(isRegionalPromptLayer(layer), `Layer ${layerId} not found or not an RP layer`);
|
||||
assert(isRPLayer(layer), `Layer ${layerId} not found or not an RP layer`);
|
||||
return layer.color;
|
||||
}),
|
||||
[layerId]
|
||||
|
@ -7,7 +7,7 @@ import { RPLayerMenu } from 'features/regionalPrompts/components/RPLayerMenu';
|
||||
import { RPLayerNegativePrompt } from 'features/regionalPrompts/components/RPLayerNegativePrompt';
|
||||
import { RPLayerPositivePrompt } from 'features/regionalPrompts/components/RPLayerPositivePrompt';
|
||||
import { RPLayerVisibilityToggle } from 'features/regionalPrompts/components/RPLayerVisibilityToggle';
|
||||
import { isRegionalPromptLayer, rpLayerSelected } from 'features/regionalPrompts/store/regionalPromptsSlice';
|
||||
import { isRPLayer, rpLayerSelected } from 'features/regionalPrompts/store/regionalPromptsSlice';
|
||||
import { memo, useCallback } from 'react';
|
||||
import { assert } from 'tsafe';
|
||||
|
||||
@ -20,7 +20,7 @@ export const RPLayerListItem = memo(({ layerId }: Props) => {
|
||||
const selectedLayer = useAppSelector((s) => s.regionalPrompts.present.selectedLayer);
|
||||
const color = useAppSelector((s) => {
|
||||
const layer = s.regionalPrompts.present.layers.find((l) => l.id === layerId);
|
||||
assert(isRegionalPromptLayer(layer), `Layer ${layerId} not found or not an RP layer`);
|
||||
assert(isRPLayer(layer), `Layer ${layerId} not found or not an RP layer`);
|
||||
return rgbaColorToString({ ...layer.color, a: selectedLayer === layerId ? 1 : 0.35 });
|
||||
});
|
||||
const onClickCapture = useCallback(() => {
|
||||
|
@ -2,7 +2,7 @@ import { IconButton, Menu, MenuButton, MenuDivider, MenuItem, MenuList } from '@
|
||||
import { createMemoizedSelector } from 'app/store/createMemoizedSelector';
|
||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||
import {
|
||||
isRegionalPromptLayer,
|
||||
isRPLayer,
|
||||
layerDeleted,
|
||||
layerMovedBackward,
|
||||
layerMovedForward,
|
||||
@ -33,7 +33,7 @@ export const RPLayerMenu = memo(({ layerId }: Props) => {
|
||||
() =>
|
||||
createMemoizedSelector(selectRegionalPromptsSlice, (regionalPrompts) => {
|
||||
const layer = regionalPrompts.present.layers.find((l) => l.id === layerId);
|
||||
assert(isRegionalPromptLayer(layer), `Layer ${layerId} not found or not an RP layer`);
|
||||
assert(isRPLayer(layer), `Layer ${layerId} not found or not an RP layer`);
|
||||
const layerIndex = regionalPrompts.present.layers.findIndex((l) => l.id === layerId);
|
||||
const layerCount = regionalPrompts.present.layers.length;
|
||||
return {
|
||||
|
@ -10,13 +10,13 @@ import { RPLayerListItem } from 'features/regionalPrompts/components/RPLayerList
|
||||
import { StageComponent } from 'features/regionalPrompts/components/StageComponent';
|
||||
import { ToolChooser } from 'features/regionalPrompts/components/ToolChooser';
|
||||
import { UndoRedoButtonGroup } from 'features/regionalPrompts/components/UndoRedoButtonGroup';
|
||||
import { isRegionalPromptLayer, selectRegionalPromptsSlice } from 'features/regionalPrompts/store/regionalPromptsSlice';
|
||||
import { isRPLayer, selectRegionalPromptsSlice } from 'features/regionalPrompts/store/regionalPromptsSlice';
|
||||
import { getRegionalPromptLayerBlobs } from 'features/regionalPrompts/util/getLayerBlobs';
|
||||
import { memo } from 'react';
|
||||
|
||||
const selectRPLayerIdsReversed = createMemoizedSelector(selectRegionalPromptsSlice, (regionalPrompts) =>
|
||||
regionalPrompts.present.layers
|
||||
.filter(isRegionalPromptLayer)
|
||||
.filter(isRPLayer)
|
||||
.map((l) => l.id)
|
||||
.reverse()
|
||||
);
|
||||
|
@ -6,7 +6,7 @@ import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||
import { useMouseEvents } from 'features/regionalPrompts/hooks/mouseEventHooks';
|
||||
import {
|
||||
$cursorPosition,
|
||||
isRegionalPromptLayer,
|
||||
isRPLayer,
|
||||
rpLayerBboxChanged,
|
||||
rpLayerTranslated,
|
||||
selectRegionalPromptsSlice,
|
||||
@ -25,7 +25,7 @@ const selectSelectedLayerColor = createMemoizedSelector(selectRegionalPromptsSli
|
||||
if (!layer) {
|
||||
return null;
|
||||
}
|
||||
assert(isRegionalPromptLayer(layer), `Layer ${regionalPrompts.present.selectedLayer} is not an RP layer`);
|
||||
assert(isRPLayer(layer), `Layer ${regionalPrompts.present.selectedLayer} is not an RP layer`);
|
||||
return layer.color;
|
||||
});
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
import { useAppSelector } from 'app/store/storeHooks';
|
||||
import { isRegionalPromptLayer, selectRegionalPromptsSlice } from 'features/regionalPrompts/store/regionalPromptsSlice';
|
||||
import { isRPLayer, selectRegionalPromptsSlice } from 'features/regionalPrompts/store/regionalPromptsSlice';
|
||||
import { useMemo } from 'react';
|
||||
import { assert } from 'tsafe';
|
||||
|
||||
@ -9,7 +9,7 @@ export const useLayerPositivePrompt = (layerId: string) => {
|
||||
() =>
|
||||
createSelector(selectRegionalPromptsSlice, (regionalPrompts) => {
|
||||
const layer = regionalPrompts.present.layers.find((l) => l.id === layerId);
|
||||
assert(isRegionalPromptLayer(layer), `Layer ${layerId} not found or not an RP layer`);
|
||||
assert(isRPLayer(layer), `Layer ${layerId} not found or not an RP layer`);
|
||||
return layer.positivePrompt;
|
||||
}),
|
||||
[layerId]
|
||||
@ -23,7 +23,7 @@ export const useLayerNegativePrompt = (layerId: string) => {
|
||||
() =>
|
||||
createSelector(selectRegionalPromptsSlice, (regionalPrompts) => {
|
||||
const layer = regionalPrompts.present.layers.find((l) => l.id === layerId);
|
||||
assert(isRegionalPromptLayer(layer), `Layer ${layerId} not found or not an RP layer`);
|
||||
assert(isRPLayer(layer), `Layer ${layerId} not found or not an RP layer`);
|
||||
return layer.negativePrompt;
|
||||
}),
|
||||
[layerId]
|
||||
@ -37,7 +37,7 @@ export const useLayerIsVisible = (layerId: string) => {
|
||||
() =>
|
||||
createSelector(selectRegionalPromptsSlice, (regionalPrompts) => {
|
||||
const layer = regionalPrompts.present.layers.find((l) => l.id === layerId);
|
||||
assert(isRegionalPromptLayer(layer), `Layer ${layerId} not found or not an RP layer`);
|
||||
assert(isRPLayer(layer), `Layer ${layerId} not found or not an RP layer`);
|
||||
return layer.isVisible;
|
||||
}),
|
||||
[layerId]
|
||||
|
@ -80,7 +80,7 @@ export const initialRegionalPromptsState: RegionalPromptsState = {
|
||||
};
|
||||
|
||||
const isLine = (obj: LayerObject): obj is LineObject => obj.kind === 'line';
|
||||
export const isRegionalPromptLayer = (layer?: Layer): layer is RegionalPromptLayer =>
|
||||
export const isRPLayer = (layer?: Layer): layer is RegionalPromptLayer =>
|
||||
layer?.kind === 'regionalPromptLayer';
|
||||
|
||||
export const regionalPromptsSlice = createSlice({
|
||||
@ -137,19 +137,19 @@ export const regionalPromptsSlice = createSlice({
|
||||
//#region RP Layers
|
||||
rpLayerSelected: (state, action: PayloadAction<string>) => {
|
||||
const layer = state.layers.find((l) => l.id === action.payload);
|
||||
if (isRegionalPromptLayer(layer)) {
|
||||
if (isRPLayer(layer)) {
|
||||
state.selectedLayer = layer.id;
|
||||
}
|
||||
},
|
||||
rpLayerIsVisibleToggled: (state, action: PayloadAction<string>) => {
|
||||
const layer = state.layers.find((l) => l.id === action.payload);
|
||||
if (isRegionalPromptLayer(layer)) {
|
||||
if (isRPLayer(layer)) {
|
||||
layer.isVisible = !layer.isVisible;
|
||||
}
|
||||
},
|
||||
rpLayerReset: (state, action: PayloadAction<string>) => {
|
||||
const layer = state.layers.find((l) => l.id === action.payload);
|
||||
if (isRegionalPromptLayer(layer)) {
|
||||
if (isRPLayer(layer)) {
|
||||
layer.objects = [];
|
||||
layer.bbox = null;
|
||||
layer.isVisible = true;
|
||||
@ -158,7 +158,7 @@ export const regionalPromptsSlice = createSlice({
|
||||
rpLayerTranslated: (state, action: PayloadAction<{ layerId: string; x: number; y: number }>) => {
|
||||
const { layerId, x, y } = action.payload;
|
||||
const layer = state.layers.find((l) => l.id === layerId);
|
||||
if (isRegionalPromptLayer(layer)) {
|
||||
if (isRPLayer(layer)) {
|
||||
layer.x = x;
|
||||
layer.y = y;
|
||||
}
|
||||
@ -166,7 +166,7 @@ export const regionalPromptsSlice = createSlice({
|
||||
rpLayerBboxChanged: (state, action: PayloadAction<{ layerId: string; bbox: IRect | null }>) => {
|
||||
const { layerId, bbox } = action.payload;
|
||||
const layer = state.layers.find((l) => l.id === layerId);
|
||||
if (isRegionalPromptLayer(layer)) {
|
||||
if (isRPLayer(layer)) {
|
||||
layer.bbox = bbox;
|
||||
}
|
||||
},
|
||||
@ -177,28 +177,28 @@ export const regionalPromptsSlice = createSlice({
|
||||
rpLayerPositivePromptChanged: (state, action: PayloadAction<{ layerId: string; prompt: string }>) => {
|
||||
const { layerId, prompt } = action.payload;
|
||||
const layer = state.layers.find((l) => l.id === layerId);
|
||||
if (isRegionalPromptLayer(layer)) {
|
||||
if (isRPLayer(layer)) {
|
||||
layer.positivePrompt = prompt;
|
||||
}
|
||||
},
|
||||
rpLayerNegativePromptChanged: (state, action: PayloadAction<{ layerId: string; prompt: string }>) => {
|
||||
const { layerId, prompt } = action.payload;
|
||||
const layer = state.layers.find((l) => l.id === layerId);
|
||||
if (isRegionalPromptLayer(layer)) {
|
||||
if (isRPLayer(layer)) {
|
||||
layer.negativePrompt = prompt;
|
||||
}
|
||||
},
|
||||
rpLayerColorChanged: (state, action: PayloadAction<{ layerId: string; color: RgbColor }>) => {
|
||||
const { layerId, color } = action.payload;
|
||||
const layer = state.layers.find((l) => l.id === layerId);
|
||||
if (isRegionalPromptLayer(layer)) {
|
||||
if (isRPLayer(layer)) {
|
||||
layer.color = color;
|
||||
}
|
||||
},
|
||||
rpLayerLineAdded: {
|
||||
reducer: (state, action: PayloadAction<[number, number, number, number], string, { uuid: string }>) => {
|
||||
const layer = state.layers.find((l) => l.id === state.selectedLayer);
|
||||
if (isRegionalPromptLayer(layer)) {
|
||||
if (isRPLayer(layer)) {
|
||||
const lineId = getRPLayerLineId(layer.id, action.meta.uuid);
|
||||
layer.objects.push({
|
||||
kind: 'line',
|
||||
@ -218,7 +218,7 @@ export const regionalPromptsSlice = createSlice({
|
||||
},
|
||||
rpLayerPointsAdded: (state, action: PayloadAction<[number, number]>) => {
|
||||
const layer = state.layers.find((l) => l.id === state.selectedLayer);
|
||||
if (isRegionalPromptLayer(layer)) {
|
||||
if (isRPLayer(layer)) {
|
||||
const lastLine = layer.objects.findLast(isLine);
|
||||
if (!lastLine) {
|
||||
return;
|
||||
@ -232,7 +232,7 @@ export const regionalPromptsSlice = createSlice({
|
||||
) => {
|
||||
const { layerId, autoNegative } = action.payload;
|
||||
const layer = state.layers.find((l) => l.id === layerId);
|
||||
if (isRegionalPromptLayer(layer)) {
|
||||
if (isRPLayer(layer)) {
|
||||
layer.autoNegative = autoNegative;
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user