tidy(ui): CanvasInitialImage

This commit is contained in:
psychedelicious 2024-07-17 14:35:02 +10:00
parent d7f1c30624
commit 0b7751c413

View File

@ -9,10 +9,9 @@ export class CanvasInitialImage {
static GROUP_NAME = `${CanvasInitialImage.NAME_PREFIX}_group`; static GROUP_NAME = `${CanvasInitialImage.NAME_PREFIX}_group`;
static OBJECT_GROUP_NAME = `${CanvasInitialImage.NAME_PREFIX}_object-group`; static OBJECT_GROUP_NAME = `${CanvasInitialImage.NAME_PREFIX}_object-group`;
private state: InitialImageEntity;
id = 'initial_image'; id = 'initial_image';
private initialImageState: InitialImageEntity;
manager: CanvasManager; manager: CanvasManager;
konva: { konva: {
@ -23,7 +22,7 @@ export class CanvasInitialImage {
image: CanvasImage | null; image: CanvasImage | null;
constructor(initialImageState: InitialImageEntity, manager: CanvasManager) { constructor(state: InitialImageEntity, manager: CanvasManager) {
this.manager = manager; this.manager = manager;
this.konva = { this.konva = {
layer: new Konva.Layer({ name: CanvasInitialImage.LAYER_NAME, imageSmoothingEnabled: true, listening: false }), layer: new Konva.Layer({ name: CanvasInitialImage.LAYER_NAME, imageSmoothingEnabled: true, listening: false }),
@ -34,26 +33,26 @@ export class CanvasInitialImage {
this.konva.layer.add(this.konva.group); this.konva.layer.add(this.konva.group);
this.image = null; this.image = null;
this.initialImageState = initialImageState; this.state = state;
} }
async render(initialImageState: InitialImageEntity) { async render(state: InitialImageEntity) {
this.initialImageState = initialImageState; this.state = state;
if (!this.initialImageState.imageObject) { if (!this.state.imageObject) {
this.konva.layer.visible(false); this.konva.layer.visible(false);
return; return;
} }
if (!this.image) { if (!this.image) {
this.image = new CanvasImage(this.initialImageState.imageObject); this.image = new CanvasImage(this.state.imageObject);
this.konva.objectGroup.add(this.image.konva.group); this.konva.objectGroup.add(this.image.konva.group);
await this.image.update(this.initialImageState.imageObject, true); await this.image.update(this.state.imageObject, true);
} else if (!this.image.isLoading && !this.image.isError) { } else if (!this.image.isLoading && !this.image.isError) {
await this.image.update(this.initialImageState.imageObject); await this.image.update(this.state.imageObject);
} }
if (this.initialImageState && this.initialImageState.isEnabled && !this.image?.isLoading && !this.image?.isError) { if (this.state && this.state.isEnabled && !this.image?.isLoading && !this.image?.isError) {
this.konva.layer.visible(true); this.konva.layer.visible(true);
} else { } else {
this.konva.layer.visible(false); this.konva.layer.visible(false);