feat(ui): node manager getter/setter

This commit is contained in:
psychedelicious 2024-06-24 11:11:20 +10:00
parent e9204b87e3
commit 59f57ff542
3 changed files with 15 additions and 9 deletions

View File

@ -1,12 +1,11 @@
import { enqueueRequested } from 'app/store/actions';
import type { AppStartListening } from 'app/store/middleware/listenerMiddleware';
import { $nodeManager } from 'features/controlLayers/konva/renderers/renderer';
import { getNodeManager } from 'features/controlLayers/konva/nodeManager';
import { isImageViewerOpenChanged } from 'features/gallery/store/gallerySlice';
import { prepareLinearUIBatch } from 'features/nodes/util/graph/buildLinearBatchConfig';
import { buildGenerationTabGraph } from 'features/nodes/util/graph/generation/buildGenerationTabGraph';
import { buildGenerationTabSDXLGraph } from 'features/nodes/util/graph/generation/buildGenerationTabSDXLGraph';
import { queueApi } from 'services/api/endpoints/queue';
import { assert } from 'tsafe';
export const addEnqueueRequestedLinear = (startAppListening: AppStartListening) => {
startAppListening({
@ -20,8 +19,7 @@ export const addEnqueueRequestedLinear = (startAppListening: AppStartListening)
let graph;
const manager = $nodeManager.get();
assert(manager, 'Konva node manager not initialized');
const manager = getNodeManager();
console.log('generation mode', manager.util.getGenerationMode());

View File

@ -21,6 +21,7 @@ import type {
import { isValidLayer } from 'features/nodes/util/graph/generation/addLayers';
import type Konva from 'konva';
import type { Vector2d } from 'konva/lib/types';
import { atom } from 'nanostores';
import { getImageDTO as defaultGetImageDTO, uploadImage as defaultUploadImage } from 'services/api/endpoints/images';
import type { ImageCategory, ImageDTO } from 'services/api/types';
import { assert } from 'tsafe';
@ -466,3 +467,13 @@ export class KonvaEntityAdapter {
return this.objectRecords.delete(id);
}
}
const $nodeManager = atom<KonvaNodeManager | null>(null);
export const setNodeManager = (manager: KonvaNodeManager) => {
$nodeManager.set(manager);
};
export const getNodeManager = () => {
const nodeManager = $nodeManager.get();
assert(nodeManager, 'Konva node manager not initialized');
return nodeManager;
};

View File

@ -4,7 +4,7 @@ import { logger } from 'app/logging/logger';
import { $isDebugging } from 'app/store/nanostores/isDebugging';
import type { RootState } from 'app/store/store';
import { setStageEventHandlers } from 'features/controlLayers/konva/events';
import { KonvaNodeManager } from 'features/controlLayers/konva/nodeManager';
import { KonvaNodeManager, setNodeManager } from 'features/controlLayers/konva/nodeManager';
import { getArrangeEntities } from 'features/controlLayers/konva/renderers/arrange';
import { createBackgroundLayer, getRenderBackground } from 'features/controlLayers/konva/renderers/background';
import { updateBboxes } from 'features/controlLayers/konva/renderers/bbox';
@ -66,12 +66,9 @@ import type {
import type Konva from 'konva';
import type { IRect, Vector2d } from 'konva/lib/types';
import { debounce } from 'lodash-es';
import { atom } from 'nanostores';
import type { RgbaColor } from 'react-colorful';
import type { ImageDTO } from 'services/api/types';
export const $nodeManager = atom<KonvaNodeManager | null>(null);
/**
* Initializes the canvas renderer. It subscribes to the redux store and listens for changes directly, bypassing the
* react rendering cycle entirely, improving canvas performance.
@ -301,7 +298,7 @@ export const initializeRenderer = (
};
const manager = new KonvaNodeManager(stage, container);
$nodeManager.set(manager);
setNodeManager(manager);
manager.background = { layer: createBackgroundLayer() };
manager.stage.add(manager.background.layer);