tidy(ui): regional prompts kind -> type

This commit is contained in:
psychedelicious
2024-04-21 10:19:54 +10:00
parent 8c0a061fa0
commit 018845cda0
2 changed files with 12 additions and 12 deletions

View File

@ -17,7 +17,7 @@ export type Tool = DrawingTool | 'move' | 'rect';
type VectorMaskLine = { type VectorMaskLine = {
id: string; id: string;
kind: 'vector_mask_line'; type: 'vector_mask_line';
tool: DrawingTool; tool: DrawingTool;
strokeWidth: number; strokeWidth: number;
points: number[]; points: number[];
@ -25,7 +25,7 @@ type VectorMaskLine = {
type VectorMaskRect = { type VectorMaskRect = {
id: string; id: string;
kind: 'vector_mask_rect'; type: 'vector_mask_rect';
x: number; x: number;
y: number; y: number;
width: number; width: number;
@ -59,7 +59,7 @@ type MaskLayerBase = LayerBase & {
}; };
export type VectorMaskLayer = MaskLayerBase & { export type VectorMaskLayer = MaskLayerBase & {
kind: 'vector_mask_layer'; type: 'vector_mask_layer';
objects: (VectorMaskLine | VectorMaskRect)[]; objects: (VectorMaskLine | VectorMaskRect)[];
}; };
@ -85,8 +85,8 @@ export const initialRegionalPromptsState: RegionalPromptsState = {
isEnabled: false, isEnabled: false,
}; };
const isLine = (obj: VectorMaskLine | VectorMaskRect): obj is VectorMaskLine => obj.kind === 'vector_mask_line'; const isLine = (obj: VectorMaskLine | VectorMaskRect): obj is VectorMaskLine => obj.type === 'vector_mask_line';
export const isVectorMaskLayer = (layer?: Layer): layer is VectorMaskLayer => layer?.kind === 'vector_mask_layer'; export const isVectorMaskLayer = (layer?: Layer): layer is VectorMaskLayer => layer?.type === 'vector_mask_layer';
export const regionalPromptsSlice = createSlice({ export const regionalPromptsSlice = createSlice({
name: 'regionalPrompts', name: 'regionalPrompts',
@ -94,14 +94,14 @@ export const regionalPromptsSlice = createSlice({
reducers: { reducers: {
//#region All Layers //#region All Layers
layerAdded: { layerAdded: {
reducer: (state, action: PayloadAction<Layer['kind'], string, { uuid: string }>) => { reducer: (state, action: PayloadAction<Layer['type'], string, { uuid: string }>) => {
const kind = action.payload; const kind = action.payload;
if (action.payload === 'vector_mask_layer') { if (action.payload === 'vector_mask_layer') {
const lastColor = state.layers[state.layers.length - 1]?.previewColor; const lastColor = state.layers[state.layers.length - 1]?.previewColor;
const color = LayerColors.next(lastColor); const color = LayerColors.next(lastColor);
const layer: VectorMaskLayer = { const layer: VectorMaskLayer = {
id: getVectorMaskLayerId(action.meta.uuid), id: getVectorMaskLayerId(action.meta.uuid),
kind, type: kind,
isVisible: true, isVisible: true,
bbox: null, bbox: null,
bboxNeedsUpdate: false, bboxNeedsUpdate: false,
@ -122,7 +122,7 @@ export const regionalPromptsSlice = createSlice({
return; return;
} }
}, },
prepare: (payload: Layer['kind']) => ({ payload, meta: { uuid: uuidv4() } }), prepare: (payload: Layer['type']) => ({ payload, meta: { uuid: uuidv4() } }),
}, },
layerSelected: (state, action: PayloadAction<string>) => { layerSelected: (state, action: PayloadAction<string>) => {
const layer = state.layers.find((l) => l.id === action.payload); const layer = state.layers.find((l) => l.id === action.payload);
@ -226,7 +226,7 @@ export const regionalPromptsSlice = createSlice({
if (layer) { if (layer) {
const lineId = getVectorMaskLayerLineId(layer.id, action.meta.uuid); const lineId = getVectorMaskLayerLineId(layer.id, action.meta.uuid);
layer.objects.push({ layer.objects.push({
kind: 'vector_mask_line', type: 'vector_mask_line',
tool: tool, tool: tool,
id: lineId, id: lineId,
// Points must be offset by the layer's x and y coordinates // Points must be offset by the layer's x and y coordinates
@ -270,7 +270,7 @@ export const regionalPromptsSlice = createSlice({
if (layer) { if (layer) {
const id = getVectorMaskLayerRectId(layer.id, action.meta.uuid); const id = getVectorMaskLayerRectId(layer.id, action.meta.uuid);
layer.objects.push({ layer.objects.push({
kind: 'vector_mask_rect', type: 'vector_mask_rect',
id, id,
x: rect.x - layer.x, x: rect.x - layer.x,
y: rect.y - layer.y, y: rect.y - layer.y,

View File

@ -282,7 +282,7 @@ const renderVectorMaskLayer = (
} }
for (const reduxObject of vmLayer.objects) { for (const reduxObject of vmLayer.objects) {
if (reduxObject.kind === 'vector_mask_line') { if (reduxObject.type === 'vector_mask_line') {
let vectorMaskLine = stage.findOne<Konva.Line>(`#${reduxObject.id}`); let vectorMaskLine = stage.findOne<Konva.Line>(`#${reduxObject.id}`);
// Create the line if it doesn't exist // Create the line if it doesn't exist
@ -313,7 +313,7 @@ const renderVectorMaskLayer = (
vectorMaskLine.stroke(rgbColor); vectorMaskLine.stroke(rgbColor);
groupNeedsCache = true; groupNeedsCache = true;
} }
} else if (reduxObject.kind === 'vector_mask_rect') { } else if (reduxObject.type === 'vector_mask_rect') {
let konvaObject = stage.findOne<Konva.Rect>(`#${reduxObject.id}`); let konvaObject = stage.findOne<Konva.Rect>(`#${reduxObject.id}`);
if (!konvaObject) { if (!konvaObject) {
konvaObject = new Konva.Rect({ konvaObject = new Konva.Rect({